Whamcloud - gitweb
LU-5916 lod: inherit default pool setting properly
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 4; 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 SRCDIR=$(cd $(dirname $0); echo $PWD)
20 export PATH=$PATH:/sbin
21
22 TMP=${TMP:-/tmp}
23
24 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
25 CREATETEST=${CREATETEST:-createtest}
26 LFS=${LFS:-lfs}
27 LFIND=${LFIND:-"$LFS find"}
28 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
29 LCTL=${LCTL:-lctl}
30 MCREATE=${MCREATE:-mcreate}
31 OPENFILE=${OPENFILE:-openfile}
32 OPENUNLINK=${OPENUNLINK:-openunlink}
33 export MULTIOP=${MULTIOP:-multiop}
34 READS=${READS:-"reads"}
35 MUNLINK=${MUNLINK:-munlink}
36 SOCKETSERVER=${SOCKETSERVER:-socketserver}
37 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
38 MEMHOG=${MEMHOG:-memhog}
39 DIRECTIO=${DIRECTIO:-directio}
40 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
41 UMOUNT=${UMOUNT:-"umount -d"}
42 STRIPES_PER_OBJ=-1
43 CHECK_GRANT=${CHECK_GRANT:-"yes"}
44 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
45 export PARALLEL=${PARALLEL:-"no"}
46
47 export NAME=${NAME:-local}
48
49 SAVE_PWD=$PWD
50
51 CLEANUP=${CLEANUP:-:}
52 SETUP=${SETUP:-:}
53 TRACE=${TRACE:-""}
54 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
55 . $LUSTRE/tests/test-framework.sh
56 init_test_env $@
57 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
58 init_logging
59
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 64b 68 71 77f 78 115 124b"
61
62 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
63 # bug number for skipped test:        LU-1593 LU-2610 LU-2833 LU-1957 LU-2805
64         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h     40      48a     180     184c"
65
66 FAIL_ON_ERROR=false
67
68 cleanup() {
69         echo -n "cln.."
70         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
71         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
72 }
73 setup() {
74         echo -n "mnt.."
75         load_modules
76         setupall || exit 10
77         echo "done"
78 }
79
80 check_kernel_version() {
81         WANT_VER=$1
82         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
83         case $GOT_VER in
84         patchless|patchless_client) return 0;;
85         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
86         esac
87         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
88         return 1
89 }
90
91 check_swap_layouts_support()
92 {
93         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
94                 { skip "Does not support layout lock."; return 0; }
95         return 1
96 }
97
98 if [ "$ONLY" == "cleanup" ]; then
99        sh llmountcleanup.sh
100        exit 0
101 fi
102
103 check_and_setup_lustre
104
105 DIR=${DIR:-$MOUNT}
106 assert_DIR
107
108 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
109         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
110 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
111 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
112 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
113 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
114 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
115 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
116
117 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
118 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
119 rm -rf $DIR/[Rdfs][0-9]*
120
121 # $RUNAS_ID may get set incorrectly somewhere else
122 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
123
124 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
125
126 build_test_filter
127
128 if [ "${ONLY}" = "MOUNT" ] ; then
129         echo "Lustre is up, please go on"
130         exit
131 fi
132
133 echo "preparing for tests involving mounts"
134 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
135 touch $EXT2_DEV
136 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
137 echo # add a newline after mke2fs.
138
139 umask 077
140
141 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
142 lctl set_param debug=-1 2> /dev/null || true
143 test_0a() {
144         touch $DIR/$tfile
145         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
146         rm $DIR/$tfile
147         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
148 }
149 run_test 0a "touch; rm ====================="
150
151 test_0b() {
152         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
153         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
154 }
155 run_test 0b "chmod 0755 $DIR ============================="
156
157 test_0c() {
158         $LCTL get_param mdc.*.import | grep "state: FULL" ||
159                 error "import not FULL"
160         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
161                 error "bad target"
162 }
163 run_test 0c "check import proc ============================="
164
165 test_1() {
166         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
167         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
168         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
169         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
170         rmdir $DIR/$tdir/d2
171         rmdir $DIR/$tdir
172         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
173 }
174 run_test 1 "mkdir; remkdir; rmdir =============================="
175
176 test_2() {
177         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
178         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
179         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
180         rm -r $DIR/$tdir
181         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
182 }
183 run_test 2 "mkdir; touch; rmdir; check file ===================="
184
185 test_3() {
186         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
187         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
188         touch $DIR/$tdir/$tfile
189         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
190         rm -r $DIR/$tdir
191         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
192 }
193 run_test 3 "mkdir; touch; rmdir; check dir ====================="
194
195 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
196 test_4() {
197         local MDTIDX=1
198
199         [ $MDSCOUNT -ge 2 ] && skip "skip now for LU-4690" && return #LU-4690
200         test_mkdir $DIR/$tdir ||
201                 error "Create remote directory failed"
202
203         touch $DIR/$tdir/$tfile ||
204                 error "Create file under remote directory failed"
205
206         rmdir $DIR/$tdir &&
207                 error "Expect error removing in-use dir $DIR/$tdir"
208
209         test -d $DIR/$tdir || error "Remote directory disappeared"
210
211         rm -rf $DIR/$tdir || error "remove remote dir error"
212 }
213 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
214
215 test_5() {
216         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
217         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
218         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
219         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
220         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
221 }
222 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
223
224 test_6a() {
225         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
226         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
227         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
228                 error "$tfile does not have perm 0666 or UID $UID"
229         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
230         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
231                 error "$tfile should be 0666 and owned by UID $UID"
232 }
233 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
234
235 test_6c() {
236         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
237         touch $DIR/$tfile
238         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
239         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
240                 error "$tfile should be owned by UID $RUNAS_ID"
241         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
242         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
243                 error "$tfile should be owned by UID $RUNAS_ID"
244 }
245 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
246
247 test_6e() {
248         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
249         touch $DIR/$tfile
250         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
251         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
252                 error "$tfile should be owned by GID $UID"
253         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
254         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
255                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
256 }
257 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
258
259 test_6g() {
260         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
261         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
262         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
263         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
264         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
265         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
266         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
267                 error "$tdir/d/subdir should be GID $RUNAS_GID"
268 }
269 run_test 6g "Is new dir in sgid dir inheriting group?"
270
271 test_6h() { # bug 7331
272         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
273         touch $DIR/$tfile || error "touch failed"
274         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
275         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
276                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
277         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
278                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
279 }
280 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
281
282 test_7a() {
283         test_mkdir $DIR/$tdir
284         $MCREATE $DIR/$tdir/$tfile
285         chmod 0666 $DIR/$tdir/$tfile
286         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
287                 error "$tdir/$tfile should be mode 0666"
288 }
289 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
290
291 test_7b() {
292         if [ ! -d $DIR/$tdir ]; then
293                 mkdir $DIR/$tdir
294         fi
295         $MCREATE $DIR/$tdir/$tfile
296         echo -n foo > $DIR/$tdir/$tfile
297         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
298         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
299 }
300 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
301
302 test_8() {
303         test_mkdir $DIR/$tdir
304         touch $DIR/$tdir/$tfile
305         chmod 0666 $DIR/$tdir/$tfile
306         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
307                 error "$tfile mode not 0666"
308 }
309 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
310
311 test_9() {
312         test_mkdir $DIR/$tdir
313         test_mkdir $DIR/$tdir/d2
314         test_mkdir $DIR/$tdir/d2/d3
315         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
316 }
317 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
318
319 test_10() {
320         test_mkdir $DIR/$tdir
321         test_mkdir $DIR/$tdir/d2
322         touch $DIR/$tdir/d2/$tfile
323         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
324                 error "$tdir/d2/$tfile not a file"
325 }
326 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
327
328 test_11() {
329         test_mkdir $DIR/$tdir
330         test_mkdir $DIR/$tdir/d2
331         chmod 0666 $DIR/$tdir/d2
332         chmod 0705 $DIR/$tdir/d2
333         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
334                 error "$tdir/d2 mode not 0705"
335 }
336 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
337
338 test_12() {
339         test_mkdir $DIR/$tdir
340         touch $DIR/$tdir/$tfile
341         chmod 0666 $DIR/$tdir/$tfile
342         chmod 0654 $DIR/$tdir/$tfile
343         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
344                 error "$tdir/d2 mode not 0654"
345 }
346 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
347
348 test_13() {
349         test_mkdir $DIR/$tdir
350         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
351         >  $DIR/$tdir/$tfile
352         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
353                 error "$tdir/$tfile size not 0 after truncate"
354 }
355 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
356
357 test_14() {
358         test_mkdir $DIR/$tdir
359         touch $DIR/$tdir/$tfile
360         rm $DIR/$tdir/$tfile
361         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
362 }
363 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
364
365 test_15() {
366         test_mkdir $DIR/$tdir
367         touch $DIR/$tdir/$tfile
368         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
369         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
370                 error "$tdir/${tfile_2} not a file after rename"
371 }
372 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
373
374 test_16() {
375         test_mkdir $DIR/$tdir
376         touch $DIR/$tdir/$tfile
377         rm -rf $DIR/$tdir/$tfile
378         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
379 }
380 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
381
382 test_17a() {
383         test_mkdir -p $DIR/$tdir
384         touch $DIR/$tdir/$tfile
385         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
386         ls -l $DIR/$tdir
387         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
388                 error "$tdir/l-exist not a symlink"
389         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
390                 error "$tdir/l-exist not referencing a file"
391         rm -f $DIR/$tdir/l-exist
392         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
393 }
394 run_test 17a "symlinks: create, remove (real) =================="
395
396 test_17b() {
397         test_mkdir -p $DIR/$tdir
398         ln -s no-such-file $DIR/$tdir/l-dangle
399         ls -l $DIR/$tdir
400         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
401                 error "$tdir/l-dangle not referencing no-such-file"
402         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
403                 error "$tdir/l-dangle not referencing non-existent file"
404         rm -f $DIR/$tdir/l-dangle
405         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
406 }
407 run_test 17b "symlinks: create, remove (dangling) =============="
408
409 test_17c() { # bug 3440 - don't save failed open RPC for replay
410         test_mkdir -p $DIR/$tdir
411         ln -s foo $DIR/$tdir/$tfile
412         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
413 }
414 run_test 17c "symlinks: open dangling (should return error) ===="
415
416 test_17d() {
417         test_mkdir -p $DIR/$tdir
418         ln -s foo $DIR/$tdir/$tfile
419         touch $DIR/$tdir/$tfile || error "creating to new symlink"
420 }
421 run_test 17d "symlinks: create dangling ========================"
422
423 test_17e() {
424         test_mkdir -p $DIR/$tdir
425         local foo=$DIR/$tdir/$tfile
426         ln -s $foo $foo || error "create symlink failed"
427         ls -l $foo || error "ls -l failed"
428         ls $foo && error "ls not failed" || true
429 }
430 run_test 17e "symlinks: create recursive symlink (should return error) ===="
431
432 test_17f() {
433         test_mkdir -p $DIR/$tdir
434         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
435         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
436         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
437         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
438         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
439         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
440         ls -l  $DIR/$tdir
441 }
442 run_test 17f "symlinks: long and very long symlink name ========================"
443
444 # str_repeat(S, N) generate a string that is string S repeated N times
445 str_repeat() {
446         local s=$1
447         local n=$2
448         local ret=''
449         while [ $((n -= 1)) -ge 0 ]; do
450                 ret=$ret$s
451         done
452         echo $ret
453 }
454
455 # Long symlinks and LU-2241
456 test_17g() {
457         test_mkdir -p $DIR/$tdir
458         local TESTS="59 60 61 4094 4095"
459
460         # Fix for inode size boundary in 2.1.4
461         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
462                 TESTS="4094 4095"
463
464         # Patch not applied to 2.2 or 2.3 branches
465         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
466         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
467                 TESTS="4094 4095"
468
469         # skip long symlink name for rhel6.5.
470         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
471         grep -q '6.5' /etc/redhat-release &>/dev/null &&
472                 TESTS="59 60 61 4062 4063"
473
474         for i in $TESTS; do
475                 local SYMNAME=$(str_repeat 'x' $i)
476                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
477                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
478         done
479 }
480 run_test 17g "symlinks: really long symlink name and inode boundaries"
481
482 test_17h() { #bug 17378
483         remote_mds_nodsh && skip "remote MDS with nodsh" && return
484         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
485         local mdt_idx
486         test_mkdir -p $DIR/$tdir
487         if [[ $MDSCOUNT -gt 1 ]]; then
488                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
489         else
490                 mdt_idx=0
491         fi
492         $SETSTRIPE -c -1 $DIR/$tdir
493 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
494         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
495         touch $DIR/$tdir/$tfile || true
496 }
497 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
498
499 test_17i() { #bug 20018
500         remote_mds_nodsh && skip "remote MDS with nodsh" && return
501         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
502         test_mkdir -p $DIR/$tdir
503         local foo=$DIR/$tdir/$tfile
504         local mdt_idx
505         if [[ $MDSCOUNT -gt 1 ]]; then
506                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
507         else
508                 mdt_idx=0
509         fi
510         ln -s $foo $foo || error "create symlink failed"
511 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
512         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
513         ls -l $foo && error "error not detected"
514         return 0
515 }
516 run_test 17i "don't panic on short symlink"
517
518 test_17k() { #bug 22301
519         [[ -z "$(which rsync 2>/dev/null)" ]] &&
520                 skip "no rsync command" && return 0
521         rsync --help | grep -q xattr ||
522                 skip_env "$(rsync --version | head -n1) does not support xattrs"
523         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
524         test_mkdir -p $DIR/$tdir
525         test_mkdir -p $DIR/$tdir.new
526         touch $DIR/$tdir/$tfile
527         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
528         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
529                 error "rsync failed with xattrs enabled"
530 }
531 run_test 17k "symlinks: rsync with xattrs enabled ========================="
532
533 test_17l() { # LU-279
534         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
535                 skip "no getfattr command" && return 0
536         mkdir -p $DIR/$tdir
537         touch $DIR/$tdir/$tfile
538         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
539         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
540                 # -h to not follow symlinks. -m '' to list all the xattrs.
541                 # grep to remove first line: '# file: $path'.
542                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
543                 do
544                         lgetxattr_size_check $path $xattr ||
545                                 error "lgetxattr_size_check $path $xattr failed"
546                 done
547         done
548 }
549 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
550
551 # LU-1540
552 test_17m() {
553         local short_sym="0123456789"
554         local WDIR=$DIR/${tdir}m
555         local mds_index
556         local devname
557         local cmd
558         local i
559         local rc=0
560
561         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
562         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
563                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
564
565         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
566                 skip "only for ldiskfs MDT" && return 0
567
568         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
569
570         mkdir -p $WDIR
571         long_sym=$short_sym
572         # create a long symlink file
573         for ((i = 0; i < 4; ++i)); do
574                 long_sym=${long_sym}${long_sym}
575         done
576
577         echo "create 512 short and long symlink files under $WDIR"
578         for ((i = 0; i < 256; ++i)); do
579                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
580                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
581         done
582
583         echo "erase them"
584         rm -f $WDIR/*
585         sync
586         wait_delete_completed
587
588         echo "recreate the 512 symlink files with a shorter string"
589         for ((i = 0; i < 512; ++i)); do
590                 # rewrite the symlink file with a shorter string
591                 ln -sf ${long_sym} $WDIR/long-$i
592                 ln -sf ${short_sym} $WDIR/short-$i
593         done
594
595         mds_index=$($LFS getstripe -M $WDIR)
596         mds_index=$((mds_index+1))
597         devname=$(mdsdevname $mds_index)
598         cmd="$E2FSCK -fnvd $devname"
599
600         echo "stop and checking mds${mds_index}: $cmd"
601         # e2fsck should not return error
602         stop mds${mds_index} -f
603         do_facet mds${mds_index} $cmd || rc=$?
604
605         start mds${mds_index} $devname $MDS_MOUNT_OPTS
606         df $MOUNT > /dev/null 2>&1
607         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
608                 "short/long symlink MDT: rc=$rc"
609         return $rc
610 }
611 run_test 17m "run e2fsck against MDT which contains short/long symlink"
612
613 check_fs_consistency_17n() {
614         local mdt_index
615         local devname
616         local cmd
617         local rc=0
618
619         for mdt_index in $(seq 1 $MDSCOUNT); do
620                 devname=$(mdsdevname $mdt_index)
621                 cmd="$E2FSCK -fnvd $devname"
622
623                 echo "stop and checking mds${mdt_index}: $cmd"
624                 # e2fsck should not return error
625                 stop mds${mdt_index}
626                 do_facet mds${mdt_index} $cmd || rc=$?
627
628                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
629                 df $MOUNT > /dev/null 2>&1
630                 [ $rc -ne 0 ] && break
631         done
632         return $rc
633 }
634
635 test_17n() {
636         local i
637
638         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
639         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
640                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
641
642         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
643                 skip "only for ldiskfs MDT" && return 0
644
645         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
646
647         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
648
649         mkdir -p $DIR/$tdir
650         for ((i=0; i<10; i++)); do
651                 $LFS mkdir -i 1 $DIR/$tdir/remote_dir_${i} ||
652                         error "create remote dir error $i"
653                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
654                         error "create files under remote dir failed $i"
655         done
656
657         check_fs_consistency_17n || error "e2fsck report error"
658
659         for ((i=0;i<10;i++)); do
660                 rm -rf $DIR/$tdir/remote_dir_${i} ||
661                         error "destroy remote dir error $i"
662         done
663
664         check_fs_consistency_17n || error "e2fsck report error"
665 }
666 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
667
668 test_17o() {
669         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
670                 skip "Need MDS version at least 2.3.64" && return
671
672         local WDIR=$DIR/${tdir}o
673         local mdt_index
674         local mdtdevname
675         local rc=0
676
677         mkdir -p $WDIR
678         mdt_index=$($LFS getstripe -M $WDIR)
679         mdt_index=$((mdt_index+1))
680         mdtdevname=$(mdsdevname $mdt_index)
681
682         touch $WDIR/$tfile
683         stop mds${mdt_index}
684         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS
685
686         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
687         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
688         ls -l $WDIR/$tfile && rc=1
689         do_facet mds${mdt_index} lctl set_param fail_loc=0
690         [[ $rc -ne 0 ]] && error "stat file should fail"
691         true
692 }
693 run_test 17o "stat file with incompat LMA feature"
694
695 test_18() {
696         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
697         ls $DIR || error "Failed to ls $DIR: $?"
698 }
699 run_test 18 "touch .../f ; ls ... =============================="
700
701 test_19a() {
702         touch $DIR/$tfile
703         ls -l $DIR
704         rm $DIR/$tfile
705         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
706 }
707 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
708
709 test_19b() {
710         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
711 }
712 run_test 19b "ls -l .../f19 (should return error) =============="
713
714 test_19c() {
715         [ $RUNAS_ID -eq $UID ] &&
716                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
717         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
718 }
719 run_test 19c "$RUNAS touch .../f19 (should return error) =="
720
721 test_19d() {
722         cat $DIR/f19 && error || true
723 }
724 run_test 19d "cat .../f19 (should return error) =============="
725
726 test_20() {
727         touch $DIR/$tfile
728         rm $DIR/$tfile
729         log "1 done"
730         touch $DIR/$tfile
731         rm $DIR/$tfile
732         log "2 done"
733         touch $DIR/$tfile
734         rm $DIR/$tfile
735         log "3 done"
736         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
737 }
738 run_test 20 "touch .../f ; ls -l ... ==========================="
739
740 test_21() {
741         test_mkdir -p $DIR/$tdir
742         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
743         ln -s dangle $DIR/$tdir/link
744         echo foo >> $DIR/$tdir/link
745         cat $DIR/$tdir/dangle
746         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
747         $CHECKSTAT -f -t file $DIR/$tdir/link ||
748                 error "$tdir/link not linked to a file"
749 }
750 run_test 21 "write to dangling link ============================"
751
752 test_22() {
753         WDIR=$DIR/$tdir
754         test_mkdir -p $DIR/$tdir
755         chown $RUNAS_ID:$RUNAS_GID $WDIR
756         (cd $WDIR || error "cd $WDIR failed";
757         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
758         $RUNAS tar xf -)
759         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
760         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
761         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
762 }
763 run_test 22 "unpack tar archive as non-root user ==============="
764
765 # was test_23
766 test_23a() {
767         test_mkdir -p $DIR/$tdir
768         local file=$DIR/$tdir/$tfile
769
770         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
771         openfile -f O_CREAT:O_EXCL $file &&
772                 error "$file recreate succeeded" || true
773 }
774 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
775
776 test_23b() { # bug 18988
777         test_mkdir -p $DIR/$tdir
778         local file=$DIR/$tdir/$tfile
779
780         rm -f $file
781         echo foo > $file || error "write filed"
782         echo bar >> $file || error "append filed"
783         $CHECKSTAT -s 8 $file || error "wrong size"
784         rm $file
785 }
786 run_test 23b "O_APPEND check =========================="
787
788 # rename sanity
789 test_24a() {
790         echo '-- same directory rename'
791         test_mkdir $DIR/$tdir
792         touch $DIR/$tdir/$tfile.1
793         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
794         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
795 }
796 run_test 24a "rename file to non-existent target"
797
798 test_24b() {
799         test_mkdir $DIR/$tdir
800         touch $DIR/$tdir/$tfile.{1,2}
801         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
802         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
803         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
804 }
805 run_test 24b "rename file to existing target"
806
807 test_24c() {
808         test_mkdir $DIR/$tdir
809         test_mkdir $DIR/$tdir/d$testnum.1
810         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
811         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
812         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
813 }
814 run_test 24c "rename directory to non-existent target"
815
816 test_24d() {
817         test_mkdir $DIR/$tdir
818         test_mkdir $DIR/$tdir/d$testnum.1
819         test_mkdir $DIR/$tdir/d$ttestnum.2
820         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
821         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
822         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
823 }
824 run_test 24d "rename directory to existing target"
825
826 test_24e() {
827         echo '-- cross directory renames --'
828         test_mkdir $DIR/R5a
829         test_mkdir $DIR/R5b
830         touch $DIR/R5a/f
831         mv $DIR/R5a/f $DIR/R5b/g
832         $CHECKSTAT -a $DIR/R5a/f || error
833         $CHECKSTAT -t file $DIR/R5b/g || error
834 }
835 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
836
837 test_24f() {
838         test_mkdir $DIR/R6a
839         test_mkdir $DIR/R6b
840         touch $DIR/R6a/f $DIR/R6b/g
841         mv $DIR/R6a/f $DIR/R6b/g
842         $CHECKSTAT -a $DIR/R6a/f || error
843         $CHECKSTAT -t file $DIR/R6b/g || error
844 }
845 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
846
847 test_24g() {
848         test_mkdir $DIR/R7a
849         test_mkdir $DIR/R7b
850         test_mkdir $DIR/R7a/d
851         mv $DIR/R7a/d $DIR/R7b/e
852         $CHECKSTAT -a $DIR/R7a/d || error
853         $CHECKSTAT -t dir $DIR/R7b/e || error
854 }
855 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
856
857 test_24h() {
858         test_mkdir $DIR/R8a
859         test_mkdir $DIR/R8b
860         test_mkdir $DIR/R8a/d
861         test_mkdir $DIR/R8b/e
862         mrename $DIR/R8a/d $DIR/R8b/e
863         $CHECKSTAT -a $DIR/R8a/d || error
864         $CHECKSTAT -t dir $DIR/R8b/e || error
865 }
866 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
867
868 test_24i() {
869         echo "-- rename error cases"
870         test_mkdir $DIR/R9
871         test_mkdir $DIR/R9/a
872         touch $DIR/R9/f
873         mrename $DIR/R9/f $DIR/R9/a
874         $CHECKSTAT -t file $DIR/R9/f || error
875         $CHECKSTAT -t dir  $DIR/R9/a || error
876         $CHECKSTAT -a $DIR/R9/a/f || error
877 }
878 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
879
880 test_24j() {
881         test_mkdir $DIR/R10
882         mrename $DIR/R10/f $DIR/R10/g
883         $CHECKSTAT -t dir $DIR/R10 || error
884         $CHECKSTAT -a $DIR/R10/f || error
885         $CHECKSTAT -a $DIR/R10/g || error
886 }
887 run_test 24j "source does not exist ============================"
888
889 test_24k() {
890         test_mkdir $DIR/R11a
891         test_mkdir $DIR/R11a/d
892         touch $DIR/R11a/f
893         mv $DIR/R11a/f $DIR/R11a/d
894         $CHECKSTAT -a $DIR/R11a/f || error
895         $CHECKSTAT -t file $DIR/R11a/d/f || error
896 }
897 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
898
899 # bug 2429 - rename foo foo foo creates invalid file
900 test_24l() {
901         f="$DIR/f24l"
902         $MULTIOP $f OcNs || error
903 }
904 run_test 24l "Renaming a file to itself ========================"
905
906 test_24m() {
907         f="$DIR/f24m"
908         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
909         # on ext3 this does not remove either the source or target files
910         # though the "expected" operation would be to remove the source
911         $CHECKSTAT -t file ${f} || error "${f} missing"
912         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
913 }
914 run_test 24m "Renaming a file to a hard link to itself ========="
915
916 test_24n() {
917     f="$DIR/f24n"
918     # this stats the old file after it was renamed, so it should fail
919     touch ${f}
920     $CHECKSTAT ${f}
921     mv ${f} ${f}.rename
922     $CHECKSTAT ${f}.rename
923     $CHECKSTAT -a ${f}
924 }
925 run_test 24n "Statting the old file after renaming (Posix rename 2)"
926
927 test_24o() {
928         check_kernel_version 37 || return 0
929         test_mkdir -p $DIR/d24o
930         rename_many -s random -v -n 10 $DIR/d24o
931 }
932 run_test 24o "rename of files during htree split ==============="
933
934 test_24p() {
935         test_mkdir $DIR/R12a
936         test_mkdir $DIR/R12b
937         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
938         mrename $DIR/R12a $DIR/R12b
939         $CHECKSTAT -a $DIR/R12a || error
940         $CHECKSTAT -t dir $DIR/R12b || error
941         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
942         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
943 }
944 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
945
946 cleanup_multiop_pause() {
947         trap 0
948         kill -USR1 $MULTIPID
949 }
950
951 test_24q() {
952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
953         test_mkdir $DIR/R13a
954         test_mkdir $DIR/R13b
955         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
956         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
957         MULTIPID=$!
958
959         trap cleanup_multiop_pause EXIT
960         mrename $DIR/R13a $DIR/R13b
961         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
962         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
963         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
964         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
965         cleanup_multiop_pause
966         wait $MULTIPID || error "multiop close failed"
967 }
968 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
969
970 test_24r() { #bug 3789
971         test_mkdir $DIR/R14a
972         test_mkdir $DIR/R14a/b
973         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
974         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
975         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
976 }
977 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
978
979 test_24s() {
980         test_mkdir $DIR/R15a
981         test_mkdir $DIR/R15a/b
982         test_mkdir $DIR/R15a/b/c
983         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
984         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
985         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
986 }
987 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
988 test_24t() {
989         test_mkdir $DIR/R16a
990         test_mkdir $DIR/R16a/b
991         test_mkdir $DIR/R16a/b/c
992         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
993         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
994         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
995 }
996 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
997
998 test_24u() { # bug12192
999         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1000         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1001 }
1002 run_test 24u "create stripe file"
1003
1004 page_size() {
1005         getconf PAGE_SIZE
1006 }
1007
1008 simple_cleanup_common() {
1009         trap 0
1010         rm -rf $DIR/$tdir
1011         wait_delete_completed
1012 }
1013
1014 max_pages_per_rpc() {
1015         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1016 }
1017
1018 test_24v() {
1019         local NRFILES=100000
1020         local FREE_INODES=$(mdt_free_inodes 0)
1021         [[ $FREE_INODES -lt $NRFILES ]] &&
1022                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1023                 return
1024
1025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1026         trap simple_cleanup_common EXIT
1027
1028         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1029         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1030
1031         mkdir -p $DIR/$tdir
1032         createmany -m $DIR/$tdir/$tfile $NRFILES
1033
1034         cancel_lru_locks mdc
1035         lctl set_param mdc.*.stats clear
1036
1037         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1038
1039         # LU-5 large readdir
1040         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1041         #               8 bytes for name(filename is mostly 5 in this test) +
1042         #               8 bytes for luda_type
1043         # take into account of overhead in lu_dirpage header and end mark in
1044         # each page, plus one in RPC_NUM calculation.
1045         DIRENT_SIZE=48
1046         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1047         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1048         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1049                                 awk '/^mds_readpage/ {print $2}')
1050         [[ $mds_readpage -gt $RPC_NUM ]] &&
1051                 error "large readdir doesn't take effect"
1052
1053         simple_cleanup_common
1054 }
1055 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1056
1057 test_24w() { # bug21506
1058         SZ1=234852
1059         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1060         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1061         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1062         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1063         [[ "$SZ1" -eq "$SZ2" ]] ||
1064                 error "Error reading at the end of the file $tfile"
1065 }
1066 run_test 24w "Reading a file larger than 4Gb"
1067
1068 test_24x() {
1069         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1070         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1071         local MDTIDX=1
1072         local remote_dir=$DIR/$tdir/remote_dir
1073
1074         mkdir -p $DIR/$tdir
1075         $LFS mkdir -i $MDTIDX $remote_dir ||
1076                 error "create remote directory failed"
1077
1078         mkdir -p $DIR/$tdir/src_dir
1079         touch $DIR/$tdir/src_file
1080         mkdir -p $remote_dir/tgt_dir
1081         touch $remote_dir/tgt_file
1082
1083         mrename $remote_dir $DIR/ &&
1084                 error "rename dir cross MDT works!"
1085
1086         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1087                 error "rename dir cross MDT works!"
1088
1089         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1090                 error "rename file cross MDT works!"
1091
1092         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1093                 error "ln file cross MDT should not work!"
1094
1095         rm -rf $DIR/$tdir || error "Can not delete directories"
1096 }
1097 run_test 24x "cross rename/link should be failed"
1098
1099 test_24y() {
1100         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1101         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1102         local MDTIDX=1
1103         local remote_dir=$DIR/$tdir/remote_dir
1104
1105         mkdir -p $DIR/$tdir
1106         $LFS mkdir -i $MDTIDX $remote_dir ||
1107                    error "create remote directory failed"
1108
1109         mkdir -p $remote_dir/src_dir
1110         touch $remote_dir/src_file
1111         mkdir -p $remote_dir/tgt_dir
1112         touch $remote_dir/tgt_file
1113
1114         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1115                 error "rename subdir in the same remote dir failed!"
1116
1117         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1118                 error "rename files in the same remote dir failed!"
1119
1120         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1121                 error "link files in the same remote dir failed!"
1122
1123         rm -rf $DIR/$tdir || error "Can not delete directories"
1124 }
1125 run_test 24y "rename/link on the same dir should succeed"
1126
1127 test_24z() {
1128         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1130         local MDTIDX=1
1131         local remote_src=$DIR/$tdir/remote_dir
1132         local remote_tgt=$DIR/$tdir/remote_tgt
1133
1134         mkdir -p $DIR/$tdir
1135         $LFS mkdir -i $MDTIDX $remote_src ||
1136                    error "create remote directory failed"
1137
1138         $LFS mkdir -i $MDTIDX $remote_tgt ||
1139                    error "create remote directory failed"
1140
1141         mrename $remote_src $remote_tgt &&
1142                 error "rename remote dirs should not work!"
1143
1144         # If target dir does not exists, it should succeed
1145         rm -rf $remote_tgt
1146         mrename $remote_src $remote_tgt ||
1147                 error "rename remote dirs(tgt dir does not exists) failed!"
1148
1149         rm -rf $DIR/$tdir || error "Can not delete directories"
1150 }
1151 run_test 24z "rename one remote dir to another remote dir should fail"
1152
1153 test_24A() { # LU-3182
1154         local NFILES=5000
1155
1156         mkdir -p $DIR/$tdir
1157         createmany -m $DIR/$tdir/$tfile $NFILES
1158         local t=`ls $DIR/$tdir | wc -l`
1159         local u=`ls $DIR/$tdir | sort -u | wc -l`
1160         if [ $t -ne $NFILES -o $u -ne $NFILES ] ; then
1161                 error "Expected $NFILES files, got $t ($u unique)"
1162         fi
1163
1164         rm -rf $DIR/$tdir || error "Can not delete directories"
1165 }
1166 run_test 24A "readdir() returns correct number of entries."
1167
1168 test_25a() {
1169         echo '== symlink sanity ============================================='
1170
1171         test_mkdir $DIR/d25
1172         ln -s d25 $DIR/s25
1173         touch $DIR/s25/foo || error
1174 }
1175 run_test 25a "create file in symlinked directory ==============="
1176
1177 test_25b() {
1178         [ ! -d $DIR/d25 ] && test_25a
1179         $CHECKSTAT -t file $DIR/s25/foo || error
1180 }
1181 run_test 25b "lookup file in symlinked directory ==============="
1182
1183 test_26a() {
1184         test_mkdir $DIR/d26
1185         test_mkdir $DIR/d26/d26-2
1186         ln -s d26/d26-2 $DIR/s26
1187         touch $DIR/s26/foo || error
1188 }
1189 run_test 26a "multiple component symlink ======================="
1190
1191 test_26b() {
1192         test_mkdir -p $DIR/d26b/d26-2
1193         ln -s d26b/d26-2/foo $DIR/s26-2
1194         touch $DIR/s26-2 || error
1195 }
1196 run_test 26b "multiple component symlink at end of lookup ======"
1197
1198 test_26c() {
1199         test_mkdir $DIR/d26.2
1200         touch $DIR/d26.2/foo
1201         ln -s d26.2 $DIR/s26.2-1
1202         ln -s s26.2-1 $DIR/s26.2-2
1203         ln -s s26.2-2 $DIR/s26.2-3
1204         chmod 0666 $DIR/s26.2-3/foo
1205 }
1206 run_test 26c "chain of symlinks ================================"
1207
1208 # recursive symlinks (bug 439)
1209 test_26d() {
1210         ln -s d26-3/foo $DIR/d26-3
1211 }
1212 run_test 26d "create multiple component recursive symlink ======"
1213
1214 test_26e() {
1215         [ ! -h $DIR/d26-3 ] && test_26d
1216         rm $DIR/d26-3
1217 }
1218 run_test 26e "unlink multiple component recursive symlink ======"
1219
1220 # recursive symlinks (bug 7022)
1221 test_26f() {
1222         test_mkdir -p $DIR/$tdir
1223         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1224         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1225         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1226         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1227         cd $tfile                || error "cd $tfile failed"
1228         ln -s .. dotdot          || error "ln dotdot failed"
1229         ln -s dotdot/lndir lndir || error "ln lndir failed"
1230         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1231         output=`ls $tfile/$tfile/lndir/bar1`
1232         [ "$output" = bar1 ] && error "unexpected output"
1233         rm -r $tfile             || error "rm $tfile failed"
1234         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1235 }
1236 run_test 26f "rm -r of a directory which has recursive symlink ="
1237
1238 test_27a() {
1239         echo '== stripe sanity =============================================='
1240         test_mkdir -p $DIR/d27 || error "mkdir failed"
1241         $GETSTRIPE $DIR/d27
1242         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1243         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1244         log "== test_27a: write to one stripe file ========================="
1245         cp /etc/hosts $DIR/d27/f0 || error
1246 }
1247 run_test 27a "one stripe file =================================="
1248
1249 test_27b() {
1250         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1251         test_mkdir -p $DIR/d27
1252         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1253         $GETSTRIPE -c $DIR/d27/f01
1254         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1255                 error "two-stripe file doesn't have two stripes"
1256
1257         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1258 }
1259 run_test 27b "create and write to two stripe file"
1260
1261 test_27d() {
1262         test_mkdir -p $DIR/d27
1263         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1264         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1265         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1266 }
1267 run_test 27d "create file with default settings ================"
1268
1269 test_27e() {
1270         test_mkdir -p $DIR/d27
1271         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1272         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1273         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1274 }
1275 run_test 27e "setstripe existing file (should return error) ======"
1276
1277 test_27f() {
1278         test_mkdir $DIR/$tdir
1279         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1280                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1281         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1282                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1283         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1284         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1285 }
1286 run_test 27f "setstripe with bad stripe size (should return error)"
1287
1288 test_27g() {
1289         test_mkdir -p $DIR/d27
1290         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1291         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1292                 error "$DIR/d27/fnone has object"
1293 }
1294 run_test 27g "$GETSTRIPE with no objects"
1295
1296 test_27i() {
1297         touch $DIR/d27/fsome || error "touch failed"
1298         [[ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ]] || error "missing objects"
1299 }
1300 run_test 27i "$GETSTRIPE with some objects"
1301
1302 test_27j() {
1303         test_mkdir -p $DIR/d27
1304         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1305 }
1306 run_test 27j "setstripe with bad stripe offset (should return error)"
1307
1308 test_27k() { # bug 2844
1309         test_mkdir -p $DIR/d27
1310         FILE=$DIR/d27/f27k
1311         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1312         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1313         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1314         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1315         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
1316         dd if=/dev/zero of=$FILE bs=4k count=1
1317         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1318         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
1319 }
1320 run_test 27k "limit i_blksize for broken user apps ============="
1321
1322 test_27l() {
1323         test_mkdir -p $DIR/d27
1324         mcreate $DIR/f27l || error "creating file"
1325         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1326                 error "setstripe should have failed" || true
1327 }
1328 run_test 27l "check setstripe permissions (should return error)"
1329
1330 test_27m() {
1331         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1332                 return
1333         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1334                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1335                 return
1336         fi
1337         trap simple_cleanup_common EXIT
1338         test_mkdir -p $DIR/$tdir
1339         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1340         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1341                 error "dd should fill OST0"
1342         i=2
1343         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1344                 i=$((i + 1))
1345                 [ $i -gt 256 ] && break
1346         done
1347         i=$((i + 1))
1348         touch $DIR/$tdir/f27m_$i
1349         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1350                 error "OST0 was full but new created file still use it"
1351         i=$((i + 1))
1352         touch $DIR/$tdir/f27m_$i
1353         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1354                 error "OST0 was full but new created file still use it"
1355         simple_cleanup_common
1356 }
1357 run_test 27m "create file while OST0 was full =================="
1358
1359 sleep_maxage() {
1360         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1361         sleep $DELAY
1362 }
1363
1364 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1365 # if the OST isn't full anymore.
1366 reset_enospc() {
1367         local OSTIDX=${1:-""}
1368
1369         local list=$(comma_list $(osts_nodes))
1370         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1371
1372         do_nodes $list lctl set_param fail_loc=0
1373         sync    # initiate all OST_DESTROYs from MDS to OST
1374         sleep_maxage
1375 }
1376
1377 exhaust_precreations() {
1378         local OSTIDX=$1
1379         local FAILLOC=$2
1380         local FAILIDX=${3:-$OSTIDX}
1381
1382         test_mkdir -p $DIR/$tdir
1383         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1384         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1385
1386         local OST=$(ostname_from_index $OSTIDX)
1387         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1388                           sed -e 's/_UUID$//;s/^.*-//')
1389
1390         # on the mdt's osc
1391         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1392         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1393                         osc.$mdtosc_proc1.prealloc_last_id)
1394         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1395                         osc.$mdtosc_proc1.prealloc_next_id)
1396
1397         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1398         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1399
1400         test_mkdir -p $DIR/$tdir/${OST}
1401         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1402 #define OBD_FAIL_OST_ENOSPC              0x215
1403         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1404         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1405         echo "Creating to objid $last_id on ost $OST..."
1406         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1407         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1408         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1409         sleep_maxage
1410 }
1411
1412 exhaust_all_precreations() {
1413         local i
1414         for (( i=0; i < OSTCOUNT; i++ )) ; do
1415                 exhaust_precreations $i $1 -1
1416         done
1417 }
1418
1419 test_27n() {
1420         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1421         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1422         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1423         remote_ost_nodsh && skip "remote OST with nodsh" && return
1424
1425         reset_enospc
1426         rm -f $DIR/$tdir/$tfile
1427         exhaust_precreations 0 0x80000215
1428         $SETSTRIPE -c -1 $DIR/$tdir
1429         touch $DIR/$tdir/$tfile || error
1430         $GETSTRIPE $DIR/$tdir/$tfile
1431         reset_enospc
1432 }
1433 run_test 27n "create file with some full OSTs =================="
1434
1435 test_27o() {
1436         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1437         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1438         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1439         remote_ost_nodsh && skip "remote OST with nodsh" && return
1440
1441         reset_enospc
1442         rm -f $DIR/$tdir/$tfile
1443         exhaust_all_precreations 0x215
1444
1445         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1446
1447         reset_enospc
1448         rm -rf $DIR/$tdir/*
1449 }
1450 run_test 27o "create file with all full OSTs (should error) ===="
1451
1452 test_27p() {
1453         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1454         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1455         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1456         remote_ost_nodsh && skip "remote OST with nodsh" && return
1457
1458         reset_enospc
1459         rm -f $DIR/$tdir/$tfile
1460         test_mkdir -p $DIR/$tdir
1461
1462         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1463         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1464         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1465
1466         exhaust_precreations 0 0x80000215
1467         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1468         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1469         $GETSTRIPE $DIR/$tdir/$tfile
1470
1471         reset_enospc
1472 }
1473 run_test 27p "append to a truncated file with some full OSTs ==="
1474
1475 test_27q() {
1476         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1477         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1478         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1479         remote_ost_nodsh && skip "remote OST with nodsh" && return
1480
1481         reset_enospc
1482         rm -f $DIR/$tdir/$tfile
1483
1484         test_mkdir -p $DIR/$tdir
1485         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1486         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1487         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1488
1489         exhaust_all_precreations 0x215
1490
1491         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1492         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1493
1494         reset_enospc
1495 }
1496 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1497
1498 test_27r() {
1499         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1501         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1502         remote_ost_nodsh && skip "remote OST with nodsh" && return
1503
1504         reset_enospc
1505         rm -f $DIR/$tdir/$tfile
1506         exhaust_precreations 0 0x80000215
1507
1508         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1509
1510         reset_enospc
1511 }
1512 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1513
1514 test_27s() { # bug 10725
1515         test_mkdir -p $DIR/$tdir
1516         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1517         local stripe_count=0
1518         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1519         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1520                 error "stripe width >= 2^32 succeeded" || true
1521
1522 }
1523 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1524
1525 test_27t() { # bug 10864
1526         WDIR=$(pwd)
1527         WLFS=$(which lfs)
1528         cd $DIR
1529         touch $tfile
1530         $WLFS getstripe $tfile
1531         cd $WDIR
1532 }
1533 run_test 27t "check that utils parse path correctly"
1534
1535 test_27u() { # bug 4900
1536         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1537         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1538         local index
1539         local list=$(comma_list $(mdts_nodes))
1540
1541 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1542         do_nodes $list $LCTL set_param fail_loc=0x139
1543         test_mkdir -p $DIR/$tdir
1544         rm -rf $DIR/$tdir/*
1545         createmany -o $DIR/$tdir/t- 1000
1546         do_nodes $list $LCTL set_param fail_loc=0
1547
1548         TLOG=$DIR/$tfile.getstripe
1549         $GETSTRIPE $DIR/$tdir > $TLOG
1550         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1551         unlinkmany $DIR/$tdir/t- 1000
1552         [[ $OBJS -gt 0 ]] &&
1553                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1554 }
1555 run_test 27u "skip object creation on OSC w/o objects =========="
1556
1557 test_27v() { # bug 4900
1558         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1560         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1561         remote_ost_nodsh && skip "remote OST with nodsh" && return
1562
1563         exhaust_all_precreations 0x215
1564         reset_enospc
1565
1566         test_mkdir -p $DIR/$tdir
1567         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1568
1569         touch $DIR/$tdir/$tfile
1570         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1571         # all except ost1
1572         for (( i=1; i < OSTCOUNT; i++ )); do
1573                 do_facet ost$i lctl set_param fail_loc=0x705
1574         done
1575         local START=`date +%s`
1576         createmany -o $DIR/$tdir/$tfile 32
1577
1578         local FINISH=`date +%s`
1579         local TIMEOUT=`lctl get_param -n timeout`
1580         local PROCESS=$((FINISH - START))
1581         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1582                error "$FINISH - $START >= $TIMEOUT / 2"
1583         sleep $((TIMEOUT / 2 - PROCESS))
1584         reset_enospc
1585 }
1586 run_test 27v "skip object creation on slow OST ================="
1587
1588 test_27w() { # bug 10997
1589         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1590         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1591         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1592                 error "stripe size $size != 65536" || true
1593         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1594                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1595 }
1596 run_test 27w "check $SETSTRIPE -S option"
1597
1598 test_27wa() {
1599         [[ $OSTCOUNT -lt 2 ]] &&
1600                 skip_env "skipping multiple stripe count/offset test" && return
1601
1602         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1603         for i in $(seq 1 $OSTCOUNT); do
1604                 offset=$((i - 1))
1605                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1606                         error "setstripe -c $i -i $offset failed"
1607                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1608                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1609                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1610                 [ $index -ne $offset ] &&
1611                         error "stripe offset $index != $offset" || true
1612         done
1613 }
1614 run_test 27wa "check $SETSTRIPE -c -i options"
1615
1616 test_27x() {
1617         remote_ost_nodsh && skip "remote OST with nodsh" && return
1618         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1619         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1620         OFFSET=$(($OSTCOUNT - 1))
1621         OSTIDX=0
1622         local OST=$(ostname_from_index $OSTIDX)
1623
1624         test_mkdir -p $DIR/$tdir
1625         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1626         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1627         sleep_maxage
1628         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1629         for i in `seq 0 $OFFSET`; do
1630                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1631                 error "OST0 was degraded but new created file still use it"
1632         done
1633         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1634 }
1635 run_test 27x "create files while OST0 is degraded"
1636
1637 test_27y() {
1638         [[ $OSTCOUNT -lt 2 ]] &&
1639                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1640         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1641         remote_ost_nodsh && skip "remote OST with nodsh" && return
1642         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1643
1644         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1645         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1646             osc.$mdtosc.prealloc_last_id)
1647         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1648             osc.$mdtosc.prealloc_next_id)
1649         local fcount=$((last_id - next_id))
1650         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1651         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1652
1653         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1654                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1655         local OST_DEACTIVE_IDX=-1
1656         local OSC
1657         local OSTIDX
1658         local OST
1659
1660         for OSC in $MDS_OSCS; do
1661                 OST=$(osc_to_ost $OSC)
1662                 OSTIDX=$(index_from_ostuuid $OST)
1663                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1664                         OST_DEACTIVE_IDX=$OSTIDX
1665                 fi
1666                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1667                         echo $OSC "is Deactivated:"
1668                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1669                 fi
1670         done
1671
1672         OSTIDX=$(index_from_ostuuid $OST)
1673         mkdir -p $DIR/$tdir
1674         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1675
1676         for OSC in $MDS_OSCS; do
1677                 OST=$(osc_to_ost $OSC)
1678                 OSTIDX=$(index_from_ostuuid $OST)
1679                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1680                         echo $OST "is degraded:"
1681                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1682                                                 obdfilter.$OST.degraded=1
1683                 fi
1684         done
1685
1686         sleep_maxage
1687         createmany -o $DIR/$tdir/$tfile $fcount
1688
1689         for OSC in $MDS_OSCS; do
1690                 OST=$(osc_to_ost $OSC)
1691                 OSTIDX=$(index_from_ostuuid $OST)
1692                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1693                         echo $OST "is recovered from degraded:"
1694                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1695                                                 obdfilter.$OST.degraded=0
1696                 else
1697                         do_facet $SINGLEMDS lctl --device %$OSC activate
1698                 fi
1699         done
1700
1701         # all osp devices get activated, hence -1 stripe count restored
1702         local stripecnt=0
1703
1704         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1705         # devices get activated.
1706         sleep_maxage
1707         $SETSTRIPE -c -1 $DIR/$tfile
1708         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1709         rm -f $DIR/$tfile
1710         [ $stripecnt -ne $OSTCOUNT ] &&
1711                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1712         return 0
1713 }
1714 run_test 27y "create files while OST0 is degraded and the rest inactive"
1715
1716 check_seq_oid()
1717 {
1718         log "check file $1"
1719
1720         lmm_count=$($GETSTRIPE -c $1)
1721         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1722         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1723
1724         local old_ifs="$IFS"
1725         IFS=$'[:]'
1726         fid=($($LFS path2fid $1))
1727         IFS="$old_ifs"
1728
1729         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1730         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1731
1732         # compare lmm_seq and lu_fid->f_seq
1733         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1734         # compare lmm_object_id and lu_fid->oid
1735         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1736
1737         # check the trusted.fid attribute of the OST objects of the file
1738         local have_obdidx=false
1739         local stripe_nr=0
1740         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1741                 # skip lines up to and including "obdidx"
1742                 [ -z "$obdidx" ] && break
1743                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1744                 $have_obdidx || continue
1745
1746                 local ost=$((obdidx + 1))
1747                 local dev=$(ostdevname $ost)
1748                 local oid_hex
1749
1750                 if [ $(facet_fstype ost$ost) != ldiskfs ]; then
1751                         echo "Currently only works with ldiskfs-based OSTs"
1752                         continue
1753                 fi
1754
1755                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1756
1757                 #don't unmount/remount the OSTs if we don't need to do that
1758                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1759                 # update too, until that use mount/ll_decode_filter_fid/mount
1760                 local dir=$(facet_mntpt ost$ost)
1761                 local opts=${OST_MOUNT_OPTS}
1762
1763                 if !  do_facet ost$ost test -b ${dev}; then
1764                         opts=$(csa_add "$opts" -o loop)
1765                 fi
1766
1767                 stop ost$ost
1768                 do_facet ost$ost mount -t $(facet_fstype ost$ost) $opts $dev $dir ||
1769                         { error "mounting $dev as $FSTYPE failed"; return 3; }
1770
1771                 seq=$(echo $seq | sed -e "s/^0x//g")
1772                 if [ $seq == 0 ]; then
1773                         oid_hex=$(echo $oid)
1774                 else
1775                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1776                 fi
1777                 local obj_file=$(do_facet ost$ost find $dir/O/$seq -name $oid_hex)
1778                 local ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID $obj_file)
1779                 do_facet ost$ost umount -d $dir
1780                 start ost$ost $dev $OST_MOUNT_OPTS
1781
1782                 # re-enable when debugfs will understand new filter_fid
1783                 #local ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1784                 #           $dev 2>/dev/null" | grep "parent=")
1785
1786                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1787
1788                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1789
1790                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1791                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1792                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1793                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1794                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1795                 local ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1796
1797                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1798                 [ $ff_pseq = $lmm_seq ] ||
1799                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1800                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1801                 [ $ff_poid = $lmm_oid ] ||
1802                         error "FF parent OID $ff_poid != $lmm_oid"
1803                 [ $ff_pstripe = $stripe_nr ] ||
1804                         error "FF stripe $ff_pstripe != $stripe_nr"
1805
1806                 stripe_nr=$((stripe_nr + 1))
1807         done
1808 }
1809
1810 test_27z() {
1811         remote_ost_nodsh && skip "remote OST with nodsh" && return
1812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1813         test_mkdir -p $DIR/$tdir
1814
1815         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1816                 { error "setstripe -c -1 failed"; return 1; }
1817         # We need to send a write to every object to get parent FID info set.
1818         # This _should_ also work for setattr, but does not currently.
1819         # touch $DIR/$tdir/$tfile-1 ||
1820         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1821                 { error "dd $tfile-1 failed"; return 2; }
1822         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1823                 { error "setstripe -c -1 failed"; return 3; }
1824         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1825                 { error "dd $tfile-2 failed"; return 4; }
1826
1827         # make sure write RPCs have been sent to OSTs
1828         sync; sleep 5; sync
1829
1830         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1831         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1832 }
1833 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1834
1835 test_27A() { # b=19102
1836         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1837         local restore_size=$($GETSTRIPE -S $MOUNT)
1838         local restore_count=$($GETSTRIPE -c $MOUNT)
1839         local restore_offset=$($GETSTRIPE -i $MOUNT)
1840         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1841         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1842                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1843         local default_size=$($GETSTRIPE -S $MOUNT)
1844         local default_offset=$($GETSTRIPE -i $MOUNT)
1845         local dsize=$((1024 * 1024))
1846         [ $default_size -eq $dsize ] ||
1847                 error "stripe size $default_size != $dsize"
1848         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1849         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1850 }
1851 run_test 27A "check filesystem-wide default LOV EA values"
1852
1853 test_27B() { # LU-2523
1854         test_mkdir -p $DIR/$tdir
1855         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1856         touch $DIR/$tdir/f0
1857         # open f1 with O_LOV_DELAY_CREATE
1858         # rename f0 onto f1
1859         # call setstripe ioctl on open file descriptor for f1
1860         # close
1861         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1862                 $DIR/$tdir/f0
1863
1864         rm -f $DIR/$tdir/f1
1865         # open f1 with O_LOV_DELAY_CREATE
1866         # unlink f1
1867         # call setstripe ioctl on open file descriptor for f1
1868         # close
1869         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1870
1871         # Allow multiop to fail in imitation of NFS's busted semantics.
1872         true
1873 }
1874 run_test 27B "call setstripe on open unlinked file/rename victim"
1875
1876 test_27C() { #LU-2871
1877         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1878
1879         declare -a ost_idx
1880         local index
1881         local found
1882         local i
1883         local j
1884
1885         test_mkdir -p $DIR/$tdir
1886         cd $DIR/$tdir
1887         for i in $(seq 0 $((OSTCOUNT - 1))); do
1888                 # set stripe across all OSTs starting from OST$i
1889                 $SETSTRIPE -i $i -c -1 $tfile$i
1890                 # get striping information
1891                 ost_idx=($($GETSTRIPE $tfile$i |
1892                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1893                 echo ${ost_idx[@]}
1894
1895                 # check the layout
1896                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1897                         error "${#ost_idx[@]} != $OSTCOUNT"
1898
1899                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1900                         found=0
1901                         for j in $(echo ${ost_idx[@]}); do
1902                                 if [ $index -eq $j ]; then
1903                                         found=1
1904                                         break
1905                                 fi
1906                         done
1907                         [ $found = 1 ] ||
1908                                 error "Can not find $index in ${ost_idx[@]}"
1909                 done
1910         done
1911 }
1912 run_test 27C "check full striping across all OSTs"
1913
1914 # createtest also checks that device nodes are created and
1915 # then visible correctly (#2091)
1916 test_28() { # bug 2091
1917         test_mkdir $DIR/d28
1918         $CREATETEST $DIR/d28/ct || error
1919 }
1920 run_test 28 "create/mknod/mkdir with bad file types ============"
1921
1922 test_29() {
1923         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1924         cancel_lru_locks mdc
1925         test_mkdir $DIR/d29
1926         touch $DIR/d29/foo
1927         log 'first d29'
1928         ls -l $DIR/d29
1929
1930         declare -i LOCKCOUNTORIG=0
1931         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1932                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1933         done
1934         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1935
1936         declare -i LOCKUNUSEDCOUNTORIG=0
1937         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1938                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1939         done
1940
1941         log 'second d29'
1942         ls -l $DIR/d29
1943         log 'done'
1944
1945         declare -i LOCKCOUNTCURRENT=0
1946         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1947                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1948         done
1949
1950         declare -i LOCKUNUSEDCOUNTCURRENT=0
1951         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1952                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1953         done
1954
1955         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
1956                 $LCTL set_param -n ldlm.dump_namespaces ""
1957                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1958                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1959                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1960                 return 2
1961         fi
1962         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
1963                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1964                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1965                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1966                 return 3
1967         fi
1968 }
1969 run_test 29 "IT_GETATTR regression  ============================"
1970
1971 test_30a() { # was test_30
1972         cp $(which ls) $DIR || cp /bin/ls $DIR
1973         $DIR/ls / || error
1974         rm $DIR/ls
1975 }
1976 run_test 30a "execute binary from Lustre (execve) =============="
1977
1978 test_30b() {
1979         cp `which ls` $DIR || cp /bin/ls $DIR
1980         chmod go+rx $DIR/ls
1981         $RUNAS $DIR/ls / || error
1982         rm $DIR/ls
1983 }
1984 run_test 30b "execute binary from Lustre as non-root ==========="
1985
1986 test_30c() { # b=22376
1987         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1988         cp `which ls` $DIR || cp /bin/ls $DIR
1989         chmod a-rw $DIR/ls
1990         cancel_lru_locks mdc
1991         cancel_lru_locks osc
1992         $RUNAS $DIR/ls / || error
1993         rm -f $DIR/ls
1994 }
1995 run_test 30c "execute binary from Lustre without read perms ===="
1996
1997 test_31a() {
1998         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1999         $CHECKSTAT -a $DIR/f31 || error
2000 }
2001 run_test 31a "open-unlink file =================================="
2002
2003 test_31b() {
2004         touch $DIR/f31 || error
2005         ln $DIR/f31 $DIR/f31b || error
2006         $MULTIOP $DIR/f31b Ouc || error
2007         $CHECKSTAT -t file $DIR/f31 || error
2008 }
2009 run_test 31b "unlink file with multiple links while open ======="
2010
2011 test_31c() {
2012         touch $DIR/f31 || error
2013         ln $DIR/f31 $DIR/f31c || error
2014         multiop_bg_pause $DIR/f31 O_uc || return 1
2015         MULTIPID=$!
2016         $MULTIOP $DIR/f31c Ouc
2017         kill -USR1 $MULTIPID
2018         wait $MULTIPID
2019 }
2020 run_test 31c "open-unlink file with multiple links ============="
2021
2022 test_31d() {
2023         opendirunlink $DIR/d31d $DIR/d31d || error
2024         $CHECKSTAT -a $DIR/d31d || error
2025 }
2026 run_test 31d "remove of open directory ========================="
2027
2028 test_31e() { # bug 2904
2029         check_kernel_version 34 || return 0
2030         openfilleddirunlink $DIR/d31e || error
2031 }
2032 run_test 31e "remove of open non-empty directory ==============="
2033
2034 test_31f() { # bug 4554
2035         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2036         set -vx
2037         test_mkdir $DIR/d31f
2038         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2039         cp /etc/hosts $DIR/d31f
2040         ls -l $DIR/d31f
2041         $GETSTRIPE $DIR/d31f/hosts
2042         multiop_bg_pause $DIR/d31f D_c || return 1
2043         MULTIPID=$!
2044
2045         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2046         test_mkdir $DIR/d31f
2047         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2048         cp /etc/hosts $DIR/d31f
2049         ls -l $DIR/d31f
2050         $GETSTRIPE $DIR/d31f/hosts
2051         multiop_bg_pause $DIR/d31f D_c || return 1
2052         MULTIPID2=$!
2053
2054         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2055         wait $MULTIPID || error "first opendir $MULTIPID failed"
2056
2057         sleep 6
2058
2059         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2060         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2061         set +vx
2062 }
2063 run_test 31f "remove of open directory with open-unlink file ==="
2064
2065 test_31g() {
2066         echo "-- cross directory link --"
2067         test_mkdir $DIR/d31ga
2068         test_mkdir $DIR/d31gb
2069         touch $DIR/d31ga/f
2070         ln $DIR/d31ga/f $DIR/d31gb/g
2071         $CHECKSTAT -t file $DIR/d31ga/f || error "source"
2072         [ `stat -c%h $DIR/d31ga/f` == '2' ] || error "source nlink"
2073         $CHECKSTAT -t file $DIR/d31gb/g || error "target"
2074         [ `stat -c%h $DIR/d31gb/g` == '2' ] || error "target nlink"
2075 }
2076 run_test 31g "cross directory link==============="
2077
2078 test_31h() {
2079         echo "-- cross directory link --"
2080         test_mkdir $DIR/d31h
2081         test_mkdir $DIR/d31h/dir
2082         touch $DIR/d31h/f
2083         ln $DIR/d31h/f $DIR/d31h/dir/g
2084         $CHECKSTAT -t file $DIR/d31h/f || error "source"
2085         [ `stat -c%h $DIR/d31h/f` == '2' ] || error "source nlink"
2086         $CHECKSTAT -t file $DIR/d31h/dir/g || error "target"
2087         [ `stat -c%h $DIR/d31h/dir/g` == '2' ] || error "target nlink"
2088 }
2089 run_test 31h "cross directory link under child==============="
2090
2091 test_31i() {
2092         echo "-- cross directory link --"
2093         test_mkdir $DIR/d31i
2094         test_mkdir $DIR/d31i/dir
2095         touch $DIR/d31i/dir/f
2096         ln $DIR/d31i/dir/f $DIR/d31i/g
2097         $CHECKSTAT -t file $DIR/d31i/dir/f || error "source"
2098         [ `stat -c%h $DIR/d31i/dir/f` == '2' ] || error "source nlink"
2099         $CHECKSTAT -t file $DIR/d31i/g || error "target"
2100         [ `stat -c%h $DIR/d31i/g` == '2' ] || error "target nlink"
2101 }
2102 run_test 31i "cross directory link under parent==============="
2103
2104
2105 test_31j() {
2106         test_mkdir $DIR/d31j
2107         test_mkdir $DIR/d31j/dir1
2108         ln $DIR/d31j/dir1 $DIR/d31j/dir2 && error "ln for dir"
2109         link $DIR/d31j/dir1 $DIR/d31j/dir3 && error "link for dir"
2110         mlink $DIR/d31j/dir1 $DIR/d31j/dir4 && error "mlink for dir"
2111         mlink $DIR/d31j/dir1 $DIR/d31j/dir1 && error "mlink to the same dir"
2112         return 0
2113 }
2114 run_test 31j "link for directory==============="
2115
2116
2117 test_31k() {
2118         test_mkdir $DIR/d31k
2119         touch $DIR/d31k/s
2120         touch $DIR/d31k/exist
2121         mlink $DIR/d31k/s $DIR/d31k/t || error "mlink"
2122         mlink $DIR/d31k/s $DIR/d31k/exist && error "mlink to exist file"
2123         mlink $DIR/d31k/s $DIR/d31k/s && error "mlink to the same file"
2124         mlink $DIR/d31k/s $DIR/d31k && error "mlink to parent dir"
2125         mlink $DIR/d31k $DIR/d31k/s && error "mlink parent dir to target"
2126         mlink $DIR/d31k/not-exist $DIR/d31k/foo && error "mlink non-existing to new"
2127         mlink $DIR/d31k/not-exist $DIR/d31k/s && error "mlink non-existing to exist"
2128         return 0
2129 }
2130 run_test 31k "link to file: the same, non-existing, dir==============="
2131
2132 test_31m() {
2133         test_mkdir $DIR/d31m
2134         touch $DIR/d31m/s
2135         test_mkdir $DIR/d31m2
2136         touch $DIR/d31m2/exist
2137         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2138         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2139         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2140         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2141         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2142         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2143         return 0
2144 }
2145 run_test 31m "link to file: the same, non-existing, dir==============="
2146
2147 test_31n() {
2148         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2149         nlink=$(stat --format=%h $DIR/$tfile)
2150         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2151         local fd=$(free_fd)
2152         local cmd="exec $fd<$DIR/$tfile"
2153         eval $cmd
2154         cmd="exec $fd<&-"
2155         trap "eval $cmd" EXIT
2156         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2157         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2158         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2159         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2160         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2161         eval $cmd
2162 }
2163 run_test 31n "check link count of unlinked file"
2164
2165 link_one() {
2166         local TEMPNAME=$(mktemp $1_XXXXXX)
2167         mlink $TEMPNAME $1 2> /dev/null &&
2168                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2169         munlink $TEMPNAME
2170 }
2171
2172 test_31o() { # LU-2901
2173         mkdir -p $DIR/$tdir
2174         for LOOP in $(seq 100); do
2175                 rm -f $DIR/$tdir/$tfile*
2176                 for THREAD in $(seq 8); do
2177                         link_one $DIR/$tdir/$tfile.$LOOP &
2178                 done
2179                 wait
2180                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2181                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2182                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2183                         break || true
2184         done
2185 }
2186 run_test 31o "duplicate hard links with same filename"
2187
2188 cleanup_test32_mount() {
2189         trap 0
2190         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2191 }
2192
2193 test_32a() {
2194         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2195         echo "== more mountpoints and symlinks ================="
2196         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2197         trap cleanup_test32_mount EXIT
2198         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2199         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2200         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2201         cleanup_test32_mount
2202 }
2203 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2204
2205 test_32b() {
2206         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2207         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2208         trap cleanup_test32_mount EXIT
2209         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2210         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2211         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2212         cleanup_test32_mount
2213 }
2214 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2215
2216 test_32c() {
2217         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2218         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2219         trap cleanup_test32_mount EXIT
2220         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2221         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2222         test_mkdir -p $DIR/$tdir/d2/test_dir
2223         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2224         cleanup_test32_mount
2225 }
2226 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2227
2228 test_32d() {
2229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2230         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2231         trap cleanup_test32_mount EXIT
2232         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2233         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2234         test_mkdir -p $DIR/$tdir/d2/test_dir
2235         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2236         cleanup_test32_mount
2237 }
2238 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2239
2240 test_32e() {
2241         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2242         test_mkdir -p $DIR/d32e/tmp
2243         TMP_DIR=$DIR/d32e/tmp
2244         ln -s $DIR/d32e $TMP_DIR/symlink11
2245         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2246         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2247         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2248 }
2249 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2250
2251 test_32f() {
2252         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2253         test_mkdir -p $DIR/d32f/tmp
2254         TMP_DIR=$DIR/d32f/tmp
2255         ln -s $DIR/d32f $TMP_DIR/symlink11
2256         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2257         ls $DIR/d32f/tmp/symlink11  || error
2258         ls $DIR/d32f/symlink01 || error
2259 }
2260 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2261
2262 test_32g() {
2263         TMP_DIR=$DIR/$tdir/tmp
2264         test_mkdir -p $DIR/$tdir/tmp
2265         test_mkdir $DIR/${tdir}2
2266         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2267         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2268         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2269         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2270         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2271         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2272 }
2273 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2274
2275 test_32h() {
2276         rm -fr $DIR/$tdir $DIR/${tdir}2
2277         TMP_DIR=$DIR/$tdir/tmp
2278         test_mkdir -p $DIR/$tdir/tmp
2279         test_mkdir $DIR/${tdir}2
2280         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2281         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2282         ls $TMP_DIR/symlink12 || error
2283         ls $DIR/$tdir/symlink02  || error
2284 }
2285 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2286
2287 test_32i() {
2288         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2289         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2290         trap cleanup_test32_mount EXIT
2291         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2292         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2293         touch $DIR/$tdir/test_file
2294         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2295         cleanup_test32_mount
2296 }
2297 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2298
2299 test_32j() {
2300         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2301         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2302         trap cleanup_test32_mount EXIT
2303         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2304         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2305         touch $DIR/$tdir/test_file
2306         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2307         cleanup_test32_mount
2308 }
2309 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2310
2311 test_32k() {
2312         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2313         rm -fr $DIR/$tdir
2314         trap cleanup_test32_mount EXIT
2315         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2316         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2317         test_mkdir -p $DIR/$tdir/d2
2318         touch $DIR/$tdir/d2/test_file || error
2319         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2320         cleanup_test32_mount
2321 }
2322 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2323
2324 test_32l() {
2325         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2326         rm -fr $DIR/$tdir
2327         trap cleanup_test32_mount EXIT
2328         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2329         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2330         test_mkdir -p $DIR/$tdir/d2
2331         touch $DIR/$tdir/d2/test_file
2332         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2333         cleanup_test32_mount
2334 }
2335 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2336
2337 test_32m() {
2338         rm -fr $DIR/d32m
2339         test_mkdir -p $DIR/d32m/tmp
2340         TMP_DIR=$DIR/d32m/tmp
2341         ln -s $DIR $TMP_DIR/symlink11
2342         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2343         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2344         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2345 }
2346 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2347
2348 test_32n() {
2349         rm -fr $DIR/d32n
2350         test_mkdir -p $DIR/d32n/tmp
2351         TMP_DIR=$DIR/d32n/tmp
2352         ln -s $DIR $TMP_DIR/symlink11
2353         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2354         ls -l $DIR/d32n/tmp/symlink11  || error
2355         ls -l $DIR/d32n/symlink01 || error
2356 }
2357 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2358
2359 test_32o() {
2360         touch $DIR/$tfile
2361         test_mkdir -p $DIR/d32o/tmp
2362         TMP_DIR=$DIR/d32o/tmp
2363         ln -s $DIR/$tfile $TMP_DIR/symlink12
2364         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2365         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2366         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2367         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2368         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2369 }
2370 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2371
2372 test_32p() {
2373     log 32p_1
2374         rm -fr $DIR/d32p
2375     log 32p_2
2376         rm -f $DIR/$tfile
2377     log 32p_3
2378         touch $DIR/$tfile
2379     log 32p_4
2380         test_mkdir -p $DIR/d32p/tmp
2381     log 32p_5
2382         TMP_DIR=$DIR/d32p/tmp
2383     log 32p_6
2384         ln -s $DIR/$tfile $TMP_DIR/symlink12
2385     log 32p_7
2386         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2387     log 32p_8
2388         cat $DIR/d32p/tmp/symlink12 || error
2389     log 32p_9
2390         cat $DIR/d32p/symlink02 || error
2391     log 32p_10
2392 }
2393 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2394
2395 cleanup_testdir_mount() {
2396         trap 0
2397         $UMOUNT -d $DIR/$tdir
2398 }
2399
2400 test_32q() {
2401         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2402         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2403         trap cleanup_testdir_mount EXIT
2404         test_mkdir -p $DIR/$tdir
2405         touch $DIR/$tdir/under_the_mount
2406         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2407         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2408         cleanup_testdir_mount
2409 }
2410 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2411
2412 test_32r() {
2413         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2414         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2415         trap cleanup_testdir_mount EXIT
2416         test_mkdir -p $DIR/$tdir
2417         touch $DIR/$tdir/under_the_mount
2418         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2419         ls $DIR/$tdir | grep -q under_the_mount && error || true
2420         cleanup_testdir_mount
2421 }
2422 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2423
2424 test_33aa() {
2425         rm -f $DIR/$tfile
2426         touch $DIR/$tfile
2427         chmod 444 $DIR/$tfile
2428         chown $RUNAS_ID $DIR/$tfile
2429         log 33_1
2430         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2431         log 33_2
2432 }
2433 run_test 33aa "write file with mode 444 (should return error) ===="
2434
2435 test_33a() {
2436         rm -fr $DIR/d33
2437         test_mkdir -p $DIR/d33
2438         chown $RUNAS_ID $DIR/d33
2439         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2440         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2441                 error "open RDWR" || true
2442 }
2443 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2444
2445 test_33b() {
2446         rm -fr $DIR/d33
2447         test_mkdir -p $DIR/d33
2448         chown $RUNAS_ID $DIR/d33
2449         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
2450 }
2451 run_test 33b "test open file with malformed flags (No panic and return error)"
2452
2453 test_33c() {
2454         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2455         local ostnum
2456         local ostname
2457         local write_bytes
2458         local all_zeros
2459
2460         remote_ost_nodsh && skip "remote OST with nodsh" && return
2461         all_zeros=:
2462         rm -fr $DIR/d33
2463         test_mkdir -p $DIR/d33
2464         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2465
2466         sync
2467         for ostnum in $(seq $OSTCOUNT); do
2468                 # test-framework's OST numbering is one-based, while Lustre's
2469                 # is zero-based
2470                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2471                 # Parsing llobdstat's output sucks; we could grep the /proc
2472                 # path, but that's likely to not be as portable as using the
2473                 # llobdstat utility.  So we parse lctl output instead.
2474                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2475                         obdfilter/$ostname/stats |
2476                         awk '/^write_bytes/ {print $7}' )
2477                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2478                 if (( ${write_bytes:-0} > 0 ))
2479                 then
2480                         all_zeros=false
2481                         break;
2482                 fi
2483         done
2484
2485         $all_zeros || return 0
2486
2487         # Write four bytes
2488         echo foo > $DIR/d33/bar
2489         # Really write them
2490         sync
2491
2492         # Total up write_bytes after writing.  We'd better find non-zeros.
2493         for ostnum in $(seq $OSTCOUNT); do
2494                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2495                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2496                         obdfilter/$ostname/stats |
2497                         awk '/^write_bytes/ {print $7}' )
2498                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2499                 if (( ${write_bytes:-0} > 0 ))
2500                 then
2501                         all_zeros=false
2502                         break;
2503                 fi
2504         done
2505
2506         if $all_zeros
2507         then
2508                 for ostnum in $(seq $OSTCOUNT); do
2509                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2510                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2511                         do_facet ost$ostnum lctl get_param -n \
2512                                 obdfilter/$ostname/stats
2513                 done
2514                 error "OST not keeping write_bytes stats (b22312)"
2515         fi
2516 }
2517 run_test 33c "test llobdstat and write_bytes"
2518
2519 test_33d() {
2520         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2522         local MDTIDX=1
2523         local remote_dir=$DIR/$tdir/remote_dir
2524
2525         mkdir -p $DIR/$tdir
2526         $LFS mkdir -i $MDTIDX $remote_dir ||
2527                 error "create remote directory failed"
2528
2529         touch $remote_dir/$tfile
2530         chmod 444 $remote_dir/$tfile
2531         chown $RUNAS_ID $remote_dir/$tfile
2532
2533         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2534
2535         chown $RUNAS_ID $remote_dir
2536         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2537                                         error "create" || true
2538         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2539                                     error "open RDWR" || true
2540         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2541                                     error "create" || true
2542 }
2543 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2544
2545 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2546 test_34a() {
2547         rm -f $DIR/f34
2548         $MCREATE $DIR/f34 || error
2549         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2550         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2551         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2552         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2553 }
2554 run_test 34a "truncate file that has not been opened ==========="
2555
2556 test_34b() {
2557         [ ! -f $DIR/f34 ] && test_34a
2558         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2559         $OPENFILE -f O_RDONLY $DIR/f34
2560         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2561         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2562 }
2563 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2564
2565 test_34c() {
2566         [ ! -f $DIR/f34 ] && test_34a
2567         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2568         $OPENFILE -f O_RDWR $DIR/f34
2569         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2570         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2571 }
2572 run_test 34c "O_RDWR opening file-with-size works =============="
2573
2574 test_34d() {
2575         [ ! -f $DIR/f34 ] && test_34a
2576         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2577         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2578         rm $DIR/f34
2579 }
2580 run_test 34d "write to sparse file ============================="
2581
2582 test_34e() {
2583         rm -f $DIR/f34e
2584         $MCREATE $DIR/f34e || error
2585         $TRUNCATE $DIR/f34e 1000 || error
2586         $CHECKSTAT -s 1000 $DIR/f34e || error
2587         $OPENFILE -f O_RDWR $DIR/f34e
2588         $CHECKSTAT -s 1000 $DIR/f34e || error
2589 }
2590 run_test 34e "create objects, some with size and some without =="
2591
2592 test_34f() { # bug 6242, 6243
2593         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2594         SIZE34F=48000
2595         rm -f $DIR/f34f
2596         $MCREATE $DIR/f34f || error
2597         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2598         dd if=$DIR/f34f of=$TMP/f34f
2599         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2600         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2601         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2602         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2603         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2604 }
2605 run_test 34f "read from a file with no objects until EOF ======="
2606
2607 test_34g() {
2608         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2609         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2610         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2611         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2612         cancel_lru_locks osc
2613         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2614                 error "wrong size after lock cancel"
2615
2616         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2617         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2618                 error "expanding truncate failed"
2619         cancel_lru_locks osc
2620         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2621                 error "wrong expanded size after lock cancel"
2622 }
2623 run_test 34g "truncate long file ==============================="
2624
2625 test_34h() {
2626         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2627         local gid=10
2628         local sz=1000
2629
2630         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2631         sync # Flush the cache so that multiop below does not block on cache
2632              # flush when getting the group lock
2633         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2634         MULTIPID=$!
2635
2636         # Since just timed wait is not good enough, let's do a sync write
2637         # that way we are sure enough time for a roundtrip + processing
2638         # passed + 2 seconds of extra margin.
2639         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2640         rm $DIR/${tfile}-1
2641         sleep 2
2642
2643         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2644                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2645                 kill -9 $MULTIPID
2646         fi
2647         wait $MULTIPID
2648         local nsz=`stat -c %s $DIR/$tfile`
2649         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2650 }
2651 run_test 34h "ftruncate file under grouplock should not block"
2652
2653 test_35a() {
2654         cp /bin/sh $DIR/f35a
2655         chmod 444 $DIR/f35a
2656         chown $RUNAS_ID $DIR/f35a
2657         $RUNAS $DIR/f35a && error || true
2658         rm $DIR/f35a
2659 }
2660 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2661
2662 test_36a() {
2663         rm -f $DIR/f36
2664         utime $DIR/f36 || error
2665 }
2666 run_test 36a "MDS utime check (mknod, utime) ==================="
2667
2668 test_36b() {
2669         echo "" > $DIR/f36
2670         utime $DIR/f36 || error
2671 }
2672 run_test 36b "OST utime check (open, utime) ===================="
2673
2674 test_36c() {
2675         rm -f $DIR/d36/f36
2676         test_mkdir $DIR/d36
2677         chown $RUNAS_ID $DIR/d36
2678         $RUNAS utime $DIR/d36/f36 || error
2679 }
2680 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2681
2682 test_36d() {
2683         [ ! -d $DIR/d36 ] && test_36c
2684         echo "" > $DIR/d36/f36
2685         $RUNAS utime $DIR/d36/f36 || error
2686 }
2687 run_test 36d "non-root OST utime check (open, utime) ==========="
2688
2689 test_36e() {
2690         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2691         test_mkdir -p $DIR/$tdir
2692         touch $DIR/$tdir/$tfile
2693         $RUNAS utime $DIR/$tdir/$tfile && \
2694                 error "utime worked, expected failure" || true
2695 }
2696 run_test 36e "utime on non-owned file (should return error) ===="
2697
2698 subr_36fh() {
2699         local fl="$1"
2700         local LANG_SAVE=$LANG
2701         local LC_LANG_SAVE=$LC_LANG
2702         export LANG=C LC_LANG=C # for date language
2703
2704         DATESTR="Dec 20  2000"
2705         test_mkdir -p $DIR/$tdir
2706         lctl set_param fail_loc=$fl
2707         date; date +%s
2708         cp /etc/hosts $DIR/$tdir/$tfile
2709         sync & # write RPC generated with "current" inode timestamp, but delayed
2710         sleep 1
2711         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2712         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2713         cancel_lru_locks osc
2714         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2715         date; date +%s
2716         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2717                 echo "BEFORE: $LS_BEFORE" && \
2718                 echo "AFTER : $LS_AFTER" && \
2719                 echo "WANT  : $DATESTR" && \
2720                 error "$DIR/$tdir/$tfile timestamps changed" || true
2721
2722         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2723 }
2724
2725 test_36f() {
2726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2727         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2728         subr_36fh "0x80000214"
2729 }
2730 run_test 36f "utime on file racing with OST BRW write =========="
2731
2732 test_36g() {
2733         remote_ost_nodsh && skip "remote OST with nodsh" && return
2734         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2735         local fmd_max_age
2736         local fmd_before
2737         local fmd_after
2738
2739         test_mkdir -p $DIR/$tdir
2740         fmd_max_age=$(do_facet ost1 \
2741                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2742                 head -n 1")
2743
2744         fmd_before=$(do_facet ost1 \
2745                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2746         touch $DIR/$tdir/$tfile
2747         sleep $((fmd_max_age + 12))
2748         fmd_after=$(do_facet ost1 \
2749                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2750
2751         echo "fmd_before: $fmd_before"
2752         echo "fmd_after: $fmd_after"
2753         [[ $fmd_after -gt $fmd_before ]] &&
2754                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2755                 error "fmd didn't expire after ping" || true
2756 }
2757 run_test 36g "filter mod data cache expiry ====================="
2758
2759 test_36h() {
2760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2761         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2762         subr_36fh "0x80000227"
2763 }
2764 run_test 36h "utime on file racing with OST BRW write =========="
2765
2766 # test_37 - duplicate with tests 32q 32r
2767
2768 test_38() {
2769         local file=$DIR/$tfile
2770         touch $file
2771         openfile -f O_DIRECTORY $file
2772         local RC=$?
2773         local ENOTDIR=20
2774         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2775         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2776 }
2777 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2778
2779 test_39() {
2780         touch $DIR/$tfile
2781         touch $DIR/${tfile}2
2782 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2783 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2784 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2785         sleep 2
2786         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2787         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2788                 echo "mtime"
2789                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2790                 echo "atime"
2791                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2792                 echo "ctime"
2793                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2794                 error "O_TRUNC didn't change timestamps"
2795         fi
2796 }
2797 run_test 39 "mtime changed on create ==========================="
2798
2799 test_39b() {
2800         test_mkdir -p $DIR/$tdir
2801         cp -p /etc/passwd $DIR/$tdir/fopen
2802         cp -p /etc/passwd $DIR/$tdir/flink
2803         cp -p /etc/passwd $DIR/$tdir/funlink
2804         cp -p /etc/passwd $DIR/$tdir/frename
2805         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2806
2807         sleep 1
2808         echo "aaaaaa" >> $DIR/$tdir/fopen
2809         echo "aaaaaa" >> $DIR/$tdir/flink
2810         echo "aaaaaa" >> $DIR/$tdir/funlink
2811         echo "aaaaaa" >> $DIR/$tdir/frename
2812
2813         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2814         local link_new=`stat -c %Y $DIR/$tdir/flink`
2815         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2816         local rename_new=`stat -c %Y $DIR/$tdir/frename`
2817
2818         cat $DIR/$tdir/fopen > /dev/null
2819         ln $DIR/$tdir/flink $DIR/$tdir/flink2
2820         rm -f $DIR/$tdir/funlink2
2821         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
2822
2823         for (( i=0; i < 2; i++ )) ; do
2824                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
2825                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
2826                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
2827                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
2828
2829                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
2830                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
2831                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
2832                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
2833
2834                 cancel_lru_locks osc
2835                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2836         done
2837 }
2838 run_test 39b "mtime change on open, link, unlink, rename  ======"
2839
2840 # this should be set to past
2841 TEST_39_MTIME=`date -d "1 year ago" +%s`
2842
2843 # bug 11063
2844 test_39c() {
2845         touch $DIR1/$tfile
2846         sleep 2
2847         local mtime0=`stat -c %Y $DIR1/$tfile`
2848
2849         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2850         local mtime1=`stat -c %Y $DIR1/$tfile`
2851         [ "$mtime1" = $TEST_39_MTIME ] || \
2852                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
2853
2854         local d1=`date +%s`
2855         echo hello >> $DIR1/$tfile
2856         local d2=`date +%s`
2857         local mtime2=`stat -c %Y $DIR1/$tfile`
2858         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
2859                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
2860
2861         mv $DIR1/$tfile $DIR1/$tfile-1
2862
2863         for (( i=0; i < 2; i++ )) ; do
2864                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
2865                 [ "$mtime2" = "$mtime3" ] || \
2866                         error "mtime ($mtime2) changed (to $mtime3) on rename"
2867
2868                 cancel_lru_locks osc
2869                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2870         done
2871 }
2872 run_test 39c "mtime change on rename ==========================="
2873
2874 # bug 21114
2875 test_39d() {
2876         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2877         touch $DIR1/$tfile
2878
2879         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2880
2881         for (( i=0; i < 2; i++ )) ; do
2882                 local mtime=`stat -c %Y $DIR1/$tfile`
2883                 [ $mtime = $TEST_39_MTIME ] || \
2884                         error "mtime($mtime) is not set to $TEST_39_MTIME"
2885
2886                 cancel_lru_locks osc
2887                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2888         done
2889 }
2890 run_test 39d "create, utime, stat =============================="
2891
2892 # bug 21114
2893 test_39e() {
2894         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2895         touch $DIR1/$tfile
2896         local mtime1=`stat -c %Y $DIR1/$tfile`
2897
2898         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2899
2900         for (( i=0; i < 2; i++ )) ; do
2901                 local mtime2=`stat -c %Y $DIR1/$tfile`
2902                 [ $mtime2 = $TEST_39_MTIME ] || \
2903                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2904
2905                 cancel_lru_locks osc
2906                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2907         done
2908 }
2909 run_test 39e "create, stat, utime, stat ========================"
2910
2911 # bug 21114
2912 test_39f() {
2913         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2914         touch $DIR1/$tfile
2915         mtime1=`stat -c %Y $DIR1/$tfile`
2916
2917         sleep 2
2918         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2919
2920         for (( i=0; i < 2; i++ )) ; do
2921                 local mtime2=`stat -c %Y $DIR1/$tfile`
2922                 [ $mtime2 = $TEST_39_MTIME ] || \
2923                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2924
2925                 cancel_lru_locks osc
2926                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2927         done
2928 }
2929 run_test 39f "create, stat, sleep, utime, stat ================="
2930
2931 # bug 11063
2932 test_39g() {
2933         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2934         echo hello >> $DIR1/$tfile
2935         local mtime1=`stat -c %Y $DIR1/$tfile`
2936
2937         sleep 2
2938         chmod o+r $DIR1/$tfile
2939
2940         for (( i=0; i < 2; i++ )) ; do
2941                 local mtime2=`stat -c %Y $DIR1/$tfile`
2942                 [ "$mtime1" = "$mtime2" ] || \
2943                         error "lost mtime: $mtime2, should be $mtime1"
2944
2945                 cancel_lru_locks osc
2946                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2947         done
2948 }
2949 run_test 39g "write, chmod, stat ==============================="
2950
2951 # bug 11063
2952 test_39h() {
2953         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2954         touch $DIR1/$tfile
2955         sleep 1
2956
2957         local d1=`date`
2958         echo hello >> $DIR1/$tfile
2959         local mtime1=`stat -c %Y $DIR1/$tfile`
2960
2961         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2962         local d2=`date`
2963         if [ "$d1" != "$d2" ]; then
2964                 echo "write and touch not within one second"
2965         else
2966                 for (( i=0; i < 2; i++ )) ; do
2967                         local mtime2=`stat -c %Y $DIR1/$tfile`
2968                         [ "$mtime2" = $TEST_39_MTIME ] || \
2969                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
2970
2971                         cancel_lru_locks osc
2972                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2973                 done
2974         fi
2975 }
2976 run_test 39h "write, utime within one second, stat ============="
2977
2978 test_39i() {
2979         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2980         touch $DIR1/$tfile
2981         sleep 1
2982
2983         echo hello >> $DIR1/$tfile
2984         local mtime1=`stat -c %Y $DIR1/$tfile`
2985
2986         mv $DIR1/$tfile $DIR1/$tfile-1
2987
2988         for (( i=0; i < 2; i++ )) ; do
2989                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2990
2991                 [ "$mtime1" = "$mtime2" ] || \
2992                         error "lost mtime: $mtime2, should be $mtime1"
2993
2994                 cancel_lru_locks osc
2995                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2996         done
2997 }
2998 run_test 39i "write, rename, stat =============================="
2999
3000 test_39j() {
3001         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3002         start_full_debug_logging
3003         touch $DIR1/$tfile
3004         sleep 1
3005
3006         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3007         lctl set_param fail_loc=0x80000412
3008         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3009                 error "multiop failed"
3010         local multipid=$!
3011         local mtime1=`stat -c %Y $DIR1/$tfile`
3012
3013         mv $DIR1/$tfile $DIR1/$tfile-1
3014
3015         kill -USR1 $multipid
3016         wait $multipid || error "multiop close failed"
3017
3018         for (( i=0; i < 2; i++ )) ; do
3019                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3020                 [ "$mtime1" = "$mtime2" ] ||
3021                         error "mtime is lost on close: $mtime2, " \
3022                               "should be $mtime1"
3023
3024                 cancel_lru_locks osc
3025                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3026         done
3027         lctl set_param fail_loc=0
3028         stop_full_debug_logging
3029 }
3030 run_test 39j "write, rename, close, stat ======================="
3031
3032 test_39k() {
3033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3034         touch $DIR1/$tfile
3035         sleep 1
3036
3037         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3038         local multipid=$!
3039         local mtime1=`stat -c %Y $DIR1/$tfile`
3040
3041         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3042
3043         kill -USR1 $multipid
3044         wait $multipid || error "multiop close failed"
3045
3046         for (( i=0; i < 2; i++ )) ; do
3047                 local mtime2=`stat -c %Y $DIR1/$tfile`
3048
3049                 [ "$mtime2" = $TEST_39_MTIME ] || \
3050                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3051
3052                 cancel_lru_locks osc
3053                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3054         done
3055 }
3056 run_test 39k "write, utime, close, stat ========================"
3057
3058 # this should be set to future
3059 TEST_39_ATIME=`date -d "1 year" +%s`
3060
3061 test_39l() {
3062         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3063         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3064         local atime_diff=$(do_facet $SINGLEMDS \
3065                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3066         rm -rf $DIR/$tdir
3067         mkdir -p $DIR/$tdir
3068
3069         # test setting directory atime to future
3070         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3071         local atime=$(stat -c %X $DIR/$tdir)
3072         [ "$atime" = $TEST_39_ATIME ] || \
3073                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3074
3075         # test setting directory atime from future to now
3076         local d1=$(date +%s)
3077         ls $DIR/$tdir
3078         local d2=$(date +%s)
3079
3080         cancel_lru_locks mdc
3081         atime=$(stat -c %X $DIR/$tdir)
3082         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3083                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3084
3085         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3086         sleep 3
3087
3088         # test setting directory atime when now > dir atime + atime_diff
3089         d1=$(date +%s)
3090         ls $DIR/$tdir
3091         d2=$(date +%s)
3092         cancel_lru_locks mdc
3093         atime=$(stat -c %X $DIR/$tdir)
3094         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3095                 error "atime is not updated  : $atime, should be $d2"
3096
3097         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3098         sleep 3
3099
3100         # test not setting directory atime when now < dir atime + atime_diff
3101         ls $DIR/$tdir
3102         cancel_lru_locks mdc
3103         atime=$(stat -c %X $DIR/$tdir)
3104         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3105                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3106
3107         do_facet $SINGLEMDS \
3108                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3109 }
3110 run_test 39l "directory atime update ==========================="
3111
3112 test_39m() {
3113         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3114         touch $DIR1/$tfile
3115         sleep 2
3116         local far_past_mtime=$(date -d "May 29 1953" +%s)
3117         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3118
3119         touch -m -d @$far_past_mtime $DIR1/$tfile
3120         touch -a -d @$far_past_atime $DIR1/$tfile
3121
3122         for (( i=0; i < 2; i++ )) ; do
3123                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3124                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3125                         error "atime or mtime set incorrectly"
3126
3127                 cancel_lru_locks osc
3128                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3129         done
3130 }
3131 run_test 39m "test atime and mtime before 1970"
3132
3133 test_39n() { # LU-3832
3134         local atime_diff=$(do_facet $SINGLEMDS \
3135                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3136         local atime0
3137         local atime1
3138         local atime2
3139
3140         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3141
3142         rm -rf $DIR/$tfile
3143         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3144         atime0=$(stat -c %X $DIR/$tfile)
3145
3146         sleep 5
3147         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3148         atime1=$(stat -c %X $DIR/$tfile)
3149
3150         sleep 5
3151         cancel_lru_locks mdc
3152         cancel_lru_locks osc
3153         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3154         atime2=$(stat -c %X $DIR/$tfile)
3155
3156         do_facet $SINGLEMDS \
3157                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3158
3159         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3160         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3161 }
3162 run_test 39n "check that O_NOATIME is honored"
3163
3164 test_39o() {
3165         TESTDIR=$DIR/$tdir/$tfile
3166         [ -e $TESTDIR ] && rm -rf $TESTDIR
3167         mkdir -p $TESTDIR
3168         cd $TESTDIR
3169         links1=2
3170         ls
3171         mkdir a b
3172         ls
3173         links2=$(stat -c %h .)
3174         [ $(($links1 + 2)) != $links2 ] &&
3175                 error "wrong links count $(($links1 + 2)) != $links2"
3176         rmdir b
3177         links3=$(stat -c %h .)
3178         [ $(($links1 + 1)) != $links3 ] &&
3179                 error "wrong links count $links1 != $links3"
3180         return 0
3181 }
3182 run_test 39o "directory cached attributes updated after create ========"
3183
3184 test_40() {
3185         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3186         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3187                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3188         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3189                 error "$tfile is not 4096 bytes in size"
3190 }
3191 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3192
3193 test_41() {
3194         # bug 1553
3195         small_write $DIR/f41 18
3196 }
3197 run_test 41 "test small file write + fstat ====================="
3198
3199 count_ost_writes() {
3200         lctl get_param -n osc.*.stats |
3201                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3202                         END { printf("%0.0f", writes) }'
3203 }
3204
3205 # decent default
3206 WRITEBACK_SAVE=500
3207 DIRTY_RATIO_SAVE=40
3208 MAX_DIRTY_RATIO=50
3209 BG_DIRTY_RATIO_SAVE=10
3210 MAX_BG_DIRTY_RATIO=25
3211
3212 start_writeback() {
3213         trap 0
3214         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3215         # dirty_ratio, dirty_background_ratio
3216         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3217                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3218                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3219                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3220         else
3221                 # if file not here, we are a 2.4 kernel
3222                 kill -CONT `pidof kupdated`
3223         fi
3224 }
3225
3226 stop_writeback() {
3227         # setup the trap first, so someone cannot exit the test at the
3228         # exact wrong time and mess up a machine
3229         trap start_writeback EXIT
3230         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3231         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3232                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3233                 sysctl -w vm.dirty_writeback_centisecs=0
3234                 sysctl -w vm.dirty_writeback_centisecs=0
3235                 # save and increase /proc/sys/vm/dirty_ratio
3236                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3237                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3238                 # save and increase /proc/sys/vm/dirty_background_ratio
3239                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3240                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3241         else
3242                 # if file not here, we are a 2.4 kernel
3243                 kill -STOP `pidof kupdated`
3244         fi
3245 }
3246
3247 # ensure that all stripes have some grant before we test client-side cache
3248 setup_test42() {
3249         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3250                 dd if=/dev/zero of=$i bs=4k count=1
3251                 rm $i
3252         done
3253 }
3254
3255 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3256 # file truncation, and file removal.
3257 test_42a() {
3258         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3259         setup_test42
3260         cancel_lru_locks osc
3261         stop_writeback
3262         sync; sleep 1; sync # just to be safe
3263         BEFOREWRITES=`count_ost_writes`
3264         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3265         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3266         AFTERWRITES=`count_ost_writes`
3267         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3268                 error "$BEFOREWRITES < $AFTERWRITES"
3269         start_writeback
3270 }
3271 run_test 42a "ensure that we don't flush on close =============="
3272
3273 test_42b() {
3274         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3275         setup_test42
3276         cancel_lru_locks osc
3277         stop_writeback
3278         sync
3279         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3280         BEFOREWRITES=$(count_ost_writes)
3281         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3282         AFTERWRITES=$(count_ost_writes)
3283         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3284                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3285         fi
3286         BEFOREWRITES=$(count_ost_writes)
3287         sync || error "sync: $?"
3288         AFTERWRITES=$(count_ost_writes)
3289         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3290                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3291         fi
3292         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3293         start_writeback
3294         return 0
3295 }
3296 run_test 42b "test destroy of file with cached dirty data ======"
3297
3298 # if these tests just want to test the effect of truncation,
3299 # they have to be very careful.  consider:
3300 # - the first open gets a {0,EOF}PR lock
3301 # - the first write conflicts and gets a {0, count-1}PW
3302 # - the rest of the writes are under {count,EOF}PW
3303 # - the open for truncate tries to match a {0,EOF}PR
3304 #   for the filesize and cancels the PWs.
3305 # any number of fixes (don't get {0,EOF} on open, match
3306 # composite locks, do smarter file size management) fix
3307 # this, but for now we want these tests to verify that
3308 # the cancellation with truncate intent works, so we
3309 # start the file with a full-file pw lock to match against
3310 # until the truncate.
3311 trunc_test() {
3312         test=$1
3313         file=$DIR/$test
3314         offset=$2
3315         cancel_lru_locks osc
3316         stop_writeback
3317         # prime the file with 0,EOF PW to match
3318         touch $file
3319         $TRUNCATE $file 0
3320         sync; sync
3321         # now the real test..
3322         dd if=/dev/zero of=$file bs=1024 count=100
3323         BEFOREWRITES=`count_ost_writes`
3324         $TRUNCATE $file $offset
3325         cancel_lru_locks osc
3326         AFTERWRITES=`count_ost_writes`
3327         start_writeback
3328 }
3329
3330 test_42c() {
3331         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3332         trunc_test 42c 1024
3333         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3334             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3335         rm $file
3336 }
3337 run_test 42c "test partial truncate of file with cached dirty data"
3338
3339 test_42d() {
3340         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3341         trunc_test 42d 0
3342         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3343             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3344         rm $file
3345 }
3346 run_test 42d "test complete truncate of file with cached dirty data"
3347
3348 test_42e() { # bug22074
3349         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3350         local TDIR=$DIR/${tdir}e
3351         local pagesz=$(page_size)
3352         local pages=16 # hardcoded 16 pages, don't change it.
3353         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3354         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3355         local max_dirty_mb
3356         local warmup_files
3357
3358         test_mkdir -p $DIR/${tdir}e
3359         $SETSTRIPE -c 1 $TDIR
3360         createmany -o $TDIR/f $files
3361
3362         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3363
3364         # we assume that with $OSTCOUNT files, at least one of them will
3365         # be allocated on OST0.
3366         warmup_files=$((OSTCOUNT * max_dirty_mb))
3367         createmany -o $TDIR/w $warmup_files
3368
3369         # write a large amount of data into one file and sync, to get good
3370         # avail_grant number from OST.
3371         for ((i=0; i<$warmup_files; i++)); do
3372                 idx=$($GETSTRIPE -i $TDIR/w$i)
3373                 [ $idx -ne 0 ] && continue
3374                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3375                 break
3376         done
3377         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3378         sync
3379         $LCTL get_param $proc_osc0/cur_dirty_bytes
3380         $LCTL get_param $proc_osc0/cur_grant_bytes
3381
3382         # create as much dirty pages as we can while not to trigger the actual
3383         # RPCs directly. but depends on the env, VFS may trigger flush during this
3384         # period, hopefully we are good.
3385         for ((i=0; i<$warmup_files; i++)); do
3386                 idx=$($GETSTRIPE -i $TDIR/w$i)
3387                 [ $idx -ne 0 ] && continue
3388                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3389         done
3390         $LCTL get_param $proc_osc0/cur_dirty_bytes
3391         $LCTL get_param $proc_osc0/cur_grant_bytes
3392
3393         # perform the real test
3394         $LCTL set_param $proc_osc0/rpc_stats 0
3395         for ((;i<$files; i++)); do
3396                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3397                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3398         done
3399         sync
3400         $LCTL get_param $proc_osc0/rpc_stats
3401
3402         local percent=0
3403         local have_ppr=false
3404         $LCTL get_param $proc_osc0/rpc_stats |
3405                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3406                         # skip lines until we are at the RPC histogram data
3407                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3408                         $have_ppr || continue
3409
3410                         # we only want the percent stat for < 16 pages
3411                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3412
3413                         percent=$((percent + WPCT))
3414                         if [[ $percent -gt 15 ]]; then
3415                                 error "less than 16-pages write RPCs" \
3416                                       "$percent% > 15%"
3417                                 break
3418                         fi
3419                 done
3420         rm -rf $TDIR
3421 }
3422 run_test 42e "verify sub-RPC writes are not done synchronously"
3423
3424 test_43() {
3425         test_mkdir -p $DIR/$tdir
3426         cp -p /bin/ls $DIR/$tdir/$tfile
3427         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3428         pid=$!
3429         # give multiop a chance to open
3430         sleep 1
3431
3432         $DIR/$tdir/$tfile && error || true
3433         kill -USR1 $pid
3434 }
3435 run_test 43 "execution of file opened for write should return -ETXTBSY"
3436
3437 test_43a() {
3438         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3439         test_mkdir -p $DIR/$tdir
3440         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3441                         cp -p multiop $DIR/$tdir/multiop
3442         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3443                         return 1
3444         MULTIOP_PID=$!
3445         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3446         kill -USR1 $MULTIOP_PID || return 2
3447         wait $MULTIOP_PID || return 3
3448         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3449 }
3450 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3451
3452 test_43b() {
3453         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3454         test_mkdir -p $DIR/$tdir
3455         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3456                         cp -p multiop $DIR/$tdir/multiop
3457         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3458                         return 1
3459         MULTIOP_PID=$!
3460         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3461         kill -USR1 $MULTIOP_PID || return 2
3462         wait $MULTIOP_PID || return 3
3463         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3464 }
3465 run_test 43b "truncate of file being executed should return -ETXTBSY"
3466
3467 test_43c() {
3468         local testdir="$DIR/$tdir"
3469         test_mkdir -p $DIR/$tdir
3470         cp $SHELL $testdir/
3471         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3472                 ( cd $testdir && md5sum -c)
3473 }
3474 run_test 43c "md5sum of copy into lustre========================"
3475
3476 test_44() {
3477         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3478         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3479         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3480 }
3481 run_test 44 "zero length read from a sparse stripe ============="
3482
3483 test_44a() {
3484         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3485                 awk '{ print $2 }')
3486         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3487         [[ $nstripe -gt $OSTCOUNT ]] &&
3488             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3489             return
3490         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3491                 awk '{ print $2 }')
3492         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3493                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3494                         awk '{ print $2 }')
3495         fi
3496
3497         OFFSETS="0 $((stride/2)) $((stride-1))"
3498         for offset in $OFFSETS; do
3499                 for i in $(seq 0 $((nstripe-1))); do
3500                         local GLOBALOFFSETS=""
3501                         # size in Bytes
3502                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3503                         local myfn=$DIR/d44a-$size
3504                         echo "--------writing $myfn at $size"
3505                         ll_sparseness_write $myfn $size ||
3506                                 error "ll_sparseness_write"
3507                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3508                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3509                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3510
3511                         for j in $(seq 0 $((nstripe-1))); do
3512                                 # size in Bytes
3513                                 size=$((((j + $nstripe )*$stride + $offset)))
3514                                 ll_sparseness_write $myfn $size ||
3515                                         error "ll_sparseness_write"
3516                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3517                         done
3518                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3519                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3520                         rm -f $myfn
3521                 done
3522         done
3523 }
3524 run_test 44a "test sparse pwrite ==============================="
3525
3526 dirty_osc_total() {
3527         tot=0
3528         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3529                 tot=$(($tot + $d))
3530         done
3531         echo $tot
3532 }
3533 do_dirty_record() {
3534         before=`dirty_osc_total`
3535         echo executing "\"$*\""
3536         eval $*
3537         after=`dirty_osc_total`
3538         echo before $before, after $after
3539 }
3540 test_45() {
3541         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3542         f="$DIR/f45"
3543         # Obtain grants from OST if it supports it
3544         echo blah > ${f}_grant
3545         stop_writeback
3546         sync
3547         do_dirty_record "echo blah > $f"
3548         [[ $before -eq $after ]] && error "write wasn't cached"
3549         do_dirty_record "> $f"
3550         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3551         do_dirty_record "echo blah > $f"
3552         [[ $before -eq $after ]] && error "write wasn't cached"
3553         do_dirty_record "sync"
3554         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3555         do_dirty_record "echo blah > $f"
3556         [[ $before -eq $after ]] && error "write wasn't cached"
3557         do_dirty_record "cancel_lru_locks osc"
3558         [[ $before -gt $after ]] ||
3559                 error "lock cancellation didn't lower dirty count"
3560         start_writeback
3561 }
3562 run_test 45 "osc io page accounting ============================"
3563
3564 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3565 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3566 # objects offset and an assert hit when an rpc was built with 1023's mapped
3567 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3568 test_46() {
3569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3570         f="$DIR/f46"
3571         stop_writeback
3572         sync
3573         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3574         sync
3575         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3576         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3577         sync
3578         start_writeback
3579 }
3580 run_test 46 "dirtying a previously written page ================"
3581
3582 # test_47 is removed "Device nodes check" is moved to test_28
3583
3584 test_48a() { # bug 2399
3585         check_kernel_version 34 || return 0
3586         test_mkdir -p $DIR/$tdir
3587         cd $DIR/$tdir
3588         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3589         test_mkdir $DIR/$tdir || error "recreate directory failed"
3590         touch foo || error "'touch foo' failed after recreating cwd"
3591         test_mkdir $DIR/$tdir/bar ||
3592                      error "'mkdir foo' failed after recreating cwd"
3593         if check_kernel_version 44; then
3594                 touch .foo || error "'touch .foo' failed after recreating cwd"
3595                 test_mkdir $DIR/$tdir/.bar ||
3596                               error "'mkdir .foo' failed after recreating cwd"
3597         fi
3598         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3599         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3600         cd . || error "'cd .' failed after recreating cwd"
3601         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3602         rmdir . && error "'rmdir .' worked after recreating cwd"
3603         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3604         cd .. || error "'cd ..' failed after recreating cwd"
3605 }
3606 run_test 48a "Access renamed working dir (should return errors)="
3607
3608 test_48b() { # bug 2399
3609         check_kernel_version 34 || return 0
3610         rm -rf $DIR/$tdir
3611         test_mkdir -p $DIR/$tdir
3612         cd $DIR/$tdir
3613         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3614         touch foo && error "'touch foo' worked after removing cwd"
3615         test_mkdir $DIR/$tdir/foo &&
3616                      error "'mkdir foo' worked after removing cwd"
3617         if check_kernel_version 44; then
3618                 touch .foo && error "'touch .foo' worked after removing cwd"
3619                 test_mkdir $DIR/$tdir/.foo &&
3620                               error "'mkdir .foo' worked after removing cwd"
3621         fi
3622         ls . > /dev/null && error "'ls .' worked after removing cwd"
3623         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3624         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3625         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3626         rmdir . && error "'rmdir .' worked after removing cwd"
3627         ln -s . foo && error "'ln -s .' worked after removing cwd"
3628         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3629 }
3630 run_test 48b "Access removed working dir (should return errors)="
3631
3632 test_48c() { # bug 2350
3633         check_kernel_version 36 || return 0
3634         #lctl set_param debug=-1
3635         #set -vx
3636         rm -rf $DIR/$tdir
3637         test_mkdir -p $DIR/$tdir/dir
3638         cd $DIR/$tdir/dir
3639         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3640         $TRACE touch foo && error "touch foo worked after removing cwd"
3641         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3642         if check_kernel_version 44; then
3643                 touch .foo && error "touch .foo worked after removing cwd"
3644                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3645         fi
3646         $TRACE ls . && error "'ls .' worked after removing cwd"
3647         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3648         is_patchless || ( $TRACE cd . &&
3649                         error "'cd .' worked after removing cwd" )
3650         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3651         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3652         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3653         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3654 }
3655 run_test 48c "Access removed working subdir (should return errors)"
3656
3657 test_48d() { # bug 2350
3658         check_kernel_version 36 || return 0
3659         #lctl set_param debug=-1
3660         #set -vx
3661         rm -rf $DIR/$tdir
3662         test_mkdir -p $DIR/$tdir/dir
3663         cd $DIR/$tdir/dir
3664         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3665         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3666         $TRACE touch foo && error "'touch foo' worked after removing parent"
3667         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3668         if check_kernel_version 44; then
3669                 touch .foo && error "'touch .foo' worked after removing parent"
3670                 test_mkdir .foo &&
3671                               error "mkdir .foo worked after removing parent"
3672         fi
3673         $TRACE ls . && error "'ls .' worked after removing parent"
3674         $TRACE ls .. && error "'ls ..' worked after removing parent"
3675         is_patchless || ( $TRACE cd . &&
3676                         error "'cd .' worked after recreate parent" )
3677         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3678         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3679         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3680         is_patchless || ( $TRACE cd .. &&
3681                         error "'cd ..' worked after removing parent" || true )
3682 }
3683 run_test 48d "Access removed parent subdir (should return errors)"
3684
3685 test_48e() { # bug 4134
3686         check_kernel_version 41 || return 0
3687         #lctl set_param debug=-1
3688         #set -vx
3689         rm -rf $DIR/$tdir
3690         test_mkdir -p $DIR/$tdir/dir
3691         cd $DIR/$tdir/dir
3692         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3693         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3694         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3695         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3696         # On a buggy kernel addition of "touch foo" after cd .. will
3697         # produce kernel oops in lookup_hash_it
3698         touch ../foo && error "'cd ..' worked after recreate parent"
3699         cd $DIR
3700         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3701 }
3702 run_test 48e "Access to recreated parent subdir (should return errors)"
3703
3704 test_49() { # LU-1030
3705         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3706         # get ost1 size - lustre-OST0000
3707         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3708                 awk '{ print $4 }')
3709         # write 800M at maximum
3710         [[ $ost1_size -lt 2 ]] && ost1_size=2
3711         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3712
3713         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3714         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3715         local dd_pid=$!
3716
3717         # change max_pages_per_rpc while writing the file
3718         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3719         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3720         # loop until dd process exits
3721         while ps ax -opid | grep -wq $dd_pid; do
3722                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3723                 sleep $((RANDOM % 5 + 1))
3724         done
3725         # restore original max_pages_per_rpc
3726         $LCTL set_param $osc1_mppc=$orig_mppc
3727         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3728 }
3729 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3730
3731 test_50() {
3732         # bug 1485
3733         test_mkdir $DIR/$tdir
3734         cd $DIR/$tdir
3735         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3736 }
3737 run_test 50 "special situations: /proc symlinks  ==============="
3738
3739 test_51a() {    # was test_51
3740         # bug 1516 - create an empty entry right after ".." then split dir
3741         test_mkdir -p $DIR/$tdir
3742         touch $DIR/$tdir/foo
3743         $MCREATE $DIR/$tdir/bar
3744         rm $DIR/$tdir/foo
3745         createmany -m $DIR/$tdir/longfile 201
3746         FNUM=202
3747         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
3748                 $MCREATE $DIR/$tdir/longfile$FNUM
3749                 FNUM=$(($FNUM + 1))
3750                 echo -n "+"
3751         done
3752         echo
3753         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3754 }
3755 run_test 51a "special situations: split htree with empty entry =="
3756
3757 export NUMTEST=70000
3758 test_51b() {
3759         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3760         local BASE=$DIR/d${base}.${TESTSUITE}
3761
3762         # cleanup the directory
3763         rm -fr $BASE
3764
3765         test_mkdir -p $BASE
3766
3767         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3768         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3769         [[ $numfree -lt 21000 ]] && skip "not enough free inodes ($numfree)" &&
3770                 return
3771
3772         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3773                 echo "reduced count to $NUMTEST due to inodes"
3774
3775         # need to check free space for the directories as well
3776         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3777         numfree=$((blkfree / 4))
3778         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3779                 echo "reduced count to $NUMTEST due to blocks"
3780
3781         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3782                 echo "failed" > $BASE/fnum
3783 }
3784 run_test 51b "exceed 64k subdirectory nlink limit"
3785
3786 test_51ba() { # LU-993
3787         local BASE=$DIR/d${base}.${TESTSUITE}
3788         # unlink all but 100 subdirectories, then check it still works
3789         local LEFT=100
3790         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3791
3792         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
3793         local DELETE=$((NUMTEST - LEFT))
3794
3795         # continue on to run this test even if 51b didn't finish,
3796         # just to delete the many subdirectories created.
3797         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
3798
3799         # for ldiskfs the nlink count should be 1, but this is OSD specific
3800         # and so this is listed for informational purposes only
3801         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
3802         unlinkmany -d $BASE/d $DELETE
3803         RC=$?
3804
3805         if [ $RC -ne 0 ]; then
3806                 if [ "$NUMPREV" == "failed" ]; then
3807                         skip "previous setup failed"
3808                         return 0
3809                 else
3810                         error "unlink of first $DELETE subdirs failed"
3811                         return $RC
3812                 fi
3813         fi
3814
3815         echo "nlink between: $(stat -c %h $BASE)"
3816         # trim the first line of ls output
3817         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
3818         [ $FOUND -ne $LEFT ] &&
3819                 error "can't find subdirs: found only $FOUND/$LEFT"
3820
3821         unlinkmany -d $BASE/d $DELETE $LEFT ||
3822                 error "unlink of second $LEFT subdirs failed"
3823         # regardless of whether the backing filesystem tracks nlink accurately
3824         # or not, the nlink count shouldn't be more than "." and ".." here
3825         local AFTER=$(stat -c %h $BASE)
3826         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
3827                 echo "nlink after: $AFTER"
3828 }
3829 run_test 51ba "verify nlink for many subdirectory cleanup"
3830
3831 test_51d() {
3832         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3833         [[ $OSTCOUNT -lt 3 ]] &&
3834                 skip_env "skipping test with few OSTs" && return
3835         test_mkdir -p $DIR/$tdir
3836         createmany -o $DIR/$tdir/t- 1000
3837         $GETSTRIPE $DIR/$tdir > $TMP/files
3838         for N in $(seq 0 $((OSTCOUNT - 1))); do
3839                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
3840                         END { printf("%0.0f", objs) }' $TMP/files)
3841                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
3842                         '($1 == '$N') { objs += 1 } \
3843                         END { printf("%0.0f", objs) }')
3844                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
3845         done
3846         unlinkmany $DIR/$tdir/t- 1000
3847
3848         NLAST=0
3849         for N in $(seq 1 $((OSTCOUNT - 1))); do
3850                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
3851                         error "OST $N has less objects vs OST $NLAST" \
3852                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
3853                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
3854                         error "OST $N has less objects vs OST $NLAST" \
3855                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
3856
3857                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
3858                         error "OST $N has less #0 objects vs OST $NLAST" \
3859                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3860                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
3861                         error "OST $N has less #0 objects vs OST $NLAST" \
3862                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3863                 NLAST=$N
3864         done
3865 }
3866 run_test 51d "check object distribution ===================="
3867
3868 test_52a() {
3869         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
3870         test_mkdir -p $DIR/$tdir
3871         touch $DIR/$tdir/foo
3872         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
3873         echo bar >> $DIR/$tdir/foo || error "append bar failed"
3874         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3875         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3876         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3877                                         error "link worked"
3878         echo foo >> $DIR/$tdir/foo || error "append foo failed"
3879         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3880         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
3881                                                      error "lsattr"
3882         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
3883         cp -r $DIR/$tdir /tmp/
3884         rm -fr $DIR/$tdir || error "cleanup rm failed"
3885 }
3886 run_test 52a "append-only flag test (should return errors) ====="
3887
3888 test_52b() {
3889         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
3890         test_mkdir -p $DIR/$tdir
3891         touch $DIR/$tdir/foo
3892         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
3893         cat test > $DIR/$tdir/foo && error "cat test worked"
3894         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3895         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3896         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3897                                         error "link worked"
3898         echo foo >> $DIR/$tdir/foo && error "echo worked"
3899         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3900         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
3901         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
3902         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
3903                                                         error "lsattr"
3904         chattr -i $DIR/$tdir/foo || error "chattr failed"
3905
3906         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
3907 }
3908 run_test 52b "immutable flag test (should return errors) ======="
3909
3910 test_53() {
3911         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3912         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3913         remote_ost_nodsh && skip "remote OST with nodsh" && return
3914
3915         local param
3916         local param_seq
3917         local ostname
3918         local mds_last
3919         local mds_last_seq
3920         local ost_last
3921         local ost_last_seq
3922         local ost_last_id
3923         local ostnum
3924         local node
3925         local found=false
3926         local support_last_seq=true
3927
3928         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
3929                 support_last_seq=false
3930
3931         # only test MDT0000
3932         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
3933         local value
3934         for value in $(do_facet $SINGLEMDS \
3935                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
3936                 param=$(echo ${value[0]} | cut -d "=" -f1)
3937                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
3938
3939                 if $support_last_seq; then
3940                         param_seq=$(echo $param |
3941                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
3942                         mds_last_seq=$(do_facet $SINGLEMDS \
3943                                        $LCTL get_param -n $param_seq)
3944                 fi
3945                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
3946
3947                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
3948                 node=$(facet_active_host ost$((ostnum+1)))
3949                 param="obdfilter.$ostname.last_id"
3950                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
3951                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
3952                         ost_last_id=$ost_last
3953
3954                         if $support_last_seq; then
3955                                 ost_last_id=$(echo $ost_last |
3956                                               awk -F':' '{print $2}' |
3957                                               sed -e "s/^0x//g")
3958                                 ost_last_seq=$(echo $ost_last |
3959                                                awk -F':' '{print $1}')
3960                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
3961                         fi
3962
3963                         if [[ $ost_last_id != $mds_last ]]; then
3964                                 error "$ost_last_id != $mds_last"
3965                         else
3966                                 found=true
3967                                 break
3968                         fi
3969                 done
3970         done
3971         $found || error "can not match last_seq/last_id for $mdtosc"
3972         return 0
3973 }
3974 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
3975
3976 test_54a() {
3977         $SOCKETSERVER $DIR/socket ||
3978                 error "$SOCKETSERVER $DIR/socket failed: $?"
3979         $SOCKETCLIENT $DIR/socket ||
3980                 error "$SOCKETCLIENT $DIR/socket failed: $?"
3981         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
3982 }
3983 run_test 54a "unix domain socket test =========================="
3984
3985 test_54b() {
3986         f="$DIR/f54b"
3987         mknod $f c 1 3
3988         chmod 0666 $f
3989         dd if=/dev/zero of=$f bs=$(page_size) count=1
3990 }
3991 run_test 54b "char device works in lustre ======================"
3992
3993 find_loop_dev() {
3994         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
3995         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
3996         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
3997
3998         for i in $(seq 3 7); do
3999                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4000                 LOOPDEV=$LOOPBASE$i
4001                 LOOPNUM=$i
4002                 break
4003         done
4004 }
4005
4006 cleanup_54c() {
4007         loopdev="$DIR/loop54c"
4008
4009         trap 0
4010         $UMOUNT -d $DIR/$tdir || rc=$?
4011         losetup -d $loopdev || true
4012         losetup -d $LOOPDEV || true
4013         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4014         return $rc
4015 }
4016
4017 test_54c() {
4018         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4019         loopdev="$DIR/loop54c"
4020
4021         find_loop_dev
4022         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4023         trap cleanup_54c EXIT
4024         mknod $loopdev b 7 $LOOPNUM
4025         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4026         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4027         losetup $loopdev $DIR/$tfile ||
4028                 error "can't set up $loopdev for $DIR/$tfile"
4029         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4030         test_mkdir -p $DIR/$tdir
4031         mount -t ext2 $loopdev $DIR/$tdir ||
4032                 error "error mounting $loopdev on $DIR/$tdir"
4033         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4034                 error "dd write"
4035         df $DIR/$tdir
4036         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4037                 error "dd read"
4038         cleanup_54c
4039 }
4040 run_test 54c "block device works in lustre ====================="
4041
4042 test_54d() {
4043         f="$DIR/f54d"
4044         string="aaaaaa"
4045         mknod $f p
4046         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4047 }
4048 run_test 54d "fifo device works in lustre ======================"
4049
4050 test_54e() {
4051         check_kernel_version 46 || return 0
4052         f="$DIR/f54e"
4053         string="aaaaaa"
4054         cp -aL /dev/console $f
4055         echo $string > $f || error "echo $string to $f failed"
4056 }
4057 run_test 54e "console/tty device works in lustre ======================"
4058
4059 #The test_55 used to be iopen test and it was removed by bz#24037.
4060 #run_test 55 "check iopen_connect_dentry() ======================"
4061
4062 test_56a() {    # was test_56
4063         rm -rf $DIR/$tdir
4064         $SETSTRIPE -d $DIR
4065         test_mkdir -p $DIR/$tdir/dir
4066         NUMFILES=3
4067         NUMFILESx2=$(($NUMFILES * 2))
4068         for i in $(seq 1 $NUMFILES); do
4069                 touch $DIR/$tdir/file$i
4070                 touch $DIR/$tdir/dir/file$i
4071         done
4072
4073         # test lfs getstripe with --recursive
4074         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4075         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4076                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4077         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4078         [[ $FILENUM -eq $NUMFILES ]] ||
4079                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4080         echo "$GETSTRIPE --recursive passed."
4081
4082         # test lfs getstripe with file instead of dir
4083         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4084         [[ $FILENUM -eq 1 ]] ||
4085                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4086         echo "$GETSTRIPE file1 passed."
4087
4088         #test lfs getstripe with --verbose
4089         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4090                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4091                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4092         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4093                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4094         echo "$GETSTRIPE --verbose passed."
4095
4096         #test lfs getstripe with --obd
4097         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4098                 grep -q "unknown obduuid" ||
4099                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4100
4101         [[ $OSTCOUNT -lt 2 ]] &&
4102                 skip_env "skipping other $GETSTRIPE --obd test" && return
4103
4104         OSTIDX=1
4105         OBDUUID=$(ostuuid_from_index $OSTIDX)
4106         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4107         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4108         [[ $FOUND -eq $FILENUM ]] ||
4109                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4110         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4111                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4112                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4113                 error "$GETSTRIPE --obd: should not show file on other obd"
4114         echo "$GETSTRIPE --obd passed"
4115 }
4116 run_test 56a "check $GETSTRIPE"
4117
4118 NUMFILES=3
4119 NUMDIRS=3
4120 setup_56() {
4121         local LOCAL_NUMFILES="$1"
4122         local LOCAL_NUMDIRS="$2"
4123         local MKDIR_PARAMS="$3"
4124
4125         if [ ! -d "$TDIR" ] ; then
4126                 test_mkdir -p $TDIR
4127                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4128                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4129                         touch $TDIR/file$i
4130                 done
4131                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4132                         test_mkdir $TDIR/dir$i
4133                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4134                                 touch $TDIR/dir$i/file$j
4135                         done
4136                 done
4137         fi
4138 }
4139
4140 setup_56_special() {
4141         LOCAL_NUMFILES=$1
4142         LOCAL_NUMDIRS=$2
4143         setup_56 $1 $2
4144         if [ ! -e "$TDIR/loop1b" ] ; then
4145                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4146                         mknod $TDIR/loop${i}b b 7 $i
4147                         mknod $TDIR/null${i}c c 1 3
4148                         ln -s $TDIR/file1 $TDIR/link${i}l
4149                 done
4150                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4151                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4152                         mknod $TDIR/dir$i/null${i}c c 1 3
4153                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4154                 done
4155         fi
4156 }
4157
4158 test_56g() {
4159         $SETSTRIPE -d $DIR
4160
4161         TDIR=$DIR/${tdir}g
4162         setup_56 $NUMFILES $NUMDIRS
4163
4164         EXPECTED=$(($NUMDIRS + 2))
4165         # test lfs find with -name
4166         for i in $(seq 1 $NUMFILES) ; do
4167                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4168                 [ $NUMS -eq $EXPECTED ] ||
4169                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4170                               "found $NUMS, expected $EXPECTED"
4171         done
4172 }
4173 run_test 56g "check lfs find -name ============================="
4174
4175 test_56h() {
4176         $SETSTRIPE -d $DIR
4177
4178         TDIR=$DIR/${tdir}g
4179         setup_56 $NUMFILES $NUMDIRS
4180
4181         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4182         # test lfs find with ! -name
4183         for i in $(seq 1 $NUMFILES) ; do
4184                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4185                 [ $NUMS -eq $EXPECTED ] ||
4186                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4187                               "found $NUMS, expected $EXPECTED"
4188         done
4189 }
4190 run_test 56h "check lfs find ! -name ============================="
4191
4192 test_56i() {
4193        tdir=${tdir}i
4194        test_mkdir -p $DIR/$tdir
4195        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4196        CMD="$LFIND -ost $UUID $DIR/$tdir"
4197        OUT=$($CMD)
4198        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4199 }
4200 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4201
4202 test_56j() {
4203         TDIR=$DIR/${tdir}g
4204         setup_56_special $NUMFILES $NUMDIRS
4205
4206         EXPECTED=$((NUMDIRS + 1))
4207         CMD="$LFIND -type d $TDIR"
4208         NUMS=$($CMD | wc -l)
4209         [ $NUMS -eq $EXPECTED ] ||
4210                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4211 }
4212 run_test 56j "check lfs find -type d ============================="
4213
4214 test_56k() {
4215         TDIR=$DIR/${tdir}g
4216         setup_56_special $NUMFILES $NUMDIRS
4217
4218         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4219         CMD="$LFIND -type f $TDIR"
4220         NUMS=$($CMD | wc -l)
4221         [ $NUMS -eq $EXPECTED ] ||
4222                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4223 }
4224 run_test 56k "check lfs find -type f ============================="
4225
4226 test_56l() {
4227         TDIR=$DIR/${tdir}g
4228         setup_56_special $NUMFILES $NUMDIRS
4229
4230         EXPECTED=$((NUMDIRS + NUMFILES))
4231         CMD="$LFIND -type b $TDIR"
4232         NUMS=$($CMD | wc -l)
4233         [ $NUMS -eq $EXPECTED ] ||
4234                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4235 }
4236 run_test 56l "check lfs find -type b ============================="
4237
4238 test_56m() {
4239         TDIR=$DIR/${tdir}g
4240         setup_56_special $NUMFILES $NUMDIRS
4241
4242         EXPECTED=$((NUMDIRS + NUMFILES))
4243         CMD="$LFIND -type c $TDIR"
4244         NUMS=$($CMD | wc -l)
4245         [ $NUMS -eq $EXPECTED ] ||
4246                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4247 }
4248 run_test 56m "check lfs find -type c ============================="
4249
4250 test_56n() {
4251         TDIR=$DIR/${tdir}g
4252         setup_56_special $NUMFILES $NUMDIRS
4253
4254         EXPECTED=$((NUMDIRS + NUMFILES))
4255         CMD="$LFIND -type l $TDIR"
4256         NUMS=$($CMD | wc -l)
4257         [ $NUMS -eq $EXPECTED ] ||
4258                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4259 }
4260 run_test 56n "check lfs find -type l ============================="
4261
4262 test_56o() {
4263         TDIR=$DIR/${tdir}o
4264         setup_56 $NUMFILES $NUMDIRS
4265
4266         utime $TDIR/file1 > /dev/null || error "utime (1)"
4267         utime $TDIR/file2 > /dev/null || error "utime (2)"
4268         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4269         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4270         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4271         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4272
4273         EXPECTED=4
4274         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4275         [ $NUMS -eq $EXPECTED ] || \
4276                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4277
4278         EXPECTED=12
4279         CMD="$LFIND -mtime 0 $TDIR"
4280         NUMS=$($CMD | wc -l)
4281         [ $NUMS -eq $EXPECTED ] ||
4282                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4283 }
4284 run_test 56o "check lfs find -mtime for old files =========================="
4285
4286 test_56p() {
4287         [ $RUNAS_ID -eq $UID ] &&
4288                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4289
4290         TDIR=$DIR/${tdir}p
4291         setup_56 $NUMFILES $NUMDIRS
4292
4293         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4294         EXPECTED=$NUMFILES
4295         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4296         NUMS=$($CMD | wc -l)
4297         [ $NUMS -eq $EXPECTED ] || \
4298                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4299
4300         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4301         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4302         NUMS=$($CMD | wc -l)
4303         [ $NUMS -eq $EXPECTED ] || \
4304                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4305 }
4306 run_test 56p "check lfs find -uid and ! -uid ==============================="
4307
4308 test_56q() {
4309         [ $RUNAS_ID -eq $UID ] &&
4310                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4311
4312         TDIR=$DIR/${tdir}q
4313         setup_56 $NUMFILES $NUMDIRS
4314
4315         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4316
4317         EXPECTED=$NUMFILES
4318         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4319         NUMS=$($CMD | wc -l)
4320         [ $NUMS -eq $EXPECTED ] ||
4321                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4322
4323         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4324         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4325         NUMS=$($CMD | wc -l)
4326         [ $NUMS -eq $EXPECTED ] ||
4327                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4328 }
4329 run_test 56q "check lfs find -gid and ! -gid ==============================="
4330
4331 test_56r() {
4332         TDIR=$DIR/${tdir}r
4333         setup_56 $NUMFILES $NUMDIRS
4334
4335         EXPECTED=12
4336         CMD="$LFIND -size 0 -type f $TDIR"
4337         NUMS=$($CMD | wc -l)
4338         [ $NUMS -eq $EXPECTED ] ||
4339                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4340         EXPECTED=0
4341         CMD="$LFIND ! -size 0 -type f $TDIR"
4342         NUMS=$($CMD | wc -l)
4343         [ $NUMS -eq $EXPECTED ] ||
4344                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4345         echo "test" > $TDIR/$tfile
4346         echo "test2" > $TDIR/$tfile.2 && sync
4347         EXPECTED=1
4348         CMD="$LFIND -size 5 -type f $TDIR"
4349         NUMS=$($CMD | wc -l)
4350         [ $NUMS -eq $EXPECTED ] ||
4351                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4352         EXPECTED=1
4353         CMD="$LFIND -size +5 -type f $TDIR"
4354         NUMS=$($CMD | wc -l)
4355         [ $NUMS -eq $EXPECTED ] ||
4356                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4357         EXPECTED=2
4358         CMD="$LFIND -size +0 -type f $TDIR"
4359         NUMS=$($CMD | wc -l)
4360         [ $NUMS -eq $EXPECTED ] ||
4361                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4362         EXPECTED=2
4363         CMD="$LFIND ! -size -5 -type f $TDIR"
4364         NUMS=$($CMD | wc -l)
4365         [ $NUMS -eq $EXPECTED ] ||
4366                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4367         EXPECTED=12
4368         CMD="$LFIND -size -5 -type f $TDIR"
4369         NUMS=$($CMD | wc -l)
4370         [ $NUMS -eq $EXPECTED ] ||
4371                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4372 }
4373 run_test 56r "check lfs find -size works =========================="
4374
4375 test_56s() { # LU-611
4376         TDIR=$DIR/${tdir}s
4377         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4378
4379         if [[ $OSTCOUNT -gt 1 ]]; then
4380                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4381                 ONESTRIPE=4
4382                 EXTRA=4
4383         else
4384                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4385                 EXTRA=0
4386         fi
4387
4388         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4389         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4390         NUMS=$($CMD | wc -l)
4391         [ $NUMS -eq $EXPECTED ] ||
4392                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4393
4394         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4395         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4396         NUMS=$($CMD | wc -l)
4397         [ $NUMS -eq $EXPECTED ] ||
4398                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4399
4400         EXPECTED=$ONESTRIPE
4401         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4402         NUMS=$($CMD | wc -l)
4403         [ $NUMS -eq $EXPECTED ] ||
4404                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4405
4406         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4407         NUMS=$($CMD | wc -l)
4408         [ $NUMS -eq $EXPECTED ] ||
4409                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4410
4411         EXPECTED=0
4412         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4413         NUMS=$($CMD | wc -l)
4414         [ $NUMS -eq $EXPECTED ] ||
4415                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4416 }
4417 run_test 56s "check lfs find -stripe-count works"
4418
4419 test_56t() { # LU-611
4420         TDIR=$DIR/${tdir}t
4421         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4422
4423         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4424
4425         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4426         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4427         NUMS=$($CMD | wc -l)
4428         [ $NUMS -eq $EXPECTED ] ||
4429                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4430
4431         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4432         NUMS=$($CMD | wc -l)
4433         [ $NUMS -eq $EXPECTED ] ||
4434                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4435
4436         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4437         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4438         NUMS=$($CMD | wc -l)
4439         [ $NUMS -eq $EXPECTED ] ||
4440                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4441
4442         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4443         NUMS=$($CMD | wc -l)
4444         [ $NUMS -eq $EXPECTED ] ||
4445                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4446
4447         EXPECTED=4
4448         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4449         NUMS=$($CMD | wc -l)
4450         [ $NUMS -eq $EXPECTED ] ||
4451                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4452
4453         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4454         NUMS=$($CMD | wc -l)
4455         [ $NUMS -eq $EXPECTED ] ||
4456                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4457
4458         EXPECTED=0
4459         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4460         NUMS=$($CMD | wc -l)
4461         [ $NUMS -eq $EXPECTED ] ||
4462                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4463 }
4464 run_test 56t "check lfs find -stripe-size works"
4465
4466 test_56u() { # LU-611
4467         TDIR=$DIR/${tdir}u
4468         setup_56 $NUMFILES $NUMDIRS "-i 0"
4469
4470         if [[ $OSTCOUNT -gt 1 ]]; then
4471                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4472                 ONESTRIPE=4
4473         else
4474                 ONESTRIPE=0
4475         fi
4476
4477         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4478         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4479         NUMS=$($CMD | wc -l)
4480         [ $NUMS -eq $EXPECTED ] ||
4481                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4482
4483         EXPECTED=$ONESTRIPE
4484         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4485         NUMS=$($CMD | wc -l)
4486         [ $NUMS -eq $EXPECTED ] ||
4487                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4488
4489         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4490         NUMS=$($CMD | wc -l)
4491         [ $NUMS -eq $EXPECTED ] ||
4492                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4493
4494         EXPECTED=0
4495         # This should produce an error and not return any files
4496         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4497         NUMS=$($CMD 2>/dev/null | wc -l)
4498         [ $NUMS -eq $EXPECTED ] ||
4499                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4500
4501         if [[ $OSTCOUNT -gt 1 ]]; then
4502                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4503                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4504                 NUMS=$($CMD | wc -l)
4505                 [ $NUMS -eq $EXPECTED ] ||
4506                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4507         fi
4508 }
4509 run_test 56u "check lfs find -stripe-index works"
4510
4511 test_56v() {
4512     local MDT_IDX=0
4513
4514     TDIR=$DIR/${tdir}v
4515     rm -rf $TDIR
4516     setup_56 $NUMFILES $NUMDIRS
4517
4518     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4519     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4520
4521     for file in $($LFIND -mdt $UUID $TDIR); do
4522         file_mdt_idx=$($GETSTRIPE -M $file)
4523         [ $file_mdt_idx -eq $MDT_IDX ] ||
4524             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4525     done
4526 }
4527 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4528
4529 # Get and check the actual stripe count of one file.
4530 # Usage: check_stripe_count <file> <expected_stripe_count>
4531 check_stripe_count() {
4532     local file=$1
4533     local expected=$2
4534     local actual
4535
4536     [[ -z "$file" || -z "$expected" ]] &&
4537         error "check_stripe_count: invalid argument!"
4538
4539     local cmd="$GETSTRIPE -c $file"
4540     actual=$($cmd) || error "$cmd failed"
4541     actual=${actual%% *}
4542
4543     if [[ $actual -ne $expected ]]; then
4544         [[ $expected -eq -1 ]] ||
4545             error "$cmd wrong: found $actual, expected $expected"
4546         [[ $actual -eq $OSTCOUNT ]] ||
4547             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4548     fi
4549 }
4550
4551 test_56w() {
4552         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4553         TDIR=$DIR/${tdir}w
4554
4555     rm -rf $TDIR || error "remove $TDIR failed"
4556     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4557
4558     local stripe_size
4559     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4560         error "$GETSTRIPE -S -d $TDIR failed"
4561     stripe_size=${stripe_size%% *}
4562
4563     local file_size=$((stripe_size * OSTCOUNT))
4564     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4565     local required_space=$((file_num * file_size))
4566     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4567     [[ $free_space -le $((required_space / 1024)) ]] &&
4568         skip_env "need at least $required_space bytes free space," \
4569                  "have $free_space kbytes" && return
4570
4571     local dd_bs=65536
4572     local dd_count=$((file_size / dd_bs))
4573
4574     # write data into the files
4575     local i
4576     local j
4577     local file
4578     for i in $(seq 1 $NUMFILES); do
4579         file=$TDIR/file$i
4580         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4581             error "write data into $file failed"
4582     done
4583     for i in $(seq 1 $NUMDIRS); do
4584         for j in $(seq 1 $NUMFILES); do
4585             file=$TDIR/dir$i/file$j
4586             yes | dd bs=$dd_bs count=$dd_count of=$file \
4587                 >/dev/null 2>&1 ||
4588                 error "write data into $file failed"
4589         done
4590     done
4591
4592     local expected=-1
4593     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4594
4595     # lfs_migrate file
4596     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4597     echo "$cmd"
4598     eval $cmd || error "$cmd failed"
4599
4600     check_stripe_count $TDIR/file1 $expected
4601
4602     # lfs_migrate dir
4603     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4604     echo "$cmd"
4605     eval $cmd || error "$cmd failed"
4606
4607     for j in $(seq 1 $NUMFILES); do
4608         check_stripe_count $TDIR/dir1/file$j $expected
4609     done
4610
4611     # lfs_migrate works with lfs find
4612     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4613          $LFS_MIGRATE -y -c $expected"
4614     echo "$cmd"
4615     eval $cmd || error "$cmd failed"
4616
4617     for i in $(seq 2 $NUMFILES); do
4618         check_stripe_count $TDIR/file$i $expected
4619     done
4620     for i in $(seq 2 $NUMDIRS); do
4621         for j in $(seq 1 $NUMFILES); do
4622             check_stripe_count $TDIR/dir$i/file$j $expected
4623         done
4624     done
4625 }
4626 run_test 56w "check lfs_migrate -c stripe_count works"
4627
4628 test_56x() {
4629         check_swap_layouts_support && return 0
4630         [[ $OSTCOUNT -lt 2 ]] &&
4631                 skip_env "need 2 OST, skipping test" && return
4632
4633         local dir0=$DIR/$tdir/$testnum
4634         mkdir -p $dir0 || error "creating dir $dir0"
4635
4636         local ref1=/etc/passwd
4637         local file1=$dir0/file1
4638
4639         $SETSTRIPE -c 2 $file1
4640         cp $ref1 $file1
4641         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4642         stripe=$($GETSTRIPE -c $file1)
4643         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4644         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4645
4646         # clean up
4647         rm -f $file1
4648 }
4649 run_test 56x "lfs migration support"
4650
4651 test_56y() {
4652         local server_version=$(get_lustre_version $SINGLEMDS)
4653         [[ $(version_code $server_version) -lt $(version_code 2.4.53) ]] &&
4654                 skip "No HSM support on $server_version MDS," \
4655                         "need 2.4.53 at least" && return
4656
4657         local res=""
4658
4659         local dir0=$DIR/$tdir/$testnum
4660         mkdir -p $dir0 || error "creating dir $dir0"
4661         local f1=$dir0/file1
4662         local f2=$dir0/file2
4663
4664         touch $f1 || error "creating std file $f1"
4665         $MULTIOP $f2 H2c || error "creating released file $f2"
4666
4667         # a directory can be raid0, so ask only for files
4668         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4669         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4670
4671         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4672         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4673
4674         # only files can be released, so no need to force file search
4675         res=$($LFIND $dir0 -L released)
4676         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4677
4678         res=$($LFIND $dir0 \! -L released)
4679         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4680
4681 }
4682 run_test 56y "lfs find -L raid0|released"
4683
4684 test_56z() { # LU-4824
4685         # This checks to make sure 'lfs find' continues after errors
4686         # There are two classes of errors that should be caught:
4687         # - If multiple paths are provided, all should be searched even if one
4688         #   errors out
4689         # - If errors are encountered during the search, it should not terminate
4690         #   early
4691         local i
4692         test_mkdir $DIR/$tdir
4693         for i in d{0..9}; do
4694                 test_mkdir $DIR/$tdir/$i
4695         done
4696         touch $DIR/$tdir/d{0..9}/$tfile
4697         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
4698                 error "$LFS find did not return an error"
4699         # Make a directory unsearchable. This should NOT be the last entry in
4700         # directory order.  Arbitrarily pick the 6th entry
4701         chmod 700 $(lfs find $DIR/$tdir -type d | sed '6!d')
4702         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
4703         # The user should be able to see 10 directories and 9 files
4704         [ $count == 19 ] || error "$LFS find did not continue after error"
4705 }
4706 run_test 56z "lfs find should continue after an error"
4707
4708 test_57a() {
4709         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4710         # note test will not do anything if MDS is not local
4711         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4712                 skip "Only applicable to ldiskfs-based MDTs"
4713                 return
4714         fi
4715
4716         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4717         local MNTDEV="osd*.*MDT*.mntdev"
4718         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4719         [ -z "$DEV" ] && error "can't access $MNTDEV"
4720         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4721                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4722                         error "can't access $DEV"
4723                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
4724                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
4725                 rm $TMP/t57a.dump
4726         done
4727 }
4728 run_test 57a "verify MDS filesystem created with large inodes =="
4729
4730 test_57b() {
4731         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4732         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4733                 skip "Only applicable to ldiskfs-based MDTs"
4734                 return
4735         fi
4736
4737         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4738         local dir=$DIR/d57b
4739
4740         local FILECOUNT=100
4741         local FILE1=$dir/f1
4742         local FILEN=$dir/f$FILECOUNT
4743
4744         rm -rf $dir || error "removing $dir"
4745         test_mkdir -p $dir || error "creating $dir"
4746         local num=$(get_mds_dir $dir)
4747         local mymds=mds$num
4748
4749         echo "mcreating $FILECOUNT files"
4750         createmany -m $dir/f 1 $FILECOUNT || \
4751                 error "creating files in $dir"
4752
4753         # verify that files do not have EAs yet
4754         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4755         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4756
4757         sync
4758         sleep 1
4759         df $dir  #make sure we get new statfs data
4760         local MDSFREE=$(do_facet $mymds \
4761                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4762         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4763         echo "opening files to create objects/EAs"
4764         local FILE
4765         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4766                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4767         done
4768
4769         # verify that files have EAs now
4770         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
4771         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
4772
4773         sleep 1  #make sure we get new statfs data
4774         df $dir
4775         local MDSFREE2=$(do_facet $mymds \
4776                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4777         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4778         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
4779                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
4780                         error "MDC before $MDCFREE != after $MDCFREE2"
4781                 else
4782                         echo "MDC before $MDCFREE != after $MDCFREE2"
4783                         echo "unable to confirm if MDS has large inodes"
4784                 fi
4785         fi
4786         rm -rf $dir
4787 }
4788 run_test 57b "default LOV EAs are stored inside large inodes ==="
4789
4790 test_58() {
4791         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4792         [ -z "$(which wiretest 2>/dev/null)" ] &&
4793                         skip_env "could not find wiretest" && return
4794         wiretest
4795 }
4796 run_test 58 "verify cross-platform wire constants =============="
4797
4798 test_59() {
4799         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4800         echo "touch 130 files"
4801         createmany -o $DIR/f59- 130
4802         echo "rm 130 files"
4803         unlinkmany $DIR/f59- 130
4804         sync
4805         # wait for commitment of removal
4806         wait_delete_completed
4807 }
4808 run_test 59 "verify cancellation of llog records async ========="
4809
4810 TEST60_HEAD="test_60 run $RANDOM"
4811 test_60a() {
4812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4813         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
4814         do_facet mgs "! which run-llog.sh &> /dev/null" &&
4815                 skip_env "missing subtest run-llog.sh" && return
4816         log "$TEST60_HEAD - from kernel mode"
4817         do_facet mgs sh run-llog.sh
4818 }
4819 run_test 60a "llog sanity tests run from kernel module =========="
4820
4821 test_60b() { # bug 6411
4822         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4823         dmesg > $DIR/$tfile
4824         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
4825                                  /llog.test/ {
4826                                          if (marker)
4827                                                  from_marker++
4828                                          from_begin++
4829                                  }
4830                                  END {
4831                                          if (marker)
4832                                                  print from_marker
4833                                          else
4834                                                  print from_begin
4835                                  }"`
4836         [[ $LLOG_COUNT -gt 50 ]] &&
4837                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
4838 }
4839 run_test 60b "limit repeated messages from CERROR/CWARN ========"
4840
4841 test_60c() {
4842         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4843         echo "create 5000 files"
4844         createmany -o $DIR/f60c- 5000
4845 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
4846         lctl set_param fail_loc=0x80000137
4847         unlinkmany $DIR/f60c- 5000
4848         lctl set_param fail_loc=0
4849 }
4850 run_test 60c "unlink file when mds full"
4851
4852 test_60d() {
4853         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4854         SAVEPRINTK=$(lctl get_param -n printk)
4855
4856         # verify "lctl mark" is even working"
4857         MESSAGE="test message ID $RANDOM $$"
4858         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4859         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
4860
4861         lctl set_param printk=0 || error "set lnet.printk failed"
4862         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
4863         MESSAGE="new test message ID $RANDOM $$"
4864         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
4865         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4866         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
4867
4868         lctl set_param -n printk="$SAVEPRINTK"
4869 }
4870 run_test 60d "test printk console message masking"
4871
4872 test_61() {
4873         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4874         f="$DIR/f61"
4875         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
4876         cancel_lru_locks osc
4877         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
4878         sync
4879 }
4880 run_test 61 "mmap() writes don't make sync hang ================"
4881
4882 # bug 2330 - insufficient obd_match error checking causes LBUG
4883 test_62() {
4884         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4885         f="$DIR/f62"
4886         echo foo > $f
4887         cancel_lru_locks osc
4888         lctl set_param fail_loc=0x405
4889         cat $f && error "cat succeeded, expect -EIO"
4890         lctl set_param fail_loc=0
4891 }
4892 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
4893 # match every page all of the time.
4894 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
4895
4896 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
4897 test_63a() {    # was test_63
4898         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4899         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
4900         lctl set_param -n osc.*.max_dirty_mb 0
4901         for i in `seq 10` ; do
4902                 dd if=/dev/zero of=$DIR/f63 bs=8k &
4903                 sleep 5
4904                 kill $!
4905                 sleep 1
4906         done
4907
4908         lctl set_param -n osc.*.max_dirty_mb $MAX_DIRTY_MB
4909         rm -f $DIR/f63 || true
4910 }
4911 run_test 63a "Verify oig_wait interruption does not crash ======="
4912
4913 # bug 2248 - async write errors didn't return to application on sync
4914 # bug 3677 - async write errors left page locked
4915 test_63b() {
4916         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4917         debugsave
4918         lctl set_param debug=-1
4919
4920         # ensure we have a grant to do async writes
4921         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
4922         rm $DIR/$tfile
4923
4924         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4925         lctl set_param fail_loc=0x80000406
4926         $MULTIOP $DIR/$tfile Owy && \
4927                 error "sync didn't return ENOMEM"
4928         sync; sleep 2; sync     # do a real sync this time to flush page
4929         lctl get_param -n llite.*.dump_page_cache | grep locked && \
4930                 error "locked page left in cache after async error" || true
4931         debugrestore
4932 }
4933 run_test 63b "async write errors should be returned to fsync ==="
4934
4935 test_64a () {
4936         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4937         df $DIR
4938         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
4939 }
4940 run_test 64a "verify filter grant calculations (in kernel) ====="
4941
4942 test_64b () {
4943         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4944         sh oos.sh $MOUNT || error "oos.sh failed: $?"
4945 }
4946 run_test 64b "check out-of-space detection on client ==========="
4947
4948 test_64c() {
4949         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
4950 }
4951 run_test 64c "verify grant shrink ========================------"
4952
4953 # bug 1414 - set/get directories' stripe info
4954 test_65a() {
4955         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4956         test_mkdir -p $DIR/$tdir
4957         touch $DIR/$tdir/f1
4958         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
4959 }
4960 run_test 65a "directory with no stripe info ===================="
4961
4962 test_65b() {
4963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4964         test_mkdir -p $DIR/$tdir
4965         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4966                                                 error "setstripe"
4967         touch $DIR/$tdir/f2
4968         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
4969 }
4970 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
4971
4972 test_65c() {
4973         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4974         if [[ $OSTCOUNT -gt 1 ]]; then
4975                 test_mkdir -p $DIR/$tdir
4976                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
4977                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
4978                 touch $DIR/$tdir/f3
4979                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
4980         fi
4981 }
4982 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
4983
4984 test_65d() {
4985         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4986         test_mkdir -p $DIR/$tdir
4987         if [[ $STRIPECOUNT -le 0 ]]; then
4988                 sc=1
4989         elif [[ $STRIPECOUNT -gt 2000 ]]; then
4990 #LOV_MAX_STRIPE_COUNT is 2000
4991                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
4992         else
4993                 sc=$(($STRIPECOUNT - 1))
4994         fi
4995         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
4996         touch $DIR/$tdir/f4 $DIR/$tdir/f5
4997         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
4998                 error "lverify failed"
4999 }
5000 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5001
5002 test_65e() {
5003         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5004         test_mkdir -p $DIR/$tdir
5005
5006         $SETSTRIPE $DIR/$tdir || error "setstripe"
5007         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5008                                         error "no stripe info failed"
5009         touch $DIR/$tdir/f6
5010         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5011 }
5012 run_test 65e "directory setstripe defaults ======================="
5013
5014 test_65f() {
5015         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5016         test_mkdir -p $DIR/${tdir}f
5017         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5018 }
5019 run_test 65f "dir setstripe permission (should return error) ==="
5020
5021 test_65g() {
5022         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5023         test_mkdir -p $DIR/$tdir
5024         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5025                                                         error "setstripe"
5026         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5027         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5028                 error "delete default stripe failed"
5029 }
5030 run_test 65g "directory setstripe -d ==========================="
5031
5032 test_65h() {
5033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5034         test_mkdir -p $DIR/$tdir
5035         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5036                                                         error "setstripe"
5037         test_mkdir -p $DIR/$tdir/dd1
5038         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5039                 error "stripe info inherit failed"
5040 }
5041 run_test 65h "directory stripe info inherit ===================="
5042
5043 test_65i() { # bug6367
5044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5045         $SETSTRIPE -S 65536 -c -1 $MOUNT
5046 }
5047 run_test 65i "set non-default striping on root directory (bug 6367)="
5048
5049 test_65ia() { # bug12836
5050         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5051         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5052 }
5053 run_test 65ia "getstripe on -1 default directory striping"
5054
5055 test_65ib() { # bug12836
5056         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5057         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5058 }
5059 run_test 65ib "getstripe -v on -1 default directory striping"
5060
5061 test_65ic() { # bug12836
5062         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5063         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5064 }
5065 run_test 65ic "new find on -1 default directory striping"
5066
5067 test_65j() { # bug6367
5068         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5069         sync; sleep 1
5070         # if we aren't already remounting for each test, do so for this test
5071         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5072                 cleanup || error "failed to unmount"
5073                 setup
5074         fi
5075         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5076 }
5077 run_test 65j "set default striping on root directory (bug 6367)="
5078
5079 test_65k() { # bug11679
5080         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5081         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5082         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5083
5084     echo "Check OST status: "
5085     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5086               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5087
5088     for OSC in $MDS_OSCS; do
5089         echo $OSC "is activate"
5090         do_facet $SINGLEMDS lctl --device %$OSC activate
5091     done
5092
5093     mkdir -p $DIR/$tdir
5094     for INACTIVE_OSC in $MDS_OSCS; do
5095         echo "Deactivate: " $INACTIVE_OSC
5096         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5097         for STRIPE_OSC in $MDS_OSCS; do
5098             OST=`osc_to_ost $STRIPE_OSC`
5099             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5100                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5101
5102             [ -f $DIR/$tdir/$IDX ] && continue
5103             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5104             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5105             RC=$?
5106             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5107         done
5108         rm -f $DIR/$tdir/*
5109         echo $INACTIVE_OSC "is Activate."
5110         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5111     done
5112 }
5113 run_test 65k "validate manual striping works properly with deactivated OSCs"
5114
5115 test_65l() { # bug 12836
5116         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5117         test_mkdir -p $DIR/$tdir/test_dir
5118         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5119         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5120 }
5121 run_test 65l "lfs find on -1 stripe dir ========================"
5122
5123 # bug 2543 - update blocks count on client
5124 test_66() {
5125         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5126         COUNT=${COUNT:-8}
5127         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5128         sync; sync_all_data; sync; sync_all_data
5129         cancel_lru_locks osc
5130         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5131         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5132 }
5133 run_test 66 "update inode blocks count on client ==============="
5134
5135 LLOOP=
5136 LLITELOOPLOAD=
5137 cleanup_68() {
5138         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5139         trap 0
5140         if [ ! -z "$LLOOP" ]; then
5141                 if swapon -s | grep -q $LLOOP; then
5142                         swapoff $LLOOP || error "swapoff failed"
5143                 fi
5144
5145                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5146                 rm -f $LLOOP
5147                 unset LLOOP
5148         fi
5149         if [ ! -z "$LLITELOOPLOAD" ]; then
5150                 rmmod llite_lloop
5151                 unset LLITELOOPLOAD
5152         fi
5153         rm -f $DIR/f68*
5154 }
5155
5156 meminfo() {
5157         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5158 }
5159
5160 swap_used() {
5161         swapon -s | awk '($1 == "'$1'") { print $4 }'
5162 }
5163
5164 # test case for lloop driver, basic function
5165 test_68a() {
5166         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5167         [ "$UID" != 0 ] && skip_env "must run as root" && return
5168         llite_lloop_enabled || \
5169                 { skip_env "llite_lloop module disabled" && return; }
5170
5171         trap cleanup_68 EXIT
5172
5173         if ! module_loaded llite_lloop; then
5174                 if load_module llite/llite_lloop; then
5175                         LLITELOOPLOAD=yes
5176                 else
5177                         skip_env "can't find module llite_lloop"
5178                         return
5179                 fi
5180         fi
5181
5182         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5183         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5184         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5185
5186         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5187         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5188
5189         cleanup_68
5190 }
5191 run_test 68a "lloop driver - basic test ========================"
5192
5193 # excercise swapping to lustre by adding a high priority swapfile entry
5194 # and then consuming memory until it is used.
5195 test_68b() {  # was test_68
5196         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5197         [ "$UID" != 0 ] && skip_env "must run as root" && return
5198         lctl get_param -n devices | grep -q obdfilter && \
5199                 skip "local OST" && return
5200
5201         grep -q llite_lloop /proc/modules
5202         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5203
5204         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5205                 skip "can't reliably test swap with TCP" && return
5206
5207         MEMTOTAL=`meminfo MemTotal`
5208         NR_BLOCKS=$((MEMTOTAL>>8))
5209         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5210
5211         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5212         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5213         mkswap $DIR/f68b
5214
5215         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5216
5217         trap cleanup_68 EXIT
5218
5219         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5220
5221         echo "before: `swapon -s | grep $LLOOP`"
5222         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5223         echo "after: `swapon -s | grep $LLOOP`"
5224         SWAPUSED=`swap_used $LLOOP`
5225
5226         cleanup_68
5227
5228         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5229 }
5230 run_test 68b "support swapping to Lustre ========================"
5231
5232 # bug5265, obdfilter oa2dentry return -ENOENT
5233 # #define OBD_FAIL_OST_ENOENT 0x217
5234 test_69() {
5235         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5236         remote_ost_nodsh && skip "remote OST with nodsh" && return
5237
5238         f="$DIR/$tfile"
5239         $SETSTRIPE -c 1 -i 0 $f
5240
5241         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5242
5243         do_facet ost1 lctl set_param fail_loc=0x217
5244         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5245         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5246
5247         do_facet ost1 lctl set_param fail_loc=0
5248         $DIRECTIO write $f 0 2 || error "write error"
5249
5250         cancel_lru_locks osc
5251         $DIRECTIO read $f 0 1 || error "read error"
5252
5253         do_facet ost1 lctl set_param fail_loc=0x217
5254         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5255
5256         do_facet ost1 lctl set_param fail_loc=0
5257         rm -f $f
5258 }
5259 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5260
5261 test_71() {
5262     test_mkdir -p $DIR/$tdir
5263     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5264 }
5265 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5266
5267 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5268         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5269         [ "$RUNAS_ID" = "$UID" ] &&
5270                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5271
5272         # Check that testing environment is properly set up. Skip if not
5273         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5274                 skip_env "User $RUNAS_ID does not exist - skipping"
5275                 return 0
5276         }
5277         touch $DIR/$tfile
5278         chmod 777 $DIR/$tfile
5279         chmod ug+s $DIR/$tfile
5280         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5281                 error "$RUNAS dd $DIR/$tfile failed"
5282         # See if we are still setuid/sgid
5283         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5284                 error "S/gid is not dropped on write"
5285         # Now test that MDS is updated too
5286         cancel_lru_locks mdc
5287         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5288                 error "S/gid is not dropped on MDS"
5289         rm -f $DIR/$tfile
5290 }
5291 run_test 72a "Test that remove suid works properly (bug5695) ===="
5292
5293 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5294         local perm
5295
5296         [ "$RUNAS_ID" = "$UID" ] && \
5297                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5298         [ "$RUNAS_ID" -eq 0 ] && \
5299                 skip_env "RUNAS_ID = 0 -- skipping" && return
5300
5301         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5302         # Check that testing environment is properly set up. Skip if not
5303         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5304                 skip_env "User $RUNAS_ID does not exist - skipping"
5305                 return 0
5306         }
5307         touch $DIR/${tfile}-f{g,u}
5308         test_mkdir $DIR/${tfile}-dg
5309         test_mkdir $DIR/${tfile}-du
5310         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5311         chmod g+s $DIR/${tfile}-{f,d}g
5312         chmod u+s $DIR/${tfile}-{f,d}u
5313         for perm in 777 2777 4777; do
5314                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5315                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5316                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5317                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5318         done
5319         true
5320 }
5321 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5322
5323 # bug 3462 - multiple simultaneous MDC requests
5324 test_73() {
5325         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5326         test_mkdir $DIR/d73-1
5327         test_mkdir $DIR/d73-2
5328         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5329         pid1=$!
5330
5331         lctl set_param fail_loc=0x80000129
5332         $MULTIOP $DIR/d73-1/f73-2 Oc &
5333         sleep 1
5334         lctl set_param fail_loc=0
5335
5336         $MULTIOP $DIR/d73-2/f73-3 Oc &
5337         pid3=$!
5338
5339         kill -USR1 $pid1
5340         wait $pid1 || return 1
5341
5342         sleep 25
5343
5344         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5345         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5346         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5347
5348         rm -rf $DIR/d73-*
5349 }
5350 run_test 73 "multiple MDC requests (should not deadlock)"
5351
5352 test_74a() { # bug 6149, 6184
5353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5354         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5355         #
5356         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5357         # will spin in a tight reconnection loop
5358         touch $DIR/f74a
5359         $LCTL set_param fail_loc=0x8000030e
5360         # get any lock that won't be difficult - lookup works.
5361         ls $DIR/f74a
5362         $LCTL set_param fail_loc=0
5363         rm -f $DIR/f74a
5364         true
5365 }
5366 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5367
5368 test_74b() { # bug 13310
5369         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5370         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5371         #
5372         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5373         # will spin in a tight reconnection loop
5374         $LCTL set_param fail_loc=0x8000030e
5375         # get a "difficult" lock
5376         touch $DIR/f74b
5377         $LCTL set_param fail_loc=0
5378         rm -f $DIR/f74b
5379         true
5380 }
5381 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5382
5383 test_74c() {
5384         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5385         #define OBD_FAIL_LDLM_NEW_LOCK
5386         $LCTL set_param fail_loc=0x319
5387         touch $DIR/$tfile && error "touch successful"
5388         $LCTL set_param fail_loc=0
5389         true
5390 }
5391 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5392
5393 num_inodes() {
5394         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5395 }
5396
5397 get_inode_slab_tunables() {
5398         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5399 }
5400
5401 set_inode_slab_tunables() {
5402         echo "lustre_inode_cache $1" > /proc/slabinfo
5403 }
5404
5405 test_76() { # Now for bug 20433, added originally in bug 1443
5406         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5407         local SLAB_SETTINGS=`get_inode_slab_tunables`
5408         local CPUS=`getconf _NPROCESSORS_ONLN`
5409         # we cannot set limit below 1 which means 1 inode in each
5410         # per-cpu cache is still allowed
5411         set_inode_slab_tunables "1 1 0"
5412         cancel_lru_locks osc
5413         BEFORE_INODES=$(num_inodes)
5414         echo "before inodes: $BEFORE_INODES"
5415         local COUNT=1000
5416         [ "$SLOW" = "no" ] && COUNT=100
5417         for i in $(seq $COUNT); do
5418                 touch $DIR/$tfile
5419                 rm -f $DIR/$tfile
5420         done
5421         cancel_lru_locks osc
5422         AFTER_INODES=$(num_inodes)
5423         echo "after inodes: $AFTER_INODES"
5424         local wait=0
5425         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5426                 sleep 2
5427                 AFTER_INODES=$(num_inodes)
5428                 wait=$((wait+2))
5429                 echo "wait $wait seconds inodes: $AFTER_INODES"
5430                 if [ $wait -gt 30 ]; then
5431                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5432                 fi
5433         done
5434         set_inode_slab_tunables "$SLAB_SETTINGS"
5435 }
5436 run_test 76 "confirm clients recycle inodes properly ===="
5437
5438
5439 export ORIG_CSUM=""
5440 set_checksums()
5441 {
5442         # Note: in sptlrpc modes which enable its own bulk checksum, the
5443         # original crc32_le bulk checksum will be automatically disabled,
5444         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5445         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5446         # In this case set_checksums() will not be no-op, because sptlrpc
5447         # bulk checksum will be enabled all through the test.
5448
5449         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5450         lctl set_param -n osc.*.checksums $1
5451         return 0
5452 }
5453
5454 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5455                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5456 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5457 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5458 set_checksum_type()
5459 {
5460         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5461         log "set checksum type to $1"
5462         return 0
5463 }
5464 F77_TMP=$TMP/f77-temp
5465 F77SZ=8
5466 setup_f77() {
5467         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5468                 error "error writing to $F77_TMP"
5469 }
5470
5471 test_77a() { # bug 10889
5472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5473         $GSS && skip "could not run with gss" && return
5474         [ ! -f $F77_TMP ] && setup_f77
5475         set_checksums 1
5476         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5477         set_checksums 0
5478         rm -f $DIR/$tfile
5479 }
5480 run_test 77a "normal checksum read/write operation"
5481
5482 test_77b() { # bug 10889
5483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5484         $GSS && skip "could not run with gss" && return
5485         [ ! -f $F77_TMP ] && setup_f77
5486         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5487         $LCTL set_param fail_loc=0x80000409
5488         set_checksums 1
5489
5490         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5491                 error "dd error: $?"
5492         $LCTL set_param fail_loc=0
5493
5494         for algo in $CKSUM_TYPES; do
5495                 cancel_lru_locks osc
5496                 set_checksum_type $algo
5497                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5498                 $LCTL set_param fail_loc=0x80000408
5499                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5500                 $LCTL set_param fail_loc=0
5501         done
5502         set_checksums 0
5503         set_checksum_type $ORIG_CSUM_TYPE
5504         rm -f $DIR/$tfile
5505 }
5506 run_test 77b "checksum error on client write, read"
5507
5508 test_77d() { # bug 10889
5509         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5510         $GSS && skip "could not run with gss" && return
5511         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5512         $LCTL set_param fail_loc=0x80000409
5513         set_checksums 1
5514         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5515                 error "direct write: rc=$?"
5516         $LCTL set_param fail_loc=0
5517         set_checksums 0
5518
5519         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5520         $LCTL set_param fail_loc=0x80000408
5521         set_checksums 1
5522         cancel_lru_locks osc
5523         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5524                 error "direct read: rc=$?"
5525         $LCTL set_param fail_loc=0
5526         set_checksums 0
5527 }
5528 run_test 77d "checksum error on OST direct write, read"
5529
5530 test_77f() { # bug 10889
5531         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5532         $GSS && skip "could not run with gss" && return
5533         set_checksums 1
5534         for algo in $CKSUM_TYPES; do
5535                 cancel_lru_locks osc
5536                 set_checksum_type $algo
5537                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5538                 $LCTL set_param fail_loc=0x409
5539                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5540                         error "direct write succeeded"
5541                 $LCTL set_param fail_loc=0
5542         done
5543         set_checksum_type $ORIG_CSUM_TYPE
5544         set_checksums 0
5545 }
5546 run_test 77f "repeat checksum error on write (expect error)"
5547
5548 test_77g() { # bug 10889
5549         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5550         $GSS && skip "could not run with gss" && return
5551         remote_ost_nodsh && skip "remote OST with nodsh" && return
5552
5553         [ ! -f $F77_TMP ] && setup_f77
5554
5555         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5556         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5557         do_facet ost1 lctl set_param fail_loc=0x8000021a
5558         set_checksums 1
5559         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5560                 error "write error: rc=$?"
5561         do_facet ost1 lctl set_param fail_loc=0
5562         set_checksums 0
5563
5564         cancel_lru_locks osc
5565         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5566         do_facet ost1 lctl set_param fail_loc=0x8000021b
5567         set_checksums 1
5568         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5569         do_facet ost1 lctl set_param fail_loc=0
5570         set_checksums 0
5571 }
5572 run_test 77g "checksum error on OST write, read"
5573
5574 test_77i() { # bug 13805
5575         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5576         $GSS && skip "could not run with gss" && return
5577         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5578         lctl set_param fail_loc=0x40b
5579         remount_client $MOUNT
5580         lctl set_param fail_loc=0
5581         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5582                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5583                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5584                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5585         done
5586         remount_client $MOUNT
5587 }
5588 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5589
5590 test_77j() { # bug 13805
5591         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5592         $GSS && skip "could not run with gss" && return
5593         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5594         lctl set_param fail_loc=0x40c
5595         remount_client $MOUNT
5596         lctl set_param fail_loc=0
5597         sleep 2 # wait async osc connect to finish
5598         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5599                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5600                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5601                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5602         done
5603         remount_client $MOUNT
5604 }
5605 run_test 77j "client only supporting ADLER32"
5606
5607 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5608 rm -f $F77_TMP
5609 unset F77_TMP
5610
5611 test_78() { # bug 10901
5612         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5613         remote_ost || { skip_env "local OST" && return; }
5614
5615         NSEQ=5
5616         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5617         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5618         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5619         echo "MemTotal: $MEMTOTAL"
5620
5621         # reserve 256MB of memory for the kernel and other running processes,
5622         # and then take 1/2 of the remaining memory for the read/write buffers.
5623         if [ $MEMTOTAL -gt 512 ] ;then
5624                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5625         else
5626                 # for those poor memory-starved high-end clusters...
5627                 MEMTOTAL=$((MEMTOTAL / 2))
5628         fi
5629         echo "Mem to use for directio: $MEMTOTAL"
5630
5631         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5632         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5633         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5634         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5635                 head -n1)
5636         echo "Smallest OST: $SMALLESTOST"
5637         [[ $SMALLESTOST -lt 10240 ]] &&
5638                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5639
5640         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5641                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5642
5643         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5644         echo "File size: $F78SIZE"
5645         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5646         for i in $(seq 1 $NSEQ); do
5647                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5648                 echo directIO rdwr round $i of $NSEQ
5649                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5650         done
5651
5652         rm -f $DIR/$tfile
5653 }
5654 run_test 78 "handle large O_DIRECT writes correctly ============"
5655
5656 test_79() { # bug 12743
5657         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5658         wait_delete_completed
5659
5660         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5661         BKFREE=$(calc_osc_kbytes kbytesfree)
5662         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5663
5664         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5665         DFTOTAL=`echo $STRING | cut -d, -f1`
5666         DFUSED=`echo $STRING  | cut -d, -f2`
5667         DFAVAIL=`echo $STRING | cut -d, -f3`
5668         DFFREE=$(($DFTOTAL - $DFUSED))
5669
5670         ALLOWANCE=$((64 * $OSTCOUNT))
5671
5672         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5673            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5674                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5675         fi
5676         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5677            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5678                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5679         fi
5680         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5681            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5682                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5683         fi
5684 }
5685 run_test 79 "df report consistency check ======================="
5686
5687 test_80() { # bug 10718
5688         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5689         # relax strong synchronous semantics for slow backends like ZFS
5690         local soc="obdfilter.*.sync_on_lock_cancel"
5691         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5692         local hosts=
5693         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5694                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5695                           facet_active_host $host; done | sort -u)
5696                 do_nodes $hosts lctl set_param $soc=never
5697         fi
5698
5699         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5700         sync; sleep 1; sync
5701         local BEFORE=`date +%s`
5702         cancel_lru_locks osc
5703         local AFTER=`date +%s`
5704         local DIFF=$((AFTER-BEFORE))
5705         if [ $DIFF -gt 1 ] ; then
5706                 error "elapsed for 1M@1T = $DIFF"
5707         fi
5708
5709         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5710
5711         rm -f $DIR/$tfile
5712 }
5713 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5714
5715 test_81a() { # LU-456
5716         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5717         remote_ost_nodsh && skip "remote OST with nodsh" && return
5718         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5719         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5720         do_facet ost1 lctl set_param fail_loc=0x80000228
5721
5722         # write should trigger a retry and success
5723         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5724         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5725         RC=$?
5726         if [ $RC -ne 0 ] ; then
5727                 error "write should success, but failed for $RC"
5728         fi
5729 }
5730 run_test 81a "OST should retry write when get -ENOSPC ==============="
5731
5732 test_81b() { # LU-456
5733         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5734         remote_ost_nodsh && skip "remote OST with nodsh" && return
5735         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5736         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5737         do_facet ost1 lctl set_param fail_loc=0x228
5738
5739         # write should retry several times and return -ENOSPC finally
5740         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5741         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5742         RC=$?
5743         ENOSPC=28
5744         if [ $RC -ne $ENOSPC ] ; then
5745                 error "dd should fail for -ENOSPC, but succeed."
5746         fi
5747 }
5748 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5749
5750 test_82() { # LU-1031
5751         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5752         local gid1=14091995
5753         local gid2=16022000
5754
5755         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5756         local MULTIPID1=$!
5757         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5758         local MULTIPID2=$!
5759         kill -USR1 $MULTIPID2
5760         sleep 2
5761         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5762                 error "First grouplock does not block second one"
5763         else
5764                 echo "Second grouplock blocks first one"
5765         fi
5766         kill -USR1 $MULTIPID1
5767         wait $MULTIPID1
5768         wait $MULTIPID2
5769 }
5770 run_test 82 "Basic grouplock test ==============================="
5771
5772 test_99a() {
5773         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
5774                 return
5775         test_mkdir -p $DIR/d99cvsroot
5776         chown $RUNAS_ID $DIR/d99cvsroot
5777         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
5778         cd $TMP
5779
5780         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
5781         cd $oldPWD
5782 }
5783 run_test 99a "cvs init ========================================="
5784
5785 test_99b() {
5786         [ -z "$(which cvs 2>/dev/null)" ] &&
5787                 skip_env "could not find cvs" && return
5788         [ ! -d $DIR/d99cvsroot ] && test_99a
5789         cd /etc/init.d
5790         # some versions of cvs import exit(1) when asked to import links or
5791         # files they can't read.  ignore those files.
5792         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
5793                         ! -perm +4 -printf '-I %f\n')
5794         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
5795                 d99reposname vtag rtag
5796 }
5797 run_test 99b "cvs import ======================================="
5798
5799 test_99c() {
5800         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5801         [ ! -d $DIR/d99cvsroot ] && test_99b
5802         cd $DIR
5803         test_mkdir -p $DIR/d99reposname
5804         chown $RUNAS_ID $DIR/d99reposname
5805         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
5806 }
5807 run_test 99c "cvs checkout ====================================="
5808
5809 test_99d() {
5810         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5811         [ ! -d $DIR/d99cvsroot ] && test_99c
5812         cd $DIR/d99reposname
5813         $RUNAS touch foo99
5814         $RUNAS cvs add -m 'addmsg' foo99
5815 }
5816 run_test 99d "cvs add =========================================="
5817
5818 test_99e() {
5819         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5820         [ ! -d $DIR/d99cvsroot ] && test_99c
5821         cd $DIR/d99reposname
5822         $RUNAS cvs update
5823 }
5824 run_test 99e "cvs update ======================================="
5825
5826 test_99f() {
5827         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5828         [ ! -d $DIR/d99cvsroot ] && test_99d
5829         cd $DIR/d99reposname
5830         $RUNAS cvs commit -m 'nomsg' foo99
5831     rm -fr $DIR/d99cvsroot
5832 }
5833 run_test 99f "cvs commit ======================================="
5834
5835 test_100() {
5836         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5837         [ "$NETTYPE" = tcp ] || \
5838                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
5839                         return ; }
5840
5841         remote_ost_nodsh && skip "remote OST with nodsh" && return
5842         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5843         remote_servers || \
5844                 { skip "useless for local single node setup" && return; }
5845
5846         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
5847                 [ "$PROT" != "tcp" ] && continue
5848                 RPORT=$(echo $REMOTE | cut -d: -f2)
5849                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
5850
5851                 rc=0
5852                 LPORT=`echo $LOCAL | cut -d: -f2`
5853                 if [ $LPORT -ge 1024 ]; then
5854                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
5855                         netstat -tna
5856                         error_exit "local: $LPORT > 1024, remote: $RPORT"
5857                 fi
5858         done
5859         [ "$rc" = 0 ] || error_exit "privileged port not found" )
5860 }
5861 run_test 100 "check local port using privileged port ==========="
5862
5863 function get_named_value()
5864 {
5865     local tag
5866
5867     tag=$1
5868     while read ;do
5869         line=$REPLY
5870         case $line in
5871         $tag*)
5872             echo $line | sed "s/^$tag[ ]*//"
5873             break
5874             ;;
5875         esac
5876     done
5877 }
5878
5879 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
5880                    awk '/^max_cached_mb/ { print $2 }')
5881
5882 cleanup_101a() {
5883         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
5884         trap 0
5885 }
5886
5887 test_101a() {
5888         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5889         local s
5890         local discard
5891         local nreads=10000
5892         local cache_limit=32
5893
5894         $LCTL set_param -n osc.*-osc*.rpc_stats 0
5895         trap cleanup_101a EXIT
5896         $LCTL set_param -n llite.*.read_ahead_stats 0
5897         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
5898
5899         #
5900         # randomly read 10000 of 64K chunks from file 3x 32MB in size
5901         #
5902         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
5903         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
5904
5905         discard=0
5906         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
5907                 get_named_value 'read but discarded' | cut -d" " -f1); do
5908                         discard=$(($discard + $s))
5909         done
5910         cleanup_101a
5911
5912         if [[ $(($discard * 10)) -gt $nreads ]]; then
5913                 $LCTL get_param osc.*-osc*.rpc_stats
5914                 $LCTL get_param llite.*.read_ahead_stats
5915                 error "too many ($discard) discarded pages"
5916         fi
5917         rm -f $DIR/$tfile || true
5918 }
5919 run_test 101a "check read-ahead for random reads ================"
5920
5921 setup_test101bc() {
5922         test_mkdir -p $DIR/$tdir
5923         STRIPE_SIZE=1048576
5924         STRIPE_COUNT=$OSTCOUNT
5925         STRIPE_OFFSET=0
5926
5927         local list=$(comma_list $(osts_nodes))
5928         set_osd_param $list '' read_cache_enable 0
5929         set_osd_param $list '' writethrough_cache_enable 0
5930
5931         trap cleanup_test101bc EXIT
5932         # prepare the read-ahead file
5933         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
5934
5935         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
5936 }
5937
5938 cleanup_test101bc() {
5939         trap 0
5940         rm -rf $DIR/$tdir
5941         rm -f $DIR/$tfile
5942
5943         local list=$(comma_list $(osts_nodes))
5944         set_osd_param $list '' read_cache_enable 1
5945         set_osd_param $list '' writethrough_cache_enable 1
5946 }
5947
5948 calc_total() {
5949         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
5950 }
5951
5952 ra_check_101() {
5953         local READ_SIZE=$1
5954         local STRIPE_SIZE=1048576
5955         local RA_INC=1048576
5956         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
5957         local FILE_LENGTH=$((64*100))
5958         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
5959                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
5960         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
5961                         get_named_value 'read but discarded' |
5962                         cut -d" " -f1 | calc_total)
5963         if [[ $DISCARD -gt $discard_limit ]]; then
5964                 $LCTL get_param llite.*.read_ahead_stats
5965                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
5966         else
5967                 echo "Read-ahead success for size ${READ_SIZE}"
5968         fi
5969 }
5970
5971 test_101b() {
5972         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5973         [[ $OSTCOUNT -lt 2 ]] &&
5974                 skip_env "skipping stride IO stride-ahead test" && return
5975         local STRIPE_SIZE=1048576
5976         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
5977         local FILE_LENGTH=$((STRIPE_SIZE*100))
5978         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
5979         # prepare the read-ahead file
5980         setup_test101bc
5981         cancel_lru_locks osc
5982         for BIDX in 2 4 8 16 32 64 128 256
5983         do
5984                 local BSIZE=$((BIDX*4096))
5985                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
5986                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
5987                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
5988                 $LCTL set_param -n llite.*.read_ahead_stats 0
5989                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
5990                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
5991                 cancel_lru_locks osc
5992                 ra_check_101 $BSIZE
5993         done
5994         cleanup_test101bc
5995         true
5996 }
5997 run_test 101b "check stride-io mode read-ahead ================="
5998
5999 test_101c() {
6000         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6001         local STRIPE_SIZE=1048576
6002         local FILE_LENGTH=$((STRIPE_SIZE*100))
6003         local nreads=10000
6004         local osc_rpc_stats
6005
6006         setup_test101bc
6007
6008         cancel_lru_locks osc
6009         $LCTL set_param osc.*.rpc_stats 0
6010         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6011         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6012                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6013                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6014                 local size
6015
6016                 if [ $lines -le 20 ]; then
6017                         continue
6018                 fi
6019                 for size in 1 2 4 8; do
6020                         local rpc=$(echo "$stats" |
6021                                     awk '($1 == "'$size':") {print $2; exit; }')
6022                         [ $rpc != 0 ] &&
6023                                 error "Small $((size*4))k read IO $rpc !"
6024                 done
6025                 echo "$osc_rpc_stats check passed!"
6026         done
6027         cleanup_test101bc
6028         true
6029 }
6030 run_test 101c "check stripe_size aligned read-ahead ================="
6031
6032 set_read_ahead() {
6033    $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6034    $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6035 }
6036
6037 test_101d() {
6038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6039         local file=$DIR/$tfile
6040         local size=${FILESIZE_101c:-500}
6041         local ra_MB=${READAHEAD_MB:-40}
6042
6043         local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6044         [ $space -gt $((size * 1024)) ] ||
6045                 { skip "Need free space ${size}M, have ${space}K" && return; }
6046
6047         echo "Creating test file $file of size ${size}M with ${space}K free space"
6048         $SETSTRIPE -c -1 $file || error "setstripe failed"
6049         dd if=/dev/zero of=$file bs=1M count=$size || error "dd failed"
6050         echo Cancel LRU locks on lustre client to flush the client cache
6051         cancel_lru_locks osc
6052
6053     echo Disable read-ahead
6054     local old_READAHEAD=$(set_read_ahead 0)
6055
6056     echo Reading the test file $file with read-ahead disabled
6057     time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
6058
6059     echo Cancel LRU locks on lustre client to flush the client cache
6060     cancel_lru_locks osc
6061     echo Enable read-ahead with ${ra_MB}MB
6062     set_read_ahead $ra_MB
6063
6064     echo Reading the test file $file with read-ahead enabled
6065     time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
6066
6067     echo read-ahead disabled time read $time_ra_OFF
6068     echo read-ahead enabled  time read $time_ra_ON
6069
6070         set_read_ahead $old_READAHEAD
6071         rm -f $file
6072         wait_delete_completed
6073
6074     [ $time_ra_ON -lt $time_ra_OFF ] ||
6075         error "read-ahead enabled  time read (${time_ra_ON}s) is more than
6076                read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
6077 }
6078 run_test 101d "file read with and without read-ahead enabled  ================="
6079
6080 test_101e() {
6081         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6082         local file=$DIR/$tfile
6083         local size_KB=500  #KB
6084         local count=100
6085         local bsize=1024
6086
6087         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6088         local need_KB=$((count * size_KB))
6089         [[ $free_KB -le $need_KB ]] &&
6090                 skip_env "Need free space $need_KB, have $free_KB" && return
6091
6092         echo "Creating $count ${size_KB}K test files"
6093         for ((i = 0; i < $count; i++)); do
6094                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6095         done
6096
6097         echo Cancel LRU locks on lustre client to flush the client cache
6098         cancel_lru_locks osc
6099
6100         echo Reset readahead stats
6101         $LCTL set_param -n llite.*.read_ahead_stats 0
6102
6103         for ((i = 0; i < $count; i++)); do
6104                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6105         done
6106
6107         local miss=$($LCTL get_param -n llite.*.read_ahead_stats | \
6108                   get_named_value 'misses' | cut -d" " -f1 | calc_total)
6109
6110         for ((i = 0; i < $count; i++)); do
6111                 rm -rf $file.$i 2>/dev/null
6112         done
6113
6114         #10000 means 20% reads are missing in readahead
6115         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6116 }
6117 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6118
6119 cleanup_test101f() {
6120     trap 0
6121     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6122     rm -rf $DIR/$tfile 2>/dev/null
6123 }
6124
6125 test_101f() {
6126         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6127     local file=$DIR/$tfile
6128     local nreads=1000
6129
6130     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6131     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6132     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6133     trap cleanup_test101f EXIT
6134
6135     echo Cancel LRU locks on lustre client to flush the client cache
6136     cancel_lru_locks osc
6137
6138     echo Reset readahead stats
6139     $LCTL set_param -n llite.*.read_ahead_stats 0
6140     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6141     # readahead should read in 2M file on second read, so only miss
6142     # 2 pages.
6143     echo Random 4K reads on 2M file for 1000 times
6144     $READS -f $file -s 2097152 -b 4096 -n $nreads
6145
6146     echo checking missing pages
6147     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6148           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6149
6150     [ $miss -lt 3 ] || error "misses too much pages!"
6151     cleanup_test101f
6152 }
6153 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6154
6155 setup_test102() {
6156         test_mkdir -p $DIR/$tdir
6157         chown $RUNAS_ID $DIR/$tdir
6158         STRIPE_SIZE=65536
6159         STRIPE_OFFSET=1
6160         STRIPE_COUNT=$OSTCOUNT
6161         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6162
6163         trap cleanup_test102 EXIT
6164         cd $DIR
6165         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6166         cd $DIR/$tdir
6167         for num in 1 2 3 4; do
6168                 for count in $(seq 1 $STRIPE_COUNT); do
6169                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6170                                 local size=`expr $STRIPE_SIZE \* $num`
6171                                 local file=file"$num-$idx-$count"
6172                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6173                         done
6174                 done
6175         done
6176
6177         cd $DIR
6178         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6179 }
6180
6181 cleanup_test102() {
6182         trap 0
6183         rm -f $TMP/f102.tar
6184         rm -rf $DIR/d0.sanity/d102
6185 }
6186
6187 test_102a() {
6188         local testfile=$DIR/$tfile
6189
6190         touch $testfile
6191
6192         [ "$UID" != 0 ] && skip_env "must run as root" && return
6193         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6194                 skip_env "must have user_xattr" && return
6195
6196         [ -z "$(which setfattr 2>/dev/null)" ] &&
6197                 skip_env "could not find setfattr" && return
6198
6199         echo "set/get xattr..."
6200         setfattr -n trusted.name1 -v value1 $testfile ||
6201                 error "setfattr -n trusted.name1=value1 $testfile failed"
6202         getfattr -n trusted.name1 $testfile 2> /dev/null |
6203           grep "trusted.name1=.value1" ||
6204                 error "$testfile missing trusted.name1=value1"
6205
6206         setfattr -n user.author1 -v author1 $testfile ||
6207                 error "setfattr -n user.author1=author1 $testfile failed"
6208         getfattr -n user.author1 $testfile 2> /dev/null |
6209           grep "user.author1=.author1" ||
6210                 error "$testfile missing trusted.author1=author1"
6211
6212         echo "listxattr..."
6213         setfattr -n trusted.name2 -v value2 $testfile ||
6214                 error "$testfile unable to set trusted.name2"
6215         setfattr -n trusted.name3 -v value3 $testfile ||
6216                 error "$testfile unable to set trusted.name3"
6217         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6218             grep "trusted.name" | wc -l) -eq 3 ] ||
6219                 error "$testfile missing 3 trusted.name xattrs"
6220
6221         setfattr -n user.author2 -v author2 $testfile ||
6222                 error "$testfile unable to set user.author2"
6223         setfattr -n user.author3 -v author3 $testfile ||
6224                 error "$testfile unable to set user.author3"
6225         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6226             grep "user.author" | wc -l) -eq 3 ] ||
6227                 error "$testfile missing 3 user.author xattrs"
6228
6229         echo "remove xattr..."
6230         setfattr -x trusted.name1 $testfile ||
6231                 error "$testfile error deleting trusted.name1"
6232         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6233                 error "$testfile did not delete trusted.name1 xattr"
6234
6235         setfattr -x user.author1 $testfile ||
6236                 error "$testfile error deleting user.author1"
6237         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6238                 error "$testfile did not delete trusted.name1 xattr"
6239
6240         # b10667: setting lustre special xattr be silently discarded
6241         echo "set lustre special xattr ..."
6242         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6243                 error "$testfile allowed setting trusted.lov"
6244 }
6245 run_test 102a "user xattr test =================================="
6246
6247 test_102b() {
6248         [ -z "$(which setfattr 2>/dev/null)" ] &&
6249                 skip_env "could not find setfattr" && return
6250
6251         # b10930: get/set/list trusted.lov xattr
6252         echo "get/set/list trusted.lov xattr ..."
6253         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6254         local testfile=$DIR/$tfile
6255         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6256                 error "setstripe failed"
6257         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6258                 error "getstripe failed"
6259         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6260                 error "can't get trusted.lov from $testfile"
6261
6262         local testfile2=${testfile}2
6263         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6264                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6265
6266         $MCREATE $testfile2
6267         setfattr -n trusted.lov -v $value $testfile2
6268         local stripe_size=$($GETSTRIPE -S $testfile2)
6269         local stripe_count=$($GETSTRIPE -c $testfile2)
6270         [[ $stripe_size -eq 65536 ]] ||
6271                 error "stripe size $stripe_size != 65536"
6272         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6273                 error "stripe count $stripe_count != $STRIPECOUNT"
6274         rm -f $DIR/$tfile
6275 }
6276 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6277
6278 test_102c() {
6279         [ -z "$(which setfattr 2>/dev/null)" ] &&
6280                 skip_env "could not find setfattr" && return
6281
6282         # b10930: get/set/list lustre.lov xattr
6283         echo "get/set/list lustre.lov xattr ..."
6284         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6285         test_mkdir -p $DIR/$tdir
6286         chown $RUNAS_ID $DIR/$tdir
6287         local testfile=$DIR/$tdir/$tfile
6288         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6289                 error "setstripe failed"
6290         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6291                 error "getstripe failed"
6292         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6293         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6294
6295         local testfile2=${testfile}2
6296         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6297                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6298
6299         $RUNAS $MCREATE $testfile2
6300         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6301         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6302         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6303         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6304         [ $stripe_count -eq $STRIPECOUNT ] ||
6305                 error "stripe count $stripe_count != $STRIPECOUNT"
6306 }
6307 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6308
6309 compare_stripe_info1() {
6310         local stripe_index_all_zero=true
6311
6312         for num in 1 2 3 4; do
6313                 for count in $(seq 1 $STRIPE_COUNT); do
6314                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6315                                 local size=$((STRIPE_SIZE * num))
6316                                 local file=file"$num-$offset-$count"
6317                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6318                                 [[ $stripe_size -ne $size ]] &&
6319                                     error "$file: size $stripe_size != $size"
6320                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6321                                 # allow fewer stripes to be created, ORI-601
6322                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6323                                     error "$file: count $stripe_count != $count"
6324                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6325                                 [[ $stripe_index -ne 0 ]] &&
6326                                         stripe_index_all_zero=false
6327                         done
6328                 done
6329         done
6330         $stripe_index_all_zero &&
6331                 error "all files are being extracted starting from OST index 0"
6332         return 0
6333 }
6334
6335 find_lustre_tar() {
6336         [ -n "$(which tar 2>/dev/null)" ] &&
6337                 strings $(which tar) | grep -q "lustre" && echo tar
6338 }
6339
6340 test_102d() {
6341         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6342         # b10930: tar test for trusted.lov xattr
6343         TAR=$(find_lustre_tar)
6344         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6345         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6346         setup_test102
6347         test_mkdir -p $DIR/d102d
6348         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6349         cd $DIR/d102d/$tdir
6350         compare_stripe_info1
6351 }
6352 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6353
6354 test_102f() {
6355         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6356         # b10930: tar test for trusted.lov xattr
6357         TAR=$(find_lustre_tar)
6358         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6359         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6360         setup_test102
6361         test_mkdir -p $DIR/d102f
6362         cd $DIR
6363         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6364         cd $DIR/d102f/$tdir
6365         compare_stripe_info1
6366 }
6367 run_test 102f "tar copy files, not keep osts ==========="
6368
6369 grow_xattr() {
6370         local xsize=${1:-1024}  # in bytes
6371         local file=$DIR/$tfile
6372
6373         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6374                 skip "must have user_xattr" && return 0
6375         [ -z "$(which setfattr 2>/dev/null)" ] &&
6376                 skip_env "could not find setfattr" && return 0
6377         [ -z "$(which getfattr 2>/dev/null)" ] &&
6378                 skip_env "could not find getfattr" && return 0
6379
6380         touch $file
6381
6382         local value="$(generate_string $xsize)"
6383
6384         local xbig=trusted.big
6385         log "save $xbig on $file"
6386         setfattr -n $xbig -v $value $file ||
6387                 error "saving $xbig on $file failed"
6388
6389         local orig=$(get_xattr_value $xbig $file)
6390         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6391
6392         local xsml=trusted.sml
6393         log "save $xsml on $file"
6394         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6395
6396         local new=$(get_xattr_value $xbig $file)
6397         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6398
6399         log "grow $xsml on $file"
6400         setfattr -n $xsml -v "$value" $file ||
6401                 error "growing $xsml on $file failed"
6402
6403         new=$(get_xattr_value $xbig $file)
6404         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6405         log "$xbig still valid after growing $xsml"
6406
6407         rm -f $file
6408 }
6409
6410 test_102h() { # bug 15777
6411         grow_xattr 1024
6412 }
6413 run_test 102h "grow xattr from inside inode to external block"
6414
6415 test_102ha() {
6416         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6417         grow_xattr $(max_xattr_size)
6418 }
6419 run_test 102ha "grow xattr from inside inode to external inode"
6420
6421 test_102i() { # bug 17038
6422         [ -z "$(which getfattr 2>/dev/null)" ] &&
6423                 skip "could not find getfattr" && return
6424         touch $DIR/$tfile
6425         ln -s $DIR/$tfile $DIR/${tfile}link
6426         getfattr -n trusted.lov $DIR/$tfile ||
6427                 error "lgetxattr on $DIR/$tfile failed"
6428         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6429                 grep -i "no such attr" ||
6430                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6431         rm -f $DIR/$tfile $DIR/${tfile}link
6432 }
6433 run_test 102i "lgetxattr test on symbolic link ============"
6434
6435 test_102j() {
6436         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6437         TAR=$(find_lustre_tar)
6438         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6439         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6440         setup_test102 "$RUNAS"
6441         test_mkdir -p $DIR/d102j
6442         chown $RUNAS_ID $DIR/d102j
6443         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6444         cd $DIR/d102j/$tdir
6445         compare_stripe_info1 "$RUNAS"
6446 }
6447 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6448
6449 test_102k() {
6450         [ -z "$(which setfattr 2>/dev/null)" ] &&
6451                 skip "could not find setfattr" && return
6452         touch $DIR/$tfile
6453         # b22187 just check that does not crash for regular file.
6454         setfattr -n trusted.lov $DIR/$tfile
6455         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6456         local test_kdir=$DIR/d102k
6457         test_mkdir $test_kdir
6458         local default_size=`$GETSTRIPE -S $test_kdir`
6459         local default_count=`$GETSTRIPE -c $test_kdir`
6460         local default_offset=`$GETSTRIPE -i $test_kdir`
6461         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6462                 error 'dir setstripe failed'
6463         setfattr -n trusted.lov $test_kdir
6464         local stripe_size=`$GETSTRIPE -S $test_kdir`
6465         local stripe_count=`$GETSTRIPE -c $test_kdir`
6466         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6467         [ $stripe_size -eq $default_size ] ||
6468                 error "stripe size $stripe_size != $default_size"
6469         [ $stripe_count -eq $default_count ] ||
6470                 error "stripe count $stripe_count != $default_count"
6471         [ $stripe_offset -eq $default_offset ] ||
6472                 error "stripe offset $stripe_offset != $default_offset"
6473         rm -rf $DIR/$tfile $test_kdir
6474 }
6475 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6476
6477 test_102l() {
6478         [ -z "$(which getfattr 2>/dev/null)" ] &&
6479                 skip "could not find getfattr" && return
6480
6481         # LU-532 trusted. xattr is invisible to non-root
6482         local testfile=$DIR/$tfile
6483
6484         touch $testfile
6485
6486         echo "listxattr as user..."
6487         chown $RUNAS_ID $testfile
6488         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6489             grep -q "trusted" &&
6490                 error "$testfile trusted xattrs are user visible"
6491
6492         return 0;
6493 }
6494 run_test 102l "listxattr size test =================================="
6495
6496 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6497         local path=$DIR/$tfile
6498         touch $path
6499
6500         listxattr_size_check $path || error "listattr_size_check $path failed"
6501 }
6502 run_test 102m "Ensure listxattr fails on small bufffer ========"
6503
6504 cleanup_test102
6505
6506 getxattr() { # getxattr path name
6507         # Return the base64 encoding of the value of xattr name on path.
6508         local path=$1
6509         local name=$2
6510
6511         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6512         # file: $path
6513         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6514         #
6515         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6516
6517         getfattr --absolute-names --encoding=base64 --name=$name $path |
6518                 awk -F= -v name=$name '$1 == name {
6519                         print substr($0, index($0, "=") + 1);
6520         }'
6521 }
6522
6523 test_102n() { # LU-4101 mdt: protect internal xattrs
6524         local file0=$DIR/$tfile.0
6525         local file1=$DIR/$tfile.1
6526         local xattr0=$TMP/$tfile.0
6527         local xattr1=$TMP/$tfile.1
6528         local name
6529         local value
6530
6531         [ -z "$(which setfattr 2>/dev/null)" ] &&
6532                 skip "could not find setfattr" && return
6533
6534         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6535         then
6536                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6537                 return
6538         fi
6539
6540         rm -rf $file0 $file1 $xattr0 $xattr1
6541         touch $file0 $file1
6542
6543         # Get 'before' xattrs of $file1.
6544         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6545
6546         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6547                 # Try to copy xattr from $file0 to $file1.
6548                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6549
6550                 setfattr --name=trusted.$name --value="$value" $file1 ||
6551                         error "setxattr 'trusted.$name' failed"
6552
6553                 # Try to set a garbage xattr.
6554                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6555
6556                 setfattr --name=trusted.$name --value="$value" $file1 ||
6557                         error "setxattr 'trusted.$name' failed"
6558
6559                 # Try to remove the xattr from $file1. We don't care if this
6560                 # appears to succeed or fail, we just don't want there to be
6561                 # any changes or crashes.
6562                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6563         done
6564
6565         # Get 'after' xattrs of file1.
6566         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6567
6568         if ! diff $xattr0 $xattr1; then
6569                 error "before and after xattrs of '$file1' differ"
6570         fi
6571
6572         rm -rf $file0 $file1 $xattr0 $xattr1
6573
6574         return 0
6575 }
6576 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6577
6578 run_acl_subtest()
6579 {
6580     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6581     return $?
6582 }
6583
6584 test_103a() {
6585         [ "$UID" != 0 ] && skip_env "must run as root" && return
6586         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6587                 skip "must have acl enabled" && return
6588         [ -z "$(which setfacl 2>/dev/null)" ] &&
6589                 skip_env "could not find setfacl" && return
6590         $GSS && skip "could not run under gss" && return
6591
6592         declare -a identity_old
6593
6594         for num in $(seq $MDSCOUNT); do
6595                 switch_identity $num true || identity_old[$num]=$?
6596         done
6597
6598         SAVE_UMASK=$(umask)
6599         umask 0022
6600         cd $DIR
6601
6602         echo "performing cp ..."
6603         run_acl_subtest cp || error "run_acl_subtest cp failed"
6604         echo "performing getfacl-noacl..."
6605         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6606         echo "performing misc..."
6607         run_acl_subtest misc || error  "misc test failed"
6608         echo "performing permissions..."
6609         run_acl_subtest permissions || error "permissions failed"
6610         echo "performing setfacl..."
6611         run_acl_subtest setfacl || error  "setfacl test failed"
6612
6613         # inheritance test got from HP
6614         echo "performing inheritance..."
6615         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6616         chmod +x make-tree || error "chmod +x failed"
6617         run_acl_subtest inheritance || error "inheritance test failed"
6618         rm -f make-tree
6619
6620         echo "LU-974 ignore umask when acl is enabled..."
6621         run_acl_subtest 974 || error "LU-974 umask test failed"
6622         if [ $MDSCOUNT -ge 2 ]; then
6623                 run_acl_subtest 974_remote ||
6624                         error "LU-974 umask test failed under remote dir"
6625         fi
6626
6627         echo "LU-2561 newly created file is same size as directory..."
6628         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6629                 run_acl_subtest 2561 || error "LU-2561 test failed"
6630         else
6631                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6632         fi
6633
6634         run_acl_subtest 4924 || error "LU-4924 test failed"
6635
6636         cd $SAVE_PWD
6637         umask $SAVE_UMASK
6638
6639         for num in $(seq $MDSCOUNT); do
6640                 if [ "${identity_old[$num]}" = 1 ]; then
6641                         switch_identity $num false || identity_old[$num]=$?
6642                 fi
6643         done
6644 }
6645 run_test 103a "acl test ========================================="
6646
6647 test_103b() {
6648         local noacl=false
6649         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
6650         local mountopts=$MDS_MOUNT_OPTS
6651
6652         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
6653                 noacl=true
6654         else
6655                 # stop the MDT
6656                 stop $SINGLEMDS || error "failed to stop MDT."
6657                 # remount the MDT
6658                 if [ -z "$MDS_MOUNT_OPTS" ]; then
6659                         MDS_MOUNT_OPTS="-o noacl"
6660                 else
6661                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
6662                 fi
6663                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6664                         error "failed to start MDT."
6665                 MDS_MOUNT_OPTS=$mountopts
6666         fi
6667
6668         touch $DIR/$tfile
6669         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
6670
6671         if ! $noacl; then
6672                 # stop the MDT
6673                 stop $SINGLEMDS || error "failed to stop MDT."
6674                 # remount the MDT
6675                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6676                         error "failed to start MDT."
6677         fi
6678
6679         true
6680 }
6681 run_test 103b "MDS mount option 'noacl'"
6682
6683 test_103c() {
6684         mkdir -p $DIR/$tdir
6685         cp -rp $DIR/$tdir $DIR/$tdir.bak
6686
6687         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
6688                 error "$DIR/$tdir shouldn't contain default ACL"
6689         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
6690                 error "$DIR/$tdir.bak shouldn't contain default ACL"
6691         true
6692 }
6693 run_test 103c "'cp -rp' won't set empty acl"
6694
6695 test_104a() {
6696         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6697         touch $DIR/$tfile
6698         lfs df || error "lfs df failed"
6699         lfs df -ih || error "lfs df -ih failed"
6700         lfs df -h $DIR || error "lfs df -h $DIR failed"
6701         lfs df -i $DIR || error "lfs df -i $DIR failed"
6702         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6703         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6704
6705         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6706         lctl --device %$OSC deactivate
6707         lfs df || error "lfs df with deactivated OSC failed"
6708         lctl --device %$OSC activate
6709         # wait the osc back to normal
6710         wait_osc_import_state client ost FULL
6711
6712         lfs df || error "lfs df with reactivated OSC failed"
6713         rm -f $DIR/$tfile
6714 }
6715 run_test 104a "lfs df [-ih] [path] test ========================="
6716
6717 test_104b() {
6718         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6719         [ $RUNAS_ID -eq $UID ] &&
6720                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6721         chmod 666 /dev/obd
6722         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6723                         grep "Permission denied" | wc -l)))
6724         if [ $denied_cnt -ne 0 ]; then
6725                 error "lfs check servers test failed"
6726         fi
6727 }
6728 run_test 104b "$RUNAS lfs check servers test ===================="
6729
6730 test_105a() {
6731         # doesn't work on 2.4 kernels
6732         touch $DIR/$tfile
6733         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6734                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
6735         else
6736                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
6737         fi
6738         rm -f $DIR/$tfile
6739 }
6740 run_test 105a "flock when mounted without -o flock test ========"
6741
6742 test_105b() {
6743         touch $DIR/$tfile
6744         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6745                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
6746         else
6747                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
6748         fi
6749         rm -f $DIR/$tfile
6750 }
6751 run_test 105b "fcntl when mounted without -o flock test ========"
6752
6753 test_105c() {
6754         touch $DIR/$tfile
6755         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6756                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
6757         else
6758                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
6759         fi
6760         rm -f $DIR/$tfile
6761 }
6762 run_test 105c "lockf when mounted without -o flock test ========"
6763
6764 test_105d() { # bug 15924
6765         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6766         test_mkdir -p $DIR/$tdir
6767         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6768                 skip "mount w/o flock enabled" && return
6769         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
6770         $LCTL set_param fail_loc=0x80000315
6771         flocks_test 2 $DIR/$tdir
6772 }
6773 run_test 105d "flock race (should not freeze) ========"
6774
6775 test_105e() { # bug 22660 && 22040
6776         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6777                 skip "mount w/o flock enabled" && return
6778         touch $DIR/$tfile
6779         flocks_test 3 $DIR/$tfile
6780 }
6781 run_test 105e "Two conflicting flocks from same process ======="
6782
6783 test_106() { #bug 10921
6784         test_mkdir -p $DIR/$tdir
6785         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
6786         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
6787 }
6788 run_test 106 "attempt exec of dir followed by chown of that dir"
6789
6790 test_107() {
6791         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6792         CDIR=`pwd`
6793         cd $DIR
6794
6795         local file=core
6796         rm -f $file
6797
6798         local save_pattern=$(sysctl -n kernel.core_pattern)
6799         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
6800         sysctl -w kernel.core_pattern=$file
6801         sysctl -w kernel.core_uses_pid=0
6802
6803         ulimit -c unlimited
6804         sleep 60 &
6805         SLEEPPID=$!
6806
6807         sleep 1
6808
6809         kill -s 11 $SLEEPPID
6810         wait $SLEEPPID
6811         if [ -e $file ]; then
6812                 size=`stat -c%s $file`
6813                 [ $size -eq 0 ] && error "Fail to create core file $file"
6814         else
6815                 error "Fail to create core file $file"
6816         fi
6817         rm -f $file
6818         sysctl -w kernel.core_pattern=$save_pattern
6819         sysctl -w kernel.core_uses_pid=$save_uses_pid
6820         cd $CDIR
6821 }
6822 run_test 107 "Coredump on SIG"
6823
6824 test_110() {
6825         test_mkdir -p $DIR/$tdir
6826         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
6827                 error "mkdir with 255 char failed"
6828         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
6829                 error "mkdir with 256 char should fail, but did not"
6830         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
6831                 error "create with 255 char failed"
6832         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
6833                 error "create with 256 char should fail, but did not"
6834
6835         ls -l $DIR/$tdir
6836         rm -rf $DIR/$tdir
6837 }
6838 run_test 110 "filename length checking"
6839
6840 test_115() {
6841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6842         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
6843                 tail -1 | cut -c11-20)
6844         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
6845         echo "Starting with $OSTIO_pre threads"
6846
6847         NUMTEST=20000
6848         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
6849         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
6850         echo "$NUMTEST creates/unlinks"
6851         test_mkdir -p $DIR/$tdir
6852         createmany -o $DIR/$tdir/$tfile $NUMTEST
6853         unlinkmany $DIR/$tdir/$tfile $NUMTEST
6854
6855         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
6856                 tail -1 | cut -c11-20)
6857
6858         # don't return an error
6859         [ $OSTIO_post == $OSTIO_pre ] && echo \
6860             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
6861             echo "This may be fine, depending on what ran before this test" &&
6862             echo "and how fast this system is." && return
6863
6864         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
6865 }
6866 run_test 115 "verify dynamic thread creation===================="
6867
6868 free_min_max () {
6869         wait_delete_completed
6870         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
6871         echo OST kbytes available: ${AVAIL[@]}
6872         MAXI=0; MAXV=${AVAIL[0]}
6873         MINI=0; MINV=${AVAIL[0]}
6874         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
6875                 #echo OST $i: ${AVAIL[i]}kb
6876                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
6877                         MAXV=${AVAIL[i]}; MAXI=$i
6878                 fi
6879                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
6880                         MINV=${AVAIL[i]}; MINI=$i
6881                 fi
6882         done
6883         echo Min free space: OST $MINI: $MINV
6884         echo Max free space: OST $MAXI: $MAXV
6885 }
6886
6887 test_116a() { # was previously test_116()
6888         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6889         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
6890
6891         echo -n "Free space priority "
6892         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
6893                 head -n1
6894         declare -a AVAIL
6895         free_min_max
6896
6897         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
6898         trap simple_cleanup_common EXIT
6899
6900         # Check if we need to generate uneven OSTs
6901         test_mkdir -p $DIR/$tdir/OST${MINI}
6902         local FILL=$(($MINV / 4))
6903         local DIFF=$(($MAXV - $MINV))
6904         local DIFF2=$(($DIFF * 100 / $MINV))
6905
6906         local threshold=$(do_facet $SINGLEMDS \
6907                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
6908         threshold=${threshold%%%}
6909         echo -n "Check for uneven OSTs: "
6910         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
6911
6912         if [[ $DIFF2 -gt $threshold ]]; then
6913                 echo "ok"
6914                 echo "Don't need to fill OST$MINI"
6915         else
6916                 # generate uneven OSTs. Write 2% over the QOS threshold value
6917                 echo "no"
6918                 DIFF=$(($threshold - $DIFF2 + 2))
6919                 DIFF2=$(( ($MINV * $DIFF)/100 ))
6920                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
6921                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
6922                         error "setstripe failed"
6923                 DIFF=$(($DIFF2 / 2048))
6924                 i=0
6925                 while [ $i -lt $DIFF ]; do
6926                         i=$(($i + 1))
6927                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
6928                                 bs=2M count=1 2>/dev/null
6929                         echo -n .
6930                 done
6931                 echo .
6932                 sync
6933                 sleep_maxage
6934                 free_min_max
6935         fi
6936
6937         DIFF=$(($MAXV - $MINV))
6938         DIFF2=$(($DIFF * 100 / $MINV))
6939         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
6940         if [[ $DIFF2 -gt $threshold ]]; then
6941                 echo "ok"
6942         else
6943                 echo "failed - QOS mode won't be used"
6944                 error_ignore 0000 "QOS imbalance criteria not met"
6945                 simple_cleanup_common
6946                 return
6947         fi
6948
6949         MINI1=$MINI; MINV1=$MINV
6950         MAXI1=$MAXI; MAXV1=$MAXV
6951
6952         # now fill using QOS
6953         $SETSTRIPE -c 1 $DIR/$tdir
6954         FILL=$(($FILL / 200))
6955         if [ $FILL -gt 600 ]; then
6956                 FILL=600
6957         fi
6958         echo "writing $FILL files to QOS-assigned OSTs"
6959         i=0
6960         while [ $i -lt $FILL ]; do
6961                 i=$((i + 1))
6962                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
6963                         count=1 2>/dev/null
6964                 echo -n .
6965         done
6966         echo "wrote $i 200k files"
6967         sync
6968         sleep_maxage
6969
6970         echo "Note: free space may not be updated, so measurements might be off"
6971         free_min_max
6972         DIFF2=$(($MAXV - $MINV))
6973         echo "free space delta: orig $DIFF final $DIFF2"
6974         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
6975         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
6976         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
6977         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
6978         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
6979         FILL=$(($DIFF2 * 100 / $DIFF - 100))
6980         [ $DIFF -gt 0 ] &&
6981                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
6982
6983         # Figure out which files were written where
6984         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6985                   awk '/'$MINI1': / {print $2; exit}')
6986         echo $UUID
6987         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
6988         echo "$MINC files created on smaller OST $MINI1"
6989         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6990                   awk '/'$MAXI1': / {print $2; exit}')
6991         echo $UUID
6992         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
6993         echo "$MAXC files created on larger OST $MAXI1"
6994         FILL=$(($MAXC * 100 / $MINC - 100))
6995         [[ $MINC -gt 0 ]] &&
6996                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
6997         [[ $MAXC -gt $MINC ]] ||
6998                 error_ignore LU-9 "stripe QOS didn't balance free space"
6999         simple_cleanup_common
7000 }
7001 run_test 116a "stripe QOS: free space balance ==================="
7002
7003 test_116b() { # LU-2093
7004         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7005         [ -z "$($LCTL get_param -n lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr |
7006                 head -1 2>/dev/null)" ] && skip "no QOS" && return
7007 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7008         local old_rr
7009         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7010                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7011         do_facet $SINGLEMDS lctl set_param \
7012                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7013         mkdir -p $DIR/$tdir
7014         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7015         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7016         do_facet $SINGLEMDS lctl set_param fail_loc=0
7017         rm -rf $DIR/$tdir
7018         do_facet $SINGLEMDS lctl set_param \
7019                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7020 }
7021 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7022
7023 test_117() # bug 10891
7024 {
7025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7026         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7027         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7028         lctl set_param fail_loc=0x21e
7029         > $DIR/$tfile || error "truncate failed"
7030         lctl set_param fail_loc=0
7031         echo "Truncate succeeded."
7032         rm -f $DIR/$tfile
7033 }
7034 run_test 117 "verify fsfilt_extend =========="
7035
7036 NO_SLOW_RESENDCOUNT=4
7037 export OLD_RESENDCOUNT=""
7038 set_resend_count () {
7039         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7040         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7041         lctl set_param -n $PROC_RESENDCOUNT $1
7042         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7043 }
7044
7045 # for reduce test_118* time (b=14842)
7046 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7047
7048 # Reset async IO behavior after error case
7049 reset_async() {
7050         FILE=$DIR/reset_async
7051
7052         # Ensure all OSCs are cleared
7053         $SETSTRIPE -c -1 $FILE
7054         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7055         sync
7056         rm $FILE
7057 }
7058
7059 test_118a() #bug 11710
7060 {
7061         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7062         reset_async
7063
7064         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7065         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7066         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7067
7068         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7069                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7070                 return 1;
7071         fi
7072         rm -f $DIR/$tfile
7073 }
7074 run_test 118a "verify O_SYNC works =========="
7075
7076 test_118b()
7077 {
7078         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7079         remote_ost_nodsh && skip "remote OST with nodsh" && return
7080
7081         reset_async
7082
7083         #define OBD_FAIL_OST_ENOENT 0x217
7084         set_nodes_failloc "$(osts_nodes)" 0x217
7085         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7086         RC=$?
7087         set_nodes_failloc "$(osts_nodes)" 0
7088         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7089         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7090                     grep -c writeback)
7091
7092         if [[ $RC -eq 0 ]]; then
7093                 error "Must return error due to dropped pages, rc=$RC"
7094                 return 1;
7095         fi
7096
7097         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7098                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7099                 return 1;
7100         fi
7101
7102         echo "Dirty pages not leaked on ENOENT"
7103
7104         # Due to the above error the OSC will issue all RPCs syncronously
7105         # until a subsequent RPC completes successfully without error.
7106         $MULTIOP $DIR/$tfile Ow4096yc
7107         rm -f $DIR/$tfile
7108
7109         return 0
7110 }
7111 run_test 118b "Reclaim dirty pages on fatal error =========="
7112
7113 test_118c()
7114 {
7115         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7116
7117         # for 118c, restore the original resend count, LU-1940
7118         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7119                                 set_resend_count $OLD_RESENDCOUNT
7120         remote_ost_nodsh && skip "remote OST with nodsh" && return
7121
7122         reset_async
7123
7124         #define OBD_FAIL_OST_EROFS               0x216
7125         set_nodes_failloc "$(osts_nodes)" 0x216
7126
7127         # multiop should block due to fsync until pages are written
7128         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7129         MULTIPID=$!
7130         sleep 1
7131
7132         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7133                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7134         fi
7135
7136         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7137                     grep -c writeback)
7138         if [[ $WRITEBACK -eq 0 ]]; then
7139                 error "No page in writeback, writeback=$WRITEBACK"
7140         fi
7141
7142         set_nodes_failloc "$(osts_nodes)" 0
7143         wait $MULTIPID
7144         RC=$?
7145         if [[ $RC -ne 0 ]]; then
7146                 error "Multiop fsync failed, rc=$RC"
7147         fi
7148
7149         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7150         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7151                     grep -c writeback)
7152         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7153                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7154         fi
7155
7156         rm -f $DIR/$tfile
7157         echo "Dirty pages flushed via fsync on EROFS"
7158         return 0
7159 }
7160 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7161
7162 # continue to use small resend count to reduce test_118* time (b=14842)
7163 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7164
7165 test_118d()
7166 {
7167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7168         remote_ost_nodsh && skip "remote OST with nodsh" && return
7169
7170         reset_async
7171
7172         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7173         set_nodes_failloc "$(osts_nodes)" 0x214
7174         # multiop should block due to fsync until pages are written
7175         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7176         MULTIPID=$!
7177         sleep 1
7178
7179         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7180                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7181         fi
7182
7183         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7184                     grep -c writeback)
7185         if [[ $WRITEBACK -eq 0 ]]; then
7186                 error "No page in writeback, writeback=$WRITEBACK"
7187         fi
7188
7189         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7190         set_nodes_failloc "$(osts_nodes)" 0
7191
7192         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7193         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7194                     grep -c writeback)
7195         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7196                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7197         fi
7198
7199         rm -f $DIR/$tfile
7200         echo "Dirty pages gaurenteed flushed via fsync"
7201         return 0
7202 }
7203 run_test 118d "Fsync validation inject a delay of the bulk =========="
7204
7205 test_118f() {
7206         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7207         reset_async
7208
7209         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7210         lctl set_param fail_loc=0x8000040a
7211
7212         # Should simulate EINVAL error which is fatal
7213         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7214         RC=$?
7215         if [[ $RC -eq 0 ]]; then
7216                 error "Must return error due to dropped pages, rc=$RC"
7217         fi
7218
7219         lctl set_param fail_loc=0x0
7220
7221         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7222         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7223         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7224                     grep -c writeback)
7225         if [[ $LOCKED -ne 0 ]]; then
7226                 error "Locked pages remain in cache, locked=$LOCKED"
7227         fi
7228
7229         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7230                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7231         fi
7232
7233         rm -f $DIR/$tfile
7234         echo "No pages locked after fsync"
7235
7236         reset_async
7237         return 0
7238 }
7239 run_test 118f "Simulate unrecoverable OSC side error =========="
7240
7241 test_118g() {
7242         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7243         reset_async
7244
7245         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7246         lctl set_param fail_loc=0x406
7247
7248         # simulate local -ENOMEM
7249         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7250         RC=$?
7251
7252         lctl set_param fail_loc=0
7253         if [[ $RC -eq 0 ]]; then
7254                 error "Must return error due to dropped pages, rc=$RC"
7255         fi
7256
7257         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7258         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7259         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7260                         grep -c writeback)
7261         if [[ $LOCKED -ne 0 ]]; then
7262                 error "Locked pages remain in cache, locked=$LOCKED"
7263         fi
7264
7265         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7266                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7267         fi
7268
7269         rm -f $DIR/$tfile
7270         echo "No pages locked after fsync"
7271
7272         reset_async
7273         return 0
7274 }
7275 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7276
7277 test_118h() {
7278         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7279         remote_ost_nodsh && skip "remote OST with nodsh" && return
7280
7281         reset_async
7282
7283         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7284         set_nodes_failloc "$(osts_nodes)" 0x20e
7285         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7286         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7287         RC=$?
7288
7289         set_nodes_failloc "$(osts_nodes)" 0
7290         if [[ $RC -eq 0 ]]; then
7291                 error "Must return error due to dropped pages, rc=$RC"
7292         fi
7293
7294         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7295         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7296         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7297                     grep -c writeback)
7298         if [[ $LOCKED -ne 0 ]]; then
7299                 error "Locked pages remain in cache, locked=$LOCKED"
7300         fi
7301
7302         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7303                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7304         fi
7305
7306         rm -f $DIR/$tfile
7307         echo "No pages locked after fsync"
7308
7309         return 0
7310 }
7311 run_test 118h "Verify timeout in handling recoverables errors  =========="
7312
7313 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7314
7315 test_118i() {
7316         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7317         remote_ost_nodsh && skip "remote OST with nodsh" && return
7318
7319         reset_async
7320
7321         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7322         set_nodes_failloc "$(osts_nodes)" 0x20e
7323
7324         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7325         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7326         PID=$!
7327         sleep 5
7328         set_nodes_failloc "$(osts_nodes)" 0
7329
7330         wait $PID
7331         RC=$?
7332         if [[ $RC -ne 0 ]]; then
7333                 error "got error, but should be not, rc=$RC"
7334         fi
7335
7336         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7337         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7338         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7339         if [[ $LOCKED -ne 0 ]]; then
7340                 error "Locked pages remain in cache, locked=$LOCKED"
7341         fi
7342
7343         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7344                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7345         fi
7346
7347         rm -f $DIR/$tfile
7348         echo "No pages locked after fsync"
7349
7350         return 0
7351 }
7352 run_test 118i "Fix error before timeout in recoverable error  =========="
7353
7354 [ "$SLOW" = "no" ] && set_resend_count 4
7355
7356 test_118j() {
7357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7358         remote_ost_nodsh && skip "remote OST with nodsh" && return
7359
7360         reset_async
7361
7362         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7363         set_nodes_failloc "$(osts_nodes)" 0x220
7364
7365         # return -EIO from OST
7366         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7367         RC=$?
7368         set_nodes_failloc "$(osts_nodes)" 0x0
7369         if [[ $RC -eq 0 ]]; then
7370                 error "Must return error due to dropped pages, rc=$RC"
7371         fi
7372
7373         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7374         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7375         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7376         if [[ $LOCKED -ne 0 ]]; then
7377                 error "Locked pages remain in cache, locked=$LOCKED"
7378         fi
7379
7380         # in recoverable error on OST we want resend and stay until it finished
7381         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7382                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7383         fi
7384
7385         rm -f $DIR/$tfile
7386         echo "No pages locked after fsync"
7387
7388         return 0
7389 }
7390 run_test 118j "Simulate unrecoverable OST side error =========="
7391
7392 test_118k()
7393 {
7394         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7395         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7396
7397         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7398         set_nodes_failloc "$(osts_nodes)" 0x20e
7399         test_mkdir -p $DIR/$tdir
7400
7401         for ((i=0;i<10;i++)); do
7402                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7403                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7404                 SLEEPPID=$!
7405                 sleep 0.500s
7406                 kill $SLEEPPID
7407                 wait $SLEEPPID
7408         done
7409
7410         set_nodes_failloc "$(osts_nodes)" 0
7411         rm -rf $DIR/$tdir
7412 }
7413 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7414
7415 test_118l()
7416 {
7417         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7418         # LU-646
7419         test_mkdir -p $DIR/$tdir
7420         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7421         rm -rf $DIR/$tdir
7422 }
7423 run_test 118l "fsync dir ========="
7424
7425 test_118m() # LU-3066
7426 {
7427         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7428         test_mkdir -p $DIR/$tdir
7429         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7430         rm -rf $DIR/$tdir
7431 }
7432 run_test 118m "fdatasync dir ========="
7433
7434 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7435
7436 test_119a() # bug 11737
7437 {
7438         BSIZE=$((512 * 1024))
7439         directio write $DIR/$tfile 0 1 $BSIZE
7440         # We ask to read two blocks, which is more than a file size.
7441         # directio will indicate an error when requested and actual
7442         # sizes aren't equeal (a normal situation in this case) and
7443         # print actual read amount.
7444         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7445         if [ "$NOB" != "$BSIZE" ]; then
7446                 error "read $NOB bytes instead of $BSIZE"
7447         fi
7448         rm -f $DIR/$tfile
7449 }
7450 run_test 119a "Short directIO read must return actual read amount"
7451
7452 test_119b() # bug 11737
7453 {
7454         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7455
7456         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7457         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7458         sync
7459         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7460                 error "direct read failed"
7461         rm -f $DIR/$tfile
7462 }
7463 run_test 119b "Sparse directIO read must return actual read amount"
7464
7465 test_119c() # bug 13099
7466 {
7467         BSIZE=1048576
7468         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7469         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7470         rm -f $DIR/$tfile
7471 }
7472 run_test 119c "Testing for direct read hitting hole"
7473
7474 test_119d() # bug 15950
7475 {
7476         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7477         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7478         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7479         BSIZE=1048576
7480         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7481         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7482         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7483         lctl set_param fail_loc=0x40d
7484         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7485         pid_dio=$!
7486         sleep 1
7487         cat $DIR/$tfile > /dev/null &
7488         lctl set_param fail_loc=0
7489         pid_reads=$!
7490         wait $pid_dio
7491         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7492         sleep 2
7493         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7494         error "the read rpcs have not completed in 2s"
7495         rm -f $DIR/$tfile
7496         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7497 }
7498 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7499
7500 test_120a() {
7501         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7502         test_mkdir -p $DIR/$tdir
7503         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7504                skip "no early lock cancel on server" && return 0
7505
7506         lru_resize_disable mdc
7507         lru_resize_disable osc
7508         cancel_lru_locks mdc
7509         # asynchronous object destroy at MDT could cause bl ast to client
7510         cancel_lru_locks osc
7511
7512         stat $DIR/$tdir > /dev/null
7513         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7514         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7515         test_mkdir $DIR/$tdir/d1
7516         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7517         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7518         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7519         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7520         lru_resize_enable mdc
7521         lru_resize_enable osc
7522 }
7523 run_test 120a "Early Lock Cancel: mkdir test"
7524
7525 test_120b() {
7526         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7527         test_mkdir -p $DIR/$tdir
7528         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7529                skip "no early lock cancel on server" && return 0
7530         lru_resize_disable mdc
7531         lru_resize_disable osc
7532         cancel_lru_locks mdc
7533         stat $DIR/$tdir > /dev/null
7534         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7535         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7536         touch $DIR/$tdir/f1
7537         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7538         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7539         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7540         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7541         lru_resize_enable mdc
7542         lru_resize_enable osc
7543 }
7544 run_test 120b "Early Lock Cancel: create test"
7545
7546 test_120c() {
7547         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7548         test_mkdir -p $DIR/$tdir
7549         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7550                skip "no early lock cancel on server" && return 0
7551         lru_resize_disable mdc
7552         lru_resize_disable osc
7553         test_mkdir -p $DIR/$tdir/d1
7554         test_mkdir -p $DIR/$tdir/d2
7555         touch $DIR/$tdir/d1/f1
7556         cancel_lru_locks mdc
7557         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7558         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7559         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7560         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7561         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7562         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7563         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7564         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7565         lru_resize_enable mdc
7566         lru_resize_enable osc
7567 }
7568 run_test 120c "Early Lock Cancel: link test"
7569
7570 test_120d() {
7571         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7572         test_mkdir -p $DIR/$tdir
7573         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7574                skip "no early lock cancel on server" && return 0
7575         lru_resize_disable mdc
7576         lru_resize_disable osc
7577         touch $DIR/$tdir
7578         cancel_lru_locks mdc
7579         stat $DIR/$tdir > /dev/null
7580         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7581         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7582         chmod a+x $DIR/$tdir
7583         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7584         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7585         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7586         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7587         lru_resize_enable mdc
7588         lru_resize_enable osc
7589 }
7590 run_test 120d "Early Lock Cancel: setattr test"
7591
7592 test_120e() {
7593         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7594         test_mkdir -p $DIR/$tdir
7595         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7596                skip "no early lock cancel on server" && return 0
7597         lru_resize_disable mdc
7598         lru_resize_disable osc
7599         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7600         cancel_lru_locks mdc
7601         cancel_lru_locks osc
7602         dd if=$DIR/$tdir/f1 of=/dev/null
7603         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7604         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7605               awk '/ldlm_cancel/ {print $2}'`
7606         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7607               awk '/ldlm_bl_callback/ {print $2}'`
7608         unlink $DIR/$tdir/f1
7609         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7610               awk '/ldlm_cancel/ {print $2}'`
7611         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7612               awk '/ldlm_bl_callback/ {print $2}'`
7613         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7614         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7615         lru_resize_enable mdc
7616         lru_resize_enable osc
7617 }
7618 run_test 120e "Early Lock Cancel: unlink test"
7619
7620 test_120f() {
7621         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7622         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7623                skip "no early lock cancel on server" && return 0
7624         test_mkdir -p $DIR/$tdir
7625         lru_resize_disable mdc
7626         lru_resize_disable osc
7627         test_mkdir -p $DIR/$tdir/d1
7628         test_mkdir -p $DIR/$tdir/d2
7629         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7630         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7631         cancel_lru_locks mdc
7632         cancel_lru_locks osc
7633         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7634         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7635         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7636         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7637               awk '/ldlm_cancel/ {print $2}'`
7638         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7639               awk '/ldlm_bl_callback/ {print $2}'`
7640         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7641         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7642               awk '/ldlm_cancel/ {print $2}'`
7643         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7644               awk '/ldlm_bl_callback/ {print $2}'`
7645         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7646         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7647         lru_resize_enable mdc
7648         lru_resize_enable osc
7649 }
7650 run_test 120f "Early Lock Cancel: rename test"
7651
7652 test_120g() {
7653         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7654         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7655                skip "no early lock cancel on server" && return 0
7656         lru_resize_disable mdc
7657         lru_resize_disable osc
7658         count=10000
7659         echo create $count files
7660         test_mkdir -p $DIR/$tdir
7661         cancel_lru_locks mdc
7662         cancel_lru_locks osc
7663         t0=`date +%s`
7664
7665         can0=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7666               awk '/ldlm_cancel/ {print $2}'`
7667         blk0=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7668               awk '/ldlm_bl_callback/ {print $2}'`
7669         createmany -o $DIR/$tdir/f $count
7670         sync
7671         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7672               awk '/ldlm_cancel/ {print $2}'`
7673         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7674               awk '/ldlm_bl_callback/ {print $2}'`
7675         t1=`date +%s`
7676         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7677         echo rm $count files
7678         rm -r $DIR/$tdir
7679         sync
7680         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7681               awk '/ldlm_cancel/ {print $2}'`
7682         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7683               awk '/ldlm_bl_callback/ {print $2}'`
7684         t2=`date +%s`
7685         echo total: $count removes in $((t2-t1))
7686         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7687         sleep 2
7688         # wait for commitment of removal
7689         lru_resize_enable mdc
7690         lru_resize_enable osc
7691 }
7692 run_test 120g "Early Lock Cancel: performance test"
7693
7694 test_121() { #bug #10589
7695         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7696         rm -rf $DIR/$tfile
7697         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
7698 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
7699         lctl set_param fail_loc=0x310
7700         cancel_lru_locks osc > /dev/null
7701         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
7702         lctl set_param fail_loc=0
7703         [[ $reads -eq $writes ]] ||
7704                 error "read $reads blocks, must be $writes blocks"
7705 }
7706 run_test 121 "read cancel race ========="
7707
7708 test_123a() { # was test 123, statahead(bug 11401)
7709         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7710         SLOWOK=0
7711         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
7712             log "testing on UP system. Performance may be not as good as expected."
7713                         SLOWOK=1
7714         fi
7715
7716         rm -rf $DIR/$tdir
7717         test_mkdir -p $DIR/$tdir
7718         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7719         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
7720         MULT=10
7721         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
7722                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
7723
7724                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7725                 lctl set_param -n llite.*.statahead_max 0
7726                 lctl get_param llite.*.statahead_max
7727                 cancel_lru_locks mdc
7728                 cancel_lru_locks osc
7729                 stime=`date +%s`
7730                 time ls -l $DIR/$tdir | wc -l
7731                 etime=`date +%s`
7732                 delta=$((etime - stime))
7733                 log "ls $i files without statahead: $delta sec"
7734                 lctl set_param llite.*.statahead_max=$max
7735
7736                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7737                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
7738                 cancel_lru_locks mdc
7739                 cancel_lru_locks osc
7740                 stime=`date +%s`
7741                 time ls -l $DIR/$tdir | wc -l
7742                 etime=`date +%s`
7743                 delta_sa=$((etime - stime))
7744                 log "ls $i files with statahead: $delta_sa sec"
7745                 lctl get_param -n llite.*.statahead_stats
7746                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7747
7748                 [[ $swrong -lt $ewrong ]] &&
7749                         log "statahead was stopped, maybe too many locks held!"
7750                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
7751
7752                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7753                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7754                     lctl set_param -n llite.*.statahead_max 0
7755                     lctl get_param llite.*.statahead_max
7756                     cancel_lru_locks mdc
7757                     cancel_lru_locks osc
7758                     stime=`date +%s`
7759                     time ls -l $DIR/$tdir | wc -l
7760                     etime=`date +%s`
7761                     delta=$((etime - stime))
7762                     log "ls $i files again without statahead: $delta sec"
7763                     lctl set_param llite.*.statahead_max=$max
7764                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7765                         if [  $SLOWOK -eq 0 ]; then
7766                                 error "ls $i files is slower with statahead!"
7767                         else
7768                                 log "ls $i files is slower with statahead!"
7769                         fi
7770                         break
7771                     fi
7772                 fi
7773
7774                 [ $delta -gt 20 ] && break
7775                 [ $delta -gt 8 ] && MULT=$((50 / delta))
7776                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
7777         done
7778         log "ls done"
7779
7780         stime=`date +%s`
7781         rm -r $DIR/$tdir
7782         sync
7783         etime=`date +%s`
7784         delta=$((etime - stime))
7785         log "rm -r $DIR/$tdir/: $delta seconds"
7786         log "rm done"
7787         lctl get_param -n llite.*.statahead_stats
7788 }
7789 run_test 123a "verify statahead work"
7790
7791 test_123b () { # statahead(bug 15027)
7792         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7793         test_mkdir -p $DIR/$tdir
7794         createmany -o $DIR/$tdir/$tfile-%d 1000
7795
7796         cancel_lru_locks mdc
7797         cancel_lru_locks osc
7798
7799 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
7800         lctl set_param fail_loc=0x80000803
7801         ls -lR $DIR/$tdir > /dev/null
7802         log "ls done"
7803         lctl set_param fail_loc=0x0
7804         lctl get_param -n llite.*.statahead_stats
7805         rm -r $DIR/$tdir
7806         sync
7807
7808 }
7809 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
7810
7811 test_124a() {
7812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7813         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
7814                 skip "no lru resize on server" && return 0
7815         local NR=2000
7816         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
7817
7818         log "create $NR files at $DIR/$tdir"
7819         createmany -o $DIR/$tdir/f $NR ||
7820                 error "failed to create $NR files in $DIR/$tdir"
7821
7822         cancel_lru_locks mdc
7823         ls -l $DIR/$tdir > /dev/null
7824
7825         local NSDIR=""
7826         local LRU_SIZE=0
7827         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
7828                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
7829                 LRU_SIZE=$($LCTL get_param -n $PARAM)
7830                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
7831                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
7832                         log "NSDIR=$NSDIR"
7833                         log "NS=$(basename $NSDIR)"
7834                         break
7835                 fi
7836         done
7837
7838         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
7839                 skip "Not enough cached locks created!"
7840                 return 0
7841         fi
7842         log "LRU=$LRU_SIZE"
7843
7844         local SLEEP=30
7845
7846         # We know that lru resize allows one client to hold $LIMIT locks
7847         # for 10h. After that locks begin to be killed by client.
7848         local MAX_HRS=10
7849         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
7850         log "LIMIT=$LIMIT"
7851
7852         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
7853         # killing locks. Some time was spent for creating locks. This means
7854         # that up to the moment of sleep finish we must have killed some of
7855         # them (10-100 locks). This depends on how fast ther were created.
7856         # Many of them were touched in almost the same moment and thus will
7857         # be killed in groups.
7858         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
7859
7860         # Use $LRU_SIZE_B here to take into account real number of locks
7861         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
7862         local LRU_SIZE_B=$LRU_SIZE
7863         log "LVF=$LVF"
7864         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
7865         log "OLD_LVF=$OLD_LVF"
7866         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
7867
7868         # Let's make sure that we really have some margin. Client checks
7869         # cached locks every 10 sec.
7870         SLEEP=$((SLEEP+20))
7871         log "Sleep ${SLEEP} sec"
7872         local SEC=0
7873         while ((SEC<$SLEEP)); do
7874                 echo -n "..."
7875                 sleep 5
7876                 SEC=$((SEC+5))
7877                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
7878                 echo -n "$LRU_SIZE"
7879         done
7880         echo ""
7881         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
7882         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
7883
7884         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
7885                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
7886                 unlinkmany $DIR/$tdir/f $NR
7887                 return
7888         }
7889
7890         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
7891         log "unlink $NR files at $DIR/$tdir"
7892         unlinkmany $DIR/$tdir/f $NR
7893 }
7894 run_test 124a "lru resize ======================================="
7895
7896 get_max_pool_limit()
7897 {
7898         local limit=$($LCTL get_param \
7899                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
7900         local max=0
7901         for l in $limit; do
7902                 if [[ $l -gt $max ]]; then
7903                         max=$l
7904                 fi
7905         done
7906         echo $max
7907 }
7908
7909 test_124b() {
7910         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7911         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
7912                 skip "no lru resize on server" && return 0
7913
7914         LIMIT=$(get_max_pool_limit)
7915
7916         NR=$(($(default_lru_size)*20))
7917         if [[ $NR -gt $LIMIT ]]; then
7918                 log "Limit lock number by $LIMIT locks"
7919                 NR=$LIMIT
7920         fi
7921         lru_resize_disable mdc
7922         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
7923                 error "failed to create $DIR/$tdir/disable_lru_resize"
7924
7925         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
7926         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
7927         cancel_lru_locks mdc
7928         stime=`date +%s`
7929         PID=""
7930         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7931         PID="$PID $!"
7932         sleep 2
7933         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7934         PID="$PID $!"
7935         sleep 2
7936         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7937         PID="$PID $!"
7938         wait $PID
7939         etime=`date +%s`
7940         nolruresize_delta=$((etime-stime))
7941         log "ls -la time: $nolruresize_delta seconds"
7942         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7943         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
7944
7945         lru_resize_enable mdc
7946         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
7947                 error "failed to create $DIR/$tdir/enable_lru_resize"
7948
7949         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
7950         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
7951         cancel_lru_locks mdc
7952         stime=`date +%s`
7953         PID=""
7954         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7955         PID="$PID $!"
7956         sleep 2
7957         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7958         PID="$PID $!"
7959         sleep 2
7960         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7961         PID="$PID $!"
7962         wait $PID
7963         etime=`date +%s`
7964         lruresize_delta=$((etime-stime))
7965         log "ls -la time: $lruresize_delta seconds"
7966         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7967
7968         if [ $lruresize_delta -gt $nolruresize_delta ]; then
7969                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
7970         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
7971                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
7972         else
7973                 log "lru resize performs the same with no lru resize"
7974         fi
7975         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
7976 }
7977 run_test 124b "lru resize (performance test) ======================="
7978
7979 test_125() { # 13358
7980         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7981         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
7982         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
7983         test_mkdir -p $DIR/d125 || error "mkdir failed"
7984         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
7985         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
7986         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
7987 }
7988 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
7989
7990 test_126() { # bug 12829/13455
7991         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7992         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
7993         $GSS && skip "must run as gss disabled" && return
7994
7995         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
7996         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
7997         rm -f $DIR/$tfile
7998         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
7999 }
8000 run_test 126 "check that the fsgid provided by the client is taken into account"
8001
8002 test_127a() { # bug 15521
8003         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8004         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8005         $LCTL set_param osc.*.stats=0
8006         FSIZE=$((2048 * 1024))
8007         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8008         cancel_lru_locks osc
8009         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8010
8011         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8012         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8013                 echo "got $COUNT $NAME"
8014                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8015                 eval $NAME=$COUNT || error "Wrong proc format"
8016
8017                 case $NAME in
8018                         read_bytes|write_bytes)
8019                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8020                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8021                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8022                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8023                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8024                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8025                                 error "sumsquare is too small: $SUMSQ"
8026                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8027                                 error "sumsquare is too big: $SUMSQ"
8028                         ;;
8029                         *) ;;
8030                 esac
8031         done < $DIR/${tfile}.tmp
8032
8033         #check that we actually got some stats
8034         [ "$read_bytes" ] || error "Missing read_bytes stats"
8035         [ "$write_bytes" ] || error "Missing write_bytes stats"
8036         [ "$read_bytes" != 0 ] || error "no read done"
8037         [ "$write_bytes" != 0 ] || error "no write done"
8038 }
8039 run_test 127a "verify the client stats are sane"
8040
8041 test_127b() { # bug LU-333
8042         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8043         $LCTL set_param llite.*.stats=0
8044         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8045         # perform 2 reads and writes so MAX is different from SUM.
8046         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8047         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8048         cancel_lru_locks osc
8049         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8050         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8051
8052         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8053         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8054                 echo "got $COUNT $NAME"
8055                 eval $NAME=$COUNT || error "Wrong proc format"
8056
8057         case $NAME in
8058                 read_bytes)
8059                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8060                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8061                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8062                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8063                         ;;
8064                 write_bytes)
8065                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8066                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8067                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8068                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8069                         ;;
8070                         *) ;;
8071                 esac
8072         done < $TMP/${tfile}.tmp
8073
8074         #check that we actually got some stats
8075         [ "$read_bytes" ] || error "Missing read_bytes stats"
8076         [ "$write_bytes" ] || error "Missing write_bytes stats"
8077         [ "$read_bytes" != 0 ] || error "no read done"
8078         [ "$write_bytes" != 0 ] || error "no write done"
8079 }
8080 run_test 127b "verify the llite client stats are sane"
8081
8082 test_128() { # bug 15212
8083         touch $DIR/$tfile
8084         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8085                 find $DIR/$tfile
8086                 find $DIR/$tfile
8087         EOF
8088
8089         result=$(grep error $TMP/$tfile.log)
8090         rm -f $DIR/$tfile
8091         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8092 }
8093 run_test 128 "interactive lfs for 2 consecutive find's"
8094
8095 set_dir_limits () {
8096         local mntdev
8097         local canondev
8098         local node
8099
8100         local LDPROC=/proc/fs/ldiskfs
8101         local facets=$(get_facets MDS)
8102
8103         for facet in ${facets//,/ }; do
8104                 canondev=$(ldiskfs_canon \
8105                            *.$(convert_facet2label $facet).mntdev $facet)
8106                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8107                                                 LDPROC=/sys/fs/ldiskfs
8108                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8109         done
8110 }
8111
8112 test_129() {
8113         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8114         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8115                 skip "Only applicable to ldiskfs-based MDTs"
8116                 return
8117         fi
8118         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8119
8120         ENOSPC=28
8121         EFBIG=27
8122
8123         rm -rf $DIR/$tdir
8124         test_mkdir -p $DIR/$tdir
8125
8126         # block size of mds1
8127         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8128         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8129         local MAX=$((MDSBLOCKSIZE * 3))
8130         set_dir_limits $MAX
8131         local I=$(stat -c%s "$DIR/$tdir")
8132         local J=0
8133         local STRIPE_COUNT=1
8134         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8135         MAX=$((MAX*STRIPE_COUNT))
8136         while [[ $I -le $MAX ]]; do
8137                 $MULTIOP $DIR/$tdir/$J Oc
8138                 rc=$?
8139                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8140                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8141                 #and EFBIG for previous versions
8142                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8143                         set_dir_limits 0
8144                         echo "return code $rc received as expected"
8145                         multiop $DIR/$tdir/$J Oc ||
8146                                 error_exit "multiop failed w/o dir size limit"
8147
8148                         I=$(stat -c%s "$DIR/$tdir")
8149
8150                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8151                                         $(version_code 2.4.51) ]
8152                         then
8153                                 [[ $I -eq $MAX ]] && return 0
8154                         else
8155                                 [[ $I -gt $MAX ]] && return 0
8156                         fi
8157                         error_exit "current dir size $I, previous limit $MAX"
8158                 elif [ $rc -ne 0 ]; then
8159                         set_dir_limits 0
8160                         error_exit "return code $rc received instead of expected " \
8161                                    "$EFBIG or $ENOSPC, files in dir $I"
8162                 fi
8163                 J=$((J+1))
8164                 I=$(stat -c%s "$DIR/$tdir")
8165         done
8166
8167         set_dir_limits 0
8168         error "exceeded dir size limit $MAX x $MDSCOUNT $MAX : $I bytes"
8169 }
8170 run_test 129 "test directory size limit ========================"
8171
8172 OLDIFS="$IFS"
8173 cleanup_130() {
8174         trap 0
8175         IFS="$OLDIFS"
8176 }
8177
8178 test_130a() {
8179         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8180         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8181                 return
8182
8183         trap cleanup_130 EXIT RETURN
8184
8185         local fm_file=$DIR/$tfile
8186         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8187         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8188                 error "dd failed for $fm_file"
8189
8190         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8191         filefrag -ves $fm_file
8192         RC=$?
8193         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8194                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8195         [ $RC != 0 ] && error "filefrag $fm_file failed"
8196
8197         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8198                       grep -v "ext:" | grep -v "found")
8199         lun=$($GETSTRIPE -i $fm_file)
8200
8201         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8202         IFS=$'\n'
8203         tot_len=0
8204         for line in $filefrag_op
8205         do
8206                 frag_lun=`echo $line | cut -d: -f5`
8207                 ext_len=`echo $line | cut -d: -f4`
8208                 if (( $frag_lun != $lun )); then
8209                         cleanup_130
8210                         error "FIEMAP on 1-stripe file($fm_file) failed"
8211                         return
8212                 fi
8213                 (( tot_len += ext_len ))
8214         done
8215
8216         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8217                 cleanup_130
8218                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8219                 return
8220         fi
8221
8222         cleanup_130
8223
8224         echo "FIEMAP on single striped file succeeded"
8225 }
8226 run_test 130a "FIEMAP (1-stripe file)"
8227
8228 test_130b() {
8229         [ "$OSTCOUNT" -lt "2" ] &&
8230                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8231
8232         [ "$OSTCOUNT" -ge "10" ] &&
8233                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8234
8235         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8236         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8237                 return
8238
8239         trap cleanup_130 EXIT RETURN
8240
8241         local fm_file=$DIR/$tfile
8242         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8243         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8244                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8245
8246         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8247                 error "dd failed on $fm_file"
8248
8249         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8250         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8251                       grep -v "ext:" | grep -v "found")
8252
8253         last_lun=$(echo $filefrag_op | cut -d: -f5)
8254
8255         IFS=$'\n'
8256         tot_len=0
8257         num_luns=1
8258         for line in $filefrag_op
8259         do
8260                 frag_lun=`echo $line | cut -d: -f5`
8261                 ext_len=`echo $line | cut -d: -f4`
8262                 if (( $frag_lun != $last_lun )); then
8263                         if (( tot_len != 1024 )); then
8264                                 cleanup_130
8265                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8266                                 return
8267                         else
8268                                 (( num_luns += 1 ))
8269                                 tot_len=0
8270                         fi
8271                 fi
8272                 (( tot_len += ext_len ))
8273                 last_lun=$frag_lun
8274         done
8275         if (( num_luns != 2 || tot_len != 1024 )); then
8276                 cleanup_130
8277                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8278                 return
8279         fi
8280
8281         cleanup_130
8282
8283         echo "FIEMAP on 2-stripe file succeeded"
8284 }
8285 run_test 130b "FIEMAP (2-stripe file)"
8286
8287 test_130c() {
8288         [ "$OSTCOUNT" -lt "2" ] &&
8289                 skip_env "skipping FIEMAP on 2-stripe file" && return
8290
8291         [ "$OSTCOUNT" -ge "10" ] &&
8292                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8293
8294         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8295         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8296                 return
8297
8298         trap cleanup_130 EXIT RETURN
8299
8300         local fm_file=$DIR/$tfile
8301         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8302         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8303                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8304
8305         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8306
8307         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8308         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8309
8310         last_lun=`echo $filefrag_op | cut -d: -f5`
8311
8312         IFS=$'\n'
8313         tot_len=0
8314         num_luns=1
8315         for line in $filefrag_op
8316         do
8317                 frag_lun=`echo $line | cut -d: -f5`
8318                 ext_len=`echo $line | cut -d: -f4`
8319                 if (( $frag_lun != $last_lun )); then
8320                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8321                         if (( logical != 512 )); then
8322                                 cleanup_130
8323                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8324                                 return
8325                         fi
8326                         if (( tot_len != 512 )); then
8327                                 cleanup_130
8328                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8329                                 return
8330                         else
8331                                 (( num_luns += 1 ))
8332                                 tot_len=0
8333                         fi
8334                 fi
8335                 (( tot_len += ext_len ))
8336                 last_lun=$frag_lun
8337         done
8338         if (( num_luns != 2 || tot_len != 512 )); then
8339                 cleanup_130
8340                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8341                 return
8342         fi
8343
8344         cleanup_130
8345
8346         echo "FIEMAP on 2-stripe file with hole succeeded"
8347 }
8348 run_test 130c "FIEMAP (2-stripe file with hole)"
8349
8350 test_130d() {
8351         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8352
8353         [ "$OSTCOUNT" -ge "10" ] &&
8354                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8355
8356         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8357         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8358
8359         trap cleanup_130 EXIT RETURN
8360
8361         local fm_file=$DIR/$tfile
8362         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8363         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8364                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8365
8366         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8367         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8368                 error "dd failed on $fm_file"
8369
8370         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8371         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8372                 grep -v "ext:" | grep -v "found"`
8373
8374         last_lun=`echo $filefrag_op | cut -d: -f5`
8375
8376         IFS=$'\n'
8377         tot_len=0
8378         num_luns=1
8379         for line in $filefrag_op
8380         do
8381                 frag_lun=`echo $line | cut -d: -f5`
8382                 ext_len=`echo $line | cut -d: -f4`
8383                 if (( $frag_lun != $last_lun )); then
8384                         if (( tot_len != 1024 )); then
8385                                 cleanup_130
8386                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8387                                 return
8388                         else
8389                                 (( num_luns += 1 ))
8390                                 tot_len=0
8391                         fi
8392                 fi
8393                 (( tot_len += ext_len ))
8394                 last_lun=$frag_lun
8395         done
8396         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8397                 cleanup_130
8398                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8399                 return
8400         fi
8401
8402         cleanup_130
8403
8404         echo "FIEMAP on N-stripe file succeeded"
8405 }
8406 run_test 130d "FIEMAP (N-stripe file)"
8407
8408 test_130e() {
8409         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8410
8411         [ "$OSTCOUNT" -ge "10" ] &&
8412                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8413
8414         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8415         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8416
8417         trap cleanup_130 EXIT RETURN
8418
8419         local fm_file=$DIR/$tfile
8420         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8421         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8422                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8423
8424         NUM_BLKS=512
8425         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8426         for ((i = 0; i < $NUM_BLKS; i++))
8427         do
8428                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8429         done
8430
8431         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8432         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8433
8434         last_lun=`echo $filefrag_op | cut -d: -f5`
8435
8436         IFS=$'\n'
8437         tot_len=0
8438         num_luns=1
8439         for line in $filefrag_op
8440         do
8441                 frag_lun=`echo $line | cut -d: -f5`
8442                 ext_len=`echo $line | cut -d: -f4`
8443                 if (( $frag_lun != $last_lun )); then
8444                         if (( tot_len != $EXPECTED_LEN )); then
8445                                 cleanup_130
8446                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8447                                 return
8448                         else
8449                                 (( num_luns += 1 ))
8450                                 tot_len=0
8451                         fi
8452                 fi
8453                 (( tot_len += ext_len ))
8454                 last_lun=$frag_lun
8455         done
8456         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8457                 cleanup_130
8458                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8459                 return
8460         fi
8461
8462         cleanup_130
8463
8464         echo "FIEMAP with continuation calls succeeded"
8465 }
8466 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8467
8468 # Test for writev/readv
8469 test_131a() {
8470         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8471         error "writev test failed"
8472         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8473         error "readv failed"
8474         rm -f $DIR/$tfile
8475 }
8476 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8477
8478 test_131b() {
8479         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8480         error "append writev test failed"
8481         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8482         error "append writev test failed"
8483         rm -f $DIR/$tfile
8484 }
8485 run_test 131b "test append writev"
8486
8487 test_131c() {
8488         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8489         error "NOT PASS"
8490 }
8491 run_test 131c "test read/write on file w/o objects"
8492
8493 test_131d() {
8494         rwv -f $DIR/$tfile -w -n 1 1572864
8495         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8496         if [ "$NOB" != 1572864 ]; then
8497                 error "Short read filed: read $NOB bytes instead of 1572864"
8498         fi
8499         rm -f $DIR/$tfile
8500 }
8501 run_test 131d "test short read"
8502
8503 test_131e() {
8504         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8505         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8506         error "read hitting hole failed"
8507         rm -f $DIR/$tfile
8508 }
8509 run_test 131e "test read hitting hole"
8510
8511 get_ost_param() {
8512         local token=$1
8513         local gl_sum=0
8514         for node in $(osts_nodes); do
8515                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8516                 [ x$gl = x"" ] && gl=0
8517                 gl_sum=$((gl_sum + gl))
8518         done
8519         echo $gl_sum
8520 }
8521
8522 som_mode_switch() {
8523         local som=$1
8524         local gl1=$2
8525         local gl2=$3
8526
8527         if [ x$som = x"enabled" ]; then
8528                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8529                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
8530                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8531         else
8532                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8533                 MOUNTOPT="$MOUNTOPT,som_preview"
8534                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8535         fi
8536
8537         # do remount to make new mount-conf parameters actual
8538         echo remounting...
8539         sync
8540         stopall
8541         setupall
8542 }
8543
8544 test_132() { #1028, SOM
8545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8546         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8547         local num=$(get_mds_dir $DIR)
8548         local mymds=mds${num}
8549         local MOUNTOPT_SAVE=$MOUNTOPT
8550
8551         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8552         cancel_lru_locks osc
8553
8554         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8555
8556         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8557         stat $DIR/$tfile >/dev/null
8558         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8559         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8560         rm $DIR/$tfile
8561         som_mode_switch $som1 $gl1 $gl2
8562
8563         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8564         cancel_lru_locks osc
8565
8566         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8567         if [ $som1 == $som2 ]; then
8568             error "som is still "$som2
8569             if [ x$som2 = x"enabled" ]; then
8570                 som2="disabled"
8571             else
8572                 som2="enabled"
8573             fi
8574         fi
8575
8576         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8577         stat $DIR/$tfile >/dev/null
8578         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8579         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8580         som_mode_switch $som2 $gl1 $gl2
8581         MOUNTOPT=$MOUNTOPT_SAVE
8582 }
8583 run_test 132 "som avoids glimpse rpc"
8584
8585 check_stats() {
8586         local res
8587         local count
8588         case $1 in
8589         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8590                  ;;
8591         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8592                  ;;
8593         *) error "Wrong argument $1" ;;
8594         esac
8595         echo $res
8596         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8597         # if the argument $3 is zero, it means any stat increment is ok.
8598         if [[ $3 -gt 0 ]]; then
8599                 count=$(echo $res | awk '{ print $2 }')
8600                 [[ $count -ne $3 ]] &&
8601                         error "The $2 counter on $1 is wrong - expected $3"
8602         fi
8603 }
8604
8605 test_133a() {
8606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8607         remote_ost_nodsh && skip "remote OST with nodsh" && return
8608         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8609
8610         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8611                 { skip "MDS doesn't support rename stats"; return; }
8612         local testdir=$DIR/${tdir}/stats_testdir
8613         mkdir -p $DIR/${tdir}
8614
8615         # clear stats.
8616         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8617         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8618
8619         # verify mdt stats first.
8620         mkdir ${testdir} || error "mkdir failed"
8621         check_stats $SINGLEMDS "mkdir" 1
8622         touch ${testdir}/${tfile} || "touch failed"
8623         check_stats $SINGLEMDS "open" 1
8624         check_stats $SINGLEMDS "close" 1
8625         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8626         check_stats $SINGLEMDS "mknod" 1
8627         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8628         check_stats $SINGLEMDS "unlink" 1
8629         rm -f ${testdir}/${tfile} || error "file remove failed"
8630         check_stats $SINGLEMDS "unlink" 2
8631
8632         # remove working dir and check mdt stats again.
8633         rmdir ${testdir} || error "rmdir failed"
8634         check_stats $SINGLEMDS "rmdir" 1
8635
8636         local testdir1=$DIR/${tdir}/stats_testdir1
8637         mkdir -p ${testdir}
8638         mkdir -p ${testdir1}
8639         touch ${testdir1}/test1
8640         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8641         check_stats $SINGLEMDS "crossdir_rename" 1
8642
8643         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8644         check_stats $SINGLEMDS "samedir_rename" 1
8645
8646         rm -rf $DIR/${tdir}
8647 }
8648 run_test 133a "Verifying MDT stats ========================================"
8649
8650 test_133b() {
8651         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8652         remote_ost_nodsh && skip "remote OST with nodsh" && return
8653         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8654         local testdir=$DIR/${tdir}/stats_testdir
8655         mkdir -p ${testdir} || error "mkdir failed"
8656         touch ${testdir}/${tfile} || "touch failed"
8657         cancel_lru_locks mdc
8658
8659         # clear stats.
8660         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8661         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8662
8663         # extra mdt stats verification.
8664         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8665         check_stats $SINGLEMDS "setattr" 1
8666         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8667         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8668         then            # LU-1740
8669                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8670                 check_stats $SINGLEMDS "getattr" 1
8671         fi
8672         $LFS df || error "lfs failed"
8673         check_stats $SINGLEMDS "statfs" 1
8674
8675         rm -rf $DIR/${tdir}
8676 }
8677 run_test 133b "Verifying extra MDT stats =================================="
8678
8679 test_133c() {
8680         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8681         remote_ost_nodsh && skip "remote OST with nodsh" && return
8682         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8683         local testdir=$DIR/${tdir}/stats_testdir
8684         test_mkdir -p ${testdir} || error "mkdir failed"
8685
8686         # verify obdfilter stats.
8687         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8688         sync
8689         cancel_lru_locks osc
8690         wait_delete_completed
8691
8692         # clear stats.
8693         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8694         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8695
8696         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
8697         sync
8698         cancel_lru_locks osc
8699         check_stats ost "write" 1
8700
8701         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
8702         check_stats ost "read" 1
8703
8704         > ${testdir}/${tfile} || error "truncate failed"
8705         check_stats ost "punch" 1
8706
8707         rm -f ${testdir}/${tfile} || error "file remove failed"
8708         wait_delete_completed
8709         check_stats ost "destroy" 1
8710
8711         rm -rf $DIR/${tdir}
8712 }
8713 run_test 133c "Verifying OST stats ========================================"
8714
8715 order_2() {
8716         local value=$1
8717         local orig=$value
8718         local order=1
8719
8720         while [ $value -ge 2 ]; do
8721                 order=$((order*2))
8722                 value=$((value/2))
8723         done
8724
8725         if [ $orig -gt $order ]; then
8726                 order=$((order*2))
8727         fi
8728         echo $order
8729 }
8730
8731 size_in_KMGT() {
8732     local value=$1
8733     local size=('K' 'M' 'G' 'T');
8734     local i=0
8735     local size_string=$value
8736
8737     while [ $value -ge 1024 ]; do
8738         if [ $i -gt 3 ]; then
8739             #T is the biggest unit we get here, if that is bigger,
8740             #just return XXXT
8741             size_string=${value}T
8742             break
8743         fi
8744         value=$((value >> 10))
8745         if [ $value -lt 1024 ]; then
8746             size_string=${value}${size[$i]}
8747             break
8748         fi
8749         i=$((i + 1))
8750     done
8751
8752     echo $size_string
8753 }
8754
8755 get_rename_size() {
8756     local size=$1
8757     local context=${2:-.}
8758     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
8759                 grep -A1 $context |
8760                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
8761     echo $sample
8762 }
8763
8764 test_133d() {
8765         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8766         remote_ost_nodsh && skip "remote OST with nodsh" && return
8767         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8768         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8769         { skip "MDS doesn't support rename stats"; return; }
8770
8771         local testdir1=$DIR/${tdir}/stats_testdir1
8772         local testdir2=$DIR/${tdir}/stats_testdir2
8773
8774         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8775
8776         mkdir -p ${testdir1} || error "mkdir failed"
8777         mkdir -p ${testdir2} || error "mkdir failed"
8778
8779         createmany -o $testdir1/test 512 || error "createmany failed"
8780
8781         # check samedir rename size
8782         mv ${testdir1}/test0 ${testdir1}/test_0
8783
8784         local testdir1_size=$(ls -l $DIR/${tdir} |
8785                 awk '/stats_testdir1/ {print $5}')
8786         local testdir2_size=$(ls -l $DIR/${tdir} |
8787                 awk '/stats_testdir2/ {print $5}')
8788
8789         testdir1_size=$(order_2 $testdir1_size)
8790         testdir2_size=$(order_2 $testdir2_size)
8791
8792         testdir1_size=$(size_in_KMGT $testdir1_size)
8793         testdir2_size=$(size_in_KMGT $testdir2_size)
8794
8795         echo "source rename dir size: ${testdir1_size}"
8796         echo "target rename dir size: ${testdir2_size}"
8797
8798         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
8799         eval $cmd || error "$cmd failed"
8800         local samedir=$($cmd | grep 'same_dir')
8801         local same_sample=$(get_rename_size $testdir1_size)
8802         [ -z "$samedir" ] && error "samedir_rename_size count error"
8803         [[ $same_sample -eq 1 ]] ||
8804                 error "samedir_rename_size error $same_sample"
8805         echo "Check same dir rename stats success"
8806
8807         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8808
8809         # check crossdir rename size
8810         mv ${testdir1}/test_0 ${testdir2}/test_0
8811
8812         testdir1_size=$(ls -l $DIR/${tdir} |
8813                 awk '/stats_testdir1/ {print $5}')
8814         testdir2_size=$(ls -l $DIR/${tdir} |
8815                 awk '/stats_testdir2/ {print $5}')
8816
8817         testdir1_size=$(order_2 $testdir1_size)
8818         testdir2_size=$(order_2 $testdir2_size)
8819
8820         testdir1_size=$(size_in_KMGT $testdir1_size)
8821         testdir2_size=$(size_in_KMGT $testdir2_size)
8822
8823         echo "source rename dir size: ${testdir1_size}"
8824         echo "target rename dir size: ${testdir2_size}"
8825
8826         eval $cmd || error "$cmd failed"
8827         local crossdir=$($cmd | grep 'crossdir')
8828         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
8829         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
8830         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
8831         [[ $src_sample -eq 1 ]] ||
8832                 error "crossdir_rename_size error $src_sample"
8833         [[ $tgt_sample -eq 1 ]] ||
8834                 error "crossdir_rename_size error $tgt_sample"
8835         echo "Check cross dir rename stats success"
8836         rm -rf $DIR/${tdir}
8837 }
8838 run_test 133d "Verifying rename_stats ========================================"
8839
8840 test_133e() {
8841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8842         local testdir=$DIR/${tdir}/stats_testdir
8843         local ctr f0 f1 bs=32768 count=42 sum
8844
8845         remote_ost_nodsh && skip "remote OST with nodsh" && return
8846         mkdir -p ${testdir} || error "mkdir failed"
8847
8848         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8849
8850         for ctr in {write,read}_bytes; do
8851                 sync
8852                 cancel_lru_locks osc
8853
8854                 do_facet ost1 $LCTL set_param -n \
8855                         "obdfilter.*.exports.clear=clear"
8856
8857                 if [ $ctr = write_bytes ]; then
8858                         f0=/dev/zero
8859                         f1=${testdir}/${tfile}
8860                 else
8861                         f0=${testdir}/${tfile}
8862                         f1=/dev/null
8863                 fi
8864
8865                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
8866                         error "dd failed"
8867                 sync
8868                 cancel_lru_locks osc
8869
8870                 sum=$(do_facet ost1 $LCTL get_param \
8871                         "obdfilter.*.exports.*.stats" |
8872                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
8873                                 $1 == ctr { sum += $7 }
8874                                 END { printf("%0.0f", sum) }')
8875
8876                 if ((sum != bs * count)); then
8877                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
8878                 fi
8879         done
8880
8881         rm -rf $DIR/${tdir}
8882 }
8883 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
8884
8885 test_133f() {
8886         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
8887         local facet
8888
8889         # First without trusting modes.
8890         find $proc_dirs -exec cat '{}' \; &> /dev/null
8891
8892         # Second verifying readability.
8893         find $proc_dirs \
8894                 -type f \
8895                 -exec cat '{}' \; &> /dev/null ||
8896                         error "proc file read failed"
8897
8898         for facet in $SINGLEMDS ost1; do
8899                 do_facet $facet find $proc_dirs \
8900                         ! -name req_history \
8901                         -exec cat '{}' \\\; &> /dev/null
8902
8903                 do_facet $facet find $proc_dirs \
8904                         ! -name req_history \
8905                         -type f \
8906                         -exec cat '{}' \\\; &> /dev/null ||
8907                                 error "proc file read failed"
8908         done
8909 }
8910 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
8911
8912 test_140() { #bug-17379
8913         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8914         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
8915         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
8916         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
8917
8918         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
8919         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
8920         local i=0
8921         while i=`expr $i + 1`; do
8922                 test_mkdir -p $i || error "Creating dir $i"
8923                 cd $i || error "Changing to $i"
8924                 ln -s ../stat stat || error "Creating stat symlink"
8925                 # Read the symlink until ELOOP present,
8926                 # not LBUGing the system is considered success,
8927                 # we didn't overrun the stack.
8928                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
8929                 [ $ret -ne 0 ] && {
8930                         if [ $ret -eq 40 ]; then
8931                                 break  # -ELOOP
8932                         else
8933                                 error "Open stat symlink"
8934                                 return
8935                         fi
8936                 }
8937         done
8938         i=`expr $i - 1`
8939         echo "The symlink depth = $i"
8940         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
8941                                         error "Invalid symlink depth"
8942
8943         # Test recursive symlink
8944         ln -s symlink_self symlink_self
8945         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
8946         echo "open symlink_self returns $ret"
8947         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
8948 }
8949 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
8950
8951 test_150() {
8952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8953         local TF="$TMP/$tfile"
8954
8955         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
8956         cp $TF $DIR/$tfile
8957         cancel_lru_locks osc
8958         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
8959         remount_client $MOUNT
8960         df -P $MOUNT
8961         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
8962
8963         $TRUNCATE $TF 6000
8964         $TRUNCATE $DIR/$tfile 6000
8965         cancel_lru_locks osc
8966         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
8967
8968         echo "12345" >>$TF
8969         echo "12345" >>$DIR/$tfile
8970         cancel_lru_locks osc
8971         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
8972
8973         echo "12345" >>$TF
8974         echo "12345" >>$DIR/$tfile
8975         cancel_lru_locks osc
8976         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
8977
8978         rm -f $TF
8979         true
8980 }
8981 run_test 150 "truncate/append tests"
8982
8983 #LU-2902 roc_hit was not able to read all values from lproc
8984 function roc_hit_init() {
8985         local list=$(comma_list $(osts_nodes))
8986         local dir=$DIR/$tdir-check
8987         local file=$dir/file
8988         local BEFORE
8989         local AFTER
8990         local idx
8991
8992         test_mkdir -p $dir
8993         #use setstripe to do a write to every ost
8994         for i in $(seq 0 $((OSTCOUNT-1))); do
8995                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
8996                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
8997                 idx=$(printf %04x $i)
8998                 BEFORE=$(get_osd_param $list *OST*$idx stats |
8999                         awk '$1 == "cache_access" {sum += $2}
9000                                 END { printf("%0.0f", sum) }')
9001
9002                 cancel_lru_locks osc
9003                 cat $file >/dev/null
9004
9005                 AFTER=$(get_osd_param $list *OST*$idx stats |
9006                         awk '$1 == "cache_access" {sum += $2}
9007                                 END { printf("%0.0f", sum) }')
9008
9009                 echo BEFORE:$BEFORE AFTER:$AFTER
9010                 if ! let "AFTER - BEFORE == 4"; then
9011                         rm -rf $dir
9012                         error "roc_hit is not safe to use"
9013                 fi
9014                 rm $file
9015         done
9016
9017         rm -rf $dir
9018 }
9019
9020 function roc_hit() {
9021         local list=$(comma_list $(osts_nodes))
9022         echo $(get_osd_param $list '' stats |
9023                 awk '$1 == "cache_hit" {sum += $2}
9024                         END { printf("%0.0f", sum) }')
9025 }
9026
9027 function set_cache() {
9028         local on=1
9029
9030         if [ "$2" == "off" ]; then
9031                 on=0;
9032         fi
9033         local list=$(comma_list $(osts_nodes))
9034         set_osd_param $list '' $1_cache_enable $on
9035
9036         cancel_lru_locks osc
9037 }
9038
9039 test_151() {
9040         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9041         remote_ost_nodsh && skip "remote OST with nodsh" && return
9042
9043         local CPAGES=3
9044         local list=$(comma_list $(osts_nodes))
9045
9046         # check whether obdfilter is cache capable at all
9047         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9048                 echo "not cache-capable obdfilter"
9049                 return 0
9050         fi
9051
9052         # check cache is enabled on all obdfilters
9053         if get_osd_param $list '' read_cache_enable | grep 0; then
9054                 echo "oss cache is disabled"
9055                 return 0
9056         fi
9057
9058         set_osd_param $list '' writethrough_cache_enable 1
9059
9060         # check write cache is enabled on all obdfilters
9061         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9062                 echo "oss write cache is NOT enabled"
9063                 return 0
9064         fi
9065
9066         roc_hit_init
9067
9068         #define OBD_FAIL_OBD_NO_LRU  0x609
9069         do_nodes $list $LCTL set_param fail_loc=0x609
9070
9071         # pages should be in the case right after write
9072         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9073                 error "dd failed"
9074
9075         local BEFORE=$(roc_hit)
9076         cancel_lru_locks osc
9077         cat $DIR/$tfile >/dev/null
9078         local AFTER=$(roc_hit)
9079
9080         do_nodes $list $LCTL set_param fail_loc=0
9081
9082         if ! let "AFTER - BEFORE == CPAGES"; then
9083                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9084         fi
9085
9086         # the following read invalidates the cache
9087         cancel_lru_locks osc
9088         set_osd_param $list '' read_cache_enable 0
9089         cat $DIR/$tfile >/dev/null
9090
9091         # now data shouldn't be found in the cache
9092         BEFORE=$(roc_hit)
9093         cancel_lru_locks osc
9094         cat $DIR/$tfile >/dev/null
9095         AFTER=$(roc_hit)
9096         if let "AFTER - BEFORE != 0"; then
9097                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9098         fi
9099
9100         set_osd_param $list '' read_cache_enable 1
9101         rm -f $DIR/$tfile
9102 }
9103 run_test 151 "test cache on oss and controls ==============================="
9104
9105 test_152() {
9106         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9107         local TF="$TMP/$tfile"
9108
9109         # simulate ENOMEM during write
9110 #define OBD_FAIL_OST_NOMEM      0x226
9111         lctl set_param fail_loc=0x80000226
9112         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9113         cp $TF $DIR/$tfile
9114         sync || error "sync failed"
9115         lctl set_param fail_loc=0
9116
9117         # discard client's cache
9118         cancel_lru_locks osc
9119
9120         # simulate ENOMEM during read
9121         lctl set_param fail_loc=0x80000226
9122         cmp $TF $DIR/$tfile || error "cmp failed"
9123         lctl set_param fail_loc=0
9124
9125         rm -f $TF
9126 }
9127 run_test 152 "test read/write with enomem ============================"
9128
9129 test_153() {
9130         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9131 }
9132 run_test 153 "test if fdatasync does not crash ======================="
9133
9134 dot_lustre_fid_permission_check() {
9135         local fid=$1
9136         local ffid=$MOUNT/.lustre/fid/$fid
9137         local test_dir=$2
9138
9139         echo "stat fid $fid"
9140         stat $ffid > /dev/null || error "stat $ffid failed."
9141         echo "touch fid $fid"
9142         touch $ffid || error "touch $ffid failed."
9143         echo "write to fid $fid"
9144         cat /etc/hosts > $ffid || error "write $ffid failed."
9145         echo "read fid $fid"
9146         diff /etc/hosts $ffid || error "read $ffid failed."
9147         echo "append write to fid $fid"
9148         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9149         echo "rename fid $fid"
9150         mv $ffid $test_dir/$tfile.1 &&
9151                 error "rename $ffid to $tfile.1 should fail."
9152         touch $test_dir/$tfile.1
9153         mv $test_dir/$tfile.1 $ffid &&
9154                 error "rename $tfile.1 to $ffid should fail."
9155         rm -f $test_dir/$tfile.1
9156         echo "truncate fid $fid"
9157         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9158         echo "link fid $fid"
9159         ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9160         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9161                 echo "setfacl fid $fid"
9162                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9163                 echo "getfacl fid $fid"
9164                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9165         fi
9166         echo "unlink fid $fid"
9167         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9168         echo "mknod fid $fid"
9169         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9170
9171         fid=[0xf00000400:0x1:0x0]
9172         ffid=$MOUNT/.lustre/fid/$fid
9173
9174         echo "stat non-exist fid $fid"
9175         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9176         echo "write to non-exist fid $fid"
9177         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9178         echo "link new fid $fid"
9179         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9180
9181         mkdir -p $test_dir/$tdir
9182         touch $test_dir/$tdir/$tfile
9183         fid=$($LFS path2fid $test_dir/$tdir)
9184         rc=$?
9185         [ $rc -ne 0 ] &&
9186                 error "error: could not get fid for $test_dir/$dir/$tfile."
9187
9188         ffid=$MOUNT/.lustre/fid/$fid
9189
9190         echo "ls $fid"
9191         ls $ffid > /dev/null || error "ls $ffid failed."
9192         echo "touch $fid/$tfile.1"
9193         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9194
9195         echo "touch $MOUNT/.lustre/fid/$tfile"
9196         touch $MOUNT/.lustre/fid/$tfile && \
9197                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9198
9199         echo "setxattr to $MOUNT/.lustre/fid"
9200         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9201
9202         echo "listxattr for $MOUNT/.lustre/fid"
9203         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9204
9205         echo "delxattr from $MOUNT/.lustre/fid"
9206         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9207
9208         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9209         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9210                 error "touch invalid fid should fail."
9211
9212         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9213         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9214                 error "touch non-normal fid should fail."
9215
9216         echo "rename $tdir to $MOUNT/.lustre/fid"
9217         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9218                 error "rename to $MOUNT/.lustre/fid should fail."
9219
9220         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9221         then            # LU-3547
9222                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9223                 local new_obf_mode=777
9224
9225                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9226                 chmod $new_obf_mode $DIR/.lustre/fid ||
9227                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9228
9229                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9230                 [ $obf_mode -eq $new_obf_mode ] ||
9231                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9232
9233                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9234                 chmod $old_obf_mode $DIR/.lustre/fid ||
9235                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9236         fi
9237
9238         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9239         fid=$($LFS path2fid $test_dir/$tfile-2)
9240         echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9241         cp /etc/passwd $MOUNT/.lustre/fid/$fid &&
9242                 error "create lov data thru .lustre should fail."
9243         echo "cp /etc/passwd $test_dir/$tfile-2"
9244         cp /etc/passwd $test_dir/$tfile-2 ||
9245                 error "copy to $test_dir/$tfile-2 failed."
9246         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9247         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9248                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9249
9250         rm -rf $test_dir/tfile.lnk
9251         rm -rf $test_dir/$tfile-2
9252 }
9253
9254 test_154A() {
9255         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9256                 skip "Need MDS version at least 2.4.1" && return
9257
9258         touch $DIR/$tfile
9259         local FID=$($LFS path2fid $DIR/$tfile)
9260         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9261
9262         # check that we get the same pathname back
9263         local FOUND=$($LFS fid2path $MOUNT $FID)
9264         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9265         [ "$FOUND" != "$DIR/$tfile" ] &&
9266                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9267
9268         rm -rf $DIR/$tfile
9269 }
9270 run_test 154A "lfs path2fid and fid2path basic checks"
9271
9272 test_154a() {
9273         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9274         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9275                 { skip "Need MDS version at least 2.2.51"; return 0; }
9276         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9277
9278         cp /etc/hosts $DIR/$tfile
9279
9280         fid=$($LFS path2fid $DIR/$tfile)
9281         rc=$?
9282         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9283
9284         dot_lustre_fid_permission_check "$fid" $DIR ||
9285                 error "dot lustre permission check $fid failed"
9286
9287         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9288
9289         touch $MOUNT/.lustre/file &&
9290                 error "creation is not allowed under .lustre"
9291
9292         mkdir $MOUNT/.lustre/dir &&
9293                 error "mkdir is not allowed under .lustre"
9294
9295         rm -rf $DIR/$tfile
9296 }
9297 run_test 154a "Open-by-FID"
9298
9299 test_154b() {
9300         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9301         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9302                 { skip "Need MDS version at least 2.2.51"; return 0; }
9303
9304         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9305
9306         local remote_dir=$DIR/$tdir/remote_dir
9307         local MDTIDX=1
9308         local rc=0
9309
9310         mkdir -p $DIR/$tdir
9311         $LFS mkdir -i $MDTIDX $remote_dir ||
9312                 error "create remote directory failed"
9313
9314         cp /etc/hosts $remote_dir/$tfile
9315
9316         fid=$($LFS path2fid $remote_dir/$tfile)
9317         rc=$?
9318         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9319
9320         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9321                 error "dot lustre permission check $fid failed"
9322         rm -rf $DIR/$tdir
9323 }
9324 run_test 154b "Open-by-FID for remote directory"
9325
9326 test_154c() {
9327         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9328                 skip "Need MDS version at least 2.4.1" && return
9329
9330         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9331         local FID1=$($LFS path2fid $DIR/$tfile.1)
9332         local FID2=$($LFS path2fid $DIR/$tfile.2)
9333         local FID3=$($LFS path2fid $DIR/$tfile.3)
9334
9335         local N=1
9336         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9337                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9338                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9339                 local want=FID$N
9340                 [ "$FID" = "${!want}" ] ||
9341                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9342                 N=$((N + 1))
9343         done
9344
9345         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9346                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9347                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9348                 N=$((N + 1))
9349         done
9350 }
9351 run_test 154c "lfs path2fid and fid2path multiple arguments"
9352
9353 test_154d() {
9354         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9355                 skip "Need MDS version at least 2.5.53" && return
9356
9357         if remote_mds; then
9358                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9359         else
9360                 nid="0@lo"
9361         fi
9362         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9363         local fd
9364         local cmd
9365
9366         rm -f $DIR/$tfile
9367         touch $DIR/$tfile
9368
9369         fid=$($LFS path2fid $DIR/$tfile)
9370         # Open the file
9371         fd=$(free_fd)
9372         cmd="exec $fd<$DIR/$tfile"
9373         eval $cmd
9374         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9375         echo $fid_list | grep $fid
9376         rc=$?
9377
9378         cmd="exec $fd>/dev/null"
9379         eval $cmd
9380         if [ $rc -ne 0 ]; then
9381                 error "FID $fid not found in open files list $fid_list"
9382         fi
9383 }
9384 run_test 154d "Verify open file fid"
9385
9386 test_154e()
9387 {
9388         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
9389                 skip "Need MDS version at least 2.6.50" && return
9390
9391         if ls -a $MOUNT | grep -q '^\.lustre$'; then
9392                 error ".lustre returned by readdir"
9393         fi
9394 }
9395 run_test 154e ".lustre is not returned by readdir"
9396
9397 test_155_small_load() {
9398     local temp=$TMP/$tfile
9399     local file=$DIR/$tfile
9400
9401     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9402         error "dd of=$temp bs=6096 count=1 failed"
9403     cp $temp $file
9404     cancel_lru_locks osc
9405     cmp $temp $file || error "$temp $file differ"
9406
9407     $TRUNCATE $temp 6000
9408     $TRUNCATE $file 6000
9409     cmp $temp $file || error "$temp $file differ (truncate1)"
9410
9411     echo "12345" >>$temp
9412     echo "12345" >>$file
9413     cmp $temp $file || error "$temp $file differ (append1)"
9414
9415     echo "12345" >>$temp
9416     echo "12345" >>$file
9417     cmp $temp $file || error "$temp $file differ (append2)"
9418
9419     rm -f $temp $file
9420     true
9421 }
9422
9423 test_155_big_load() {
9424     remote_ost_nodsh && skip "remote OST with nodsh" && return
9425     local temp=$TMP/$tfile
9426     local file=$DIR/$tfile
9427
9428     free_min_max
9429     local cache_size=$(do_facet ost$((MAXI+1)) \
9430         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9431     local large_file_size=$((cache_size * 2))
9432
9433     echo "OSS cache size: $cache_size KB"
9434     echo "Large file size: $large_file_size KB"
9435
9436     [ $MAXV -le $large_file_size ] && \
9437         skip_env "max available OST size needs > $large_file_size KB" && \
9438         return 0
9439
9440     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9441
9442     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9443         error "dd of=$temp bs=$large_file_size count=1k failed"
9444     cp $temp $file
9445     ls -lh $temp $file
9446     cancel_lru_locks osc
9447     cmp $temp $file || error "$temp $file differ"
9448
9449     rm -f $temp $file
9450     true
9451 }
9452
9453 test_155a() {
9454         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9455         set_cache read on
9456         set_cache writethrough on
9457         test_155_small_load
9458 }
9459 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9460
9461 test_155b() {
9462         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9463         set_cache read on
9464         set_cache writethrough off
9465         test_155_small_load
9466 }
9467 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9468
9469 test_155c() {
9470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9471         set_cache read off
9472         set_cache writethrough on
9473         test_155_small_load
9474 }
9475 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9476
9477 test_155d() {
9478         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9479         set_cache read off
9480         set_cache writethrough off
9481         test_155_small_load
9482 }
9483 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9484
9485 test_155e() {
9486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9487         set_cache read on
9488         set_cache writethrough on
9489         test_155_big_load
9490 }
9491 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9492
9493 test_155f() {
9494         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9495         set_cache read on
9496         set_cache writethrough off
9497         test_155_big_load
9498 }
9499 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9500
9501 test_155g() {
9502         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9503         set_cache read off
9504         set_cache writethrough on
9505         test_155_big_load
9506 }
9507 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9508
9509 test_155h() {
9510         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9511         set_cache read off
9512         set_cache writethrough off
9513         test_155_big_load
9514 }
9515 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9516
9517 test_156() {
9518         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9519         local CPAGES=3
9520         local BEFORE
9521         local AFTER
9522         local file="$DIR/$tfile"
9523
9524         [ "$(facet_fstype ost1)" = "zfs" ] &&
9525                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9526                 return
9527
9528         roc_hit_init
9529
9530     log "Turn on read and write cache"
9531     set_cache read on
9532     set_cache writethrough on
9533
9534     log "Write data and read it back."
9535     log "Read should be satisfied from the cache."
9536     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9537     BEFORE=`roc_hit`
9538     cancel_lru_locks osc
9539     cat $file >/dev/null
9540     AFTER=`roc_hit`
9541     if ! let "AFTER - BEFORE == CPAGES"; then
9542         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9543     else
9544         log "cache hits:: before: $BEFORE, after: $AFTER"
9545     fi
9546
9547     log "Read again; it should be satisfied from the cache."
9548     BEFORE=$AFTER
9549     cancel_lru_locks osc
9550     cat $file >/dev/null
9551     AFTER=`roc_hit`
9552     if ! let "AFTER - BEFORE == CPAGES"; then
9553         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9554     else
9555         log "cache hits:: before: $BEFORE, after: $AFTER"
9556     fi
9557
9558
9559     log "Turn off the read cache and turn on the write cache"
9560     set_cache read off
9561     set_cache writethrough on
9562
9563     log "Read again; it should be satisfied from the cache."
9564     BEFORE=`roc_hit`
9565     cancel_lru_locks osc
9566     cat $file >/dev/null
9567     AFTER=`roc_hit`
9568     if ! let "AFTER - BEFORE == CPAGES"; then
9569         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9570     else
9571         log "cache hits:: before: $BEFORE, after: $AFTER"
9572     fi
9573
9574     log "Read again; it should not be satisfied from the cache."
9575     BEFORE=$AFTER
9576     cancel_lru_locks osc
9577     cat $file >/dev/null
9578     AFTER=`roc_hit`
9579     if ! let "AFTER - BEFORE == 0"; then
9580         error "IN CACHE: before: $BEFORE, after: $AFTER"
9581     else
9582         log "cache hits:: before: $BEFORE, after: $AFTER"
9583     fi
9584
9585     log "Write data and read it back."
9586     log "Read should be satisfied from the cache."
9587     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9588     BEFORE=`roc_hit`
9589     cancel_lru_locks osc
9590     cat $file >/dev/null
9591     AFTER=`roc_hit`
9592     if ! let "AFTER - BEFORE == CPAGES"; then
9593         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9594     else
9595         log "cache hits:: before: $BEFORE, after: $AFTER"
9596     fi
9597
9598     log "Read again; it should not be satisfied from the cache."
9599     BEFORE=$AFTER
9600     cancel_lru_locks osc
9601     cat $file >/dev/null
9602     AFTER=`roc_hit`
9603     if ! let "AFTER - BEFORE == 0"; then
9604         error "IN CACHE: before: $BEFORE, after: $AFTER"
9605     else
9606         log "cache hits:: before: $BEFORE, after: $AFTER"
9607     fi
9608
9609
9610     log "Turn off read and write cache"
9611     set_cache read off
9612     set_cache writethrough off
9613
9614     log "Write data and read it back"
9615     log "It should not be satisfied from the cache."
9616     rm -f $file
9617     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9618     cancel_lru_locks osc
9619     BEFORE=`roc_hit`
9620     cat $file >/dev/null
9621     AFTER=`roc_hit`
9622     if ! let "AFTER - BEFORE == 0"; then
9623         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9624     else
9625         log "cache hits:: before: $BEFORE, after: $AFTER"
9626     fi
9627
9628
9629     log "Turn on the read cache and turn off the write cache"
9630     set_cache read on
9631     set_cache writethrough off
9632
9633     log "Write data and read it back"
9634     log "It should not be satisfied from the cache."
9635     rm -f $file
9636     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9637     BEFORE=`roc_hit`
9638     cancel_lru_locks osc
9639     cat $file >/dev/null
9640     AFTER=`roc_hit`
9641     if ! let "AFTER - BEFORE == 0"; then
9642         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9643     else
9644         log "cache hits:: before: $BEFORE, after: $AFTER"
9645     fi
9646
9647     log "Read again; it should be satisfied from the cache."
9648     BEFORE=`roc_hit`
9649     cancel_lru_locks osc
9650     cat $file >/dev/null
9651     AFTER=`roc_hit`
9652     if ! let "AFTER - BEFORE == CPAGES"; then
9653         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9654     else
9655         log "cache hits:: before: $BEFORE, after: $AFTER"
9656     fi
9657
9658     rm -f $file
9659 }
9660 run_test 156 "Verification of tunables ============================"
9661
9662 #Changelogs
9663 err17935 () {
9664         if [[ $MDSCOUNT -gt 1 ]]; then
9665                 error_ignore bz17935 $*
9666         else
9667                 error $*
9668         fi
9669 }
9670
9671 changelog_chmask()
9672 {
9673         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
9674
9675         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
9676
9677         if [ $MASK -eq 1 ]; then
9678                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
9679         else
9680                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
9681         fi
9682 }
9683
9684 changelog_extract_field() {
9685         local mdt=$1
9686         local cltype=$2
9687         local file=$3
9688         local identifier=$4
9689
9690         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
9691                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
9692                 tail -1
9693 }
9694
9695 test_160a() {
9696         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9697         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9698         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9699                 { skip "Need MDS version at least 2.2.0"; return; }
9700
9701         local CL_USERS="mdd.$MDT0.changelog_users"
9702         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9703         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9704         echo "Registered as changelog user $USER"
9705         $GET_CL_USERS | grep -q $USER ||
9706                 error "User $USER not found in changelog_users"
9707
9708         # change something
9709         test_mkdir -p $DIR/$tdir/pics/2008/zachy
9710         touch $DIR/$tdir/pics/2008/zachy/timestamp
9711         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
9712         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
9713         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
9714         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
9715         rm $DIR/$tdir/pics/desktop.jpg
9716
9717         $LFS changelog $MDT0 | tail -5
9718
9719         echo "verifying changelog mask"
9720         changelog_chmask "MKDIR"
9721         changelog_chmask "CLOSE"
9722
9723         test_mkdir -p $DIR/$tdir/pics/zach/sofia
9724         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9725
9726         changelog_chmask "MKDIR"
9727         changelog_chmask "CLOSE"
9728
9729         test_mkdir -p $DIR/$tdir/pics/2008/sofia
9730         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9731
9732         $LFS changelog $MDT0
9733         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
9734         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
9735         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
9736         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
9737
9738         # verify contents
9739         echo "verifying target fid"
9740         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
9741         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
9742         [ "$fidc" == "$fidf" ] ||
9743                 err17935 "fid in changelog $fidc != file fid $fidf"
9744         echo "verifying parent fid"
9745         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
9746         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
9747         [ "$fidc" == "$fidf" ] ||
9748                 err17935 "pfid in changelog $fidc != dir fid $fidf"
9749
9750         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9751         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
9752         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9753         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
9754         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
9755                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
9756
9757         MIN_REC=$($GET_CL_USERS |
9758                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
9759         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
9760         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
9761         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
9762                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
9763
9764         # LU-3446 changelog index reset on MDT restart
9765         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
9766         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9767         $LFS changelog_clear $MDT0 $USER 0
9768         stop $SINGLEMDS || error "Fail to stop MDT."
9769         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
9770         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9771         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
9772         [ $CUR_REC1 == $CUR_REC2 ] ||
9773                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
9774
9775         echo "verifying user deregister"
9776         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9777         $GET_CL_USERS | grep -q $USER &&
9778                 error "User $USER still in changelog_users"
9779
9780         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
9781         if [ $USERS -eq 0 ]; then
9782                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9783                 touch $DIR/$tdir/chloe
9784                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9785                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
9786                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
9787         else
9788                 echo "$USERS other changelog users; can't verify off"
9789         fi
9790 }
9791 run_test 160a "changelog sanity"
9792
9793 test_160b() { # LU-3587
9794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9795         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9796         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9797                 { skip "Need MDS version at least 2.2.0"; return; }
9798
9799         local CL_USERS="mdd.$MDT0.changelog_users"
9800         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9801         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9802         echo "Registered as changelog user $USER"
9803         $GET_CL_USERS | grep -q $USER ||
9804                 error "User $USER not found in changelog_users"
9805
9806         local LONGNAME1=$(str_repeat a 255)
9807         local LONGNAME2=$(str_repeat b 255)
9808
9809         cd $DIR
9810         echo "creating very long named file"
9811         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
9812         echo "moving very long named file"
9813         mv $LONGNAME1 $LONGNAME2
9814
9815         $LFS changelog $MDT0 | grep RENME
9816
9817         echo "deregistering $USER"
9818         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9819
9820         rm -f $LONGNAME2
9821 }
9822 run_test 160b "Verify that very long rename doesn't crash in changelog"
9823
9824 test_160c() {
9825         local rc=0
9826         local server_version=$(lustre_version_code $SINGLEMDS)
9827
9828         [[ $server_version -gt $(version_code 2.5.57) ]] ||
9829                 [[ $server_version -gt $(version_code 2.5.1) &&
9830                    $server_version -lt $(version_code 2.5.50) ]] ||
9831                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
9832         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9833
9834         # Registration step
9835         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
9836                 changelog_register -n)
9837
9838         rm -rf $DIR/$tdir
9839         mkdir -p $DIR/$tdir
9840         $MCREATE $DIR/$tdir/foo_160c
9841         changelog_chmask "TRUNC"
9842         $TRUNCATE $DIR/$tdir/foo_160c 200
9843         changelog_chmask "TRUNC"
9844         $TRUNCATE $DIR/$tdir/foo_160c 199
9845         $LFS changelog $MDT0
9846         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
9847         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
9848         $LFS changelog_clear $MDT0 $USER 0
9849
9850         # Deregistration step
9851         echo "deregistering $USER"
9852         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9853 }
9854 run_test 160c "verify that changelog log catch the truncate event"
9855
9856 test_161a() {
9857         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9858     test_mkdir -p $DIR/$tdir
9859     cp /etc/hosts $DIR/$tdir/$tfile
9860     test_mkdir $DIR/$tdir/foo1
9861     test_mkdir $DIR/$tdir/foo2
9862     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
9863     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
9864     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
9865     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
9866         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
9867         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9868                 $LFS fid2path $DIR $FID
9869                 err17935 "bad link ea"
9870         fi
9871     # middle
9872     rm $DIR/$tdir/foo2/zachary
9873     # last
9874     rm $DIR/$tdir/foo2/thor
9875     # first
9876     rm $DIR/$tdir/$tfile
9877     # rename
9878     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
9879     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
9880         then
9881         $LFS fid2path $DIR $FID
9882         err17935 "bad link rename"
9883     fi
9884     rm $DIR/$tdir/foo2/maggie
9885
9886         # overflow the EA
9887         local longname=filename_avg_len_is_thirty_two_
9888         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
9889                 error "failed to hardlink many files"
9890         links=$($LFS fid2path $DIR $FID | wc -l)
9891         echo -n "${links}/1000 links in link EA"
9892         [[ $links -gt 60 ]] ||
9893                 err17935 "expected at least 60 links in link EA"
9894         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
9895                 error "failed to unlink many hardlinks"
9896 }
9897 run_test 161a "link ea sanity"
9898
9899 test_161b() {
9900         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9901         [ $MDSCOUNT -lt 2 ] &&
9902                 skip "skipping remote directory test" && return
9903         local MDTIDX=1
9904         local remote_dir=$DIR/$tdir/remote_dir
9905
9906         mkdir -p $DIR/$tdir
9907         $LFS mkdir -i $MDTIDX $remote_dir ||
9908                 error "create remote directory failed"
9909
9910         cp /etc/hosts $remote_dir/$tfile
9911         mkdir -p $remote_dir/foo1
9912         mkdir -p $remote_dir/foo2
9913         ln $remote_dir/$tfile $remote_dir/foo1/sofia
9914         ln $remote_dir/$tfile $remote_dir/foo2/zachary
9915         ln $remote_dir/$tfile $remote_dir/foo1/luna
9916         ln $remote_dir/$tfile $remote_dir/foo2/thor
9917
9918         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
9919                      tr -d ']')
9920         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9921                 $LFS fid2path $DIR $FID
9922                 err17935 "bad link ea"
9923         fi
9924         # middle
9925         rm $remote_dir/foo2/zachary
9926         # last
9927         rm $remote_dir/foo2/thor
9928         # first
9929         rm $remote_dir/$tfile
9930         # rename
9931         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
9932         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
9933         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
9934                 $LFS fid2path $DIR $FID
9935                 err17935 "bad link rename"
9936         fi
9937         rm $remote_dir/foo2/maggie
9938
9939         # overflow the EA
9940         local longname=filename_avg_len_is_thirty_two_
9941         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
9942                 error "failed to hardlink many files"
9943         links=$($LFS fid2path $DIR $FID | wc -l)
9944         echo -n "${links}/1000 links in link EA"
9945         [[ ${links} -gt 60 ]] ||
9946                 err17935 "expected at least 60 links in link EA"
9947         unlinkmany $remote_dir/foo2/$longname 1000 ||
9948         error "failed to unlink many hardlinks"
9949 }
9950 run_test 161b "link ea sanity under remote directory"
9951
9952 test_161c() {
9953         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9954         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
9955                 skip "Need MDS version at least 2.1.5" && return
9956
9957         # define CLF_RENAME_LAST 0x0001
9958         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
9959         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
9960                 changelog_register -n)
9961         rm -rf $DIR/$tdir
9962         mkdir -p $DIR/$tdir
9963         touch $DIR/$tdir/foo_161c
9964         touch $DIR/$tdir/bar_161c
9965         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
9966         $LFS changelog $MDT0 | grep RENME
9967         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
9968                 cut -f5 -d' ')
9969         $LFS changelog_clear $MDT0 $USER 0
9970         if [ x$flags != "x0x1" ]; then
9971                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9972                         $USER
9973                 error "flag $flags is not 0x1"
9974         fi
9975         echo "rename overwrite a target having nlink = 1," \
9976                 "changelog record has flags of $flags"
9977
9978         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
9979         touch $DIR/$tdir/foo_161c
9980         touch $DIR/$tdir/bar_161c
9981         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
9982         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
9983         $LFS changelog $MDT0 | grep RENME
9984         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
9985         $LFS changelog_clear $MDT0 $USER 0
9986         if [ x$flags != "x0x0" ]; then
9987                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9988                         $USER
9989                 error "flag $flags is not 0x0"
9990         fi
9991         echo "rename overwrite a target having nlink > 1," \
9992                 "changelog record has flags of $flags"
9993
9994         # rename doesn't overwrite a target (changelog flag 0x0)
9995         touch $DIR/$tdir/foo_161c
9996         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
9997         $LFS changelog $MDT0 | grep RENME
9998         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
9999         $LFS changelog_clear $MDT0 $USER 0
10000         if [ x$flags != "x0x0" ]; then
10001                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10002                         $USER
10003                 error "flag $flags is not 0x0"
10004         fi
10005         echo "rename doesn't overwrite a target," \
10006                 "changelog record has flags of $flags"
10007
10008         # define CLF_UNLINK_LAST 0x0001
10009         # unlink a file having nlink = 1 (changelog flag 0x1)
10010         rm -f $DIR/$tdir/foo2_161c
10011         $LFS changelog $MDT0 | grep UNLNK
10012         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10013         $LFS changelog_clear $MDT0 $USER 0
10014         if [ x$flags != "x0x1" ]; then
10015                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10016                         $USER
10017                 error "flag $flags is not 0x1"
10018         fi
10019         echo "unlink a file having nlink = 1," \
10020                 "changelog record has flags of $flags"
10021
10022         # unlink a file having nlink > 1 (changelog flag 0x0)
10023         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10024         rm -f $DIR/$tdir/foobar_161c
10025         $LFS changelog $MDT0 | grep UNLNK
10026         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10027         $LFS changelog_clear $MDT0 $USER 0
10028         if [ x$flags != "x0x0" ]; then
10029                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10030                         $USER
10031                 error "flag $flags is not 0x0"
10032         fi
10033         echo "unlink a file having nlink > 1," \
10034                 "changelog record has flags of $flags"
10035         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10036 }
10037 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10038
10039 check_path() {
10040     local expected=$1
10041     shift
10042     local fid=$2
10043
10044     local path=$(${LFS} fid2path $*)
10045     RC=$?
10046
10047     if [ $RC -ne 0 ]; then
10048         err17935 "path looked up of $expected failed. Error $RC"
10049         return $RC
10050     elif [ "${path}" != "${expected}" ]; then
10051         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10052         return 2
10053     fi
10054     echo "fid $fid resolves to path $path (expected $expected)"
10055 }
10056
10057 test_162() {
10058         # Make changes to filesystem
10059         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10060         test_mkdir -p $DIR/$tdir/d2
10061         touch $DIR/$tdir/d2/$tfile
10062         touch $DIR/$tdir/d2/x1
10063         touch $DIR/$tdir/d2/x2
10064         test_mkdir -p $DIR/$tdir/d2/a/b/c
10065         test_mkdir -p $DIR/$tdir/d2/p/q/r
10066         # regular file
10067         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10068         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
10069
10070         # softlink
10071         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10072         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10073         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
10074
10075         # softlink to wrong file
10076         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10077         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10078         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
10079
10080         # hardlink
10081         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10082         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10083         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10084         # fid2path dir/fsname should both work
10085         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
10086         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
10087
10088         # hardlink count: check that there are 2 links
10089         # Doesnt work with CMD yet: 17935
10090         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10091                 err17935 "expected 2 links"
10092
10093         # hardlink indexing: remove the first link
10094         rm $DIR/$tdir/d2/p/q/r/hlink
10095         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
10096
10097         return 0
10098 }
10099 run_test 162 "path lookup sanity"
10100
10101 test_169() {
10102         # do directio so as not to populate the page cache
10103         log "creating a 10 Mb file"
10104         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10105         log "starting reads"
10106         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10107         log "truncating the file"
10108         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10109         log "killing dd"
10110         kill %+ || true # reads might have finished
10111         echo "wait until dd is finished"
10112         wait
10113         log "removing the temporary file"
10114         rm -rf $DIR/$tfile || error "tmp file removal failed"
10115 }
10116 run_test 169 "parallel read and truncate should not deadlock"
10117
10118 test_170() {
10119         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10120         $LCTL clear     # bug 18514
10121         $LCTL debug_daemon start $TMP/${tfile}_log_good
10122         touch $DIR/$tfile
10123         $LCTL debug_daemon stop
10124         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10125                error "sed failed to read log_good"
10126
10127         $LCTL debug_daemon start $TMP/${tfile}_log_good
10128         rm -rf $DIR/$tfile
10129         $LCTL debug_daemon stop
10130
10131         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10132                error "lctl df log_bad failed"
10133
10134         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10135         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10136
10137         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10138         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10139
10140         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10141                 error "bad_line good_line1 good_line2 are empty"
10142
10143         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10144         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10145         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10146
10147         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10148         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10149         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10150
10151         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10152                 error "bad_line_new good_line_new are empty"
10153
10154         local expected_good=$((good_line1 + good_line2*2))
10155
10156         rm -f $TMP/${tfile}*
10157         # LU-231, short malformed line may not be counted into bad lines
10158         if [ $bad_line -ne $bad_line_new ] &&
10159                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10160                 error "expected $bad_line bad lines, but got $bad_line_new"
10161                 return 1
10162         fi
10163
10164         if [ $expected_good -ne $good_line_new ]; then
10165                 error "expected $expected_good good lines, but got $good_line_new"
10166                 return 2
10167         fi
10168         true
10169 }
10170 run_test 170 "test lctl df to handle corrupted log ====================="
10171
10172 test_171() { # bug20592
10173         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10174 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10175         $LCTL set_param fail_loc=0x50e
10176         $LCTL set_param fail_val=3000
10177         multiop_bg_pause $DIR/$tfile O_s || true
10178         local MULTIPID=$!
10179         kill -USR1 $MULTIPID
10180         # cause log dump
10181         sleep 3
10182         wait $MULTIPID
10183         if dmesg | grep "recursive fault"; then
10184                 error "caught a recursive fault"
10185         fi
10186         $LCTL set_param fail_loc=0
10187         true
10188 }
10189 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10190
10191 # it would be good to share it with obdfilter-survey/libecho code
10192 setup_obdecho_osc () {
10193         local rc=0
10194         local ost_nid=$1
10195         local obdfilter_name=$2
10196         echo "Creating new osc for $obdfilter_name on $ost_nid"
10197         # make sure we can find loopback nid
10198         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10199
10200         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10201                            ${obdfilter_name}_osc_UUID || rc=2; }
10202         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10203                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10204         return $rc
10205 }
10206
10207 cleanup_obdecho_osc () {
10208         local obdfilter_name=$1
10209         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10210         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10211         return 0
10212 }
10213
10214 obdecho_test() {
10215         local OBD=$1
10216         local node=$2
10217         local pages=${3:-64}
10218         local rc=0
10219         local id
10220
10221         local count=10
10222         local obd_size=$(get_obd_size $node $OBD)
10223         local page_size=$(get_page_size $node)
10224         if [[ -n "$obd_size" ]]; then
10225                 local new_count=$((obd_size / (pages * page_size / 1024)))
10226                 [[ $new_count -ge $count ]] || count=$new_count
10227         fi
10228
10229         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10230         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10231                            rc=2; }
10232         if [ $rc -eq 0 ]; then
10233             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10234             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10235         fi
10236         echo "New object id is $id"
10237         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10238                            rc=4; }
10239         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10240                            "test_brw $count w v $pages $id" || rc=4; }
10241         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10242                            rc=4; }
10243         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10244                                         "cleanup" || rc=5; }
10245         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10246                                         "detach" || rc=6; }
10247         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10248         return $rc
10249 }
10250
10251 test_180a() {
10252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10253         remote_ost_nodsh && skip "remote OST with nodsh" && return
10254         local rc=0
10255         local rmmod_local=0
10256
10257         if ! module_loaded obdecho; then
10258             load_module obdecho/obdecho
10259             rmmod_local=1
10260         fi
10261
10262         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10263         local host=$(lctl get_param -n osc.$osc.import |
10264                              awk '/current_connection:/ {print $2}' )
10265         local target=$(lctl get_param -n osc.$osc.import |
10266                              awk '/target:/ {print $2}' )
10267         target=${target%_UUID}
10268
10269         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10270         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10271         [[ -n $target ]] && cleanup_obdecho_osc $target
10272         [ $rmmod_local -eq 1 ] && rmmod obdecho
10273         return $rc
10274 }
10275 run_test 180a "test obdecho on osc"
10276
10277 test_180b() {
10278         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10279         remote_ost_nodsh && skip "remote OST with nodsh" && return
10280         local rc=0
10281         local rmmod_remote=0
10282
10283         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10284                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10285                       "modprobe obdecho; }" && rmmod_remote=1
10286         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10287         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10288         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10289         return $rc
10290 }
10291 run_test 180b "test obdecho directly on obdfilter"
10292
10293 test_180c() { # LU-2598
10294         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10295         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10296                 skip "Need MDS version at least 2.4.0" && return
10297
10298         local rc=0
10299         local rmmod_remote=false
10300         local pages=16384 # 64MB bulk I/O RPC size
10301         local target
10302
10303         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10304                 rmmod_remote=true || error "failed to load module obdecho"
10305
10306         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10307                 head -n1)
10308         if [ -n "$target" ]; then
10309                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10310         else
10311                 echo "there is no obdfilter target on ost1"
10312                 rc=2
10313         fi
10314         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10315         return $rc
10316 }
10317 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10318
10319 test_181() { # bug 22177
10320         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10321         # create enough files to index the directory
10322         createmany -o $DIR/$tdir/foobar 4000
10323         # print attributes for debug purpose
10324         lsattr -d .
10325         # open dir
10326         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10327         MULTIPID=$!
10328         # remove the files & current working dir
10329         unlinkmany $DIR/$tdir/foobar 4000
10330         rmdir $DIR/$tdir
10331         kill -USR1 $MULTIPID
10332         wait $MULTIPID
10333         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10334         return 0
10335 }
10336 run_test 181 "Test open-unlinked dir ========================"
10337
10338 test_182() {
10339         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10340         # disable MDC RPC lock wouldn't crash client
10341         local fcount=1000
10342         local tcount=4
10343
10344         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10345 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10346         $LCTL set_param fail_loc=0x804
10347
10348         for (( i=0; i < $tcount; i++ )) ; do
10349                 mkdir $DIR/$tdir/$i
10350                 createmany -o $DIR/$tdir/$i/f- $fcount &
10351         done
10352         wait
10353
10354         for (( i=0; i < $tcount; i++ )) ; do
10355                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10356         done
10357         wait
10358
10359         rm -rf $DIR/$tdir
10360
10361         $LCTL set_param fail_loc=0
10362 }
10363 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10364
10365 test_183() { # LU-2275
10366         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10367                 skip "Need MDS version at least 2.3.56" && return
10368
10369         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10370         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10371         echo aaa > $DIR/$tdir/$tfile
10372
10373 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10374         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10375
10376         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10377         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10378
10379         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10380
10381         # Flush negative dentry cache
10382         touch $DIR/$tdir/$tfile
10383
10384         # We are not checking for any leaked references here, they'll
10385         # become evident next time we do cleanup with module unload.
10386         rm -rf $DIR/$tdir
10387 }
10388 run_test 183 "No crash or request leak in case of strange dispositions ========"
10389
10390 # test suite 184 is for LU-2016, LU-2017
10391 test_184a() {
10392         check_swap_layouts_support && return 0
10393
10394         dir0=$DIR/$tdir/$testnum
10395         test_mkdir -p $dir0 || error "creating dir $dir0"
10396         ref1=/etc/passwd
10397         ref2=/etc/group
10398         file1=$dir0/f1
10399         file2=$dir0/f2
10400         $SETSTRIPE -c1 $file1
10401         cp $ref1 $file1
10402         $SETSTRIPE -c2 $file2
10403         cp $ref2 $file2
10404         gen1=$($GETSTRIPE -g $file1)
10405         gen2=$($GETSTRIPE -g $file2)
10406
10407         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10408         gen=$($GETSTRIPE -g $file1)
10409         [[ $gen1 != $gen ]] ||
10410                 "Layout generation on $file1 does not change"
10411         gen=$($GETSTRIPE -g $file2)
10412         [[ $gen2 != $gen ]] ||
10413                 "Layout generation on $file2 does not change"
10414
10415         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10416         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10417 }
10418 run_test 184a "Basic layout swap"
10419
10420 test_184b() {
10421         check_swap_layouts_support && return 0
10422
10423         dir0=$DIR/$tdir/$testnum
10424         mkdir -p $dir0 || error "creating dir $dir0"
10425         file1=$dir0/f1
10426         file2=$dir0/f2
10427         file3=$dir0/f3
10428         dir1=$dir0/d1
10429         dir2=$dir0/d2
10430         mkdir $dir1 $dir2
10431         $SETSTRIPE -c1 $file1
10432         $SETSTRIPE -c2 $file2
10433         $SETSTRIPE -c1 $file3
10434         chown $RUNAS_ID $file3
10435         gen1=$($GETSTRIPE -g $file1)
10436         gen2=$($GETSTRIPE -g $file2)
10437
10438         $LFS swap_layouts $dir1 $dir2 &&
10439                 error "swap of directories layouts should fail"
10440         $LFS swap_layouts $dir1 $file1 &&
10441                 error "swap of directory and file layouts should fail"
10442         $RUNAS $LFS swap_layouts $file1 $file2 &&
10443                 error "swap of file we cannot write should fail"
10444         $LFS swap_layouts $file1 $file3 &&
10445                 error "swap of file with different owner should fail"
10446         /bin/true # to clear error code
10447 }
10448 run_test 184b "Forbidden layout swap (will generate errors)"
10449
10450 test_184c() {
10451         check_swap_layouts_support && return 0
10452
10453         local dir0=$DIR/$tdir/$testnum
10454         mkdir -p $dir0 || error "creating dir $dir0"
10455
10456         local ref1=$dir0/ref1
10457         local ref2=$dir0/ref2
10458         local file1=$dir0/file1
10459         local file2=$dir0/file2
10460         # create a file large enough for the concurent test
10461         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10462         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10463         echo "ref file size: ref1($(stat -c %s $ref1))," \
10464              "ref2($(stat -c %s $ref2))"
10465
10466         cp $ref2 $file2
10467         dd if=$ref1 of=$file1 bs=16k &
10468         local DD_PID=$!
10469
10470         # Make sure dd starts to copy file
10471         while [ ! -f $file1 ]; do sleep 0.1; done
10472
10473         $LFS swap_layouts $file1 $file2
10474         local rc=$?
10475         wait $DD_PID
10476         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10477         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10478
10479         # how many bytes copied before swapping layout
10480         local copied=$(stat -c %s $file2)
10481         local remaining=$(stat -c %s $ref1)
10482         remaining=$((remaining - copied))
10483         echo "Copied $copied bytes before swapping layout..."
10484
10485         cmp -n $copied $file1 $ref2 | grep differ &&
10486                 error "Content mismatch [0, $copied) of ref2 and file1"
10487         cmp -n $copied $file2 $ref1 ||
10488                 error "Content mismatch [0, $copied) of ref1 and file2"
10489         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10490                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10491
10492         # clean up
10493         rm -f $ref1 $ref2 $file1 $file2
10494 }
10495 run_test 184c "Concurrent write and layout swap"
10496
10497 test_184d() {
10498         check_swap_layouts_support && return 0
10499         [ -z "$(which getfattr 2>/dev/null)" ] &&
10500                 skip "no getfattr command" && return 0
10501
10502         local file1=$DIR/$tdir/$tfile-1
10503         local file2=$DIR/$tdir/$tfile-2
10504         local file3=$DIR/$tdir/$tfile-3
10505         local lovea1
10506         local lovea2
10507
10508         mkdir -p $DIR/$tdir
10509         touch $file1 || error "create $file1 failed"
10510         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10511                 error "create $file2 failed"
10512         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10513                 error "create $file3 failed"
10514         lovea1=$($LFS getstripe $file1 | sed 1d)
10515
10516         $LFS swap_layouts $file2 $file3 ||
10517                 error "swap $file2 $file3 layouts failed"
10518         $LFS swap_layouts $file1 $file2 ||
10519                 error "swap $file1 $file2 layouts failed"
10520
10521         lovea2=$($LFS getstripe $file2 | sed 1d)
10522         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10523
10524         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10525         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
10526 }
10527 run_test 184d "allow stripeless layouts swap"
10528
10529
10530 test_185() { # LU-2441
10531         # LU-3553 - no volatile file support in old servers
10532         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10533                 { skip "Need MDS version at least 2.3.60"; return 0; }
10534
10535         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10536         touch $DIR/$tdir/spoo
10537         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10538         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10539                 error "cannot create/write a volatile file"
10540         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10541                 error "FID is still valid after close"
10542
10543         multiop_bg_pause $DIR/$tdir vVw4096_c
10544         local multi_pid=$!
10545
10546         local OLD_IFS=$IFS
10547         IFS=":"
10548         local fidv=($fid)
10549         IFS=$OLD_IFS
10550         # assume that the next FID for this client is sequential, since stdout
10551         # is unfortunately eaten by multiop_bg_pause
10552         local n=$((${fidv[1]} + 1))
10553         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10554         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10555                 error "FID is missing before close"
10556         kill -USR1 $multi_pid
10557         # 1 second delay, so if mtime change we will see it
10558         sleep 1
10559         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10560         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10561 }
10562 run_test 185 "Volatile file support"
10563
10564 test_187a() {
10565         local dir0=$DIR/$tdir/$testnum
10566         mkdir -p $dir0 || error "creating dir $dir0"
10567
10568         local file=$dir0/file1
10569         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10570         local dv1=$($LFS data_version $file)
10571         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10572         local dv2=$($LFS data_version $file)
10573         [[ $dv1 != $dv2 ]] ||
10574                 error "data version did not change on write $dv1 == $dv2"
10575
10576         # clean up
10577         rm -f $file1
10578 }
10579 run_test 187a "Test data version change"
10580
10581 test_187b() {
10582         local dir0=$DIR/$tdir/$testnum
10583         mkdir -p $dir0 || error "creating dir $dir0"
10584
10585         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
10586         [[ ${DV[0]} != ${DV[1]} ]] ||
10587                 error "data version did not change on write"\
10588                       " ${DV[0]} == ${DV[1]}"
10589
10590         # clean up
10591         rm -f $file1
10592 }
10593 run_test 187b "Test data version change on volatile file"
10594
10595 # OST pools tests
10596 check_file_in_pool()
10597 {
10598         local file=$1
10599         local pool=$2
10600         local tlist="$3"
10601         local res=$($GETSTRIPE $file | grep 0x | cut -f2)
10602         for i in $res
10603         do
10604                 for t in $tlist ; do
10605                         [ "$i" -eq "$t" ] && continue 2
10606                 done
10607
10608                 echo "pool list: $tlist"
10609                 echo "striping: $res"
10610                 error_noexit "$file not allocated in $pool"
10611                 return 1
10612         done
10613         return 0
10614 }
10615
10616 pool_add() {
10617         echo "Creating new pool"
10618         local pool=$1
10619
10620         create_pool $FSNAME.$pool ||
10621                 { error_noexit "No pool created, result code $?"; return 1; }
10622         [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
10623                 { error_noexit "$pool not in lfs pool_list"; return 2; }
10624 }
10625
10626 pool_add_targets() {
10627         echo "Adding targets to pool"
10628         local pool=$1
10629         local first=$2
10630         local last=$3
10631         local step=${4:-1}
10632
10633         local list=$(seq $first $step $last)
10634
10635         local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
10636         do_facet mgs $LCTL pool_add \
10637                         $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
10638         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
10639                         | sort -u | tr '\n' ' ' " "$t" || { 
10640                 error_noexit "Add to pool failed"
10641                 return 1
10642         }
10643         local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
10644         local addcount=$(((last - first) / step + 1))
10645         [ $lfscount -eq $addcount ] || {
10646                 error_noexit "lfs pool_list bad ost count" \
10647                                                 "$lfscount != $addcount"
10648                 return 2
10649         }
10650 }
10651
10652 pool_set_dir() {
10653         local pool=$1
10654         local tdir=$2
10655         echo "Setting pool on directory $tdir"
10656
10657         $SETSTRIPE -c 2 -p $pool $tdir && return 0
10658
10659         error_noexit "Cannot set pool $pool to $tdir"
10660         return 1
10661 }
10662
10663 pool_check_dir() {
10664         local pool=$1
10665         local tdir=$2
10666         echo "Checking pool on directory $tdir"
10667
10668         local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
10669         [ "$res" = "$pool" ] && return 0
10670
10671         error_noexit "Pool on '$tdir' is '$res', not '$pool'"
10672         return 1
10673 }
10674
10675 pool_dir_rel_path() {
10676         echo "Testing relative path works well"
10677         local pool=$1
10678         local tdir=$2
10679         local root=$3
10680
10681         mkdir -p $root/$tdir/$tdir
10682         cd $root/$tdir
10683         pool_set_dir $pool $tdir          || return 1
10684         pool_set_dir $pool ./$tdir        || return 2
10685         pool_set_dir $pool ../$tdir       || return 3
10686         pool_set_dir $pool ../$tdir/$tdir || return 4
10687         rm -rf $tdir; cd - > /dev/null
10688 }
10689
10690 pool_alloc_files() {
10691         echo "Checking files allocation from directory pool"
10692         local pool=$1
10693         local tdir=$2
10694         local count=$3
10695         local tlist="$4"
10696
10697         local failed=0
10698         for i in $(seq -w 1 $count)
10699         do
10700                 local file=$tdir/file-$i
10701                 touch $file
10702                 check_file_in_pool $file $pool "$tlist" || \
10703                         failed=$((failed + 1))
10704         done
10705         [ "$failed" = 0 ] && return 0
10706
10707         error_noexit "$failed files not allocated in $pool"
10708         return 1
10709 }
10710
10711 pool_create_files() {
10712         echo "Creating files in pool"
10713         local pool=$1
10714         local tdir=$2
10715         local count=$3
10716         local tlist="$4"
10717
10718         mkdir -p $tdir
10719         local failed=0
10720         for i in $(seq -w 1 $count)
10721         do
10722                 local file=$tdir/spoo-$i
10723                 $SETSTRIPE -p $pool $file
10724                 check_file_in_pool $file $pool "$tlist" || \
10725                         failed=$((failed + 1))
10726         done
10727         [ "$failed" = 0 ] && return 0
10728
10729         error_noexit "$failed files not allocated in $pool"
10730         return 1
10731 }
10732
10733 pool_lfs_df() {
10734         echo "Checking 'lfs df' output"
10735         local pool=$1
10736
10737         local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
10738                         tr '\n' ' ')
10739         local res=$($LFS df --pool $FSNAME.$pool |
10740                         awk '{print $1}' |
10741                         grep "$FSNAME-OST" |
10742                         tr '\n' ' ')
10743         [ "$res" = "$t" ] && return 0
10744
10745         error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
10746         return 1
10747 }
10748
10749 pool_file_rel_path() {
10750         echo "Creating files in a pool with relative pathname"
10751         local pool=$1
10752         local tdir=$2
10753
10754         mkdir -p $tdir ||
10755                 { error_noexit "unable to create $tdir"; return 1 ; }
10756         local file="/..$tdir/$tfile-1"
10757         $SETSTRIPE -p $pool $file ||
10758                 { error_noexit "unable to create $file" ; return 2 ; }
10759
10760         cd $tdir
10761         $SETSTRIPE -p $pool $tfile-2 || {
10762                 error_noexit "unable to create $tfile-2 in $tdir"
10763                 return 3
10764         }
10765 }
10766
10767 pool_remove_first_target() {
10768         echo "Removing first target from a pool"
10769         local pool=$1
10770
10771         local pname="lov.$FSNAME-*.pools.$pool"
10772         local t=$($LCTL get_param -n $pname | head -n1)
10773         do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10774         wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
10775                 error_noexit "$t not removed from $FSNAME.$pool"
10776                 return 1
10777         }
10778 }
10779
10780 pool_remove_all_targets() {
10781         echo "Removing all targets from pool"
10782         local pool=$1
10783         local file=$2
10784         local pname="lov.$FSNAME-*.pools.$pool"
10785         for t in $($LCTL get_param -n $pname | sort -u)
10786         do
10787                 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10788         done
10789         wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
10790                 error_noexit "Pool $FSNAME.$pool cannot be drained"
10791                 return 1
10792         }
10793         # striping on an empty/nonexistant pool should fall back
10794         # to "pool of everything"
10795         touch $file || {
10796                 error_noexit "failed to use fallback striping for empty pool"
10797                 return 2
10798         }
10799         # setstripe on an empty pool should fail
10800         $SETSTRIPE -p $pool $file 2>/dev/null && {
10801                 error_noexit "expected failure when creating file" \
10802                                                         "with empty pool"
10803                 return 3
10804         }
10805         return 0
10806 }
10807
10808 pool_remove() {
10809         echo "Destroying pool"
10810         local pool=$1
10811         local file=$2
10812
10813         do_facet mgs $LCTL pool_destroy $FSNAME.$pool
10814
10815         sleep 2
10816         # striping on an empty/nonexistant pool should fall back 
10817         # to "pool of everything"
10818         touch $file || {
10819                 error_noexit "failed to use fallback striping for missing pool"
10820                 return 1
10821         }
10822         # setstripe on an empty pool should fail
10823         $SETSTRIPE -p $pool $file 2>/dev/null && {
10824                 error_noexit "expected failure when creating file" \
10825                                                         "with missing pool"
10826                 return 2
10827         }
10828
10829         # get param should return err once pool is gone
10830         if wait_update $HOSTNAME "lctl get_param -n \
10831                 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
10832         then
10833                 remove_pool_from_list $FSNAME.$pool
10834                 return 0
10835         fi
10836         error_noexit "Pool $FSNAME.$pool is not destroyed"
10837         return 3
10838 }
10839
10840 test_200() {
10841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10842         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
10843
10844         local POOL=${POOL:-cea1}
10845         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
10846         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
10847         # Pool OST targets
10848         local first_ost=0
10849         local last_ost=$(($OSTCOUNT - 1))
10850         local ost_step=2
10851         local ost_list=$(seq $first_ost $ost_step $last_ost)
10852         local ost_range="$first_ost $last_ost $ost_step"
10853         local test_path=$POOL_ROOT/$POOL_DIR_NAME
10854         local file_dir=$POOL_ROOT/file_tst
10855         local subdir=$test_path/subdir
10856
10857         local rc=0
10858         while : ; do
10859                 # former test_200a test_200b
10860                 pool_add $POOL                          || { rc=$? ; break; }
10861                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
10862                 # former test_200c test_200d
10863                 mkdir -p $test_path
10864                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
10865                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
10866                 mkdir -p $subdir
10867                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
10868                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
10869                                                         || { rc=$? ; break; }
10870                 # former test_200e test_200f
10871                 local files=$((OSTCOUNT*3))
10872                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
10873                                                         || { rc=$? ; break; }
10874                 pool_create_files $POOL $file_dir $files "$ost_list" \
10875                                                         || { rc=$? ; break; }
10876                 # former test_200g test_200h
10877                 pool_lfs_df $POOL                       || { rc=$? ; break; }
10878                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
10879
10880                 # former test_201a test_201b test_201c
10881                 pool_remove_first_target $POOL          || { rc=$? ; break; }
10882
10883                 local f=$test_path/$tfile
10884                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
10885                 pool_remove $POOL $f                    || { rc=$? ; break; }
10886                 break
10887         done
10888
10889         cleanup_pools
10890         return $rc
10891 }
10892 run_test 200 "OST pools"
10893
10894 # usage: default_attr <count | size | offset>
10895 default_attr() {
10896         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
10897 }
10898
10899 # usage: check_default_stripe_attr
10900 check_default_stripe_attr() {
10901         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
10902         case $1 in
10903         --stripe-count|--count)
10904                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
10905         --stripe-size|--size)
10906                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
10907         --stripe-index|--index)
10908                 EXPECTED=-1;;
10909         *)
10910                 error "unknown getstripe attr '$1'"
10911         esac
10912
10913         [ $ACTUAL != $EXPECTED ] &&
10914                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
10915 }
10916
10917 test_204a() {
10918         test_mkdir -p $DIR/$tdir
10919         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
10920
10921         check_default_stripe_attr --stripe-count
10922         check_default_stripe_attr --stripe-size
10923         check_default_stripe_attr --stripe-index
10924
10925         return 0
10926 }
10927 run_test 204a "Print default stripe attributes ================="
10928
10929 test_204b() {
10930         test_mkdir -p $DIR/$tdir
10931         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10932
10933         check_default_stripe_attr --stripe-size
10934         check_default_stripe_attr --stripe-index
10935
10936         return 0
10937 }
10938 run_test 204b "Print default stripe size and offset  ==========="
10939
10940 test_204c() {
10941         test_mkdir -p $DIR/$tdir
10942         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10943
10944         check_default_stripe_attr --stripe-count
10945         check_default_stripe_attr --stripe-index
10946
10947         return 0
10948 }
10949 run_test 204c "Print default stripe count and offset ==========="
10950
10951 test_204d() {
10952         test_mkdir -p $DIR/$tdir
10953         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10954
10955         check_default_stripe_attr --stripe-count
10956         check_default_stripe_attr --stripe-size
10957
10958         return 0
10959 }
10960 run_test 204d "Print default stripe count and size ============="
10961
10962 test_204e() {
10963         test_mkdir -p $DIR/$tdir
10964         $SETSTRIPE -d $DIR/$tdir
10965
10966         check_default_stripe_attr --stripe-count --raw
10967         check_default_stripe_attr --stripe-size --raw
10968         check_default_stripe_attr --stripe-index --raw
10969
10970         return 0
10971 }
10972 run_test 204e "Print raw stripe attributes ================="
10973
10974 test_204f() {
10975         test_mkdir -p $DIR/$tdir
10976         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10977
10978         check_default_stripe_attr --stripe-size --raw
10979         check_default_stripe_attr --stripe-index --raw
10980
10981         return 0
10982 }
10983 run_test 204f "Print raw stripe size and offset  ==========="
10984
10985 test_204g() {
10986         test_mkdir -p $DIR/$tdir
10987         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10988
10989         check_default_stripe_attr --stripe-count --raw
10990         check_default_stripe_attr --stripe-index --raw
10991
10992         return 0
10993 }
10994 run_test 204g "Print raw stripe count and offset ==========="
10995
10996 test_204h() {
10997         test_mkdir -p $DIR/$tdir
10998         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10999
11000         check_default_stripe_attr --stripe-count --raw
11001         check_default_stripe_attr --stripe-size --raw
11002
11003         return 0
11004 }
11005 run_test 204h "Print raw stripe count and size ============="
11006
11007 # Figure out which job scheduler is being used, if any,
11008 # or use a fake one
11009 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11010         JOBENV=SLURM_JOB_ID
11011 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11012         JOBENV=LSB_JOBID
11013 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11014         JOBENV=PBS_JOBID
11015 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11016         JOBENV=LOADL_STEP_ID
11017 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11018         JOBENV=JOB_ID
11019 else
11020         JOBENV=FAKE_JOBID
11021 fi
11022
11023 verify_jobstats() {
11024         local cmd=$1
11025         local target=$2
11026
11027         # clear old jobstats
11028         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11029         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11030
11031         # use a new JobID for this test, or we might see an old one
11032         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11033
11034         JOBVAL=${!JOBENV}
11035         log "Test: $cmd"
11036         log "Using JobID environment variable $JOBENV=$JOBVAL"
11037
11038         if [ $JOBENV = "FAKE_JOBID" ]; then
11039                 FAKE_JOBID=$JOBVAL $cmd
11040         else
11041                 $cmd
11042         fi
11043
11044         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11045                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11046                 do_facet $FACET lctl get_param mdt.*.job_stats |
11047                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11048         fi
11049         if [ "$target" = "ost" -o "$target" = "both" ]; then
11050                 FACET=ost1
11051                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11052                         grep $JOBVAL || error "No job stats found on OST $FACET"
11053         fi
11054 }
11055
11056 jobstats_set() {
11057         trap 0
11058         NEW_JOBENV=${1:-$OLD_JOBENV}
11059         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11060         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11061 }
11062
11063 test_205() { # Job stats
11064         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11065         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11066                 skip "Server doesn't support jobstats" && return 0
11067         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11068
11069         local cmd
11070         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11071         if [ $OLD_JOBENV != $JOBENV ]; then
11072                 jobstats_set $JOBENV
11073                 trap jobstats_set EXIT
11074         fi
11075
11076         # mkdir
11077         cmd="mkdir $DIR/$tfile"
11078         verify_jobstats "$cmd" "mdt"
11079         # rmdir
11080         cmd="rm -fr $DIR/$tfile"
11081         verify_jobstats "$cmd" "mdt"
11082         # mknod
11083         cmd="mknod $DIR/$tfile c 1 3"
11084         verify_jobstats "$cmd" "mdt"
11085         # unlink
11086         cmd="rm -f $DIR/$tfile"
11087         verify_jobstats "$cmd" "mdt"
11088         # open & close
11089         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11090         verify_jobstats "$cmd" "mdt"
11091         # setattr
11092         cmd="touch $DIR/$tfile"
11093         verify_jobstats "$cmd" "both"
11094         # write
11095         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11096         verify_jobstats "$cmd" "ost"
11097         # read
11098         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11099         verify_jobstats "$cmd" "ost"
11100         # truncate
11101         cmd="$TRUNCATE $DIR/$tfile 0"
11102         verify_jobstats "$cmd" "both"
11103         # rename
11104         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11105         verify_jobstats "$cmd" "mdt"
11106
11107         # cleanup
11108         rm -f $DIR/jobstats_test_rename
11109
11110         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11111 }
11112 run_test 205 "Verify job stats"
11113
11114 # LU-1480, LU-1773 and LU-1657
11115 test_206() {
11116         mkdir -p $DIR/$tdir
11117         $SETSTRIPE -c -1 $DIR/$tdir
11118 #define OBD_FAIL_LOV_INIT 0x1403
11119         $LCTL set_param fail_loc=0xa0001403
11120         $LCTL set_param fail_val=1
11121         touch $DIR/$tdir/$tfile || true
11122 }
11123 run_test 206 "fail lov_init_raid0() doesn't lbug"
11124
11125 test_207a() {
11126         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11127         local fsz=`stat -c %s $DIR/$tfile`
11128         cancel_lru_locks mdc
11129
11130         # do not return layout in getattr intent
11131 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11132         $LCTL set_param fail_loc=0x170
11133         local sz=`stat -c %s $DIR/$tfile`
11134
11135         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11136
11137         rm -rf $DIR/$tfile
11138 }
11139 run_test 207a "can refresh layout at glimpse"
11140
11141 test_207b() {
11142         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11143         local cksum=`md5sum $DIR/$tfile`
11144         local fsz=`stat -c %s $DIR/$tfile`
11145         cancel_lru_locks mdc
11146         cancel_lru_locks osc
11147
11148         # do not return layout in getattr intent
11149 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11150         $LCTL set_param fail_loc=0x171
11151
11152         # it will refresh layout after the file is opened but before read issues
11153         echo checksum is "$cksum"
11154         echo "$cksum" |md5sum -c --quiet || error "file differs"
11155
11156         rm -rf $DIR/$tfile
11157 }
11158 run_test 207b "can refresh layout at open"
11159
11160 test_208() {
11161         # FIXME: in this test suite, only RD lease is used. This is okay
11162         # for now as only exclusive open is supported. After generic lease
11163         # is done, this test suite should be revised. - Jinshan
11164
11165         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11166                 { skip "Need MDS version at least 2.4.52"; return 0; }
11167
11168         echo "==== test 1: verify get lease work"
11169         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11170
11171         echo "==== test 2: verify lease can be broken by upcoming open"
11172         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11173         local PID=$!
11174         sleep 1
11175
11176         $MULTIOP $DIR/$tfile oO_RDONLY:c
11177         kill -USR1 $PID && wait $PID || error "break lease error"
11178
11179         echo "==== test 3: verify lease can't be granted if an open already exists"
11180         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11181         local PID=$!
11182         sleep 1
11183
11184         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11185         kill -USR1 $PID && wait $PID || error "open file error"
11186
11187         echo "==== test 4: lease can sustain over recovery"
11188         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11189         PID=$!
11190         sleep 1
11191
11192         fail mds1
11193
11194         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11195
11196         echo "==== test 5: lease broken can't be regained by replay"
11197         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11198         PID=$!
11199         sleep 1
11200
11201         # open file to break lease and then recovery
11202         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11203         fail mds1
11204
11205         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11206
11207         rm -f $DIR/$tfile
11208 }
11209 run_test 208 "Exclusive open"
11210
11211 test_209() {
11212         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11213                 skip_env "must have disp_stripe" && return
11214
11215         touch $DIR/$tfile
11216         sync; sleep 5; sync;
11217
11218         echo 3 > /proc/sys/vm/drop_caches
11219         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11220
11221         # open/close 500 times
11222         for i in $(seq 500); do
11223                 cat $DIR/$tfile
11224         done
11225
11226         echo 3 > /proc/sys/vm/drop_caches
11227         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11228
11229         echo "before: $req_before, after: $req_after"
11230         [ $((req_after - req_before)) -ge 300 ] &&
11231                 error "open/close requests are not freed"
11232         return 0
11233 }
11234 run_test 209 "read-only open/close requests should be freed promptly"
11235
11236 test_212() {
11237         size=`date +%s`
11238         size=$((size % 8192 + 1))
11239         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11240         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11241         rm -f $DIR/f212 $DIR/f212.xyz
11242 }
11243 run_test 212 "Sendfile test ============================================"
11244
11245 test_213() {
11246         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11247         cancel_lru_locks osc
11248         lctl set_param fail_loc=0x8000040f
11249         # generate a read lock
11250         cat $DIR/$tfile > /dev/null
11251         # write to the file, it will try to cancel the above read lock.
11252         cat /etc/hosts >> $DIR/$tfile
11253 }
11254 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11255
11256 test_214() { # for bug 20133
11257         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11258         for (( i=0; i < 340; i++ )) ; do
11259                 touch $DIR/$tdir/d214c/a$i
11260         done
11261
11262         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11263         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11264         ls $DIR/d214c || error "ls $DIR/d214c failed"
11265         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11266         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11267 }
11268 run_test 214 "hash-indexed directory test - bug 20133"
11269
11270 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11271 create_lnet_proc_files() {
11272         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
11273         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11274
11275         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11276         rm -f "$TMP/lnet_$1.sys_tmp"
11277 }
11278
11279 # counterpart of create_lnet_proc_files
11280 remove_lnet_proc_files() {
11281         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11282 }
11283
11284 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11285 # 3rd arg as regexp for body
11286 check_lnet_proc_stats() {
11287         local l=$(cat "$TMP/lnet_$1" |wc -l)
11288         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11289
11290         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11291 }
11292
11293 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11294 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11295 # optional and can be regexp for 2nd line (lnet.routes case)
11296 check_lnet_proc_entry() {
11297         local blp=2          # blp stands for 'position of 1st line of body'
11298         [ -z "$5" ] || blp=3 # lnet.routes case
11299
11300         local l=$(cat "$TMP/lnet_$1" |wc -l)
11301         # subtracting one from $blp because the body can be empty
11302         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11303
11304         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11305                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11306
11307         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11308                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11309
11310         # bail out if any unexpected line happened
11311         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11312         [ "$?" != 0 ] || error "$2 misformatted"
11313 }
11314
11315 test_215() { # for bugs 18102, 21079, 21517
11316         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11317         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11318         local P='[1-9][0-9]*'           # positive numeric
11319         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11320         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11321         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11322         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11323
11324         local L1 # regexp for 1st line
11325         local L2 # regexp for 2nd line (optional)
11326         local BR # regexp for the rest (body)
11327
11328         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
11329         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11330         create_lnet_proc_files "stats"
11331         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
11332         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11333         remove_lnet_proc_files "stats"
11334
11335         # /proc/sys/lnet/routes should look like this:
11336         # Routing disabled/enabled
11337         # net hops priority state router
11338         # where net is a string like tcp0, hops > 0, priority >= 0,
11339         # state is up/down,
11340         # router is a string like 192.168.1.1@tcp2
11341         L1="^Routing (disabled|enabled)$"
11342         L2="^net +hops +priority +state +router$"
11343         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11344         create_lnet_proc_files "routes"
11345         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
11346         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11347         remove_lnet_proc_files "routes"
11348
11349         # /proc/sys/lnet/routers should look like this:
11350         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11351         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11352         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11353         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11354         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11355         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11356         create_lnet_proc_files "routers"
11357         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
11358         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11359         remove_lnet_proc_files "routers"
11360
11361         # /proc/sys/lnet/peers should look like this:
11362         # nid refs state last max rtr min tx min queue
11363         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11364         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11365         # numeric (0 or >0 or <0), queue >= 0.
11366         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11367         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11368         create_lnet_proc_files "peers"
11369         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
11370         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11371         remove_lnet_proc_files "peers"
11372
11373         # /proc/sys/lnet/buffers  should look like this:
11374         # pages count credits min
11375         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11376         L1="^pages +count +credits +min$"
11377         BR="^ +$N +$N +$I +$I$"
11378         create_lnet_proc_files "buffers"
11379         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
11380         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11381         remove_lnet_proc_files "buffers"
11382
11383         # /proc/sys/lnet/nis should look like this:
11384         # nid status alive refs peer rtr max tx min
11385         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11386         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11387         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11388         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11389         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11390         create_lnet_proc_files "nis"
11391         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
11392         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11393         remove_lnet_proc_files "nis"
11394
11395         # can we successfully write to /proc/sys/lnet/stats?
11396         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
11397         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11398 }
11399 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
11400
11401 test_216() { # bug 20317
11402         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11403         remote_ost_nodsh && skip "remote OST with nodsh" && return
11404
11405         local node
11406         local facets=$(get_facets OST)
11407         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11408
11409         save_lustre_params client "osc.*.contention_seconds" > $p
11410         save_lustre_params $facets \
11411                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11412         save_lustre_params $facets \
11413                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11414         save_lustre_params $facets \
11415                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11416         clear_osc_stats
11417
11418         # agressive lockless i/o settings
11419         for node in $(osts_nodes); do
11420                 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'
11421         done
11422         lctl set_param -n osc.*.contention_seconds 60
11423
11424         $DIRECTIO write $DIR/$tfile 0 10 4096
11425         $CHECKSTAT -s 40960 $DIR/$tfile
11426
11427         # disable lockless i/o
11428         for node in $(osts_nodes); do
11429                 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'
11430         done
11431         lctl set_param -n osc.*.contention_seconds 0
11432         clear_osc_stats
11433
11434         dd if=/dev/zero of=$DIR/$tfile count=0
11435         $CHECKSTAT -s 0 $DIR/$tfile
11436
11437         restore_lustre_params <$p
11438         rm -f $p
11439         rm $DIR/$tfile
11440 }
11441 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11442
11443 test_217() { # bug 22430
11444         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11445         local node
11446         local nid
11447
11448         for node in $(nodes_list); do
11449                 nid=$(host_nids_address $node $NETTYPE)
11450                 if [[ $nid = *-* ]] ; then
11451                         echo "lctl ping $nid@$NETTYPE"
11452                         lctl ping $nid@$NETTYPE
11453                 else
11454                         echo "skipping $node (no hyphen detected)"
11455                 fi
11456         done
11457 }
11458 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11459
11460 test_218() {
11461        # do directio so as not to populate the page cache
11462        log "creating a 10 Mb file"
11463        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11464        log "starting reads"
11465        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11466        log "truncating the file"
11467        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11468        log "killing dd"
11469        kill %+ || true # reads might have finished
11470        echo "wait until dd is finished"
11471        wait
11472        log "removing the temporary file"
11473        rm -rf $DIR/$tfile || error "tmp file removal failed"
11474 }
11475 run_test 218 "parallel read and truncate should not deadlock ======================="
11476
11477 test_219() {
11478         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11479         # write one partial page
11480         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11481         # set no grant so vvp_io_commit_write will do sync write
11482         $LCTL set_param fail_loc=0x411
11483         # write a full page at the end of file
11484         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11485
11486         $LCTL set_param fail_loc=0
11487         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11488         $LCTL set_param fail_loc=0x411
11489         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11490 }
11491 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11492
11493 test_220() { #LU-325
11494         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11495         remote_ost_nodsh && skip "remote OST with nodsh" && return
11496         local OSTIDX=0
11497
11498         test_mkdir -p $DIR/$tdir
11499         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11500                 awk '{print $2}' | sed -e 's/_UUID$//')
11501
11502         # on the mdt's osc
11503         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11504         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11505                         osc.$mdtosc_proc1.prealloc_last_id)
11506         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11507                         osc.$mdtosc_proc1.prealloc_next_id)
11508
11509         $LFS df -i
11510
11511         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11512         #define OBD_FAIL_OST_ENOINO              0x229
11513         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11514         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11515         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11516
11517         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11518
11519         MDSOBJS=$((last_id - next_id))
11520         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11521
11522         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11523         echo "OST still has $count kbytes free"
11524
11525         echo "create $MDSOBJS files @next_id..."
11526         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11527
11528         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11529                         osc.$mdtosc_proc1.prealloc_last_id)
11530         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11531                         osc.$mdtosc_proc1.prealloc_next_id)
11532
11533         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11534         $LFS df -i
11535
11536         echo "cleanup..."
11537
11538         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11539         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11540
11541         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11542         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11543         echo "unlink $MDSOBJS files @$next_id..."
11544         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11545 }
11546 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11547
11548 test_221() {
11549         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11550         dd if=`which date` of=$MOUNT/date oflag=sync
11551         chmod +x $MOUNT/date
11552
11553         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11554         $LCTL set_param fail_loc=0x80001401
11555
11556         $MOUNT/date > /dev/null
11557         rm -f $MOUNT/date
11558 }
11559 run_test 221 "make sure fault and truncate race to not cause OOM"
11560
11561 test_222a () {
11562         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11563        rm -rf $DIR/$tdir
11564        test_mkdir -p $DIR/$tdir
11565        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11566        createmany -o $DIR/$tdir/$tfile 10
11567        cancel_lru_locks mdc
11568        cancel_lru_locks osc
11569        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11570        $LCTL set_param fail_loc=0x31a
11571        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11572        $LCTL set_param fail_loc=0
11573        rm -r $DIR/$tdir
11574 }
11575 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11576
11577 test_222b () {
11578         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11579        rm -rf $DIR/$tdir
11580        test_mkdir -p $DIR/$tdir
11581        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11582        createmany -o $DIR/$tdir/$tfile 10
11583        cancel_lru_locks mdc
11584        cancel_lru_locks osc
11585        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11586        $LCTL set_param fail_loc=0x31a
11587        rm -r $DIR/$tdir || "AGL for rmdir failed"
11588        $LCTL set_param fail_loc=0
11589 }
11590 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11591
11592 test_223 () {
11593         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11594        rm -rf $DIR/$tdir
11595        test_mkdir -p $DIR/$tdir
11596        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11597        createmany -o $DIR/$tdir/$tfile 10
11598        cancel_lru_locks mdc
11599        cancel_lru_locks osc
11600        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11601        $LCTL set_param fail_loc=0x31b
11602        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11603        $LCTL set_param fail_loc=0
11604        rm -r $DIR/$tdir
11605 }
11606 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11607
11608 test_224a() { # LU-1039, MRP-303
11609         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11610         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11611         $LCTL set_param fail_loc=0x508
11612         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11613         $LCTL set_param fail_loc=0
11614         df $DIR
11615 }
11616 run_test 224a "Don't panic on bulk IO failure"
11617
11618 test_224b() { # LU-1039, MRP-303
11619         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11620         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11621         cancel_lru_locks osc
11622         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11623         $LCTL set_param fail_loc=0x515
11624         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11625         $LCTL set_param fail_loc=0
11626         df $DIR
11627 }
11628 run_test 224b "Don't panic on bulk IO failure"
11629
11630 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11631 test_225a () {
11632         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11633         if [ -z ${MDSSURVEY} ]; then
11634               skip_env "mds-survey not found" && return
11635         fi
11636
11637         [ $MDSCOUNT -ge 2 ] &&
11638                 skip "skipping now for more than one MDT" && return
11639
11640        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11641             { skip "Need MDS version at least 2.2.51"; return; }
11642
11643        local mds=$(facet_host $SINGLEMDS)
11644        local target=$(do_nodes $mds 'lctl dl' | \
11645                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11646
11647        local cmd1="file_count=1000 thrhi=4"
11648        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11649        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11650        local cmd="$cmd1 $cmd2 $cmd3"
11651
11652        rm -f ${TMP}/mds_survey*
11653        echo + $cmd
11654        eval $cmd || error "mds-survey with zero-stripe failed"
11655        cat ${TMP}/mds_survey*
11656        rm -f ${TMP}/mds_survey*
11657 }
11658 run_test 225a "Metadata survey sanity with zero-stripe"
11659
11660 test_225b () {
11661         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11662
11663         if [ -z ${MDSSURVEY} ]; then
11664               skip_env "mds-survey not found" && return
11665         fi
11666         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11667             { skip "Need MDS version at least 2.2.51"; return; }
11668
11669         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11670               skip_env "Need to mount OST to test" && return
11671         fi
11672
11673         [ $MDSCOUNT -ge 2 ] &&
11674                 skip "skipping now for more than one MDT" && return
11675        local mds=$(facet_host $SINGLEMDS)
11676        local target=$(do_nodes $mds 'lctl dl' | \
11677                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11678
11679        local cmd1="file_count=1000 thrhi=4"
11680        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11681        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11682        local cmd="$cmd1 $cmd2 $cmd3"
11683
11684        rm -f ${TMP}/mds_survey*
11685        echo + $cmd
11686        eval $cmd || error "mds-survey with stripe_count failed"
11687        cat ${TMP}/mds_survey*
11688        rm -f ${TMP}/mds_survey*
11689 }
11690 run_test 225b "Metadata survey sanity with stripe_count = 1"
11691
11692 mcreate_path2fid () {
11693         local mode=$1
11694         local major=$2
11695         local minor=$3
11696         local name=$4
11697         local desc=$5
11698         local path=$DIR/$tdir/$name
11699         local fid
11700         local rc
11701         local fid_path
11702
11703         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11704                 error "cannot create $desc"
11705
11706         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11707         rc=$?
11708         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11709
11710         fid_path=$($LFS fid2path $MOUNT $fid)
11711         rc=$?
11712         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11713
11714         [ "$path" == "$fid_path" ] ||
11715                 error "fid2path returned $fid_path, expected $path"
11716
11717         echo "pass with $path and $fid"
11718 }
11719
11720 test_226a () {
11721         rm -rf $DIR/$tdir
11722         mkdir -p $DIR/$tdir
11723
11724         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11725         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11726         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11727         mcreate_path2fid 0040666 0 0 dir "directory"
11728         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11729         mcreate_path2fid 0100666 0 0 file "regular file"
11730         mcreate_path2fid 0120666 0 0 link "symbolic link"
11731         mcreate_path2fid 0140666 0 0 sock "socket"
11732 }
11733 run_test 226a "call path2fid and fid2path on files of all type"
11734
11735 test_226b () {
11736         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11737         rm -rf $DIR/$tdir
11738         local MDTIDX=1
11739
11740         mkdir -p $DIR/$tdir
11741         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
11742                 error "create remote directory failed"
11743         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
11744         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
11745                                 "character special file (null)"
11746         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
11747                                 "character special file (no device)"
11748         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
11749         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
11750                                 "block special file (loop)"
11751         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
11752         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
11753         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
11754 }
11755 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
11756
11757 # LU-1299 Executing or running ldd on a truncated executable does not
11758 # cause an out-of-memory condition.
11759 test_227() {
11760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11761         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
11762         dd if=$(which date) of=$MOUNT/date bs=1k count=1
11763         chmod +x $MOUNT/date
11764
11765         $MOUNT/date > /dev/null
11766         ldd $MOUNT/date > /dev/null
11767         rm -f $MOUNT/date
11768 }
11769 run_test 227 "running truncated executable does not cause OOM"
11770
11771 # LU-1512 try to reuse idle OI blocks
11772 test_228a() {
11773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11774         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11775                 skip "non-ldiskfs backend" && return
11776
11777         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11778         local myDIR=$DIR/$tdir
11779
11780         mkdir -p $myDIR
11781         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11782         $LCTL set_param fail_loc=0x80001002
11783         createmany -o $myDIR/t- 10000
11784         $LCTL set_param fail_loc=0
11785         # The guard is current the largest FID holder
11786         touch $myDIR/guard
11787         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11788                     tr -d '[')
11789         local IDX=$(($SEQ % 64))
11790
11791         do_facet $SINGLEMDS sync
11792         # Make sure journal flushed.
11793         sleep 6
11794         local blk1=$(do_facet $SINGLEMDS \
11795                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11796                      grep Blockcount | awk '{print $4}')
11797
11798         # Remove old files, some OI blocks will become idle.
11799         unlinkmany $myDIR/t- 10000
11800         # Create new files, idle OI blocks should be reused.
11801         createmany -o $myDIR/t- 2000
11802         do_facet $SINGLEMDS sync
11803         # Make sure journal flushed.
11804         sleep 6
11805         local blk2=$(do_facet $SINGLEMDS \
11806                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11807                      grep Blockcount | awk '{print $4}')
11808
11809         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11810 }
11811 run_test 228a "try to reuse idle OI blocks"
11812
11813 test_228b() {
11814         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11815         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11816                 skip "non-ldiskfs backend" && return
11817
11818         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11819         local myDIR=$DIR/$tdir
11820
11821         mkdir -p $myDIR
11822         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11823         $LCTL set_param fail_loc=0x80001002
11824         createmany -o $myDIR/t- 10000
11825         $LCTL set_param fail_loc=0
11826         # The guard is current the largest FID holder
11827         touch $myDIR/guard
11828         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11829                     tr -d '[')
11830         local IDX=$(($SEQ % 64))
11831
11832         do_facet $SINGLEMDS sync
11833         # Make sure journal flushed.
11834         sleep 6
11835         local blk1=$(do_facet $SINGLEMDS \
11836                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11837                      grep Blockcount | awk '{print $4}')
11838
11839         # Remove old files, some OI blocks will become idle.
11840         unlinkmany $myDIR/t- 10000
11841
11842         # stop the MDT
11843         stop $SINGLEMDS || error "Fail to stop MDT."
11844         # remount the MDT
11845         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11846
11847         df $MOUNT || error "Fail to df."
11848         # Create new files, idle OI blocks should be reused.
11849         createmany -o $myDIR/t- 2000
11850         do_facet $SINGLEMDS sync
11851         # Make sure journal flushed.
11852         sleep 6
11853         local blk2=$(do_facet $SINGLEMDS \
11854                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11855                      grep Blockcount | awk '{print $4}')
11856
11857         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11858 }
11859 run_test 228b "idle OI blocks can be reused after MDT restart"
11860
11861 #LU-1881
11862 test_228c() {
11863         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11864         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11865                 skip "non-ldiskfs backend" && return
11866
11867         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11868         local myDIR=$DIR/$tdir
11869
11870         mkdir -p $myDIR
11871         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11872         $LCTL set_param fail_loc=0x80001002
11873         # 20000 files can guarantee there are index nodes in the OI file
11874         createmany -o $myDIR/t- 20000
11875         $LCTL set_param fail_loc=0
11876         # The guard is current the largest FID holder
11877         touch $myDIR/guard
11878         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11879                     tr -d '[')
11880         local IDX=$(($SEQ % 64))
11881
11882         do_facet $SINGLEMDS sync
11883         # Make sure journal flushed.
11884         sleep 6
11885         local blk1=$(do_facet $SINGLEMDS \
11886                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11887                      grep Blockcount | awk '{print $4}')
11888
11889         # Remove old files, some OI blocks will become idle.
11890         unlinkmany $myDIR/t- 20000
11891         rm -f $myDIR/guard
11892         # The OI file should become empty now
11893
11894         # Create new files, idle OI blocks should be reused.
11895         createmany -o $myDIR/t- 2000
11896         do_facet $SINGLEMDS sync
11897         # Make sure journal flushed.
11898         sleep 6
11899         local blk2=$(do_facet $SINGLEMDS \
11900                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11901                      grep Blockcount | awk '{print $4}')
11902
11903         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11904 }
11905 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
11906
11907 test_229() { # LU-2482, LU-3448
11908         local server_version=$(get_lustre_version $SINGLEMDS)
11909         [[ $(version_code $server_version) -lt $(version_code 2.4.53) ]] &&
11910                 skip "No HSM support on $server_version MDS," \
11911                         "need 2.4.53 at least" && return
11912         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11913         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
11914
11915         rm -f $DIR/$tfile
11916
11917         # Create a file with a released layout and stripe count 2.
11918         $MULTIOP $DIR/$tfile H2c ||
11919                 error "failed to create file with released layout"
11920
11921         $GETSTRIPE -v $DIR/$tfile
11922
11923         local pattern=$($GETSTRIPE -L $DIR/$tfile)
11924         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
11925
11926         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
11927         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
11928         stat $DIR/$tfile || error "failed to stat released file"
11929
11930         chown $RUNAS_ID $DIR/$tfile ||
11931                 error "chown $RUNAS_ID $DIR/$tfile failed"
11932
11933         chgrp $RUNAS_ID $DIR/$tfile ||
11934                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
11935
11936         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
11937         rm $DIR/$tfile || error "failed to remove released file"
11938 }
11939 run_test 229 "getstripe/stat/rm/attr changes work on released files"
11940
11941 test_230a() {
11942         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11943         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11944         local MDTIDX=1
11945
11946         mkdir -p $DIR/$tdir/test_230_local
11947         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
11948         [ $mdt_idx -ne 0 ] &&
11949                 error "create local directory on wrong MDT $mdt_idx"
11950
11951         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
11952                         error "create remote directory failed"
11953         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
11954         [ $mdt_idx -ne $MDTIDX ] &&
11955                 error "create remote directory on wrong MDT $mdt_idx"
11956
11957         createmany -o $DIR/$tdir/test_230/t- 10 ||
11958                 error "create files on remote directory failed"
11959         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
11960         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
11961         rm -r $DIR/$tdir || error "unlink remote directory failed"
11962 }
11963 run_test 230a "Create remote directory and files under the remote directory"
11964
11965 test_230b() {
11966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11967         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11968         local MDTIDX=1
11969         local remote_dir=$DIR/$tdir/remote_dir
11970         local rc=0
11971
11972         mkdir -p $DIR/$tdir
11973         $LFS mkdir -i $MDTIDX $remote_dir ||
11974                 error "create remote directory failed"
11975
11976         $LFS mkdir -i 0 $remote_dir/new_dir &&
11977                 error "nested remote directory create succeed!"
11978
11979         do_facet mds$((MDTIDX + 1)) lctl set_param mdt.*.enable_remote_dir=1
11980         $LFS mkdir -i 0 $remote_dir/new_dir || rc=$?
11981         do_facet mds$((MDTIDX + 1)) lctl set_param mdt.*.enable_remote_dir=0
11982
11983         [ $rc -ne 0 ] &&
11984            error "create remote directory failed after set enable_remote_dir"
11985
11986         rm -rf $remote_dir || error "first unlink remote directory failed"
11987
11988         $RUNAS -G$RUNAS_GID $LFS mkdir -i $MDTIDX $DIR/$tfile &&
11989                                                         error "chown worked"
11990
11991         do_facet mds$MDTIDX lctl set_param \
11992                                 mdt.*.enable_remote_dir_gid=$RUNAS_GID
11993         $LFS mkdir -i $MDTIDX $remote_dir || rc=$?
11994         do_facet mds$MDTIDX lctl set_param mdt.*.enable_remote_dir_gid=0
11995
11996         [ $rc -ne 0 ] &&
11997            error "create remote dir failed after set enable_remote_dir_gid"
11998
11999         rm -r $DIR/$tdir || error "second unlink remote directory failed"
12000 }
12001 run_test 230b "nested remote directory should be failed"
12002
12003 test_231a()
12004 {
12005         # For simplicity this test assumes that max_pages_per_rpc
12006         # is the same across all OSCs
12007         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12008         local bulk_size=$((max_pages * 4096))
12009
12010         mkdir -p $DIR/$tdir
12011
12012         # clear the OSC stats
12013         $LCTL set_param osc.*.stats=0 &>/dev/null
12014
12015         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12016         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12017                 oflag=direct &>/dev/null || error "dd failed"
12018
12019         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12020         if [ x$nrpcs != "x1" ]; then
12021                 error "found $nrpc ost_write RPCs, not 1 as expected"
12022         fi
12023
12024         # Drop the OSC cache, otherwise we will read from it
12025         cancel_lru_locks osc
12026
12027         # clear the OSC stats
12028         $LCTL set_param osc.*.stats=0 &>/dev/null
12029
12030         # Client reads $bulk_size.
12031         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12032                 iflag=direct &>/dev/null || error "dd failed"
12033
12034         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12035         if [ x$nrpcs != "x1" ]; then
12036                 error "found $nrpc ost_read RPCs, not 1 as expected"
12037         fi
12038 }
12039 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12040
12041 test_231b() {
12042         mkdir -p $DIR/$tdir
12043         local i
12044         for i in {0..1023}; do
12045                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12046                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12047                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12048         done
12049         sync
12050 }
12051 run_test 231b "must not assert on fully utilized OST request buffer"
12052
12053 test_232() {
12054         mkdir -p $DIR/$tdir
12055         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12056         $LCTL set_param fail_loc=0x31c
12057
12058         # ignore dd failure
12059         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12060
12061         $LCTL set_param fail_loc=0
12062         umount_client $MOUNT || error "umount failed"
12063         mount_client $MOUNT || error "mount failed"
12064 }
12065 run_test 232 "failed lock should not block umount"
12066
12067 test_233a() {
12068         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12069         { skip "Need MDS version at least 2.3.64"; return; }
12070
12071         local fid=$($LFS path2fid $MOUNT)
12072         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12073                 error "cannot access $MOUNT using its FID '$fid'"
12074 }
12075 run_test 233a "checking that OBF of the FS root succeeds"
12076
12077 test_233b() {
12078         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12079         { skip "Need MDS version at least 2.5.90"; return; }
12080
12081         local fid=$($LFS path2fid $MOUNT/.lustre)
12082         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12083                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12084
12085         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12086         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12087                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12088 }
12089 run_test 233b "checking that OBF of the FS .lustre succeeds"
12090
12091 test_234() {
12092         local p="$TMP/sanityN-$TESTNAME.parameters"
12093         save_lustre_params client "llite.*.xattr_cache" > $p
12094         lctl set_param llite.*.xattr_cache 1 ||
12095                 { skip "xattr cache is not supported"; return 0; }
12096
12097         mkdir -p $DIR/$tdir || error "mkdir failed"
12098         touch $DIR/$tdir/$tfile || error "touch failed"
12099         # OBD_FAIL_LLITE_XATTR_ENOMEM
12100         $LCTL set_param fail_loc=0x1405
12101         if [ ! -f /etc/SuSE-release ]; then
12102                 # attr pre-2.4.44-7 had a bug with rc
12103                 # LU-3703 - SLES clients have older attr
12104                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12105                         error "getfattr should have failed with ENOMEM"
12106         fi
12107         $LCTL set_param fail_loc=0x0
12108         rm -rf $DIR/$tdir
12109
12110         restore_lustre_params < $p
12111         rm -f $p
12112 }
12113 run_test 234 "xattr cache should not crash on ENOMEM"
12114
12115 test_235() {
12116         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12117                 skip "Need MDS version at least 2.4.52" && return
12118         flock_deadlock $DIR/$tfile
12119         local RC=$?
12120         case $RC in
12121                 0)
12122                 ;;
12123                 124) error "process hangs on a deadlock"
12124                 ;;
12125                 *) error "error executing flock_deadlock $DIR/$tfile"
12126                 ;;
12127         esac
12128 }
12129 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12130
12131 #LU-2935
12132 test_236() {
12133         check_swap_layouts_support && return 0
12134         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
12135
12136         local ref1=/etc/passwd
12137         local ref2=/etc/group
12138         local file1=$DIR/$tdir/f1
12139         local file2=$DIR/$tdir/f2
12140
12141         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12142         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12143         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12144         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12145         local fd=$(free_fd)
12146         local cmd="exec $fd<>$file2"
12147         eval $cmd
12148         rm $file2
12149         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12150                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12151         cmd="exec $fd>&-"
12152         eval $cmd
12153         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12154
12155         #cleanup
12156         rm -rf $DIR/$tdir
12157 }
12158 run_test 236 "Layout swap on open unlinked file"
12159
12160 # LU-4659 linkea consistency
12161 test_238() {
12162         local server_version=$(lustre_version_code $SINGLEMDS)
12163
12164         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12165                 [[ $server_version -gt $(version_code 2.5.1) &&
12166                    $server_version -lt $(version_code 2.5.50) ]] ||
12167                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
12168
12169         touch $DIR/$tfile
12170         ln $DIR/$tfile $DIR/$tfile.lnk
12171         touch $DIR/$tfile.new
12172         mv $DIR/$tfile.new $DIR/$tfile
12173         local fid1=$(lfs path2fid $DIR/$tfile)
12174         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12175         local path1=$(lfs fid2path $FSNAME $fid1)
12176         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12177         local path2=$(lfs fid2path $FSNAME $fid2)
12178         [ $tfile.lnk == $path2 ] ||
12179                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12180         rm -f $DIR/$tfile*
12181 }
12182 run_test 238 "Verify linkea consistency"
12183 #
12184 # tests that do cleanup/setup should be run at the end
12185 #
12186
12187 test_900() {
12188         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12189         local ls
12190         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
12191         $LCTL set_param fail_loc=0x903
12192         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
12193         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
12194                 echo "clear" > $ls
12195         done
12196         FAIL_ON_ERROR=true cleanup
12197         FAIL_ON_ERROR=true setup
12198 }
12199 run_test 900 "umount should not race with any mgc requeue thread"
12200
12201 complete $SECONDS
12202 check_and_cleanup_lustre
12203 if [ "$I_MOUNTED" != "yes" ]; then
12204         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
12205 fi
12206 exit_status