Whamcloud - gitweb
LU-5878 lfs: migrate file to its proper destination
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 8; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
12 ALWAYS_EXCEPT="                42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # with LOD/OSP landing
16 # bug number for skipped tests: LU-2036
17 ALWAYS_EXCEPT="                 76     $ALWAYS_EXCEPT"
18
19 SRCDIR=$(cd $(dirname $0); echo $PWD)
20 export PATH=$PATH:/sbin
21
22 TMP=${TMP:-/tmp}
23
24 CC=${CC:-cc}
25 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
26 CREATETEST=${CREATETEST:-createtest}
27 LFS=${LFS:-lfs}
28 LFIND=${LFIND:-"$LFS find"}
29 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
30 LCTL=${LCTL:-lctl}
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_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
56 . $LUSTRE/tests/test-framework.sh
57 init_test_env $@
58 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
59 init_logging
60
61 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 64b 68 71 77f 78 115 124b 230d"
62
63 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
64         # bug number for skipped test: LU-1593 LU-1957 LU-2805
65         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  34h     180     184c"
66         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b 51ba"
67 fi
68
69 FAIL_ON_ERROR=false
70
71 cleanup() {
72         echo -n "cln.."
73         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
74         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
75 }
76 setup() {
77         echo -n "mnt.."
78         load_modules
79         setupall || exit 10
80         echo "done"
81 }
82
83 check_kernel_version() {
84         WANT_VER=$1
85         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
86         case $GOT_VER in
87         patchless|patchless_client) return 0;;
88         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
89         esac
90         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
91         return 1
92 }
93
94 check_swap_layouts_support()
95 {
96         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
97                 { skip "Does not support layout lock."; return 0; }
98         return 1
99 }
100
101 if [ "$ONLY" == "cleanup" ]; then
102        sh llmountcleanup.sh
103        exit 0
104 fi
105
106 check_and_setup_lustre
107
108 DIR=${DIR:-$MOUNT}
109 assert_DIR
110
111 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
112         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
113 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
114 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
115 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
116 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
117 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
118 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
119
120 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
121 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
122 rm -rf $DIR/[Rdfs][0-9]*
123
124 # $RUNAS_ID may get set incorrectly somewhere else
125 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
126
127 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
128
129 build_test_filter
130
131 if [ "${ONLY}" = "MOUNT" ] ; then
132         echo "Lustre is up, please go on"
133         exit
134 fi
135
136 echo "preparing for tests involving mounts"
137 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
138 touch $EXT2_DEV
139 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
140 echo # add a newline after mke2fs.
141
142 umask 077
143
144 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
145 lctl set_param debug=-1 2> /dev/null || true
146 test_0a() {
147         touch $DIR/$tfile
148         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
149         rm $DIR/$tfile
150         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
151 }
152 run_test 0a "touch; rm ====================="
153
154 test_0b() {
155         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
156         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
157 }
158 run_test 0b "chmod 0755 $DIR ============================="
159
160 test_0c() {
161         $LCTL get_param mdc.*.import | grep "state: FULL" ||
162                 error "import not FULL"
163         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
164                 error "bad target"
165 }
166 run_test 0c "check import proc ============================="
167
168 test_1() {
169         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
170         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
171         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
172         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
173         rmdir $DIR/$tdir/d2
174         rmdir $DIR/$tdir
175         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
176 }
177 run_test 1 "mkdir; remkdir; rmdir =============================="
178
179 test_2() {
180         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
181         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
182         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
183         rm -r $DIR/$tdir
184         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
185 }
186 run_test 2 "mkdir; touch; rmdir; check file ===================="
187
188 test_3() {
189         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
190         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
191         touch $DIR/$tdir/$tfile
192         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
193         rm -r $DIR/$tdir
194         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
195 }
196 run_test 3 "mkdir; touch; rmdir; check dir ====================="
197
198 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
199 test_4() {
200         local MDTIDX=1
201
202         test_mkdir $DIR/$tdir ||
203                 error "Create remote directory failed"
204
205         touch $DIR/$tdir/$tfile ||
206                 error "Create file under remote directory failed"
207
208         rmdir $DIR/$tdir &&
209                 error "Expect error removing in-use dir $DIR/$tdir"
210
211         test -d $DIR/$tdir || error "Remote directory disappeared"
212
213         rm -rf $DIR/$tdir || error "remove remote dir error"
214 }
215 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
216
217 test_5() {
218         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
219         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
220         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
221         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
222         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
223 }
224 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
225
226 test_6a() {
227         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
228         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
229         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
230                 error "$tfile does not have perm 0666 or UID $UID"
231         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
232         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
233                 error "$tfile should be 0666 and owned by UID $UID"
234 }
235 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
236
237 test_6c() {
238         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
239         touch $DIR/$tfile
240         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
241         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
242                 error "$tfile should be owned by UID $RUNAS_ID"
243         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
244         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
245                 error "$tfile should be owned by UID $RUNAS_ID"
246 }
247 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
248
249 test_6e() {
250         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
251         touch $DIR/$tfile
252         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
253         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
254                 error "$tfile should be owned by GID $UID"
255         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
256         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
257                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
258 }
259 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
260
261 test_6g() {
262         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
263         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
264         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
265         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
266         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
267         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
268         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
269                 error "$tdir/d/subdir should be GID $RUNAS_GID"
270 }
271 run_test 6g "Is new dir in sgid dir inheriting group?"
272
273 test_6h() { # bug 7331
274         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
275         touch $DIR/$tfile || error "touch failed"
276         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
277         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
278                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
279         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
280                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
281 }
282 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
283
284 test_7a() {
285         test_mkdir $DIR/$tdir
286         $MCREATE $DIR/$tdir/$tfile
287         chmod 0666 $DIR/$tdir/$tfile
288         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
289                 error "$tdir/$tfile should be mode 0666"
290 }
291 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
292
293 test_7b() {
294         if [ ! -d $DIR/$tdir ]; then
295                 mkdir $DIR/$tdir
296         fi
297         $MCREATE $DIR/$tdir/$tfile
298         echo -n foo > $DIR/$tdir/$tfile
299         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
300         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
301 }
302 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
303
304 test_8() {
305         test_mkdir $DIR/$tdir
306         touch $DIR/$tdir/$tfile
307         chmod 0666 $DIR/$tdir/$tfile
308         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
309                 error "$tfile mode not 0666"
310 }
311 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
312
313 test_9() {
314         test_mkdir $DIR/$tdir
315         test_mkdir $DIR/$tdir/d2
316         test_mkdir $DIR/$tdir/d2/d3
317         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
318 }
319 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
320
321 test_10() {
322         test_mkdir $DIR/$tdir
323         test_mkdir $DIR/$tdir/d2
324         touch $DIR/$tdir/d2/$tfile
325         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
326                 error "$tdir/d2/$tfile not a file"
327 }
328 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
329
330 test_11() {
331         test_mkdir $DIR/$tdir
332         test_mkdir $DIR/$tdir/d2
333         chmod 0666 $DIR/$tdir/d2
334         chmod 0705 $DIR/$tdir/d2
335         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
336                 error "$tdir/d2 mode not 0705"
337 }
338 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
339
340 test_12() {
341         test_mkdir $DIR/$tdir
342         touch $DIR/$tdir/$tfile
343         chmod 0666 $DIR/$tdir/$tfile
344         chmod 0654 $DIR/$tdir/$tfile
345         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
346                 error "$tdir/d2 mode not 0654"
347 }
348 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
349
350 test_13() {
351         test_mkdir $DIR/$tdir
352         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
353         >  $DIR/$tdir/$tfile
354         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
355                 error "$tdir/$tfile size not 0 after truncate"
356 }
357 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
358
359 test_14() {
360         test_mkdir $DIR/$tdir
361         touch $DIR/$tdir/$tfile
362         rm $DIR/$tdir/$tfile
363         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
364 }
365 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
366
367 test_15() {
368         test_mkdir $DIR/$tdir
369         touch $DIR/$tdir/$tfile
370         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
371         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
372                 error "$tdir/${tfile_2} not a file after rename"
373 }
374 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
375
376 test_16() {
377         test_mkdir $DIR/$tdir
378         touch $DIR/$tdir/$tfile
379         rm -rf $DIR/$tdir/$tfile
380         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
381 }
382 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
383
384 test_17a() {
385         test_mkdir -p $DIR/$tdir
386         touch $DIR/$tdir/$tfile
387         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
388         ls -l $DIR/$tdir
389         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
390                 error "$tdir/l-exist not a symlink"
391         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
392                 error "$tdir/l-exist not referencing a file"
393         rm -f $DIR/$tdir/l-exist
394         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
395 }
396 run_test 17a "symlinks: create, remove (real) =================="
397
398 test_17b() {
399         test_mkdir -p $DIR/$tdir
400         ln -s no-such-file $DIR/$tdir/l-dangle
401         ls -l $DIR/$tdir
402         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
403                 error "$tdir/l-dangle not referencing no-such-file"
404         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
405                 error "$tdir/l-dangle not referencing non-existent file"
406         rm -f $DIR/$tdir/l-dangle
407         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
408 }
409 run_test 17b "symlinks: create, remove (dangling) =============="
410
411 test_17c() { # bug 3440 - don't save failed open RPC for replay
412         test_mkdir -p $DIR/$tdir
413         ln -s foo $DIR/$tdir/$tfile
414         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
415 }
416 run_test 17c "symlinks: open dangling (should return error) ===="
417
418 test_17d() {
419         test_mkdir -p $DIR/$tdir
420         ln -s foo $DIR/$tdir/$tfile
421         touch $DIR/$tdir/$tfile || error "creating to new symlink"
422 }
423 run_test 17d "symlinks: create dangling ========================"
424
425 test_17e() {
426         test_mkdir -p $DIR/$tdir
427         local foo=$DIR/$tdir/$tfile
428         ln -s $foo $foo || error "create symlink failed"
429         ls -l $foo || error "ls -l failed"
430         ls $foo && error "ls not failed" || true
431 }
432 run_test 17e "symlinks: create recursive symlink (should return error) ===="
433
434 test_17f() {
435         test_mkdir -p $DIR/$tdir
436         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
437         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
438         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
439         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
440         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
441         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
442         ls -l  $DIR/$tdir
443 }
444 run_test 17f "symlinks: long and very long symlink name ========================"
445
446 # str_repeat(S, N) generate a string that is string S repeated N times
447 str_repeat() {
448         local s=$1
449         local n=$2
450         local ret=''
451         while [ $((n -= 1)) -ge 0 ]; do
452                 ret=$ret$s
453         done
454         echo $ret
455 }
456
457 # Long symlinks and LU-2241
458 test_17g() {
459         test_mkdir -p $DIR/$tdir
460         local TESTS="59 60 61 4094 4095"
461
462         # Fix for inode size boundary in 2.1.4
463         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
464                 TESTS="4094 4095"
465
466         # Patch not applied to 2.2 or 2.3 branches
467         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
468         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
469                 TESTS="4094 4095"
470
471         # skip long symlink name for rhel6.5.
472         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
473         grep -q '6.5' /etc/redhat-release &>/dev/null &&
474                 TESTS="59 60 61 4062 4063"
475
476         for i in $TESTS; do
477                 local SYMNAME=$(str_repeat 'x' $i)
478                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
479                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
480         done
481 }
482 run_test 17g "symlinks: really long symlink name and inode boundaries"
483
484 test_17h() { #bug 17378
485         remote_mds_nodsh && skip "remote MDS with nodsh" && return
486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
487         local mdt_idx
488         test_mkdir -p $DIR/$tdir
489         if [[ $MDSCOUNT -gt 1 ]]; then
490                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
491         else
492                 mdt_idx=0
493         fi
494         $SETSTRIPE -c -1 $DIR/$tdir
495 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
496         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
497         touch $DIR/$tdir/$tfile || true
498 }
499 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
500
501 test_17i() { #bug 20018
502         remote_mds_nodsh && skip "remote MDS with nodsh" && return
503         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
504         test_mkdir -c1 $DIR/$tdir
505         local foo=$DIR/$tdir/$tfile
506         local mdt_idx
507         if [[ $MDSCOUNT -gt 1 ]]; then
508                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
509         else
510                 mdt_idx=0
511         fi
512         ln -s $foo $foo || error "create symlink failed"
513 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
514         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
515         ls -l $foo && error "error not detected"
516         return 0
517 }
518 run_test 17i "don't panic on short symlink"
519
520 test_17k() { #bug 22301
521         [[ -z "$(which rsync 2>/dev/null)" ]] &&
522                 skip "no rsync command" && return 0
523         rsync --help | grep -q xattr ||
524                 skip_env "$(rsync --version | head -n1) does not support xattrs"
525         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
526         test_mkdir -p $DIR/$tdir
527         test_mkdir -p $DIR/$tdir.new
528         touch $DIR/$tdir/$tfile
529         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
530         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
531                 error "rsync failed with xattrs enabled"
532 }
533 run_test 17k "symlinks: rsync with xattrs enabled ========================="
534
535 test_17l() { # LU-279
536         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
537                 skip "no getfattr command" && return 0
538         mkdir -p $DIR/$tdir
539         touch $DIR/$tdir/$tfile
540         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
541         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
542                 # -h to not follow symlinks. -m '' to list all the xattrs.
543                 # grep to remove first line: '# file: $path'.
544                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
545                 do
546                         lgetxattr_size_check $path $xattr ||
547                                 error "lgetxattr_size_check $path $xattr failed"
548                 done
549         done
550 }
551 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
552
553 # LU-1540
554 test_17m() {
555         local short_sym="0123456789"
556         local WDIR=$DIR/${tdir}m
557         local mds_index
558         local devname
559         local cmd
560         local i
561         local rc=0
562
563         remote_mds_nodsh && skip "remote MDS with nodsh" && return
564         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
565         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
566                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
567
568         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
569                 skip "only for ldiskfs MDT" && return 0
570
571         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
572
573         mkdir -p $WDIR
574         long_sym=$short_sym
575         # create a long symlink file
576         for ((i = 0; i < 4; ++i)); do
577                 long_sym=${long_sym}${long_sym}
578         done
579
580         echo "create 512 short and long symlink files under $WDIR"
581         for ((i = 0; i < 256; ++i)); do
582                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
583                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
584         done
585
586         echo "erase them"
587         rm -f $WDIR/*
588         sync
589         wait_delete_completed
590
591         echo "recreate the 512 symlink files with a shorter string"
592         for ((i = 0; i < 512; ++i)); do
593                 # rewrite the symlink file with a shorter string
594                 ln -sf ${long_sym} $WDIR/long-$i
595                 ln -sf ${short_sym} $WDIR/short-$i
596         done
597
598         mds_index=$($LFS getstripe -M $WDIR)
599         mds_index=$((mds_index+1))
600         devname=$(mdsdevname $mds_index)
601         cmd="$E2FSCK -fnvd $devname"
602
603         echo "stop and checking mds${mds_index}: $cmd"
604         # e2fsck should not return error
605         stop mds${mds_index}
606         do_facet mds${mds_index} $cmd || rc=$?
607
608         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
609         df $MOUNT > /dev/null 2>&1
610         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
611                 "short/long symlink MDT: rc=$rc"
612         return $rc
613 }
614 run_test 17m "run e2fsck against MDT which contains short/long symlink"
615
616 check_fs_consistency_17n() {
617         local mdt_index
618         local devname
619         local cmd
620         local rc=0
621
622         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
623         # so it only check MDT1/MDT2 instead of all of MDTs.
624         for mdt_index in $(seq 1 2); do
625                 devname=$(mdsdevname $mdt_index)
626                 cmd="$E2FSCK -fnvd $devname"
627
628                 echo "stop and checking mds${mdt_index}: $cmd"
629                 # e2fsck should not return error
630                 stop mds${mdt_index}
631                 do_facet mds${mdt_index} $cmd || rc=$?
632
633                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
634                         error "mount mds${mdt_index} failed"
635                 df $MOUNT > /dev/null 2>&1
636                 [ $rc -ne 0 ] && break
637         done
638         return $rc
639 }
640
641 test_17n() {
642         local i
643
644         remote_mds_nodsh && skip "remote MDS with nodsh" && return
645         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
646         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
647                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
648
649         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
650                 skip "only for ldiskfs MDT" && return 0
651
652         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
653
654         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
655
656         mkdir $DIR/$tdir
657         for ((i=0; i<10; i++)); do
658                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
659                         error "create remote dir error $i"
660                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
661                         error "create files under remote dir failed $i"
662         done
663
664         check_fs_consistency_17n ||
665                 error "e2fsck report error after create files under remote dir"
666
667         for ((i=0;i<10;i++)); do
668                 rm -rf $DIR/$tdir/remote_dir_${i} ||
669                         error "destroy remote dir error $i"
670         done
671
672         check_fs_consistency_17n ||
673                 error "e2fsck report error after unlink files under remote dir"
674
675         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
676                 skip "lustre < 2.4.50 does not support migrate mv " && return
677
678         for ((i=0; i<10; i++)); do
679                 mkdir -p $DIR/$tdir/remote_dir_${i}
680                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
681                         error "create files under remote dir failed $i"
682                 $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} ||
683                         error "migrate remote dir error $i"
684         done
685         check_fs_consistency_17n || error "e2fsck report error after migration"
686
687         for ((i=0;i<10;i++)); do
688                 rm -rf $DIR/$tdir/remote_dir_${i} ||
689                         error "destroy remote dir error $i"
690         done
691
692         check_fs_consistency_17n || error "e2fsck report error after unlink"
693 }
694 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
695
696 test_17o() {
697         remote_mds_nodsh && skip "remote MDS with nodsh" && return
698         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
699                 skip "Need MDS version at least 2.3.64" && return
700
701         local WDIR=$DIR/${tdir}o
702         local mdt_index
703         local mdtdevname
704         local rc=0
705
706         mkdir -p $WDIR
707         mdt_index=$($LFS getstripe -M $WDIR)
708         mdt_index=$((mdt_index+1))
709         mdtdevname=$(mdsdevname $mdt_index)
710
711         touch $WDIR/$tfile
712         stop mds${mdt_index}
713         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS ||
714                 error "mount mds${mdt_index} failed"
715
716         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
717         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
718         ls -l $WDIR/$tfile && rc=1
719         do_facet mds${mdt_index} lctl set_param fail_loc=0
720         [[ $rc -ne 0 ]] && error "stat file should fail"
721         true
722 }
723 run_test 17o "stat file with incompat LMA feature"
724
725 test_18() {
726         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
727         ls $DIR || error "Failed to ls $DIR: $?"
728 }
729 run_test 18 "touch .../f ; ls ... =============================="
730
731 test_19a() {
732         touch $DIR/$tfile
733         ls -l $DIR
734         rm $DIR/$tfile
735         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
736 }
737 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
738
739 test_19b() {
740         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
741 }
742 run_test 19b "ls -l .../f19 (should return error) =============="
743
744 test_19c() {
745         [ $RUNAS_ID -eq $UID ] &&
746                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
747         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
748 }
749 run_test 19c "$RUNAS touch .../f19 (should return error) =="
750
751 test_19d() {
752         cat $DIR/f19 && error || true
753 }
754 run_test 19d "cat .../f19 (should return error) =============="
755
756 test_20() {
757         touch $DIR/$tfile
758         rm $DIR/$tfile
759         log "1 done"
760         touch $DIR/$tfile
761         rm $DIR/$tfile
762         log "2 done"
763         touch $DIR/$tfile
764         rm $DIR/$tfile
765         log "3 done"
766         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
767 }
768 run_test 20 "touch .../f ; ls -l ... ==========================="
769
770 test_21() {
771         test_mkdir -p $DIR/$tdir
772         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
773         ln -s dangle $DIR/$tdir/link
774         echo foo >> $DIR/$tdir/link
775         cat $DIR/$tdir/dangle
776         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
777         $CHECKSTAT -f -t file $DIR/$tdir/link ||
778                 error "$tdir/link not linked to a file"
779 }
780 run_test 21 "write to dangling link ============================"
781
782 test_22() {
783         WDIR=$DIR/$tdir
784         test_mkdir -p $DIR/$tdir
785         chown $RUNAS_ID:$RUNAS_GID $WDIR
786         (cd $WDIR || error "cd $WDIR failed";
787         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
788         $RUNAS tar xf -)
789         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
790         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
791         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
792 }
793 run_test 22 "unpack tar archive as non-root user ==============="
794
795 # was test_23
796 test_23a() {
797         test_mkdir -p $DIR/$tdir
798         local file=$DIR/$tdir/$tfile
799
800         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
801         openfile -f O_CREAT:O_EXCL $file &&
802                 error "$file recreate succeeded" || true
803 }
804 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
805
806 test_23b() { # bug 18988
807         test_mkdir -p $DIR/$tdir
808         local file=$DIR/$tdir/$tfile
809
810         rm -f $file
811         echo foo > $file || error "write filed"
812         echo bar >> $file || error "append filed"
813         $CHECKSTAT -s 8 $file || error "wrong size"
814         rm $file
815 }
816 run_test 23b "O_APPEND check =========================="
817
818 # rename sanity
819 test_24a() {
820         echo '-- same directory rename'
821         test_mkdir $DIR/$tdir
822         touch $DIR/$tdir/$tfile.1
823         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
824         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
825 }
826 run_test 24a "rename file to non-existent target"
827
828 test_24b() {
829         test_mkdir $DIR/$tdir
830         touch $DIR/$tdir/$tfile.{1,2}
831         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
832         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
833         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
834 }
835 run_test 24b "rename file to existing target"
836
837 test_24c() {
838         test_mkdir $DIR/$tdir
839         test_mkdir $DIR/$tdir/d$testnum.1
840         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
841         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
842         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
843 }
844 run_test 24c "rename directory to non-existent target"
845
846 test_24d() {
847         test_mkdir -c1 $DIR/$tdir
848         test_mkdir -c1 $DIR/$tdir/d$testnum.1
849         test_mkdir -c1 $DIR/$tdir/d$testnum.2
850         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
851         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
852         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
853 }
854 run_test 24d "rename directory to existing target"
855
856 test_24e() {
857         echo '-- cross directory renames --'
858         test_mkdir $DIR/R5a
859         test_mkdir $DIR/R5b
860         touch $DIR/R5a/f
861         mv $DIR/R5a/f $DIR/R5b/g
862         $CHECKSTAT -a $DIR/R5a/f || error
863         $CHECKSTAT -t file $DIR/R5b/g || error
864 }
865 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
866
867 test_24f() {
868         test_mkdir $DIR/R6a
869         test_mkdir $DIR/R6b
870         touch $DIR/R6a/f $DIR/R6b/g
871         mv $DIR/R6a/f $DIR/R6b/g
872         $CHECKSTAT -a $DIR/R6a/f || error
873         $CHECKSTAT -t file $DIR/R6b/g || error
874 }
875 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
876
877 test_24g() {
878         test_mkdir $DIR/R7a
879         test_mkdir $DIR/R7b
880         test_mkdir $DIR/R7a/d
881         mv $DIR/R7a/d $DIR/R7b/e
882         $CHECKSTAT -a $DIR/R7a/d || error
883         $CHECKSTAT -t dir $DIR/R7b/e || error
884 }
885 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
886
887 test_24h() {
888         test_mkdir -c1 $DIR/R8a
889         test_mkdir -c1 $DIR/R8b
890         test_mkdir -c1 $DIR/R8a/d
891         test_mkdir -c1 $DIR/R8b/e
892         mrename $DIR/R8a/d $DIR/R8b/e
893         $CHECKSTAT -a $DIR/R8a/d || error
894         $CHECKSTAT -t dir $DIR/R8b/e || error
895 }
896 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
897
898 test_24i() {
899         echo "-- rename error cases"
900         test_mkdir $DIR/R9
901         test_mkdir $DIR/R9/a
902         touch $DIR/R9/f
903         mrename $DIR/R9/f $DIR/R9/a
904         $CHECKSTAT -t file $DIR/R9/f || error
905         $CHECKSTAT -t dir  $DIR/R9/a || error
906         $CHECKSTAT -a $DIR/R9/a/f || error
907 }
908 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
909
910 test_24j() {
911         test_mkdir $DIR/R10
912         mrename $DIR/R10/f $DIR/R10/g
913         $CHECKSTAT -t dir $DIR/R10 || error
914         $CHECKSTAT -a $DIR/R10/f || error
915         $CHECKSTAT -a $DIR/R10/g || error
916 }
917 run_test 24j "source does not exist ============================"
918
919 test_24k() {
920         test_mkdir $DIR/R11a
921         test_mkdir $DIR/R11a/d
922         touch $DIR/R11a/f
923         mv $DIR/R11a/f $DIR/R11a/d
924         $CHECKSTAT -a $DIR/R11a/f || error
925         $CHECKSTAT -t file $DIR/R11a/d/f || error
926 }
927 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
928
929 # bug 2429 - rename foo foo foo creates invalid file
930 test_24l() {
931         f="$DIR/f24l"
932         $MULTIOP $f OcNs || error
933 }
934 run_test 24l "Renaming a file to itself ========================"
935
936 test_24m() {
937         f="$DIR/f24m"
938         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
939         # on ext3 this does not remove either the source or target files
940         # though the "expected" operation would be to remove the source
941         $CHECKSTAT -t file ${f} || error "${f} missing"
942         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
943 }
944 run_test 24m "Renaming a file to a hard link to itself ========="
945
946 test_24n() {
947     f="$DIR/f24n"
948     # this stats the old file after it was renamed, so it should fail
949     touch ${f}
950     $CHECKSTAT ${f}
951     mv ${f} ${f}.rename
952     $CHECKSTAT ${f}.rename
953     $CHECKSTAT -a ${f}
954 }
955 run_test 24n "Statting the old file after renaming (Posix rename 2)"
956
957 test_24o() {
958         check_kernel_version 37 || return 0
959         test_mkdir -p $DIR/d24o
960         rename_many -s random -v -n 10 $DIR/d24o
961 }
962 run_test 24o "rename of files during htree split ==============="
963
964 test_24p() {
965         test_mkdir $DIR/R12a
966         test_mkdir $DIR/R12b
967         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
968         mrename $DIR/R12a $DIR/R12b
969         $CHECKSTAT -a $DIR/R12a || error
970         $CHECKSTAT -t dir $DIR/R12b || error
971         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
972         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
973 }
974 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
975
976 cleanup_multiop_pause() {
977         trap 0
978         kill -USR1 $MULTIPID
979 }
980
981 test_24q() {
982         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
983         test_mkdir $DIR/R13a
984         test_mkdir $DIR/R13b
985         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
986         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
987         MULTIPID=$!
988
989         trap cleanup_multiop_pause EXIT
990         mrename $DIR/R13a $DIR/R13b
991         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
992         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
993         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
994         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
995         cleanup_multiop_pause
996         wait $MULTIPID || error "multiop close failed"
997 }
998 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
999
1000 test_24r() { #bug 3789
1001         test_mkdir $DIR/R14a
1002         test_mkdir $DIR/R14a/b
1003         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1004         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1005         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1006 }
1007 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1008
1009 test_24s() {
1010         test_mkdir $DIR/R15a
1011         test_mkdir $DIR/R15a/b
1012         test_mkdir $DIR/R15a/b/c
1013         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1014         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1015         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1016 }
1017 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1018 test_24t() {
1019         test_mkdir $DIR/R16a
1020         test_mkdir $DIR/R16a/b
1021         test_mkdir $DIR/R16a/b/c
1022         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1023         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1024         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1025 }
1026 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1027
1028 test_24u() { # bug12192
1029         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1030         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1031 }
1032 run_test 24u "create stripe file"
1033
1034 page_size() {
1035         getconf PAGE_SIZE
1036 }
1037
1038 simple_cleanup_common() {
1039         trap 0
1040         rm -rf $DIR/$tdir
1041         wait_delete_completed
1042 }
1043
1044 max_pages_per_rpc() {
1045         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1046 }
1047
1048 test_24v() {
1049         local NRFILES=100000
1050         local FREE_INODES=$(mdt_free_inodes 0)
1051         [[ $FREE_INODES -lt $NRFILES ]] &&
1052                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1053                 return
1054
1055         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1056         trap simple_cleanup_common EXIT
1057
1058         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1059         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1060
1061         mkdir -p $DIR/$tdir
1062         createmany -m $DIR/$tdir/$tfile $NRFILES
1063
1064         cancel_lru_locks mdc
1065         lctl set_param mdc.*.stats clear
1066
1067         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1068
1069         # LU-5 large readdir
1070         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1071         #               8 bytes for name(filename is mostly 5 in this test) +
1072         #               8 bytes for luda_type
1073         # take into account of overhead in lu_dirpage header and end mark in
1074         # each page, plus one in RPC_NUM calculation.
1075         DIRENT_SIZE=48
1076         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1077         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1078         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1079                                 awk '/^mds_readpage/ {print $2}')
1080         [[ $mds_readpage -gt $RPC_NUM ]] &&
1081                 error "large readdir doesn't take effect"
1082
1083         simple_cleanup_common
1084 }
1085 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1086
1087 test_24w() { # bug21506
1088         SZ1=234852
1089         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1090         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1091         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1092         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1093         [[ "$SZ1" -eq "$SZ2" ]] ||
1094                 error "Error reading at the end of the file $tfile"
1095 }
1096 run_test 24w "Reading a file larger than 4Gb"
1097
1098 test_24x() {
1099         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1100         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1101         local MDTIDX=1
1102         local remote_dir=$DIR/$tdir/remote_dir
1103
1104         mkdir -p $DIR/$tdir
1105         $LFS mkdir -i $MDTIDX $remote_dir ||
1106                 error "create remote directory failed"
1107
1108         mkdir -p $DIR/$tdir/src_dir
1109         touch $DIR/$tdir/src_file
1110         mkdir -p $remote_dir/tgt_dir
1111         touch $remote_dir/tgt_file
1112
1113         mrename $remote_dir $DIR/ &&
1114                 error "rename dir cross MDT works!"
1115
1116         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1117                 error "rename dir cross MDT works!"
1118
1119         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1120                 error "rename file cross MDT works!"
1121
1122         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1123                 error "ln file cross MDT should not work!"
1124
1125         rm -rf $DIR/$tdir || error "Can not delete directories"
1126 }
1127 run_test 24x "cross rename/link should be failed"
1128
1129 test_24y() {
1130         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1131         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1132         local MDTIDX=1
1133         local remote_dir=$DIR/$tdir/remote_dir
1134
1135         mkdir -p $DIR/$tdir
1136         $LFS mkdir -i $MDTIDX $remote_dir ||
1137                    error "create remote directory failed"
1138
1139         mkdir -p $remote_dir/src_dir
1140         touch $remote_dir/src_file
1141         mkdir -p $remote_dir/tgt_dir
1142         touch $remote_dir/tgt_file
1143
1144         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1145                 error "rename subdir in the same remote dir failed!"
1146
1147         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1148                 error "rename files in the same remote dir failed!"
1149
1150         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1151                 error "link files in the same remote dir failed!"
1152
1153         rm -rf $DIR/$tdir || error "Can not delete directories"
1154 }
1155 run_test 24y "rename/link on the same dir should succeed"
1156
1157 test_24z() {
1158         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1159         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1160         local MDTIDX=1
1161         local remote_src=$DIR/$tdir/remote_dir
1162         local remote_tgt=$DIR/$tdir/remote_tgt
1163
1164         mkdir -p $DIR/$tdir
1165         $LFS mkdir -i $MDTIDX $remote_src ||
1166                    error "create remote directory failed"
1167
1168         $LFS mkdir -i $MDTIDX $remote_tgt ||
1169                    error "create remote directory failed"
1170
1171         mrename $remote_src $remote_tgt &&
1172                 error "rename remote dirs should not work!"
1173
1174         # If target dir does not exists, it should succeed
1175         rm -rf $remote_tgt
1176         mrename $remote_src $remote_tgt ||
1177                 error "rename remote dirs(tgt dir does not exists) failed!"
1178
1179         rm -rf $DIR/$tdir || error "Can not delete directories"
1180 }
1181 run_test 24z "rename one remote dir to another remote dir should fail"
1182
1183 test_24A() { # LU-3182
1184         local NFILES=5000
1185
1186         rm -rf $DIR/$tdir
1187         mkdir -p $DIR/$tdir
1188         createmany -m $DIR/$tdir/$tfile $NFILES
1189         local t=$(ls $DIR/$tdir | wc -l)
1190         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1191         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1192         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1193                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1194         fi
1195
1196         rm -rf $DIR/$tdir || error "Can not delete directories"
1197 }
1198 run_test 24A "readdir() returns correct number of entries."
1199
1200 test_24B() { # LU-4805
1201         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1202         local count
1203
1204         mkdir $DIR/$tdir
1205         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1206                 error "create striped dir failed"
1207
1208         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1209         [ $count -eq 2 ] || error "Expected 2, got $count"
1210
1211         touch $DIR/$tdir/striped_dir/a
1212
1213         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1214         [ $count -eq 3 ] || error "Expected 3, got $count"
1215
1216         touch $DIR/$tdir/striped_dir/.f
1217
1218         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1219         [ $count -eq 4 ] || error "Expected 4, got $count"
1220
1221         rm -rf $DIR/$tdir || error "Can not delete directories"
1222 }
1223 run_test 24B "readdir for striped dir return correct number of entries"
1224
1225 test_24C() {
1226         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1227
1228         mkdir $DIR/$tdir
1229         mkdir $DIR/$tdir/d0
1230         mkdir $DIR/$tdir/d1
1231
1232         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1233                 error "create striped dir failed"
1234
1235         cd $DIR/$tdir/d0/striped_dir
1236
1237         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1238         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1239         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1240
1241         [ "$d0_ino" = "$parent_ino" ] ||
1242                 error ".. wrong, expect $d0_ino, get $parent_ino"
1243
1244         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1245                 error "mv striped dir failed"
1246
1247         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1248
1249         [ "$d1_ino" = "$parent_ino" ] ||
1250                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1251 }
1252 run_test 24C "check .. in striped dir"
1253
1254 test_25a() {
1255         echo '== symlink sanity ============================================='
1256
1257         test_mkdir $DIR/d25
1258         ln -s d25 $DIR/s25
1259         touch $DIR/s25/foo || error
1260 }
1261 run_test 25a "create file in symlinked directory ==============="
1262
1263 test_25b() {
1264         [ ! -d $DIR/d25 ] && test_25a
1265         $CHECKSTAT -t file $DIR/s25/foo || error
1266 }
1267 run_test 25b "lookup file in symlinked directory ==============="
1268
1269 test_26a() {
1270         test_mkdir $DIR/d26
1271         test_mkdir $DIR/d26/d26-2
1272         ln -s d26/d26-2 $DIR/s26
1273         touch $DIR/s26/foo || error
1274 }
1275 run_test 26a "multiple component symlink ======================="
1276
1277 test_26b() {
1278         test_mkdir -p $DIR/d26b/d26-2
1279         ln -s d26b/d26-2/foo $DIR/s26-2
1280         touch $DIR/s26-2 || error
1281 }
1282 run_test 26b "multiple component symlink at end of lookup ======"
1283
1284 test_26c() {
1285         test_mkdir $DIR/d26.2
1286         touch $DIR/d26.2/foo
1287         ln -s d26.2 $DIR/s26.2-1
1288         ln -s s26.2-1 $DIR/s26.2-2
1289         ln -s s26.2-2 $DIR/s26.2-3
1290         chmod 0666 $DIR/s26.2-3/foo
1291 }
1292 run_test 26c "chain of symlinks ================================"
1293
1294 # recursive symlinks (bug 439)
1295 test_26d() {
1296         ln -s d26-3/foo $DIR/d26-3
1297 }
1298 run_test 26d "create multiple component recursive symlink ======"
1299
1300 test_26e() {
1301         [ ! -h $DIR/d26-3 ] && test_26d
1302         rm $DIR/d26-3
1303 }
1304 run_test 26e "unlink multiple component recursive symlink ======"
1305
1306 # recursive symlinks (bug 7022)
1307 test_26f() {
1308         test_mkdir -p $DIR/$tdir
1309         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1310         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1311         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1312         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1313         cd $tfile                || error "cd $tfile failed"
1314         ln -s .. dotdot          || error "ln dotdot failed"
1315         ln -s dotdot/lndir lndir || error "ln lndir failed"
1316         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1317         output=`ls $tfile/$tfile/lndir/bar1`
1318         [ "$output" = bar1 ] && error "unexpected output"
1319         rm -r $tfile             || error "rm $tfile failed"
1320         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1321 }
1322 run_test 26f "rm -r of a directory which has recursive symlink ="
1323
1324 test_27a() {
1325         echo '== stripe sanity =============================================='
1326         test_mkdir -p $DIR/d27 || error "mkdir failed"
1327         $GETSTRIPE $DIR/d27
1328         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1329         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1330         log "== test_27a: write to one stripe file ========================="
1331         cp /etc/hosts $DIR/d27/f0 || error
1332 }
1333 run_test 27a "one stripe file =================================="
1334
1335 test_27b() {
1336         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1337         test_mkdir -p $DIR/d27
1338         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1339         $GETSTRIPE -c $DIR/d27/f01
1340         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1341                 error "two-stripe file doesn't have two stripes"
1342
1343         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1344 }
1345 run_test 27b "create and write to two stripe file"
1346
1347 test_27d() {
1348         test_mkdir -p $DIR/d27
1349         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1350         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1351         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1352 }
1353 run_test 27d "create file with default settings ================"
1354
1355 test_27e() {
1356         test_mkdir -p $DIR/d27
1357         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1358         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1359         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1360 }
1361 run_test 27e "setstripe existing file (should return error) ======"
1362
1363 test_27f() {
1364         test_mkdir $DIR/$tdir
1365         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1366                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1367         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1368                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1369         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1370         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1371 }
1372 run_test 27f "setstripe with bad stripe size (should return error)"
1373
1374 test_27g() {
1375         test_mkdir -p $DIR/d27
1376         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1377         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1378                 error "$DIR/d27/fnone has object"
1379 }
1380 run_test 27g "$GETSTRIPE with no objects"
1381
1382 test_27i() {
1383         touch $DIR/d27/fsome || error "touch failed"
1384         [[ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ]] || error "missing objects"
1385 }
1386 run_test 27i "$GETSTRIPE with some objects"
1387
1388 test_27j() {
1389         test_mkdir -p $DIR/d27
1390         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1391 }
1392 run_test 27j "setstripe with bad stripe offset (should return error)"
1393
1394 test_27k() { # bug 2844
1395         test_mkdir -p $DIR/d27
1396         FILE=$DIR/d27/f27k
1397         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1398         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1399         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1400         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1401         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1402         dd if=/dev/zero of=$FILE bs=4k count=1
1403         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1404         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1405 }
1406 run_test 27k "limit i_blksize for broken user apps ============="
1407
1408 test_27l() {
1409         test_mkdir -p $DIR/d27
1410         mcreate $DIR/f27l || error "creating file"
1411         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1412                 error "setstripe should have failed" || true
1413 }
1414 run_test 27l "check setstripe permissions (should return error)"
1415
1416 test_27m() {
1417         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1418                 return
1419         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1420                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1421                 return
1422         fi
1423         trap simple_cleanup_common EXIT
1424         test_mkdir -p $DIR/$tdir
1425         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1426         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1427                 error "dd should fill OST0"
1428         i=2
1429         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1430                 i=$((i + 1))
1431                 [ $i -gt 256 ] && break
1432         done
1433         i=$((i + 1))
1434         touch $DIR/$tdir/f27m_$i
1435         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1436                 error "OST0 was full but new created file still use it"
1437         i=$((i + 1))
1438         touch $DIR/$tdir/f27m_$i
1439         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1440                 error "OST0 was full but new created file still use it"
1441         simple_cleanup_common
1442 }
1443 run_test 27m "create file while OST0 was full =================="
1444
1445 sleep_maxage() {
1446         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1447         sleep $DELAY
1448 }
1449
1450 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1451 # if the OST isn't full anymore.
1452 reset_enospc() {
1453         local OSTIDX=${1:-""}
1454
1455         local list=$(comma_list $(osts_nodes))
1456         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1457
1458         do_nodes $list lctl set_param fail_loc=0
1459         sync    # initiate all OST_DESTROYs from MDS to OST
1460         sleep_maxage
1461 }
1462
1463 exhaust_precreations() {
1464         local OSTIDX=$1
1465         local FAILLOC=$2
1466         local FAILIDX=${3:-$OSTIDX}
1467
1468         test_mkdir -p $DIR/$tdir
1469         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1470         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1471
1472         local OST=$(ostname_from_index $OSTIDX)
1473         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1474                           sed -e 's/_UUID$//;s/^.*-//')
1475
1476         # on the mdt's osc
1477         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1478         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1479                         osc.$mdtosc_proc1.prealloc_last_id)
1480         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1481                         osc.$mdtosc_proc1.prealloc_next_id)
1482
1483         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1484         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1485
1486         test_mkdir -p $DIR/$tdir/${OST}
1487         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1488 #define OBD_FAIL_OST_ENOSPC              0x215
1489         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1490         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1491         echo "Creating to objid $last_id on ost $OST..."
1492         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1493         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1494         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1495         sleep_maxage
1496 }
1497
1498 exhaust_all_precreations() {
1499         local i
1500         for (( i=0; i < OSTCOUNT; i++ )) ; do
1501                 exhaust_precreations $i $1 -1
1502         done
1503 }
1504
1505 test_27n() {
1506         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1507         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1508         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1509         remote_ost_nodsh && skip "remote OST with nodsh" && return
1510
1511         reset_enospc
1512         rm -f $DIR/$tdir/$tfile
1513         exhaust_precreations 0 0x80000215
1514         $SETSTRIPE -c -1 $DIR/$tdir
1515         touch $DIR/$tdir/$tfile || error
1516         $GETSTRIPE $DIR/$tdir/$tfile
1517         reset_enospc
1518 }
1519 run_test 27n "create file with some full OSTs =================="
1520
1521 test_27o() {
1522         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1523         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1524         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1525         remote_ost_nodsh && skip "remote OST with nodsh" && return
1526
1527         reset_enospc
1528         rm -f $DIR/$tdir/$tfile
1529         exhaust_all_precreations 0x215
1530
1531         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1532
1533         reset_enospc
1534         rm -rf $DIR/$tdir/*
1535 }
1536 run_test 27o "create file with all full OSTs (should error) ===="
1537
1538 test_27p() {
1539         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1541         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1542         remote_ost_nodsh && skip "remote OST with nodsh" && return
1543
1544         reset_enospc
1545         rm -f $DIR/$tdir/$tfile
1546         test_mkdir -p $DIR/$tdir
1547
1548         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1549         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1550         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1551
1552         exhaust_precreations 0 0x80000215
1553         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1554         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1555         $GETSTRIPE $DIR/$tdir/$tfile
1556
1557         reset_enospc
1558 }
1559 run_test 27p "append to a truncated file with some full OSTs ==="
1560
1561 test_27q() {
1562         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1563         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1564         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1565         remote_ost_nodsh && skip "remote OST with nodsh" && return
1566
1567         reset_enospc
1568         rm -f $DIR/$tdir/$tfile
1569
1570         test_mkdir -p $DIR/$tdir
1571         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1572         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1573         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1574
1575         exhaust_all_precreations 0x215
1576
1577         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1578         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1579
1580         reset_enospc
1581 }
1582 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1583
1584 test_27r() {
1585         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1586         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1587         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1588         remote_ost_nodsh && skip "remote OST with nodsh" && return
1589
1590         reset_enospc
1591         rm -f $DIR/$tdir/$tfile
1592         exhaust_precreations 0 0x80000215
1593
1594         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1595
1596         reset_enospc
1597 }
1598 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1599
1600 test_27s() { # bug 10725
1601         test_mkdir -p $DIR/$tdir
1602         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1603         local stripe_count=0
1604         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1605         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1606                 error "stripe width >= 2^32 succeeded" || true
1607
1608 }
1609 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1610
1611 test_27t() { # bug 10864
1612         WDIR=$(pwd)
1613         WLFS=$(which lfs)
1614         cd $DIR
1615         touch $tfile
1616         $WLFS getstripe $tfile
1617         cd $WDIR
1618 }
1619 run_test 27t "check that utils parse path correctly"
1620
1621 test_27u() { # bug 4900
1622         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1623         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1624         local index
1625         local list=$(comma_list $(mdts_nodes))
1626
1627 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1628         do_nodes $list $LCTL set_param fail_loc=0x139
1629         test_mkdir -p $DIR/$tdir
1630         rm -rf $DIR/$tdir/*
1631         createmany -o $DIR/$tdir/t- 1000
1632         do_nodes $list $LCTL set_param fail_loc=0
1633
1634         TLOG=$DIR/$tfile.getstripe
1635         $GETSTRIPE $DIR/$tdir > $TLOG
1636         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1637         unlinkmany $DIR/$tdir/t- 1000
1638         [[ $OBJS -gt 0 ]] &&
1639                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1640 }
1641 run_test 27u "skip object creation on OSC w/o objects =========="
1642
1643 test_27v() { # bug 4900
1644         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1645         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1646         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1647         remote_ost_nodsh && skip "remote OST with nodsh" && return
1648
1649         exhaust_all_precreations 0x215
1650         reset_enospc
1651
1652         test_mkdir -p $DIR/$tdir
1653         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1654
1655         touch $DIR/$tdir/$tfile
1656         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1657         # all except ost1
1658         for (( i=1; i < OSTCOUNT; i++ )); do
1659                 do_facet ost$i lctl set_param fail_loc=0x705
1660         done
1661         local START=`date +%s`
1662         createmany -o $DIR/$tdir/$tfile 32
1663
1664         local FINISH=`date +%s`
1665         local TIMEOUT=`lctl get_param -n timeout`
1666         local PROCESS=$((FINISH - START))
1667         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1668                error "$FINISH - $START >= $TIMEOUT / 2"
1669         sleep $((TIMEOUT / 2 - PROCESS))
1670         reset_enospc
1671 }
1672 run_test 27v "skip object creation on slow OST ================="
1673
1674 test_27w() { # bug 10997
1675         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1676         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1677         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1678                 error "stripe size $size != 65536" || true
1679         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1680                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1681 }
1682 run_test 27w "check $SETSTRIPE -S option"
1683
1684 test_27wa() {
1685         [[ $OSTCOUNT -lt 2 ]] &&
1686                 skip_env "skipping multiple stripe count/offset test" && return
1687
1688         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1689         for i in $(seq 1 $OSTCOUNT); do
1690                 offset=$((i - 1))
1691                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1692                         error "setstripe -c $i -i $offset failed"
1693                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1694                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1695                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1696                 [ $index -ne $offset ] &&
1697                         error "stripe offset $index != $offset" || true
1698         done
1699 }
1700 run_test 27wa "check $SETSTRIPE -c -i options"
1701
1702 test_27x() {
1703         remote_ost_nodsh && skip "remote OST with nodsh" && return
1704         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1705         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1706         OFFSET=$(($OSTCOUNT - 1))
1707         OSTIDX=0
1708         local OST=$(ostname_from_index $OSTIDX)
1709
1710         test_mkdir -p $DIR/$tdir
1711         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1712         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1713         sleep_maxage
1714         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1715         for i in `seq 0 $OFFSET`; do
1716                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1717                 error "OST0 was degraded but new created file still use it"
1718         done
1719         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1720 }
1721 run_test 27x "create files while OST0 is degraded"
1722
1723 test_27y() {
1724         [[ $OSTCOUNT -lt 2 ]] &&
1725                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1726         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1727         remote_ost_nodsh && skip "remote OST with nodsh" && return
1728         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1729
1730         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1731         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1732             osc.$mdtosc.prealloc_last_id)
1733         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1734             osc.$mdtosc.prealloc_next_id)
1735         local fcount=$((last_id - next_id))
1736         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1737         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1738
1739         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1740                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1741         local OST_DEACTIVE_IDX=-1
1742         local OSC
1743         local OSTIDX
1744         local OST
1745
1746         for OSC in $MDS_OSCS; do
1747                 OST=$(osc_to_ost $OSC)
1748                 OSTIDX=$(index_from_ostuuid $OST)
1749                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1750                         OST_DEACTIVE_IDX=$OSTIDX
1751                 fi
1752                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1753                         echo $OSC "is Deactivated:"
1754                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1755                 fi
1756         done
1757
1758         OSTIDX=$(index_from_ostuuid $OST)
1759         mkdir -p $DIR/$tdir
1760         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1761
1762         for OSC in $MDS_OSCS; do
1763                 OST=$(osc_to_ost $OSC)
1764                 OSTIDX=$(index_from_ostuuid $OST)
1765                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1766                         echo $OST "is degraded:"
1767                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1768                                                 obdfilter.$OST.degraded=1
1769                 fi
1770         done
1771
1772         sleep_maxage
1773         createmany -o $DIR/$tdir/$tfile $fcount
1774
1775         for OSC in $MDS_OSCS; do
1776                 OST=$(osc_to_ost $OSC)
1777                 OSTIDX=$(index_from_ostuuid $OST)
1778                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1779                         echo $OST "is recovered from degraded:"
1780                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1781                                                 obdfilter.$OST.degraded=0
1782                 else
1783                         do_facet $SINGLEMDS lctl --device %$OSC activate
1784                 fi
1785         done
1786
1787         # all osp devices get activated, hence -1 stripe count restored
1788         local stripecnt=0
1789
1790         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1791         # devices get activated.
1792         sleep_maxage
1793         $SETSTRIPE -c -1 $DIR/$tfile
1794         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1795         rm -f $DIR/$tfile
1796         [ $stripecnt -ne $OSTCOUNT ] &&
1797                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1798         return 0
1799 }
1800 run_test 27y "create files while OST0 is degraded and the rest inactive"
1801
1802 check_seq_oid()
1803 {
1804         log "check file $1"
1805
1806         lmm_count=$($GETSTRIPE -c $1)
1807         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1808         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1809
1810         local old_ifs="$IFS"
1811         IFS=$'[:]'
1812         fid=($($LFS path2fid $1))
1813         IFS="$old_ifs"
1814
1815         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1816         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1817
1818         # compare lmm_seq and lu_fid->f_seq
1819         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1820         # compare lmm_object_id and lu_fid->oid
1821         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1822
1823         # check the trusted.fid attribute of the OST objects of the file
1824         local have_obdidx=false
1825         local stripe_nr=0
1826         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1827                 # skip lines up to and including "obdidx"
1828                 [ -z "$obdidx" ] && break
1829                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1830                 $have_obdidx || continue
1831
1832                 local ost=$((obdidx + 1))
1833                 local dev=$(ostdevname $ost)
1834                 local oid_hex
1835
1836                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1837
1838                 seq=$(echo $seq | sed -e "s/^0x//g")
1839                 if [ $seq == 0 ]; then
1840                         oid_hex=$(echo $oid)
1841                 else
1842                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1843                 fi
1844                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1845
1846                 local ff
1847                 #
1848                 # Don't unmount/remount the OSTs if we don't need to do that.
1849                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1850                 # update too, until that use mount/ll_decode_filter_fid/mount.
1851                 # Re-enable when debugfs will understand new filter_fid.
1852                 #
1853                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1854                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1855                                 $dev 2>/dev/null" | grep "parent=")
1856                 else
1857                         stop ost$ost
1858                         mount_fstype ost$ost
1859                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1860                                 $(facet_mntpt ost$ost)/$obj_file)
1861                         unmount_fstype ost$ost
1862                         start ost$ost $dev $OST_MOUNT_OPTS
1863                 fi
1864
1865                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1866
1867                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1868
1869                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1870                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1871                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1872                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1873                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1874                 local ff_pstripe
1875                 if echo $ff_parent | grep -q 'stripe='; then
1876                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1877                 else
1878                         #
1879                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1880                         # into f_ver in this case.  See the comment on
1881                         # ff_parent.
1882                         #
1883                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1884                                 sed -e 's/\]//')
1885                 fi
1886
1887                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1888                 [ $ff_pseq = $lmm_seq ] ||
1889                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1890                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1891                 [ $ff_poid = $lmm_oid ] ||
1892                         error "FF parent OID $ff_poid != $lmm_oid"
1893                 (($ff_pstripe == $stripe_nr)) ||
1894                         error "FF stripe $ff_pstripe != $stripe_nr"
1895
1896                 stripe_nr=$((stripe_nr + 1))
1897         done
1898 }
1899
1900 test_27z() {
1901         remote_ost_nodsh && skip "remote OST with nodsh" && return
1902         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1903         test_mkdir -p $DIR/$tdir
1904
1905         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1906                 { error "setstripe -c -1 failed"; return 1; }
1907         # We need to send a write to every object to get parent FID info set.
1908         # This _should_ also work for setattr, but does not currently.
1909         # touch $DIR/$tdir/$tfile-1 ||
1910         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1911                 { error "dd $tfile-1 failed"; return 2; }
1912         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1913                 { error "setstripe -c -1 failed"; return 3; }
1914         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1915                 { error "dd $tfile-2 failed"; return 4; }
1916
1917         # make sure write RPCs have been sent to OSTs
1918         sync; sleep 5; sync
1919
1920         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1921         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1922 }
1923 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1924
1925 test_27A() { # b=19102
1926         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1927         local restore_size=$($GETSTRIPE -S $MOUNT)
1928         local restore_count=$($GETSTRIPE -c $MOUNT)
1929         local restore_offset=$($GETSTRIPE -i $MOUNT)
1930         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1931         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1932                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1933         local default_size=$($GETSTRIPE -S $MOUNT)
1934         local default_offset=$($GETSTRIPE -i $MOUNT)
1935         local dsize=$((1024 * 1024))
1936         [ $default_size -eq $dsize ] ||
1937                 error "stripe size $default_size != $dsize"
1938         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1939         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1940 }
1941 run_test 27A "check filesystem-wide default LOV EA values"
1942
1943 test_27B() { # LU-2523
1944         test_mkdir -p $DIR/$tdir
1945         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1946         touch $DIR/$tdir/f0
1947         # open f1 with O_LOV_DELAY_CREATE
1948         # rename f0 onto f1
1949         # call setstripe ioctl on open file descriptor for f1
1950         # close
1951         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1952                 $DIR/$tdir/f0
1953
1954         rm -f $DIR/$tdir/f1
1955         # open f1 with O_LOV_DELAY_CREATE
1956         # unlink f1
1957         # call setstripe ioctl on open file descriptor for f1
1958         # close
1959         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1960
1961         # Allow multiop to fail in imitation of NFS's busted semantics.
1962         true
1963 }
1964 run_test 27B "call setstripe on open unlinked file/rename victim"
1965
1966 test_27C() { #LU-2871
1967         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1968
1969         declare -a ost_idx
1970         local index
1971         local found
1972         local i
1973         local j
1974
1975         test_mkdir -p $DIR/$tdir
1976         cd $DIR/$tdir
1977         for i in $(seq 0 $((OSTCOUNT - 1))); do
1978                 # set stripe across all OSTs starting from OST$i
1979                 $SETSTRIPE -i $i -c -1 $tfile$i
1980                 # get striping information
1981                 ost_idx=($($GETSTRIPE $tfile$i |
1982                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1983                 echo ${ost_idx[@]}
1984
1985                 # check the layout
1986                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1987                         error "${#ost_idx[@]} != $OSTCOUNT"
1988
1989                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1990                         found=0
1991                         for j in $(echo ${ost_idx[@]}); do
1992                                 if [ $index -eq $j ]; then
1993                                         found=1
1994                                         break
1995                                 fi
1996                         done
1997                         [ $found = 1 ] ||
1998                                 error "Can not find $index in ${ost_idx[@]}"
1999                 done
2000         done
2001 }
2002 run_test 27C "check full striping across all OSTs"
2003
2004 test_27D() {
2005         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2006         local POOL=${POOL:-testpool}
2007         local first_ost=0
2008         local last_ost=$(($OSTCOUNT - 1))
2009         local ost_step=1
2010         local ost_list=$(seq $first_ost $ost_step $last_ost)
2011         local ost_range="$first_ost $last_ost $ost_step"
2012
2013         mkdir -p $DIR/$tdir
2014         pool_add $POOL || error "pool_add failed"
2015         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2016         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2017                 error "llapi_layout_test failed"
2018         cleanup_pools || error "cleanup_pools failed"
2019 }
2020 run_test 27D "validate llapi_layout API"
2021
2022 # createtest also checks that device nodes are created and
2023 # then visible correctly (#2091)
2024 test_28() { # bug 2091
2025         test_mkdir $DIR/d28
2026         $CREATETEST $DIR/d28/ct || error
2027 }
2028 run_test 28 "create/mknod/mkdir with bad file types ============"
2029
2030 test_29() {
2031         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2032         cancel_lru_locks mdc
2033         test_mkdir $DIR/d29
2034         touch $DIR/d29/foo
2035         log 'first d29'
2036         ls -l $DIR/d29
2037
2038         declare -i LOCKCOUNTORIG=0
2039         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2040                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2041         done
2042         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2043
2044         declare -i LOCKUNUSEDCOUNTORIG=0
2045         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2046                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2047         done
2048
2049         log 'second d29'
2050         ls -l $DIR/d29
2051         log 'done'
2052
2053         declare -i LOCKCOUNTCURRENT=0
2054         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2055                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2056         done
2057
2058         declare -i LOCKUNUSEDCOUNTCURRENT=0
2059         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2060                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2061         done
2062
2063         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2064                 $LCTL set_param -n ldlm.dump_namespaces ""
2065                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2066                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2067                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2068                 return 2
2069         fi
2070         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2071                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2072                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2073                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2074                 return 3
2075         fi
2076 }
2077 run_test 29 "IT_GETATTR regression  ============================"
2078
2079 test_30a() { # was test_30
2080         cp $(which ls) $DIR || cp /bin/ls $DIR
2081         $DIR/ls / || error
2082         rm $DIR/ls
2083 }
2084 run_test 30a "execute binary from Lustre (execve) =============="
2085
2086 test_30b() {
2087         cp `which ls` $DIR || cp /bin/ls $DIR
2088         chmod go+rx $DIR/ls
2089         $RUNAS $DIR/ls / || error
2090         rm $DIR/ls
2091 }
2092 run_test 30b "execute binary from Lustre as non-root ==========="
2093
2094 test_30c() { # b=22376
2095         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2096         cp `which ls` $DIR || cp /bin/ls $DIR
2097         chmod a-rw $DIR/ls
2098         cancel_lru_locks mdc
2099         cancel_lru_locks osc
2100         $RUNAS $DIR/ls / || error
2101         rm -f $DIR/ls
2102 }
2103 run_test 30c "execute binary from Lustre without read perms ===="
2104
2105 test_31a() {
2106         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2107         $CHECKSTAT -a $DIR/f31 || error
2108 }
2109 run_test 31a "open-unlink file =================================="
2110
2111 test_31b() {
2112         touch $DIR/f31 || error
2113         ln $DIR/f31 $DIR/f31b || error
2114         $MULTIOP $DIR/f31b Ouc || error
2115         $CHECKSTAT -t file $DIR/f31 || error
2116 }
2117 run_test 31b "unlink file with multiple links while open ======="
2118
2119 test_31c() {
2120         touch $DIR/f31 || error
2121         ln $DIR/f31 $DIR/f31c || error
2122         multiop_bg_pause $DIR/f31 O_uc || return 1
2123         MULTIPID=$!
2124         $MULTIOP $DIR/f31c Ouc
2125         kill -USR1 $MULTIPID
2126         wait $MULTIPID
2127 }
2128 run_test 31c "open-unlink file with multiple links ============="
2129
2130 test_31d() {
2131         opendirunlink $DIR/d31d $DIR/d31d || error
2132         $CHECKSTAT -a $DIR/d31d || error
2133 }
2134 run_test 31d "remove of open directory ========================="
2135
2136 test_31e() { # bug 2904
2137         check_kernel_version 34 || return 0
2138         openfilleddirunlink $DIR/d31e || error
2139 }
2140 run_test 31e "remove of open non-empty directory ==============="
2141
2142 test_31f() { # bug 4554
2143         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2144         set -vx
2145         test_mkdir $DIR/d31f
2146         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2147         cp /etc/hosts $DIR/d31f
2148         ls -l $DIR/d31f
2149         $GETSTRIPE $DIR/d31f/hosts
2150         multiop_bg_pause $DIR/d31f D_c || return 1
2151         MULTIPID=$!
2152
2153         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2154         test_mkdir $DIR/d31f
2155         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2156         cp /etc/hosts $DIR/d31f
2157         ls -l $DIR/d31f
2158         $GETSTRIPE $DIR/d31f/hosts
2159         multiop_bg_pause $DIR/d31f D_c || return 1
2160         MULTIPID2=$!
2161
2162         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2163         wait $MULTIPID || error "first opendir $MULTIPID failed"
2164
2165         sleep 6
2166
2167         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2168         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2169         set +vx
2170 }
2171 run_test 31f "remove of open directory with open-unlink file ==="
2172
2173 test_31g() {
2174         echo "-- cross directory link --"
2175         test_mkdir -c1 $DIR/${tdir}ga
2176         test_mkdir -c1 $DIR/${tdir}gb
2177         touch $DIR/${tdir}ga/f
2178         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2179         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2180         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2181         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2182         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2183 }
2184 run_test 31g "cross directory link==============="
2185
2186 test_31h() {
2187         echo "-- cross directory link --"
2188         test_mkdir -c1 $DIR/${tdir}
2189         test_mkdir -c1 $DIR/${tdir}/dir
2190         touch $DIR/${tdir}/f
2191         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2192         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2193         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2194         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2195         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2196 }
2197 run_test 31h "cross directory link under child==============="
2198
2199 test_31i() {
2200         echo "-- cross directory link --"
2201         test_mkdir -c1 $DIR/$tdir
2202         test_mkdir -c1 $DIR/$tdir/dir
2203         touch $DIR/$tdir/dir/f
2204         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2205         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2206         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2207         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2208         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2209 }
2210 run_test 31i "cross directory link under parent==============="
2211
2212 test_31j() {
2213         test_mkdir -c1 -p $DIR/$tdir
2214         test_mkdir -c1 -p $DIR/$tdir/dir1
2215         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2216         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2217         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2218         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2219         return 0
2220 }
2221 run_test 31j "link for directory==============="
2222
2223 test_31k() {
2224         test_mkdir -c1 -p $DIR/$tdir
2225         touch $DIR/$tdir/s
2226         touch $DIR/$tdir/exist
2227         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2228         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2229         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2230         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2231         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2232         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2233         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2234         return 0
2235 }
2236 run_test 31k "link to file: the same, non-existing, dir==============="
2237
2238 test_31m() {
2239         mkdir $DIR/d31m
2240         touch $DIR/d31m/s
2241         mkdir $DIR/d31m2
2242         touch $DIR/d31m2/exist
2243         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2244         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2245         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2246         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2247         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2248         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2249         return 0
2250 }
2251 run_test 31m "link to file: the same, non-existing, dir==============="
2252
2253 test_31n() {
2254         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2255         nlink=$(stat --format=%h $DIR/$tfile)
2256         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2257         local fd=$(free_fd)
2258         local cmd="exec $fd<$DIR/$tfile"
2259         eval $cmd
2260         cmd="exec $fd<&-"
2261         trap "eval $cmd" EXIT
2262         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2263         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2264         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2265         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2266         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2267         eval $cmd
2268 }
2269 run_test 31n "check link count of unlinked file"
2270
2271 link_one() {
2272         local TEMPNAME=$(mktemp $1_XXXXXX)
2273         mlink $TEMPNAME $1 2> /dev/null &&
2274                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2275         munlink $TEMPNAME
2276 }
2277
2278 test_31o() { # LU-2901
2279         mkdir -p $DIR/$tdir
2280         for LOOP in $(seq 100); do
2281                 rm -f $DIR/$tdir/$tfile*
2282                 for THREAD in $(seq 8); do
2283                         link_one $DIR/$tdir/$tfile.$LOOP &
2284                 done
2285                 wait
2286                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2287                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2288                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2289                         break || true
2290         done
2291 }
2292 run_test 31o "duplicate hard links with same filename"
2293
2294 test_31p() {
2295         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2296
2297         mkdir $DIR/$tdir
2298         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2299         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2300
2301         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2302                 error "open unlink test1 failed"
2303         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2304                 error "open unlink test2 failed"
2305
2306         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2307                 error "test1 still exists"
2308         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2309                 error "test2 still exists"
2310 }
2311 run_test 31p "remove of open striped directory"
2312
2313 cleanup_test32_mount() {
2314         trap 0
2315         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2316 }
2317
2318 test_32a() {
2319         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2320         echo "== more mountpoints and symlinks ================="
2321         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2322         trap cleanup_test32_mount EXIT
2323         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2324         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2325         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2326         cleanup_test32_mount
2327 }
2328 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2329
2330 test_32b() {
2331         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2332         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2333         trap cleanup_test32_mount EXIT
2334         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2335         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2336         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2337         cleanup_test32_mount
2338 }
2339 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2340
2341 test_32c() {
2342         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2343         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2344         trap cleanup_test32_mount EXIT
2345         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2346         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2347         test_mkdir -p $DIR/$tdir/d2/test_dir
2348         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2349         cleanup_test32_mount
2350 }
2351 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2352
2353 test_32d() {
2354         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2355         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2356         trap cleanup_test32_mount EXIT
2357         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2358         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2359         test_mkdir -p $DIR/$tdir/d2/test_dir
2360         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2361         cleanup_test32_mount
2362 }
2363 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2364
2365 test_32e() {
2366         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2367         test_mkdir -p $DIR/d32e/tmp
2368         TMP_DIR=$DIR/d32e/tmp
2369         ln -s $DIR/d32e $TMP_DIR/symlink11
2370         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2371         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2372         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2373 }
2374 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2375
2376 test_32f() {
2377         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2378         test_mkdir -p $DIR/d32f/tmp
2379         TMP_DIR=$DIR/d32f/tmp
2380         ln -s $DIR/d32f $TMP_DIR/symlink11
2381         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2382         ls $DIR/d32f/tmp/symlink11  || error
2383         ls $DIR/d32f/symlink01 || error
2384 }
2385 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2386
2387 test_32g() {
2388         TMP_DIR=$DIR/$tdir/tmp
2389         test_mkdir -p $DIR/$tdir/tmp
2390         test_mkdir $DIR/${tdir}2
2391         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2392         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2393         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2394         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2395         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2396         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2397 }
2398 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2399
2400 test_32h() {
2401         rm -fr $DIR/$tdir $DIR/${tdir}2
2402         TMP_DIR=$DIR/$tdir/tmp
2403         test_mkdir -p $DIR/$tdir/tmp
2404         test_mkdir $DIR/${tdir}2
2405         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2406         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2407         ls $TMP_DIR/symlink12 || error
2408         ls $DIR/$tdir/symlink02  || error
2409 }
2410 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2411
2412 test_32i() {
2413         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2414         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2415         trap cleanup_test32_mount EXIT
2416         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2417         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2418         touch $DIR/$tdir/test_file
2419         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2420         cleanup_test32_mount
2421 }
2422 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2423
2424 test_32j() {
2425         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2426         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2427         trap cleanup_test32_mount EXIT
2428         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2429         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2430         touch $DIR/$tdir/test_file
2431         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2432         cleanup_test32_mount
2433 }
2434 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2435
2436 test_32k() {
2437         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2438         rm -fr $DIR/$tdir
2439         trap cleanup_test32_mount EXIT
2440         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2441         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2442         test_mkdir -p $DIR/$tdir/d2
2443         touch $DIR/$tdir/d2/test_file || error
2444         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2445         cleanup_test32_mount
2446 }
2447 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2448
2449 test_32l() {
2450         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2451         rm -fr $DIR/$tdir
2452         trap cleanup_test32_mount EXIT
2453         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2454         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2455         test_mkdir -p $DIR/$tdir/d2
2456         touch $DIR/$tdir/d2/test_file
2457         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2458         cleanup_test32_mount
2459 }
2460 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2461
2462 test_32m() {
2463         rm -fr $DIR/d32m
2464         test_mkdir -p $DIR/d32m/tmp
2465         TMP_DIR=$DIR/d32m/tmp
2466         ln -s $DIR $TMP_DIR/symlink11
2467         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2468         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2469         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2470 }
2471 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2472
2473 test_32n() {
2474         rm -fr $DIR/d32n
2475         test_mkdir -p $DIR/d32n/tmp
2476         TMP_DIR=$DIR/d32n/tmp
2477         ln -s $DIR $TMP_DIR/symlink11
2478         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2479         ls -l $DIR/d32n/tmp/symlink11  || error
2480         ls -l $DIR/d32n/symlink01 || error
2481 }
2482 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2483
2484 test_32o() {
2485         touch $DIR/$tfile
2486         test_mkdir -p $DIR/d32o/tmp
2487         TMP_DIR=$DIR/d32o/tmp
2488         ln -s $DIR/$tfile $TMP_DIR/symlink12
2489         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2490         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2491         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2492         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2493         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2494 }
2495 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2496
2497 test_32p() {
2498     log 32p_1
2499         rm -fr $DIR/d32p
2500     log 32p_2
2501         rm -f $DIR/$tfile
2502     log 32p_3
2503         touch $DIR/$tfile
2504     log 32p_4
2505         test_mkdir -p $DIR/d32p/tmp
2506     log 32p_5
2507         TMP_DIR=$DIR/d32p/tmp
2508     log 32p_6
2509         ln -s $DIR/$tfile $TMP_DIR/symlink12
2510     log 32p_7
2511         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2512     log 32p_8
2513         cat $DIR/d32p/tmp/symlink12 || error
2514     log 32p_9
2515         cat $DIR/d32p/symlink02 || error
2516     log 32p_10
2517 }
2518 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2519
2520 cleanup_testdir_mount() {
2521         trap 0
2522         $UMOUNT -d $DIR/$tdir
2523 }
2524
2525 test_32q() {
2526         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2527         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2528         trap cleanup_testdir_mount EXIT
2529         test_mkdir -p $DIR/$tdir
2530         touch $DIR/$tdir/under_the_mount
2531         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2532         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2533         cleanup_testdir_mount
2534 }
2535 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2536
2537 test_32r() {
2538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2539         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2540         trap cleanup_testdir_mount EXIT
2541         test_mkdir -p $DIR/$tdir
2542         touch $DIR/$tdir/under_the_mount
2543         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2544         ls $DIR/$tdir | grep -q under_the_mount && error || true
2545         cleanup_testdir_mount
2546 }
2547 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2548
2549 test_33aa() {
2550         rm -f $DIR/$tfile
2551         touch $DIR/$tfile
2552         chmod 444 $DIR/$tfile
2553         chown $RUNAS_ID $DIR/$tfile
2554         log 33_1
2555         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2556         log 33_2
2557 }
2558 run_test 33aa "write file with mode 444 (should return error) ===="
2559
2560 test_33a() {
2561         rm -fr $DIR/d33
2562         test_mkdir -p $DIR/d33
2563         chown $RUNAS_ID $DIR/d33
2564         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2565         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2566                 error "open RDWR" || true
2567 }
2568 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2569
2570 test_33b() {
2571         rm -fr $DIR/d33
2572         test_mkdir -p $DIR/d33
2573         chown $RUNAS_ID $DIR/d33
2574         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33
2575 }
2576 run_test 33b "test open file with malformed flags (No panic)"
2577
2578 test_33c() {
2579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2580         local ostnum
2581         local ostname
2582         local write_bytes
2583         local all_zeros
2584
2585         remote_ost_nodsh && skip "remote OST with nodsh" && return
2586         all_zeros=:
2587         rm -fr $DIR/d33
2588         test_mkdir -p $DIR/d33
2589         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2590
2591         sync
2592         for ostnum in $(seq $OSTCOUNT); do
2593                 # test-framework's OST numbering is one-based, while Lustre's
2594                 # is zero-based
2595                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2596                 # Parsing llobdstat's output sucks; we could grep the /proc
2597                 # path, but that's likely to not be as portable as using the
2598                 # llobdstat utility.  So we parse lctl output instead.
2599                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2600                         obdfilter/$ostname/stats |
2601                         awk '/^write_bytes/ {print $7}' )
2602                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2603                 if (( ${write_bytes:-0} > 0 ))
2604                 then
2605                         all_zeros=false
2606                         break;
2607                 fi
2608         done
2609
2610         $all_zeros || return 0
2611
2612         # Write four bytes
2613         echo foo > $DIR/d33/bar
2614         # Really write them
2615         sync
2616
2617         # Total up write_bytes after writing.  We'd better find non-zeros.
2618         for ostnum in $(seq $OSTCOUNT); do
2619                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2620                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2621                         obdfilter/$ostname/stats |
2622                         awk '/^write_bytes/ {print $7}' )
2623                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2624                 if (( ${write_bytes:-0} > 0 ))
2625                 then
2626                         all_zeros=false
2627                         break;
2628                 fi
2629         done
2630
2631         if $all_zeros
2632         then
2633                 for ostnum in $(seq $OSTCOUNT); do
2634                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2635                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2636                         do_facet ost$ostnum lctl get_param -n \
2637                                 obdfilter/$ostname/stats
2638                 done
2639                 error "OST not keeping write_bytes stats (b22312)"
2640         fi
2641 }
2642 run_test 33c "test llobdstat and write_bytes"
2643
2644 test_33d() {
2645         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2646         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2647         local MDTIDX=1
2648         local remote_dir=$DIR/$tdir/remote_dir
2649
2650         mkdir -p $DIR/$tdir
2651         $LFS mkdir -i $MDTIDX $remote_dir ||
2652                 error "create remote directory failed"
2653
2654         touch $remote_dir/$tfile
2655         chmod 444 $remote_dir/$tfile
2656         chown $RUNAS_ID $remote_dir/$tfile
2657
2658         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2659
2660         chown $RUNAS_ID $remote_dir
2661         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2662                                         error "create" || true
2663         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2664                                     error "open RDWR" || true
2665         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2666                                     error "create" || true
2667 }
2668 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2669
2670 test_33e() {
2671         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2672
2673         mkdir $DIR/$tdir
2674
2675         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2676         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2677         mkdir $DIR/$tdir/local_dir
2678
2679         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2680         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2681         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2682
2683         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2684                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2685
2686         rmdir $DIR/$tdir/* || error "rmdir failed"
2687
2688         umask 777
2689         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2690         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2691         mkdir $DIR/$tdir/local_dir
2692
2693         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2694         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2695         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2696
2697         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2698                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2699
2700         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2701
2702         umask 000
2703         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2704         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2705         mkdir $DIR/$tdir/local_dir
2706
2707         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2708         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2709         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2710
2711         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2712                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2713 }
2714 run_test 33e "mkdir and striped directory should have same mode"
2715
2716 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2717 test_34a() {
2718         rm -f $DIR/f34
2719         $MCREATE $DIR/f34 || error
2720         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2721         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2722         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2723         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2724 }
2725 run_test 34a "truncate file that has not been opened ==========="
2726
2727 test_34b() {
2728         [ ! -f $DIR/f34 ] && test_34a
2729         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2730         $OPENFILE -f O_RDONLY $DIR/f34
2731         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2732         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2733 }
2734 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2735
2736 test_34c() {
2737         [ ! -f $DIR/f34 ] && test_34a
2738         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2739         $OPENFILE -f O_RDWR $DIR/f34
2740         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2741         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2742 }
2743 run_test 34c "O_RDWR opening file-with-size works =============="
2744
2745 test_34d() {
2746         [ ! -f $DIR/f34 ] && test_34a
2747         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2748         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2749         rm $DIR/f34
2750 }
2751 run_test 34d "write to sparse file ============================="
2752
2753 test_34e() {
2754         rm -f $DIR/f34e
2755         $MCREATE $DIR/f34e || error
2756         $TRUNCATE $DIR/f34e 1000 || error
2757         $CHECKSTAT -s 1000 $DIR/f34e || error
2758         $OPENFILE -f O_RDWR $DIR/f34e
2759         $CHECKSTAT -s 1000 $DIR/f34e || error
2760 }
2761 run_test 34e "create objects, some with size and some without =="
2762
2763 test_34f() { # bug 6242, 6243
2764         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2765         SIZE34F=48000
2766         rm -f $DIR/f34f
2767         $MCREATE $DIR/f34f || error
2768         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2769         dd if=$DIR/f34f of=$TMP/f34f
2770         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2771         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2772         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2773         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2774         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2775 }
2776 run_test 34f "read from a file with no objects until EOF ======="
2777
2778 test_34g() {
2779         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2780         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2781         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2782         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2783         cancel_lru_locks osc
2784         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2785                 error "wrong size after lock cancel"
2786
2787         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2788         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2789                 error "expanding truncate failed"
2790         cancel_lru_locks osc
2791         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2792                 error "wrong expanded size after lock cancel"
2793 }
2794 run_test 34g "truncate long file ==============================="
2795
2796 test_34h() {
2797         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2798         local gid=10
2799         local sz=1000
2800
2801         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2802         sync # Flush the cache so that multiop below does not block on cache
2803              # flush when getting the group lock
2804         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2805         MULTIPID=$!
2806
2807         # Since just timed wait is not good enough, let's do a sync write
2808         # that way we are sure enough time for a roundtrip + processing
2809         # passed + 2 seconds of extra margin.
2810         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2811         rm $DIR/${tfile}-1
2812         sleep 2
2813
2814         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2815                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2816                 kill -9 $MULTIPID
2817         fi
2818         wait $MULTIPID
2819         local nsz=`stat -c %s $DIR/$tfile`
2820         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2821 }
2822 run_test 34h "ftruncate file under grouplock should not block"
2823
2824 test_35a() {
2825         cp /bin/sh $DIR/f35a
2826         chmod 444 $DIR/f35a
2827         chown $RUNAS_ID $DIR/f35a
2828         $RUNAS $DIR/f35a && error || true
2829         rm $DIR/f35a
2830 }
2831 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2832
2833 test_36a() {
2834         rm -f $DIR/f36
2835         utime $DIR/f36 || error
2836 }
2837 run_test 36a "MDS utime check (mknod, utime) ==================="
2838
2839 test_36b() {
2840         echo "" > $DIR/f36
2841         utime $DIR/f36 || error
2842 }
2843 run_test 36b "OST utime check (open, utime) ===================="
2844
2845 test_36c() {
2846         rm -f $DIR/d36/f36
2847         test_mkdir $DIR/d36
2848         chown $RUNAS_ID $DIR/d36
2849         $RUNAS utime $DIR/d36/f36 || error
2850 }
2851 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2852
2853 test_36d() {
2854         [ ! -d $DIR/d36 ] && test_36c
2855         echo "" > $DIR/d36/f36
2856         $RUNAS utime $DIR/d36/f36 || error
2857 }
2858 run_test 36d "non-root OST utime check (open, utime) ==========="
2859
2860 test_36e() {
2861         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2862         test_mkdir -p $DIR/$tdir
2863         touch $DIR/$tdir/$tfile
2864         $RUNAS utime $DIR/$tdir/$tfile && \
2865                 error "utime worked, expected failure" || true
2866 }
2867 run_test 36e "utime on non-owned file (should return error) ===="
2868
2869 subr_36fh() {
2870         local fl="$1"
2871         local LANG_SAVE=$LANG
2872         local LC_LANG_SAVE=$LC_LANG
2873         export LANG=C LC_LANG=C # for date language
2874
2875         DATESTR="Dec 20  2000"
2876         test_mkdir -p $DIR/$tdir
2877         lctl set_param fail_loc=$fl
2878         date; date +%s
2879         cp /etc/hosts $DIR/$tdir/$tfile
2880         sync & # write RPC generated with "current" inode timestamp, but delayed
2881         sleep 1
2882         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2883         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2884         cancel_lru_locks osc
2885         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2886         date; date +%s
2887         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2888                 echo "BEFORE: $LS_BEFORE" && \
2889                 echo "AFTER : $LS_AFTER" && \
2890                 echo "WANT  : $DATESTR" && \
2891                 error "$DIR/$tdir/$tfile timestamps changed" || true
2892
2893         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2894 }
2895
2896 test_36f() {
2897         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2898         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2899         subr_36fh "0x80000214"
2900 }
2901 run_test 36f "utime on file racing with OST BRW write =========="
2902
2903 test_36g() {
2904         remote_ost_nodsh && skip "remote OST with nodsh" && return
2905         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2906         local fmd_max_age
2907         local fmd_before
2908         local fmd_after
2909
2910         test_mkdir -p $DIR/$tdir
2911         fmd_max_age=$(do_facet ost1 \
2912                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2913                 head -n 1")
2914
2915         fmd_before=$(do_facet ost1 \
2916                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2917         touch $DIR/$tdir/$tfile
2918         sleep $((fmd_max_age + 12))
2919         fmd_after=$(do_facet ost1 \
2920                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2921
2922         echo "fmd_before: $fmd_before"
2923         echo "fmd_after: $fmd_after"
2924         [[ $fmd_after -gt $fmd_before ]] &&
2925                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2926                 error "fmd didn't expire after ping" || true
2927 }
2928 run_test 36g "filter mod data cache expiry ====================="
2929
2930 test_36h() {
2931         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2932         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2933         subr_36fh "0x80000227"
2934 }
2935 run_test 36h "utime on file racing with OST BRW write =========="
2936
2937 test_36i() {
2938         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2939
2940         mkdir $DIR/$tdir
2941         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
2942
2943         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
2944         local new_mtime=$((mtime + 200))
2945
2946         #change Modify time of striped dir
2947         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
2948                         error "change mtime failed"
2949
2950         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
2951
2952         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
2953 }
2954 run_test 36i "change mtime on striped directory"
2955
2956 # test_37 - duplicate with tests 32q 32r
2957
2958 test_38() {
2959         local file=$DIR/$tfile
2960         touch $file
2961         openfile -f O_DIRECTORY $file
2962         local RC=$?
2963         local ENOTDIR=20
2964         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2965         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2966 }
2967 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2968
2969 test_39() {
2970         touch $DIR/$tfile
2971         touch $DIR/${tfile}2
2972 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2973 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2974 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2975         sleep 2
2976         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2977         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2978                 echo "mtime"
2979                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2980                 echo "atime"
2981                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2982                 echo "ctime"
2983                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2984                 error "O_TRUNC didn't change timestamps"
2985         fi
2986 }
2987 run_test 39 "mtime changed on create ==========================="
2988
2989 test_39b() {
2990         test_mkdir -p -c1 $DIR/$tdir
2991         cp -p /etc/passwd $DIR/$tdir/fopen
2992         cp -p /etc/passwd $DIR/$tdir/flink
2993         cp -p /etc/passwd $DIR/$tdir/funlink
2994         cp -p /etc/passwd $DIR/$tdir/frename
2995         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2996
2997         sleep 1
2998         echo "aaaaaa" >> $DIR/$tdir/fopen
2999         echo "aaaaaa" >> $DIR/$tdir/flink
3000         echo "aaaaaa" >> $DIR/$tdir/funlink
3001         echo "aaaaaa" >> $DIR/$tdir/frename
3002
3003         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3004         local link_new=`stat -c %Y $DIR/$tdir/flink`
3005         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3006         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3007
3008         cat $DIR/$tdir/fopen > /dev/null
3009         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3010         rm -f $DIR/$tdir/funlink2
3011         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3012
3013         for (( i=0; i < 2; i++ )) ; do
3014                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3015                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3016                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3017                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3018
3019                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3020                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3021                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3022                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3023
3024                 cancel_lru_locks osc
3025                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3026         done
3027 }
3028 run_test 39b "mtime change on open, link, unlink, rename  ======"
3029
3030 # this should be set to past
3031 TEST_39_MTIME=`date -d "1 year ago" +%s`
3032
3033 # bug 11063
3034 test_39c() {
3035         touch $DIR1/$tfile
3036         sleep 2
3037         local mtime0=`stat -c %Y $DIR1/$tfile`
3038
3039         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3040         local mtime1=`stat -c %Y $DIR1/$tfile`
3041         [ "$mtime1" = $TEST_39_MTIME ] || \
3042                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3043
3044         local d1=`date +%s`
3045         echo hello >> $DIR1/$tfile
3046         local d2=`date +%s`
3047         local mtime2=`stat -c %Y $DIR1/$tfile`
3048         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3049                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3050
3051         mv $DIR1/$tfile $DIR1/$tfile-1
3052
3053         for (( i=0; i < 2; i++ )) ; do
3054                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3055                 [ "$mtime2" = "$mtime3" ] || \
3056                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3057
3058                 cancel_lru_locks osc
3059                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3060         done
3061 }
3062 run_test 39c "mtime change on rename ==========================="
3063
3064 # bug 21114
3065 test_39d() {
3066         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3067         touch $DIR1/$tfile
3068
3069         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3070
3071         for (( i=0; i < 2; i++ )) ; do
3072                 local mtime=`stat -c %Y $DIR1/$tfile`
3073                 [ $mtime = $TEST_39_MTIME ] || \
3074                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3075
3076                 cancel_lru_locks osc
3077                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3078         done
3079 }
3080 run_test 39d "create, utime, stat =============================="
3081
3082 # bug 21114
3083 test_39e() {
3084         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3085         touch $DIR1/$tfile
3086         local mtime1=`stat -c %Y $DIR1/$tfile`
3087
3088         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3089
3090         for (( i=0; i < 2; i++ )) ; do
3091                 local mtime2=`stat -c %Y $DIR1/$tfile`
3092                 [ $mtime2 = $TEST_39_MTIME ] || \
3093                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3094
3095                 cancel_lru_locks osc
3096                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3097         done
3098 }
3099 run_test 39e "create, stat, utime, stat ========================"
3100
3101 # bug 21114
3102 test_39f() {
3103         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3104         touch $DIR1/$tfile
3105         mtime1=`stat -c %Y $DIR1/$tfile`
3106
3107         sleep 2
3108         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3109
3110         for (( i=0; i < 2; i++ )) ; do
3111                 local mtime2=`stat -c %Y $DIR1/$tfile`
3112                 [ $mtime2 = $TEST_39_MTIME ] || \
3113                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3114
3115                 cancel_lru_locks osc
3116                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3117         done
3118 }
3119 run_test 39f "create, stat, sleep, utime, stat ================="
3120
3121 # bug 11063
3122 test_39g() {
3123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3124         echo hello >> $DIR1/$tfile
3125         local mtime1=`stat -c %Y $DIR1/$tfile`
3126
3127         sleep 2
3128         chmod o+r $DIR1/$tfile
3129
3130         for (( i=0; i < 2; i++ )) ; do
3131                 local mtime2=`stat -c %Y $DIR1/$tfile`
3132                 [ "$mtime1" = "$mtime2" ] || \
3133                         error "lost mtime: $mtime2, should be $mtime1"
3134
3135                 cancel_lru_locks osc
3136                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3137         done
3138 }
3139 run_test 39g "write, chmod, stat ==============================="
3140
3141 # bug 11063
3142 test_39h() {
3143         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3144         touch $DIR1/$tfile
3145         sleep 1
3146
3147         local d1=`date`
3148         echo hello >> $DIR1/$tfile
3149         local mtime1=`stat -c %Y $DIR1/$tfile`
3150
3151         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3152         local d2=`date`
3153         if [ "$d1" != "$d2" ]; then
3154                 echo "write and touch not within one second"
3155         else
3156                 for (( i=0; i < 2; i++ )) ; do
3157                         local mtime2=`stat -c %Y $DIR1/$tfile`
3158                         [ "$mtime2" = $TEST_39_MTIME ] || \
3159                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3160
3161                         cancel_lru_locks osc
3162                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3163                 done
3164         fi
3165 }
3166 run_test 39h "write, utime within one second, stat ============="
3167
3168 test_39i() {
3169         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3170         touch $DIR1/$tfile
3171         sleep 1
3172
3173         echo hello >> $DIR1/$tfile
3174         local mtime1=`stat -c %Y $DIR1/$tfile`
3175
3176         mv $DIR1/$tfile $DIR1/$tfile-1
3177
3178         for (( i=0; i < 2; i++ )) ; do
3179                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3180
3181                 [ "$mtime1" = "$mtime2" ] || \
3182                         error "lost mtime: $mtime2, should be $mtime1"
3183
3184                 cancel_lru_locks osc
3185                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3186         done
3187 }
3188 run_test 39i "write, rename, stat =============================="
3189
3190 test_39j() {
3191         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3192         start_full_debug_logging
3193         touch $DIR1/$tfile
3194         sleep 1
3195
3196         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3197         lctl set_param fail_loc=0x80000412
3198         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3199                 error "multiop failed"
3200         local multipid=$!
3201         local mtime1=`stat -c %Y $DIR1/$tfile`
3202
3203         mv $DIR1/$tfile $DIR1/$tfile-1
3204
3205         kill -USR1 $multipid
3206         wait $multipid || error "multiop close failed"
3207
3208         for (( i=0; i < 2; i++ )) ; do
3209                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3210                 [ "$mtime1" = "$mtime2" ] ||
3211                         error "mtime is lost on close: $mtime2, " \
3212                               "should be $mtime1"
3213
3214                 cancel_lru_locks osc
3215                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3216         done
3217         lctl set_param fail_loc=0
3218         stop_full_debug_logging
3219 }
3220 run_test 39j "write, rename, close, stat ======================="
3221
3222 test_39k() {
3223         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3224         touch $DIR1/$tfile
3225         sleep 1
3226
3227         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3228         local multipid=$!
3229         local mtime1=`stat -c %Y $DIR1/$tfile`
3230
3231         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3232
3233         kill -USR1 $multipid
3234         wait $multipid || error "multiop close failed"
3235
3236         for (( i=0; i < 2; i++ )) ; do
3237                 local mtime2=`stat -c %Y $DIR1/$tfile`
3238
3239                 [ "$mtime2" = $TEST_39_MTIME ] || \
3240                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3241
3242                 cancel_lru_locks osc
3243                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3244         done
3245 }
3246 run_test 39k "write, utime, close, stat ========================"
3247
3248 # this should be set to future
3249 TEST_39_ATIME=`date -d "1 year" +%s`
3250
3251 test_39l() {
3252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3253         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3254         local atime_diff=$(do_facet $SINGLEMDS \
3255                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3256         rm -rf $DIR/$tdir
3257         mkdir -p $DIR/$tdir
3258
3259         # test setting directory atime to future
3260         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3261         local atime=$(stat -c %X $DIR/$tdir)
3262         [ "$atime" = $TEST_39_ATIME ] || \
3263                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3264
3265         # test setting directory atime from future to now
3266         local d1=$(date +%s)
3267         ls $DIR/$tdir
3268         local d2=$(date +%s)
3269
3270         cancel_lru_locks mdc
3271         atime=$(stat -c %X $DIR/$tdir)
3272         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3273                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3274
3275         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3276         sleep 3
3277
3278         # test setting directory atime when now > dir atime + atime_diff
3279         d1=$(date +%s)
3280         ls $DIR/$tdir
3281         d2=$(date +%s)
3282         cancel_lru_locks mdc
3283         atime=$(stat -c %X $DIR/$tdir)
3284         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3285                 error "atime is not updated  : $atime, should be $d2"
3286
3287         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3288         sleep 3
3289
3290         # test not setting directory atime when now < dir atime + atime_diff
3291         ls $DIR/$tdir
3292         cancel_lru_locks mdc
3293         atime=$(stat -c %X $DIR/$tdir)
3294         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3295                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3296
3297         do_facet $SINGLEMDS \
3298                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3299 }
3300 run_test 39l "directory atime update ==========================="
3301
3302 test_39m() {
3303         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3304         touch $DIR1/$tfile
3305         sleep 2
3306         local far_past_mtime=$(date -d "May 29 1953" +%s)
3307         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3308
3309         touch -m -d @$far_past_mtime $DIR1/$tfile
3310         touch -a -d @$far_past_atime $DIR1/$tfile
3311
3312         for (( i=0; i < 2; i++ )) ; do
3313                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3314                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3315                         error "atime or mtime set incorrectly"
3316
3317                 cancel_lru_locks osc
3318                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3319         done
3320 }
3321 run_test 39m "test atime and mtime before 1970"
3322
3323 test_39n() { # LU-3832
3324         local atime_diff=$(do_facet $SINGLEMDS \
3325                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3326         local atime0
3327         local atime1
3328         local atime2
3329
3330         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3331
3332         rm -rf $DIR/$tfile
3333         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3334         atime0=$(stat -c %X $DIR/$tfile)
3335
3336         sleep 5
3337         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3338         atime1=$(stat -c %X $DIR/$tfile)
3339
3340         sleep 5
3341         cancel_lru_locks mdc
3342         cancel_lru_locks osc
3343         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3344         atime2=$(stat -c %X $DIR/$tfile)
3345
3346         do_facet $SINGLEMDS \
3347                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3348
3349         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3350         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3351 }
3352 run_test 39n "check that O_NOATIME is honored"
3353
3354 test_39o() {
3355         TESTDIR=$DIR/$tdir/$tfile
3356         [ -e $TESTDIR ] && rm -rf $TESTDIR
3357         test_mkdir -p $TESTDIR
3358         cd $TESTDIR
3359         links1=2
3360         ls
3361         mkdir a b
3362         ls
3363         links2=$(stat -c %h .)
3364         [ $(($links1 + 2)) != $links2 ] &&
3365                 error "wrong links count $(($links1 + 2)) != $links2"
3366         rmdir b
3367         links3=$(stat -c %h .)
3368         [ $(($links1 + 1)) != $links3 ] &&
3369                 error "wrong links count $links1 != $links3"
3370         return 0
3371 }
3372 run_test 39o "directory cached attributes updated after create ========"
3373
3374 test_39p() {
3375         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3376         local MDTIDX=1
3377         TESTDIR=$DIR/$tdir/$tfile
3378         [ -e $TESTDIR ] && rm -rf $TESTDIR
3379         mkdir -p $TESTDIR
3380         cd $TESTDIR
3381         links1=2
3382         ls
3383         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3384         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3385         ls
3386         links2=$(stat -c %h .)
3387         [ $(($links1 + 2)) != $links2 ] &&
3388                 error "wrong links count $(($links1 + 2)) != $links2"
3389         rmdir remote_dir2
3390         links3=$(stat -c %h .)
3391         [ $(($links1 + 1)) != $links3 ] &&
3392                 error "wrong links count $links1 != $links3"
3393         return 0
3394 }
3395 run_test 39p "remote directory cached attributes updated after create ========"
3396
3397
3398 test_40() {
3399         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3400         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3401                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3402         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3403                 error "$tfile is not 4096 bytes in size"
3404 }
3405 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3406
3407 test_41() {
3408         # bug 1553
3409         small_write $DIR/f41 18
3410 }
3411 run_test 41 "test small file write + fstat ====================="
3412
3413 count_ost_writes() {
3414         lctl get_param -n osc.*.stats |
3415                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3416                         END { printf("%0.0f", writes) }'
3417 }
3418
3419 # decent default
3420 WRITEBACK_SAVE=500
3421 DIRTY_RATIO_SAVE=40
3422 MAX_DIRTY_RATIO=50
3423 BG_DIRTY_RATIO_SAVE=10
3424 MAX_BG_DIRTY_RATIO=25
3425
3426 start_writeback() {
3427         trap 0
3428         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3429         # dirty_ratio, dirty_background_ratio
3430         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3431                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3432                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3433                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3434         else
3435                 # if file not here, we are a 2.4 kernel
3436                 kill -CONT `pidof kupdated`
3437         fi
3438 }
3439
3440 stop_writeback() {
3441         # setup the trap first, so someone cannot exit the test at the
3442         # exact wrong time and mess up a machine
3443         trap start_writeback EXIT
3444         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3445         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3446                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3447                 sysctl -w vm.dirty_writeback_centisecs=0
3448                 sysctl -w vm.dirty_writeback_centisecs=0
3449                 # save and increase /proc/sys/vm/dirty_ratio
3450                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3451                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3452                 # save and increase /proc/sys/vm/dirty_background_ratio
3453                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3454                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3455         else
3456                 # if file not here, we are a 2.4 kernel
3457                 kill -STOP `pidof kupdated`
3458         fi
3459 }
3460
3461 # ensure that all stripes have some grant before we test client-side cache
3462 setup_test42() {
3463         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3464                 dd if=/dev/zero of=$i bs=4k count=1
3465                 rm $i
3466         done
3467 }
3468
3469 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3470 # file truncation, and file removal.
3471 test_42a() {
3472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3473         setup_test42
3474         cancel_lru_locks osc
3475         stop_writeback
3476         sync; sleep 1; sync # just to be safe
3477         BEFOREWRITES=`count_ost_writes`
3478         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3479         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3480         AFTERWRITES=`count_ost_writes`
3481         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3482                 error "$BEFOREWRITES < $AFTERWRITES"
3483         start_writeback
3484 }
3485 run_test 42a "ensure that we don't flush on close =============="
3486
3487 test_42b() {
3488         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3489         setup_test42
3490         cancel_lru_locks osc
3491         stop_writeback
3492         sync
3493         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3494         BEFOREWRITES=$(count_ost_writes)
3495         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3496         AFTERWRITES=$(count_ost_writes)
3497         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3498                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3499         fi
3500         BEFOREWRITES=$(count_ost_writes)
3501         sync || error "sync: $?"
3502         AFTERWRITES=$(count_ost_writes)
3503         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3504                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3505         fi
3506         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3507         start_writeback
3508         return 0
3509 }
3510 run_test 42b "test destroy of file with cached dirty data ======"
3511
3512 # if these tests just want to test the effect of truncation,
3513 # they have to be very careful.  consider:
3514 # - the first open gets a {0,EOF}PR lock
3515 # - the first write conflicts and gets a {0, count-1}PW
3516 # - the rest of the writes are under {count,EOF}PW
3517 # - the open for truncate tries to match a {0,EOF}PR
3518 #   for the filesize and cancels the PWs.
3519 # any number of fixes (don't get {0,EOF} on open, match
3520 # composite locks, do smarter file size management) fix
3521 # this, but for now we want these tests to verify that
3522 # the cancellation with truncate intent works, so we
3523 # start the file with a full-file pw lock to match against
3524 # until the truncate.
3525 trunc_test() {
3526         test=$1
3527         file=$DIR/$test
3528         offset=$2
3529         cancel_lru_locks osc
3530         stop_writeback
3531         # prime the file with 0,EOF PW to match
3532         touch $file
3533         $TRUNCATE $file 0
3534         sync; sync
3535         # now the real test..
3536         dd if=/dev/zero of=$file bs=1024 count=100
3537         BEFOREWRITES=`count_ost_writes`
3538         $TRUNCATE $file $offset
3539         cancel_lru_locks osc
3540         AFTERWRITES=`count_ost_writes`
3541         start_writeback
3542 }
3543
3544 test_42c() {
3545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3546         trunc_test 42c 1024
3547         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3548             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3549         rm $file
3550 }
3551 run_test 42c "test partial truncate of file with cached dirty data"
3552
3553 test_42d() {
3554         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3555         trunc_test 42d 0
3556         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3557             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3558         rm $file
3559 }
3560 run_test 42d "test complete truncate of file with cached dirty data"
3561
3562 test_42e() { # bug22074
3563         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3564         local TDIR=$DIR/${tdir}e
3565         local pagesz=$(page_size)
3566         local pages=16 # hardcoded 16 pages, don't change it.
3567         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3568         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3569         local max_dirty_mb
3570         local warmup_files
3571
3572         test_mkdir -p $DIR/${tdir}e
3573         $SETSTRIPE -c 1 $TDIR
3574         createmany -o $TDIR/f $files
3575
3576         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3577
3578         # we assume that with $OSTCOUNT files, at least one of them will
3579         # be allocated on OST0.
3580         warmup_files=$((OSTCOUNT * max_dirty_mb))
3581         createmany -o $TDIR/w $warmup_files
3582
3583         # write a large amount of data into one file and sync, to get good
3584         # avail_grant number from OST.
3585         for ((i=0; i<$warmup_files; i++)); do
3586                 idx=$($GETSTRIPE -i $TDIR/w$i)
3587                 [ $idx -ne 0 ] && continue
3588                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3589                 break
3590         done
3591         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3592         sync
3593         $LCTL get_param $proc_osc0/cur_dirty_bytes
3594         $LCTL get_param $proc_osc0/cur_grant_bytes
3595
3596         # create as much dirty pages as we can while not to trigger the actual
3597         # RPCs directly. but depends on the env, VFS may trigger flush during this
3598         # period, hopefully we are good.
3599         for ((i=0; i<$warmup_files; i++)); do
3600                 idx=$($GETSTRIPE -i $TDIR/w$i)
3601                 [ $idx -ne 0 ] && continue
3602                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3603         done
3604         $LCTL get_param $proc_osc0/cur_dirty_bytes
3605         $LCTL get_param $proc_osc0/cur_grant_bytes
3606
3607         # perform the real test
3608         $LCTL set_param $proc_osc0/rpc_stats 0
3609         for ((;i<$files; i++)); do
3610                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3611                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3612         done
3613         sync
3614         $LCTL get_param $proc_osc0/rpc_stats
3615
3616         local percent=0
3617         local have_ppr=false
3618         $LCTL get_param $proc_osc0/rpc_stats |
3619                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3620                         # skip lines until we are at the RPC histogram data
3621                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3622                         $have_ppr || continue
3623
3624                         # we only want the percent stat for < 16 pages
3625                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3626
3627                         percent=$((percent + WPCT))
3628                         if [[ $percent -gt 15 ]]; then
3629                                 error "less than 16-pages write RPCs" \
3630                                       "$percent% > 15%"
3631                                 break
3632                         fi
3633                 done
3634         rm -rf $TDIR
3635 }
3636 run_test 42e "verify sub-RPC writes are not done synchronously"
3637
3638 test_43() {
3639         test_mkdir -p $DIR/$tdir
3640         cp -p /bin/ls $DIR/$tdir/$tfile
3641         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3642         pid=$!
3643         # give multiop a chance to open
3644         sleep 1
3645
3646         $DIR/$tdir/$tfile && error || true
3647         kill -USR1 $pid
3648 }
3649 run_test 43 "execution of file opened for write should return -ETXTBSY"
3650
3651 test_43a() {
3652         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3653         test_mkdir -p $DIR/$tdir
3654         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3655                         cp -p multiop $DIR/$tdir/multiop
3656         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3657                         return 1
3658         MULTIOP_PID=$!
3659         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3660         kill -USR1 $MULTIOP_PID || return 2
3661         wait $MULTIOP_PID || return 3
3662         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3663 }
3664 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3665
3666 test_43b() {
3667         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3668         test_mkdir -p $DIR/$tdir
3669         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3670                         cp -p multiop $DIR/$tdir/multiop
3671         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3672                         return 1
3673         MULTIOP_PID=$!
3674         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3675         kill -USR1 $MULTIOP_PID || return 2
3676         wait $MULTIOP_PID || return 3
3677         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3678 }
3679 run_test 43b "truncate of file being executed should return -ETXTBSY"
3680
3681 test_43c() {
3682         local testdir="$DIR/$tdir"
3683         test_mkdir -p $DIR/$tdir
3684         cp $SHELL $testdir/
3685         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3686                 ( cd $testdir && md5sum -c)
3687 }
3688 run_test 43c "md5sum of copy into lustre========================"
3689
3690 test_44() {
3691         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3692         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3693         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3694 }
3695 run_test 44 "zero length read from a sparse stripe ============="
3696
3697 test_44a() {
3698         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3699                 awk '{ print $2 }')
3700         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3701         [[ $nstripe -gt $OSTCOUNT ]] &&
3702             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3703             return
3704         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3705                 awk '{ print $2 }')
3706         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3707                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3708                         awk '{ print $2 }')
3709         fi
3710
3711         OFFSETS="0 $((stride/2)) $((stride-1))"
3712         for offset in $OFFSETS; do
3713                 for i in $(seq 0 $((nstripe-1))); do
3714                         local GLOBALOFFSETS=""
3715                         # size in Bytes
3716                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3717                         local myfn=$DIR/d44a-$size
3718                         echo "--------writing $myfn at $size"
3719                         ll_sparseness_write $myfn $size ||
3720                                 error "ll_sparseness_write"
3721                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3722                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3723                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3724
3725                         for j in $(seq 0 $((nstripe-1))); do
3726                                 # size in Bytes
3727                                 size=$((((j + $nstripe )*$stride + $offset)))
3728                                 ll_sparseness_write $myfn $size ||
3729                                         error "ll_sparseness_write"
3730                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3731                         done
3732                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3733                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3734                         rm -f $myfn
3735                 done
3736         done
3737 }
3738 run_test 44a "test sparse pwrite ==============================="
3739
3740 dirty_osc_total() {
3741         tot=0
3742         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3743                 tot=$(($tot + $d))
3744         done
3745         echo $tot
3746 }
3747 do_dirty_record() {
3748         before=`dirty_osc_total`
3749         echo executing "\"$*\""
3750         eval $*
3751         after=`dirty_osc_total`
3752         echo before $before, after $after
3753 }
3754 test_45() {
3755         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3756         f="$DIR/f45"
3757         # Obtain grants from OST if it supports it
3758         echo blah > ${f}_grant
3759         stop_writeback
3760         sync
3761         do_dirty_record "echo blah > $f"
3762         [[ $before -eq $after ]] && error "write wasn't cached"
3763         do_dirty_record "> $f"
3764         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3765         do_dirty_record "echo blah > $f"
3766         [[ $before -eq $after ]] && error "write wasn't cached"
3767         do_dirty_record "sync"
3768         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3769         do_dirty_record "echo blah > $f"
3770         [[ $before -eq $after ]] && error "write wasn't cached"
3771         do_dirty_record "cancel_lru_locks osc"
3772         [[ $before -gt $after ]] ||
3773                 error "lock cancellation didn't lower dirty count"
3774         start_writeback
3775 }
3776 run_test 45 "osc io page accounting ============================"
3777
3778 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3779 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3780 # objects offset and an assert hit when an rpc was built with 1023's mapped
3781 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3782 test_46() {
3783         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3784         f="$DIR/f46"
3785         stop_writeback
3786         sync
3787         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3788         sync
3789         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3790         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3791         sync
3792         start_writeback
3793 }
3794 run_test 46 "dirtying a previously written page ================"
3795
3796 # test_47 is removed "Device nodes check" is moved to test_28
3797
3798 test_48a() { # bug 2399
3799         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3800         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3801                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3802                 return
3803         check_kernel_version 34 || return 0
3804         test_mkdir -p $DIR/$tdir
3805         cd $DIR/$tdir
3806         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3807         test_mkdir $DIR/$tdir || error "recreate directory failed"
3808         touch foo || error "'touch foo' failed after recreating cwd"
3809         test_mkdir $DIR/$tdir/bar ||
3810                      error "'mkdir foo' failed after recreating cwd"
3811         if check_kernel_version 44; then
3812                 touch .foo || error "'touch .foo' failed after recreating cwd"
3813                 test_mkdir $DIR/$tdir/.bar ||
3814                               error "'mkdir .foo' failed after recreating cwd"
3815         fi
3816         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3817         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3818         cd . || error "'cd .' failed after recreating cwd"
3819         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3820         rmdir . && error "'rmdir .' worked after recreating cwd"
3821         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3822         cd .. || error "'cd ..' failed after recreating cwd"
3823 }
3824 run_test 48a "Access renamed working dir (should return errors)="
3825
3826 test_48b() { # bug 2399
3827         check_kernel_version 34 || return 0
3828         rm -rf $DIR/$tdir
3829         test_mkdir -p $DIR/$tdir
3830         cd $DIR/$tdir
3831         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3832         touch foo && error "'touch foo' worked after removing cwd"
3833         test_mkdir $DIR/$tdir/foo &&
3834                      error "'mkdir foo' worked after removing cwd"
3835         if check_kernel_version 44; then
3836                 touch .foo && error "'touch .foo' worked after removing cwd"
3837                 test_mkdir $DIR/$tdir/.foo &&
3838                               error "'mkdir .foo' worked after removing cwd"
3839         fi
3840         ls . > /dev/null && error "'ls .' worked after removing cwd"
3841         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3842         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3843         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3844         rmdir . && error "'rmdir .' worked after removing cwd"
3845         ln -s . foo && error "'ln -s .' worked after removing cwd"
3846         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3847 }
3848 run_test 48b "Access removed working dir (should return errors)="
3849
3850 test_48c() { # bug 2350
3851         check_kernel_version 36 || return 0
3852         #lctl set_param debug=-1
3853         #set -vx
3854         rm -rf $DIR/$tdir
3855         test_mkdir -p $DIR/$tdir/dir
3856         cd $DIR/$tdir/dir
3857         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3858         $TRACE touch foo && error "touch foo worked after removing cwd"
3859         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3860         if check_kernel_version 44; then
3861                 touch .foo && error "touch .foo worked after removing cwd"
3862                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3863         fi
3864         $TRACE ls . && error "'ls .' worked after removing cwd"
3865         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3866         is_patchless || ( $TRACE cd . &&
3867                         error "'cd .' worked after removing cwd" )
3868         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3869         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3870         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3871         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3872 }
3873 run_test 48c "Access removed working subdir (should return errors)"
3874
3875 test_48d() { # bug 2350
3876         check_kernel_version 36 || return 0
3877         #lctl set_param debug=-1
3878         #set -vx
3879         rm -rf $DIR/$tdir
3880         test_mkdir -p $DIR/$tdir/dir
3881         cd $DIR/$tdir/dir
3882         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3883         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3884         $TRACE touch foo && error "'touch foo' worked after removing parent"
3885         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3886         if check_kernel_version 44; then
3887                 touch .foo && error "'touch .foo' worked after removing parent"
3888                 test_mkdir .foo &&
3889                               error "mkdir .foo worked after removing parent"
3890         fi
3891         $TRACE ls . && error "'ls .' worked after removing parent"
3892         $TRACE ls .. && error "'ls ..' worked after removing parent"
3893         is_patchless || ( $TRACE cd . &&
3894                         error "'cd .' worked after recreate parent" )
3895         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3896         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3897         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3898         is_patchless || ( $TRACE cd .. &&
3899                         error "'cd ..' worked after removing parent" || true )
3900 }
3901 run_test 48d "Access removed parent subdir (should return errors)"
3902
3903 test_48e() { # bug 4134
3904         check_kernel_version 41 || return 0
3905         #lctl set_param debug=-1
3906         #set -vx
3907         rm -rf $DIR/$tdir
3908         test_mkdir -p $DIR/$tdir/dir
3909         cd $DIR/$tdir/dir
3910         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3911         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3912         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3913         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3914         # On a buggy kernel addition of "touch foo" after cd .. will
3915         # produce kernel oops in lookup_hash_it
3916         touch ../foo && error "'cd ..' worked after recreate parent"
3917         cd $DIR
3918         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3919 }
3920 run_test 48e "Access to recreated parent subdir (should return errors)"
3921
3922 test_49() { # LU-1030
3923         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3924         # get ost1 size - lustre-OST0000
3925         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3926                 awk '{ print $4 }')
3927         # write 800M at maximum
3928         [[ $ost1_size -lt 2 ]] && ost1_size=2
3929         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3930
3931         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3932         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3933         local dd_pid=$!
3934
3935         # change max_pages_per_rpc while writing the file
3936         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3937         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3938         # loop until dd process exits
3939         while ps ax -opid | grep -wq $dd_pid; do
3940                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3941                 sleep $((RANDOM % 5 + 1))
3942         done
3943         # restore original max_pages_per_rpc
3944         $LCTL set_param $osc1_mppc=$orig_mppc
3945         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3946 }
3947 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3948
3949 test_50() {
3950         # bug 1485
3951         test_mkdir $DIR/$tdir
3952         cd $DIR/$tdir
3953         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3954 }
3955 run_test 50 "special situations: /proc symlinks  ==============="
3956
3957 test_51a() {    # was test_51
3958         # bug 1516 - create an empty entry right after ".." then split dir
3959         test_mkdir -c1 $DIR/$tdir
3960         touch $DIR/$tdir/foo
3961         $MCREATE $DIR/$tdir/bar
3962         rm $DIR/$tdir/foo
3963         createmany -m $DIR/$tdir/longfile 201
3964         FNUM=202
3965         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
3966                 $MCREATE $DIR/$tdir/longfile$FNUM
3967                 FNUM=$(($FNUM + 1))
3968                 echo -n "+"
3969         done
3970         echo
3971         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3972 }
3973 run_test 51a "special situations: split htree with empty entry =="
3974
3975 export NUMTEST=70000
3976 test_51b() {
3977         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3978         local BASE=$DIR/d${base}.${TESTSUITE}
3979
3980         # cleanup the directory
3981         rm -fr $BASE
3982
3983         test_mkdir -p -c1 $BASE
3984
3985         $LFS df
3986         $LFS df -i
3987         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3988         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3989         [[ $numfree -lt 21000 ]] &&
3990                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
3991                 return
3992
3993         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3994                 echo "reduced count to $NUMTEST due to inodes on MDT$mdtidx"
3995
3996         # need to check free space for the directories as well
3997         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3998         numfree=$((blkfree / 4))
3999         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$((numfree - 50)) &&
4000                 echo "reduced count to $NUMTEST due to blocks on MDT$mdtidx"
4001
4002         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
4003         {
4004                 $LFS df
4005                 $LFS df -i
4006                 echo "failed" > $BASE/fnum
4007                 error "failed to create $NUMTEST subdirs in MDT$mdtidx:$BASE"
4008         }
4009 }
4010 run_test 51b "exceed 64k subdirectory nlink limit"
4011
4012 test_51ba() { # LU-993
4013         local BASE=$DIR/d${base}.${TESTSUITE}
4014         # unlink all but 100 subdirectories, then check it still works
4015         local LEFT=100
4016         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4017
4018         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4019         local DELETE=$((NUMTEST - LEFT))
4020
4021         # continue on to run this test even if 51b didn't finish,
4022         # just to delete the many subdirectories created.
4023         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4024
4025         # for ldiskfs the nlink count should be 1, but this is OSD specific
4026         # and so this is listed for informational purposes only
4027         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4028         unlinkmany -d $BASE/d $DELETE
4029         RC=$?
4030
4031         if [ $RC -ne 0 ]; then
4032                 if [ "$NUMPREV" == "failed" ]; then
4033                         skip "previous setup failed"
4034                         return 0
4035                 else
4036                         error "unlink of first $DELETE subdirs failed"
4037                         return $RC
4038                 fi
4039         fi
4040
4041         echo "nlink between: $(stat -c %h $BASE)"
4042         # trim the first line of ls output
4043         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4044         [ $FOUND -ne $LEFT ] &&
4045                 error "can't find subdirs: found only $FOUND/$LEFT"
4046
4047         unlinkmany -d $BASE/d $DELETE $LEFT ||
4048                 error "unlink of second $LEFT subdirs failed"
4049         # regardless of whether the backing filesystem tracks nlink accurately
4050         # or not, the nlink count shouldn't be more than "." and ".." here
4051         local AFTER=$(stat -c %h $BASE)
4052         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4053                 echo "nlink after: $AFTER"
4054 }
4055 run_test 51ba "verify nlink for many subdirectory cleanup"
4056
4057 test_51d() {
4058         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4059         [[ $OSTCOUNT -lt 3 ]] &&
4060                 skip_env "skipping test with few OSTs" && return
4061         test_mkdir -p $DIR/$tdir
4062         createmany -o $DIR/$tdir/t- 1000
4063         $GETSTRIPE $DIR/$tdir > $TMP/files
4064         for N in $(seq 0 $((OSTCOUNT - 1))); do
4065                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4066                         END { printf("%0.0f", objs) }' $TMP/files)
4067                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4068                         '($1 == '$N') { objs += 1 } \
4069                         END { printf("%0.0f", objs) }')
4070                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4071         done
4072         unlinkmany $DIR/$tdir/t- 1000
4073
4074         NLAST=0
4075         for N in $(seq 1 $((OSTCOUNT - 1))); do
4076                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4077                         error "OST $N has less objects vs OST $NLAST" \
4078                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4079                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4080                         error "OST $N has less objects vs OST $NLAST" \
4081                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4082
4083                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4084                         error "OST $N has less #0 objects vs OST $NLAST" \
4085                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4086                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4087                         error "OST $N has less #0 objects vs OST $NLAST" \
4088                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4089                 NLAST=$N
4090         done
4091 }
4092 run_test 51d "check object distribution ===================="
4093
4094 test_51e() {
4095         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4096                 skip "Only applicable to ldiskfs-based MDTs"
4097                 return
4098         fi
4099
4100         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4101         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4102
4103         touch $DIR/$tdir/d0/foo
4104         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4105                 error "file exceed 65000 nlink limit!"
4106         unlinkmany $DIR/$tdir/d0/f- 65001
4107         return 0
4108 }
4109 run_test 51e "check file nlink limit"
4110
4111 test_52a() {
4112         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4113         test_mkdir -p $DIR/$tdir
4114         touch $DIR/$tdir/foo
4115         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4116         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4117         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4118         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4119         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4120                                         error "link worked"
4121         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4122         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4123         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4124                                                      error "lsattr"
4125         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4126         cp -r $DIR/$tdir /tmp/
4127         rm -fr $DIR/$tdir || error "cleanup rm failed"
4128 }
4129 run_test 52a "append-only flag test (should return errors) ====="
4130
4131 test_52b() {
4132         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4133         test_mkdir -p $DIR/$tdir
4134         touch $DIR/$tdir/foo
4135         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4136         cat test > $DIR/$tdir/foo && error "cat test worked"
4137         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4138         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4139         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4140                                         error "link worked"
4141         echo foo >> $DIR/$tdir/foo && error "echo worked"
4142         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4143         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4144         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4145         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4146                                                         error "lsattr"
4147         chattr -i $DIR/$tdir/foo || error "chattr failed"
4148
4149         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4150 }
4151 run_test 52b "immutable flag test (should return errors) ======="
4152
4153 test_53() {
4154         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4155         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4156         remote_ost_nodsh && skip "remote OST with nodsh" && return
4157
4158         local param
4159         local param_seq
4160         local ostname
4161         local mds_last
4162         local mds_last_seq
4163         local ost_last
4164         local ost_last_seq
4165         local ost_last_id
4166         local ostnum
4167         local node
4168         local found=false
4169         local support_last_seq=true
4170
4171         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4172                 support_last_seq=false
4173
4174         # only test MDT0000
4175         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4176         local value
4177         for value in $(do_facet $SINGLEMDS \
4178                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4179                 param=$(echo ${value[0]} | cut -d "=" -f1)
4180                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4181
4182                 if $support_last_seq; then
4183                         param_seq=$(echo $param |
4184                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4185                         mds_last_seq=$(do_facet $SINGLEMDS \
4186                                        $LCTL get_param -n $param_seq)
4187                 fi
4188                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4189
4190                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4191                 node=$(facet_active_host ost$((ostnum+1)))
4192                 param="obdfilter.$ostname.last_id"
4193                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4194                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4195                         ost_last_id=$ost_last
4196
4197                         if $support_last_seq; then
4198                                 ost_last_id=$(echo $ost_last |
4199                                               awk -F':' '{print $2}' |
4200                                               sed -e "s/^0x//g")
4201                                 ost_last_seq=$(echo $ost_last |
4202                                                awk -F':' '{print $1}')
4203                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4204                         fi
4205
4206                         if [[ $ost_last_id != $mds_last ]]; then
4207                                 error "$ost_last_id != $mds_last"
4208                         else
4209                                 found=true
4210                                 break
4211                         fi
4212                 done
4213         done
4214         $found || error "can not match last_seq/last_id for $mdtosc"
4215         return 0
4216 }
4217 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4218
4219 test_54a() {
4220         $SOCKETSERVER $DIR/socket ||
4221                 error "$SOCKETSERVER $DIR/socket failed: $?"
4222         $SOCKETCLIENT $DIR/socket ||
4223                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4224         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4225 }
4226 run_test 54a "unix domain socket test =========================="
4227
4228 test_54b() {
4229         f="$DIR/f54b"
4230         mknod $f c 1 3
4231         chmod 0666 $f
4232         dd if=/dev/zero of=$f bs=$(page_size) count=1
4233 }
4234 run_test 54b "char device works in lustre ======================"
4235
4236 find_loop_dev() {
4237         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4238         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4239         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4240
4241         for i in $(seq 3 7); do
4242                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4243                 LOOPDEV=$LOOPBASE$i
4244                 LOOPNUM=$i
4245                 break
4246         done
4247 }
4248
4249 cleanup_54c() {
4250         loopdev="$DIR/loop54c"
4251
4252         trap 0
4253         $UMOUNT -d $DIR/$tdir || rc=$?
4254         losetup -d $loopdev || true
4255         losetup -d $LOOPDEV || true
4256         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4257         return $rc
4258 }
4259
4260 test_54c() {
4261         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4262         loopdev="$DIR/loop54c"
4263
4264         find_loop_dev
4265         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4266         trap cleanup_54c EXIT
4267         mknod $loopdev b 7 $LOOPNUM
4268         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4269         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4270         losetup $loopdev $DIR/$tfile ||
4271                 error "can't set up $loopdev for $DIR/$tfile"
4272         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4273         test_mkdir -p $DIR/$tdir
4274         mount -t ext2 $loopdev $DIR/$tdir ||
4275                 error "error mounting $loopdev on $DIR/$tdir"
4276         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4277                 error "dd write"
4278         df $DIR/$tdir
4279         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4280                 error "dd read"
4281         cleanup_54c
4282 }
4283 run_test 54c "block device works in lustre ====================="
4284
4285 test_54d() {
4286         f="$DIR/f54d"
4287         string="aaaaaa"
4288         mknod $f p
4289         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4290 }
4291 run_test 54d "fifo device works in lustre ======================"
4292
4293 test_54e() {
4294         check_kernel_version 46 || return 0
4295         f="$DIR/f54e"
4296         string="aaaaaa"
4297         cp -aL /dev/console $f
4298         echo $string > $f || error "echo $string to $f failed"
4299 }
4300 run_test 54e "console/tty device works in lustre ======================"
4301
4302 #The test_55 used to be iopen test and it was removed by bz#24037.
4303 #run_test 55 "check iopen_connect_dentry() ======================"
4304
4305 test_56a() {    # was test_56
4306         rm -rf $DIR/$tdir
4307         $SETSTRIPE -d $DIR
4308         test_mkdir -p $DIR/$tdir/dir
4309         NUMFILES=3
4310         NUMFILESx2=$(($NUMFILES * 2))
4311         for i in $(seq 1 $NUMFILES); do
4312                 touch $DIR/$tdir/file$i
4313                 touch $DIR/$tdir/dir/file$i
4314         done
4315
4316         # test lfs getstripe with --recursive
4317         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4318         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4319                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4320         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4321         [[ $FILENUM -eq $NUMFILES ]] ||
4322                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4323         echo "$GETSTRIPE --recursive passed."
4324
4325         # test lfs getstripe with file instead of dir
4326         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4327         [[ $FILENUM -eq 1 ]] ||
4328                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4329         echo "$GETSTRIPE file1 passed."
4330
4331         #test lfs getstripe with --verbose
4332         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4333                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4334                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4335         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4336                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4337         echo "$GETSTRIPE --verbose passed."
4338
4339         #test lfs getstripe with --obd
4340         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4341                 grep -q "unknown obduuid" ||
4342                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4343
4344         [[ $OSTCOUNT -lt 2 ]] &&
4345                 skip_env "skipping other $GETSTRIPE --obd test" && return
4346
4347         OSTIDX=1
4348         OBDUUID=$(ostuuid_from_index $OSTIDX)
4349         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4350         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4351         [[ $FOUND -eq $FILENUM ]] ||
4352                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4353         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4354                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4355                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4356                 error "$GETSTRIPE --obd: should not show file on other obd"
4357         echo "$GETSTRIPE --obd passed"
4358 }
4359 run_test 56a "check $GETSTRIPE"
4360
4361 NUMFILES=3
4362 NUMDIRS=3
4363 setup_56() {
4364         local LOCAL_NUMFILES="$1"
4365         local LOCAL_NUMDIRS="$2"
4366         local MKDIR_PARAMS="$3"
4367         local DIR_STRIPE_PARAMS="$4"
4368
4369         if [ ! -d "$TDIR" ] ; then
4370                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4371                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4372                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4373                         touch $TDIR/file$i
4374                 done
4375                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4376                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4377                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4378                                 touch $TDIR/dir$i/file$j
4379                         done
4380                 done
4381         fi
4382 }
4383
4384 setup_56_special() {
4385         LOCAL_NUMFILES=$1
4386         LOCAL_NUMDIRS=$2
4387         setup_56 $1 $2
4388         if [ ! -e "$TDIR/loop1b" ] ; then
4389                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4390                         mknod $TDIR/loop${i}b b 7 $i
4391                         mknod $TDIR/null${i}c c 1 3
4392                         ln -s $TDIR/file1 $TDIR/link${i}l
4393                 done
4394                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4395                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4396                         mknod $TDIR/dir$i/null${i}c c 1 3
4397                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4398                 done
4399         fi
4400 }
4401
4402 test_56g() {
4403         $SETSTRIPE -d $DIR
4404
4405         TDIR=$DIR/${tdir}g
4406         setup_56 $NUMFILES $NUMDIRS
4407
4408         EXPECTED=$(($NUMDIRS + 2))
4409         # test lfs find with -name
4410         for i in $(seq 1 $NUMFILES) ; do
4411                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4412                 [ $NUMS -eq $EXPECTED ] ||
4413                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4414                               "found $NUMS, expected $EXPECTED"
4415         done
4416 }
4417 run_test 56g "check lfs find -name ============================="
4418
4419 test_56h() {
4420         $SETSTRIPE -d $DIR
4421
4422         TDIR=$DIR/${tdir}g
4423         setup_56 $NUMFILES $NUMDIRS
4424
4425         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4426         # test lfs find with ! -name
4427         for i in $(seq 1 $NUMFILES) ; do
4428                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4429                 [ $NUMS -eq $EXPECTED ] ||
4430                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4431                               "found $NUMS, expected $EXPECTED"
4432         done
4433 }
4434 run_test 56h "check lfs find ! -name ============================="
4435
4436 test_56i() {
4437        tdir=${tdir}i
4438        test_mkdir -p $DIR/$tdir
4439        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4440        CMD="$LFIND -ost $UUID $DIR/$tdir"
4441        OUT=$($CMD)
4442        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4443 }
4444 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4445
4446 test_56j() {
4447         TDIR=$DIR/${tdir}g
4448         setup_56_special $NUMFILES $NUMDIRS
4449
4450         EXPECTED=$((NUMDIRS + 1))
4451         CMD="$LFIND -type d $TDIR"
4452         NUMS=$($CMD | wc -l)
4453         [ $NUMS -eq $EXPECTED ] ||
4454                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4455 }
4456 run_test 56j "check lfs find -type d ============================="
4457
4458 test_56k() {
4459         TDIR=$DIR/${tdir}g
4460         setup_56_special $NUMFILES $NUMDIRS
4461
4462         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4463         CMD="$LFIND -type f $TDIR"
4464         NUMS=$($CMD | wc -l)
4465         [ $NUMS -eq $EXPECTED ] ||
4466                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4467 }
4468 run_test 56k "check lfs find -type f ============================="
4469
4470 test_56l() {
4471         TDIR=$DIR/${tdir}g
4472         setup_56_special $NUMFILES $NUMDIRS
4473
4474         EXPECTED=$((NUMDIRS + NUMFILES))
4475         CMD="$LFIND -type b $TDIR"
4476         NUMS=$($CMD | wc -l)
4477         [ $NUMS -eq $EXPECTED ] ||
4478                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4479 }
4480 run_test 56l "check lfs find -type b ============================="
4481
4482 test_56m() {
4483         TDIR=$DIR/${tdir}g
4484         setup_56_special $NUMFILES $NUMDIRS
4485
4486         EXPECTED=$((NUMDIRS + NUMFILES))
4487         CMD="$LFIND -type c $TDIR"
4488         NUMS=$($CMD | wc -l)
4489         [ $NUMS -eq $EXPECTED ] ||
4490                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4491 }
4492 run_test 56m "check lfs find -type c ============================="
4493
4494 test_56n() {
4495         TDIR=$DIR/${tdir}g
4496         setup_56_special $NUMFILES $NUMDIRS
4497
4498         EXPECTED=$((NUMDIRS + NUMFILES))
4499         CMD="$LFIND -type l $TDIR"
4500         NUMS=$($CMD | wc -l)
4501         [ $NUMS -eq $EXPECTED ] ||
4502                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4503 }
4504 run_test 56n "check lfs find -type l ============================="
4505
4506 test_56o() {
4507         TDIR=$DIR/${tdir}o
4508         setup_56 $NUMFILES $NUMDIRS
4509         utime $TDIR/file1 > /dev/null || error "utime (1)"
4510         utime $TDIR/file2 > /dev/null || error "utime (2)"
4511         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4512         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4513         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4514         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4515
4516         EXPECTED=4
4517         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4518         [ $NUMS -eq $EXPECTED ] || \
4519                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4520
4521         EXPECTED=12
4522         CMD="$LFIND -mtime 0 $TDIR"
4523         NUMS=$($CMD | wc -l)
4524         [ $NUMS -eq $EXPECTED ] ||
4525                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4526 }
4527 run_test 56o "check lfs find -mtime for old files =========================="
4528
4529 test_56p() {
4530         [ $RUNAS_ID -eq $UID ] &&
4531                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4532
4533         TDIR=$DIR/${tdir}p
4534         setup_56 $NUMFILES $NUMDIRS
4535
4536         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4537         EXPECTED=$NUMFILES
4538         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4539         NUMS=$($CMD | wc -l)
4540         [ $NUMS -eq $EXPECTED ] || \
4541                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4542
4543         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4544         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4545         NUMS=$($CMD | wc -l)
4546         [ $NUMS -eq $EXPECTED ] || \
4547                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4548 }
4549 run_test 56p "check lfs find -uid and ! -uid ==============================="
4550
4551 test_56q() {
4552         [ $RUNAS_ID -eq $UID ] &&
4553                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4554
4555         TDIR=$DIR/${tdir}q
4556         setup_56 $NUMFILES $NUMDIRS
4557
4558         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4559
4560         EXPECTED=$NUMFILES
4561         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4562         NUMS=$($CMD | wc -l)
4563         [ $NUMS -eq $EXPECTED ] ||
4564                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4565
4566         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4567         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4568         NUMS=$($CMD | wc -l)
4569         [ $NUMS -eq $EXPECTED ] ||
4570                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4571 }
4572 run_test 56q "check lfs find -gid and ! -gid ==============================="
4573
4574 test_56r() {
4575         TDIR=$DIR/${tdir}r
4576         setup_56 $NUMFILES $NUMDIRS
4577
4578         EXPECTED=12
4579         CMD="$LFIND -size 0 -type f $TDIR"
4580         NUMS=$($CMD | wc -l)
4581         [ $NUMS -eq $EXPECTED ] ||
4582                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4583         EXPECTED=0
4584         CMD="$LFIND ! -size 0 -type f $TDIR"
4585         NUMS=$($CMD | wc -l)
4586         [ $NUMS -eq $EXPECTED ] ||
4587                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4588         echo "test" > $TDIR/$tfile
4589         echo "test2" > $TDIR/$tfile.2 && sync
4590         EXPECTED=1
4591         CMD="$LFIND -size 5 -type f $TDIR"
4592         NUMS=$($CMD | wc -l)
4593         [ $NUMS -eq $EXPECTED ] ||
4594                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4595         EXPECTED=1
4596         CMD="$LFIND -size +5 -type f $TDIR"
4597         NUMS=$($CMD | wc -l)
4598         [ $NUMS -eq $EXPECTED ] ||
4599                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4600         EXPECTED=2
4601         CMD="$LFIND -size +0 -type f $TDIR"
4602         NUMS=$($CMD | wc -l)
4603         [ $NUMS -eq $EXPECTED ] ||
4604                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4605         EXPECTED=2
4606         CMD="$LFIND ! -size -5 -type f $TDIR"
4607         NUMS=$($CMD | wc -l)
4608         [ $NUMS -eq $EXPECTED ] ||
4609                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4610         EXPECTED=12
4611         CMD="$LFIND -size -5 -type f $TDIR"
4612         NUMS=$($CMD | wc -l)
4613         [ $NUMS -eq $EXPECTED ] ||
4614                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4615 }
4616 run_test 56r "check lfs find -size works =========================="
4617
4618 test_56s() { # LU-611
4619         TDIR=$DIR/${tdir}s
4620         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4621
4622         if [[ $OSTCOUNT -gt 1 ]]; then
4623                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4624                 ONESTRIPE=4
4625                 EXTRA=4
4626         else
4627                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4628                 EXTRA=0
4629         fi
4630
4631         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4632         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4633         NUMS=$($CMD | wc -l)
4634         [ $NUMS -eq $EXPECTED ] || {
4635                 $GETSTRIPE -R $TDIR
4636                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4637         }
4638
4639         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4640         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4641         NUMS=$($CMD | wc -l)
4642         [ $NUMS -eq $EXPECTED ] || {
4643                 $GETSTRIPE -R $TDIR
4644                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4645         }
4646
4647         EXPECTED=$ONESTRIPE
4648         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4649         NUMS=$($CMD | wc -l)
4650         [ $NUMS -eq $EXPECTED ] || {
4651                 $GETSTRIPE -R $TDIR
4652                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4653         }
4654
4655         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4656         NUMS=$($CMD | wc -l)
4657         [ $NUMS -eq $EXPECTED ] || {
4658                 $GETSTRIPE -R $TDIR
4659                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4660         }
4661
4662         EXPECTED=0
4663         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4664         NUMS=$($CMD | wc -l)
4665         [ $NUMS -eq $EXPECTED ] || {
4666                 $GETSTRIPE -R $TDIR
4667                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4668         }
4669 }
4670 run_test 56s "check lfs find -stripe-count works"
4671
4672 test_56t() { # LU-611
4673         TDIR=$DIR/${tdir}t
4674         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4675
4676         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4677
4678         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4679         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4680         NUMS=$($CMD | wc -l)
4681         [ $NUMS -eq $EXPECTED ] ||
4682                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4683
4684         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4685         NUMS=$($CMD | wc -l)
4686         [ $NUMS -eq $EXPECTED ] ||
4687                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4688
4689         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4690         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4691         NUMS=$($CMD | wc -l)
4692         [ $NUMS -eq $EXPECTED ] ||
4693                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4694
4695         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4696         NUMS=$($CMD | wc -l)
4697         [ $NUMS -eq $EXPECTED ] ||
4698                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4699
4700         EXPECTED=4
4701         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4702         NUMS=$($CMD | wc -l)
4703         [ $NUMS -eq $EXPECTED ] ||
4704                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4705
4706         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4707         NUMS=$($CMD | wc -l)
4708         [ $NUMS -eq $EXPECTED ] ||
4709                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4710
4711         EXPECTED=0
4712         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4713         NUMS=$($CMD | wc -l)
4714         [ $NUMS -eq $EXPECTED ] ||
4715                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4716 }
4717 run_test 56t "check lfs find -stripe-size works"
4718
4719 test_56u() { # LU-611
4720         TDIR=$DIR/${tdir}u
4721         setup_56 $NUMFILES $NUMDIRS "-i 0"
4722
4723         if [[ $OSTCOUNT -gt 1 ]]; then
4724                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4725                 ONESTRIPE=4
4726         else
4727                 ONESTRIPE=0
4728         fi
4729
4730         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4731         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4732         NUMS=$($CMD | wc -l)
4733         [ $NUMS -eq $EXPECTED ] ||
4734                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4735
4736         EXPECTED=$ONESTRIPE
4737         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4738         NUMS=$($CMD | wc -l)
4739         [ $NUMS -eq $EXPECTED ] ||
4740                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4741
4742         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4743         NUMS=$($CMD | wc -l)
4744         [ $NUMS -eq $EXPECTED ] ||
4745                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4746
4747         EXPECTED=0
4748         # This should produce an error and not return any files
4749         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4750         NUMS=$($CMD 2>/dev/null | wc -l)
4751         [ $NUMS -eq $EXPECTED ] ||
4752                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4753
4754         if [[ $OSTCOUNT -gt 1 ]]; then
4755                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4756                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4757                 NUMS=$($CMD | wc -l)
4758                 [ $NUMS -eq $EXPECTED ] ||
4759                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4760         fi
4761 }
4762 run_test 56u "check lfs find -stripe-index works"
4763
4764 test_56v() {
4765     local MDT_IDX=0
4766
4767     TDIR=$DIR/${tdir}v
4768     rm -rf $TDIR
4769     setup_56 $NUMFILES $NUMDIRS
4770
4771     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4772     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4773
4774     for file in $($LFIND -mdt $UUID $TDIR); do
4775         file_mdt_idx=$($GETSTRIPE -M $file)
4776         [ $file_mdt_idx -eq $MDT_IDX ] ||
4777             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4778     done
4779 }
4780 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4781
4782 test_56w() {
4783         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4784         TDIR=$DIR/${tdir}w
4785
4786     rm -rf $TDIR || error "remove $TDIR failed"
4787     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4788
4789     local stripe_size
4790     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4791         error "$GETSTRIPE -S -d $TDIR failed"
4792     stripe_size=${stripe_size%% *}
4793
4794     local file_size=$((stripe_size * OSTCOUNT))
4795     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4796     local required_space=$((file_num * file_size))
4797     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4798     [[ $free_space -le $((required_space / 1024)) ]] &&
4799         skip_env "need at least $required_space bytes free space," \
4800                  "have $free_space kbytes" && return
4801
4802     local dd_bs=65536
4803     local dd_count=$((file_size / dd_bs))
4804
4805     # write data into the files
4806     local i
4807     local j
4808     local file
4809     for i in $(seq 1 $NUMFILES); do
4810         file=$TDIR/file$i
4811         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4812             error "write data into $file failed"
4813     done
4814     for i in $(seq 1 $NUMDIRS); do
4815         for j in $(seq 1 $NUMFILES); do
4816             file=$TDIR/dir$i/file$j
4817             yes | dd bs=$dd_bs count=$dd_count of=$file \
4818                 >/dev/null 2>&1 ||
4819                 error "write data into $file failed"
4820         done
4821     done
4822
4823     local expected=-1
4824     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4825
4826     # lfs_migrate file
4827     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4828     echo "$cmd"
4829     eval $cmd || error "$cmd failed"
4830
4831     check_stripe_count $TDIR/file1 $expected
4832
4833         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
4834         then
4835                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
4836                 # OST 1 if it is on OST 0. This file is small enough to
4837                 # be on only one stripe.
4838                 file=$TDIR/migr_1_ost
4839                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
4840                         error "write data into $file failed"
4841                 local obdidx=$($LFS getstripe -i $file)
4842                 local oldmd5=$(md5sum $file)
4843                 local newobdidx=0
4844                 [[ $obdidx -eq 0 ]] && newobdidx=1
4845                 cmd="$LFS migrate -i $newobdidx $file"
4846                 echo $cmd
4847                 eval $cmd || error "$cmd failed"
4848                 local realobdix=$($LFS getstripe -i $file)
4849                 local newmd5=$(md5sum $file)
4850                 [[ $newobdidx -ne $realobdix ]] &&
4851                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
4852                 [[ "$oldmd5" != "$newmd5" ]] &&
4853                         error "md5sum differ: $oldmd5, $newmd5"
4854         fi
4855
4856     # lfs_migrate dir
4857     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4858     echo "$cmd"
4859     eval $cmd || error "$cmd failed"
4860
4861     for j in $(seq 1 $NUMFILES); do
4862         check_stripe_count $TDIR/dir1/file$j $expected
4863     done
4864
4865     # lfs_migrate works with lfs find
4866     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4867          $LFS_MIGRATE -y -c $expected"
4868     echo "$cmd"
4869     eval $cmd || error "$cmd failed"
4870
4871     for i in $(seq 2 $NUMFILES); do
4872         check_stripe_count $TDIR/file$i $expected
4873     done
4874     for i in $(seq 2 $NUMDIRS); do
4875         for j in $(seq 1 $NUMFILES); do
4876             check_stripe_count $TDIR/dir$i/file$j $expected
4877         done
4878     done
4879 }
4880 run_test 56w "check lfs_migrate -c stripe_count works"
4881
4882 test_56x() {
4883         check_swap_layouts_support && return 0
4884         [[ $OSTCOUNT -lt 2 ]] &&
4885                 skip_env "need 2 OST, skipping test" && return
4886
4887         local dir0=$DIR/$tdir/$testnum
4888         mkdir -p $dir0 || error "creating dir $dir0"
4889
4890         local ref1=/etc/passwd
4891         local file1=$dir0/file1
4892
4893         $SETSTRIPE -c 2 $file1
4894         cp $ref1 $file1
4895         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4896         stripe=$($GETSTRIPE -c $file1)
4897         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4898         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4899
4900         # clean up
4901         rm -f $file1
4902 }
4903 run_test 56x "lfs migration support"
4904
4905 test_56y() {
4906         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4907                 skip "No HSM support on MDS of $(get_lustre_version)," \
4908                          "need 2.4.53 at least" && return
4909         local res=""
4910
4911         local dir0=$DIR/$tdir/$testnum
4912         mkdir -p $dir0 || error "creating dir $dir0"
4913         local f1=$dir0/file1
4914         local f2=$dir0/file2
4915
4916         touch $f1 || error "creating std file $f1"
4917         $MULTIOP $f2 H2c || error "creating released file $f2"
4918
4919         # a directory can be raid0, so ask only for files
4920         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4921         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4922
4923         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4924         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4925
4926         # only files can be released, so no need to force file search
4927         res=$($LFIND $dir0 -L released)
4928         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4929
4930         res=$($LFIND $dir0 \! -L released)
4931         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4932
4933 }
4934 run_test 56y "lfs find -L raid0|released"
4935
4936 test_56z() { # LU-4824
4937         # This checks to make sure 'lfs find' continues after errors
4938         # There are two classes of errors that should be caught:
4939         # - If multiple paths are provided, all should be searched even if one
4940         #   errors out
4941         # - If errors are encountered during the search, it should not terminate
4942         #   early
4943         local i
4944         test_mkdir $DIR/$tdir
4945         for i in d{0..9}; do
4946                 test_mkdir $DIR/$tdir/$i
4947         done
4948         touch $DIR/$tdir/d{0..9}/$tfile
4949         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
4950                 error "$LFS find did not return an error"
4951         # Make a directory unsearchable. This should NOT be the last entry in
4952         # directory order.  Arbitrarily pick the 6th entry
4953         chmod 700 $(lfs find $DIR/$tdir -type d | sed '6!d')
4954         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
4955         # The user should be able to see 10 directories and 9 files
4956         [ $count == 19 ] || error "$LFS find did not continue after error"
4957 }
4958 run_test 56z "lfs find should continue after an error"
4959
4960 test_57a() {
4961         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4962         # note test will not do anything if MDS is not local
4963         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4964                 skip "Only applicable to ldiskfs-based MDTs"
4965                 return
4966         fi
4967
4968         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4969         local MNTDEV="osd*.*MDT*.mntdev"
4970         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4971         [ -z "$DEV" ] && error "can't access $MNTDEV"
4972         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4973                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4974                         error "can't access $DEV"
4975                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
4976                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
4977                 rm $TMP/t57a.dump
4978         done
4979 }
4980 run_test 57a "verify MDS filesystem created with large inodes =="
4981
4982 test_57b() {
4983         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4984         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4985                 skip "Only applicable to ldiskfs-based MDTs"
4986                 return
4987         fi
4988
4989         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4990         local dir=$DIR/d57b
4991
4992         local FILECOUNT=100
4993         local FILE1=$dir/f1
4994         local FILEN=$dir/f$FILECOUNT
4995
4996         rm -rf $dir || error "removing $dir"
4997         test_mkdir -p $dir || error "creating $dir"
4998         local num=$(get_mds_dir $dir)
4999         local mymds=mds$num
5000
5001         echo "mcreating $FILECOUNT files"
5002         createmany -m $dir/f 1 $FILECOUNT || \
5003                 error "creating files in $dir"
5004
5005         # verify that files do not have EAs yet
5006         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5007         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5008
5009         sync
5010         sleep 1
5011         df $dir  #make sure we get new statfs data
5012         local MDSFREE=$(do_facet $mymds \
5013                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
5014         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
5015         echo "opening files to create objects/EAs"
5016         local FILE
5017         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5018                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5019         done
5020
5021         # verify that files have EAs now
5022         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5023         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5024
5025         sleep 1  #make sure we get new statfs data
5026         df $dir
5027         local MDSFREE2=$(do_facet $mymds \
5028                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
5029         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
5030         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5031                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5032                         error "MDC before $MDCFREE != after $MDCFREE2"
5033                 else
5034                         echo "MDC before $MDCFREE != after $MDCFREE2"
5035                         echo "unable to confirm if MDS has large inodes"
5036                 fi
5037         fi
5038         rm -rf $dir
5039 }
5040 run_test 57b "default LOV EAs are stored inside large inodes ==="
5041
5042 test_58() {
5043         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5044         [ -z "$(which wiretest 2>/dev/null)" ] &&
5045                         skip_env "could not find wiretest" && return
5046         wiretest
5047 }
5048 run_test 58 "verify cross-platform wire constants =============="
5049
5050 test_59() {
5051         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5052         echo "touch 130 files"
5053         createmany -o $DIR/f59- 130
5054         echo "rm 130 files"
5055         unlinkmany $DIR/f59- 130
5056         sync
5057         # wait for commitment of removal
5058         wait_delete_completed
5059 }
5060 run_test 59 "verify cancellation of llog records async ========="
5061
5062 TEST60_HEAD="test_60 run $RANDOM"
5063 test_60a() {
5064         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5065         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5066         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5067                 skip_env "missing subtest run-llog.sh" && return
5068         log "$TEST60_HEAD - from kernel mode"
5069         do_facet mgs sh run-llog.sh
5070 }
5071 run_test 60a "llog sanity tests run from kernel module =========="
5072
5073 test_60b() { # bug 6411
5074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5075         dmesg > $DIR/$tfile
5076         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5077                                  /llog.test/ {
5078                                          if (marker)
5079                                                  from_marker++
5080                                          from_begin++
5081                                  }
5082                                  END {
5083                                          if (marker)
5084                                                  print from_marker
5085                                          else
5086                                                  print from_begin
5087                                  }"`
5088         [[ $LLOG_COUNT -gt 50 ]] &&
5089                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5090 }
5091 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5092
5093 test_60c() {
5094         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5095         echo "create 5000 files"
5096         createmany -o $DIR/f60c- 5000
5097 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5098         lctl set_param fail_loc=0x80000137
5099         unlinkmany $DIR/f60c- 5000
5100         lctl set_param fail_loc=0
5101 }
5102 run_test 60c "unlink file when mds full"
5103
5104 test_60d() {
5105         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5106         SAVEPRINTK=$(lctl get_param -n printk)
5107
5108         # verify "lctl mark" is even working"
5109         MESSAGE="test message ID $RANDOM $$"
5110         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5111         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5112
5113         lctl set_param printk=0 || error "set lnet.printk failed"
5114         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5115         MESSAGE="new test message ID $RANDOM $$"
5116         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5117         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5118         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5119
5120         lctl set_param -n printk="$SAVEPRINTK"
5121 }
5122 run_test 60d "test printk console message masking"
5123
5124 test_61() {
5125         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5126         f="$DIR/f61"
5127         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5128         cancel_lru_locks osc
5129         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5130         sync
5131 }
5132 run_test 61 "mmap() writes don't make sync hang ================"
5133
5134 # bug 2330 - insufficient obd_match error checking causes LBUG
5135 test_62() {
5136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5137         f="$DIR/f62"
5138         echo foo > $f
5139         cancel_lru_locks osc
5140         lctl set_param fail_loc=0x405
5141         cat $f && error "cat succeeded, expect -EIO"
5142         lctl set_param fail_loc=0
5143 }
5144 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5145 # match every page all of the time.
5146 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5147
5148 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5149 # Though this test is irrelevant anymore, it helped to reveal some
5150 # other grant bugs (LU-4482), let's keep it.
5151 test_63a() {   # was test_63
5152         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5153         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5154         for i in `seq 10` ; do
5155                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5156                 sleep 5
5157                 kill $!
5158                 sleep 1
5159         done
5160
5161         rm -f $DIR/f63 || true
5162 }
5163 run_test 63a "Verify oig_wait interruption does not crash ======="
5164
5165 # bug 2248 - async write errors didn't return to application on sync
5166 # bug 3677 - async write errors left page locked
5167 test_63b() {
5168         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5169         debugsave
5170         lctl set_param debug=-1
5171
5172         # ensure we have a grant to do async writes
5173         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5174         rm $DIR/$tfile
5175
5176         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5177         lctl set_param fail_loc=0x80000406
5178         $MULTIOP $DIR/$tfile Owy && \
5179                 error "sync didn't return ENOMEM"
5180         sync; sleep 2; sync     # do a real sync this time to flush page
5181         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5182                 error "locked page left in cache after async error" || true
5183         debugrestore
5184 }
5185 run_test 63b "async write errors should be returned to fsync ==="
5186
5187 test_64a () {
5188         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5189         df $DIR
5190         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5191 }
5192 run_test 64a "verify filter grant calculations (in kernel) ====="
5193
5194 test_64b () {
5195         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5196         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5197 }
5198 run_test 64b "check out-of-space detection on client ==========="
5199
5200 test_64c() {
5201         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5202 }
5203 run_test 64c "verify grant shrink ========================------"
5204
5205 # bug 1414 - set/get directories' stripe info
5206 test_65a() {
5207         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5208         test_mkdir -p $DIR/$tdir
5209         touch $DIR/$tdir/f1
5210         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5211 }
5212 run_test 65a "directory with no stripe info ===================="
5213
5214 test_65b() {
5215         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5216         test_mkdir -p $DIR/$tdir
5217         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5218                                                 error "setstripe"
5219         touch $DIR/$tdir/f2
5220         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5221 }
5222 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5223
5224 test_65c() {
5225         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5226         if [[ $OSTCOUNT -gt 1 ]]; then
5227                 test_mkdir -p $DIR/$tdir
5228                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5229                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5230                 touch $DIR/$tdir/f3
5231                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5232         fi
5233 }
5234 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5235
5236 test_65d() {
5237         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5238         test_mkdir -p $DIR/$tdir
5239         if [[ $STRIPECOUNT -le 0 ]]; then
5240                 sc=1
5241         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5242 #LOV_MAX_STRIPE_COUNT is 2000
5243                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5244         else
5245                 sc=$(($STRIPECOUNT - 1))
5246         fi
5247         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5248         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5249         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5250                 error "lverify failed"
5251 }
5252 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5253
5254 test_65e() {
5255         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5256         test_mkdir -p $DIR/$tdir
5257
5258         $SETSTRIPE $DIR/$tdir || error "setstripe"
5259         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5260                                         error "no stripe info failed"
5261         touch $DIR/$tdir/f6
5262         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5263 }
5264 run_test 65e "directory setstripe defaults ======================="
5265
5266 test_65f() {
5267         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5268         test_mkdir -p $DIR/${tdir}f
5269         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5270 }
5271 run_test 65f "dir setstripe permission (should return error) ==="
5272
5273 test_65g() {
5274         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5275         test_mkdir -p $DIR/$tdir
5276         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5277                                                         error "setstripe"
5278         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5279         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5280                 error "delete default stripe failed"
5281 }
5282 run_test 65g "directory setstripe -d ==========================="
5283
5284 test_65h() {
5285         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5286         test_mkdir -p $DIR/$tdir
5287         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5288                                                         error "setstripe"
5289         test_mkdir -p $DIR/$tdir/dd1
5290         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5291                 error "stripe info inherit failed"
5292 }
5293 run_test 65h "directory stripe info inherit ===================="
5294
5295 test_65i() { # bug6367
5296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5297         $SETSTRIPE -S 65536 -c -1 $MOUNT
5298 }
5299 run_test 65i "set non-default striping on root directory (bug 6367)="
5300
5301 test_65ia() { # bug12836
5302         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5303         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5304 }
5305 run_test 65ia "getstripe on -1 default directory striping"
5306
5307 test_65ib() { # bug12836
5308         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5309         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5310 }
5311 run_test 65ib "getstripe -v on -1 default directory striping"
5312
5313 test_65ic() { # bug12836
5314         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5315         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5316 }
5317 run_test 65ic "new find on -1 default directory striping"
5318
5319 test_65j() { # bug6367
5320         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5321         sync; sleep 1
5322         # if we aren't already remounting for each test, do so for this test
5323         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5324                 cleanup || error "failed to unmount"
5325                 setup
5326         fi
5327         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5328 }
5329 run_test 65j "set default striping on root directory (bug 6367)="
5330
5331 test_65k() { # bug11679
5332         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5333         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5334         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5335
5336     echo "Check OST status: "
5337     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5338               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5339
5340     for OSC in $MDS_OSCS; do
5341         echo $OSC "is activate"
5342         do_facet $SINGLEMDS lctl --device %$OSC activate
5343     done
5344
5345     mkdir -p $DIR/$tdir
5346     for INACTIVE_OSC in $MDS_OSCS; do
5347         echo "Deactivate: " $INACTIVE_OSC
5348         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5349         for STRIPE_OSC in $MDS_OSCS; do
5350             OST=`osc_to_ost $STRIPE_OSC`
5351             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5352                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5353
5354             [ -f $DIR/$tdir/$IDX ] && continue
5355             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5356             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5357             RC=$?
5358             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5359         done
5360         rm -f $DIR/$tdir/*
5361         echo $INACTIVE_OSC "is Activate."
5362         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5363     done
5364 }
5365 run_test 65k "validate manual striping works properly with deactivated OSCs"
5366
5367 test_65l() { # bug 12836
5368         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5369         test_mkdir -p $DIR/$tdir/test_dir
5370         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5371         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5372 }
5373 run_test 65l "lfs find on -1 stripe dir ========================"
5374
5375 # bug 2543 - update blocks count on client
5376 test_66() {
5377         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5378         COUNT=${COUNT:-8}
5379         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5380         sync; sync_all_data; sync; sync_all_data
5381         cancel_lru_locks osc
5382         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5383         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5384 }
5385 run_test 66 "update inode blocks count on client ==============="
5386
5387 LLOOP=
5388 LLITELOOPLOAD=
5389 cleanup_68() {
5390         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5391         trap 0
5392         if [ ! -z "$LLOOP" ]; then
5393                 if swapon -s | grep -q $LLOOP; then
5394                         swapoff $LLOOP || error "swapoff failed"
5395                 fi
5396
5397                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5398                 rm -f $LLOOP
5399                 unset LLOOP
5400         fi
5401         if [ ! -z "$LLITELOOPLOAD" ]; then
5402                 rmmod llite_lloop
5403                 unset LLITELOOPLOAD
5404         fi
5405         rm -f $DIR/f68*
5406 }
5407
5408 meminfo() {
5409         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5410 }
5411
5412 swap_used() {
5413         swapon -s | awk '($1 == "'$1'") { print $4 }'
5414 }
5415
5416 # test case for lloop driver, basic function
5417 test_68a() {
5418         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5419         [ "$UID" != 0 ] && skip_env "must run as root" && return
5420         llite_lloop_enabled || \
5421                 { skip_env "llite_lloop module disabled" && return; }
5422
5423         trap cleanup_68 EXIT
5424
5425         if ! module_loaded llite_lloop; then
5426                 if load_module llite/llite_lloop; then
5427                         LLITELOOPLOAD=yes
5428                 else
5429                         skip_env "can't find module llite_lloop"
5430                         return
5431                 fi
5432         fi
5433
5434         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5435         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5436         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5437
5438         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5439         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5440
5441         cleanup_68
5442 }
5443 run_test 68a "lloop driver - basic test ========================"
5444
5445 # excercise swapping to lustre by adding a high priority swapfile entry
5446 # and then consuming memory until it is used.
5447 test_68b() {  # was test_68
5448         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5449         [ "$UID" != 0 ] && skip_env "must run as root" && return
5450         lctl get_param -n devices | grep -q obdfilter && \
5451                 skip "local OST" && return
5452
5453         grep -q llite_lloop /proc/modules
5454         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5455
5456         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5457                 skip "can't reliably test swap with TCP" && return
5458
5459         MEMTOTAL=`meminfo MemTotal`
5460         NR_BLOCKS=$((MEMTOTAL>>8))
5461         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5462
5463         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5464         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5465         mkswap $DIR/f68b
5466
5467         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5468
5469         trap cleanup_68 EXIT
5470
5471         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5472
5473         echo "before: `swapon -s | grep $LLOOP`"
5474         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5475         echo "after: `swapon -s | grep $LLOOP`"
5476         SWAPUSED=`swap_used $LLOOP`
5477
5478         cleanup_68
5479
5480         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5481 }
5482 run_test 68b "support swapping to Lustre ========================"
5483
5484 # bug5265, obdfilter oa2dentry return -ENOENT
5485 # #define OBD_FAIL_OST_ENOENT 0x217
5486 test_69() {
5487         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5488         remote_ost_nodsh && skip "remote OST with nodsh" && return
5489
5490         f="$DIR/$tfile"
5491         $SETSTRIPE -c 1 -i 0 $f
5492
5493         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5494
5495         do_facet ost1 lctl set_param fail_loc=0x217
5496         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5497         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5498
5499         do_facet ost1 lctl set_param fail_loc=0
5500         $DIRECTIO write $f 0 2 || error "write error"
5501
5502         cancel_lru_locks osc
5503         $DIRECTIO read $f 0 1 || error "read error"
5504
5505         do_facet ost1 lctl set_param fail_loc=0x217
5506         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5507
5508         do_facet ost1 lctl set_param fail_loc=0
5509         rm -f $f
5510 }
5511 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5512
5513 test_71() {
5514     test_mkdir -p $DIR/$tdir
5515     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5516 }
5517 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5518
5519 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5521         [ "$RUNAS_ID" = "$UID" ] &&
5522                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5523
5524         # Check that testing environment is properly set up. Skip if not
5525         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5526                 skip_env "User $RUNAS_ID does not exist - skipping"
5527                 return 0
5528         }
5529         touch $DIR/$tfile
5530         chmod 777 $DIR/$tfile
5531         chmod ug+s $DIR/$tfile
5532         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5533                 error "$RUNAS dd $DIR/$tfile failed"
5534         # See if we are still setuid/sgid
5535         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5536                 error "S/gid is not dropped on write"
5537         # Now test that MDS is updated too
5538         cancel_lru_locks mdc
5539         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5540                 error "S/gid is not dropped on MDS"
5541         rm -f $DIR/$tfile
5542 }
5543 run_test 72a "Test that remove suid works properly (bug5695) ===="
5544
5545 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5546         local perm
5547
5548         [ "$RUNAS_ID" = "$UID" ] && \
5549                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5550         [ "$RUNAS_ID" -eq 0 ] && \
5551                 skip_env "RUNAS_ID = 0 -- skipping" && return
5552
5553         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5554         # Check that testing environment is properly set up. Skip if not
5555         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5556                 skip_env "User $RUNAS_ID does not exist - skipping"
5557                 return 0
5558         }
5559         touch $DIR/${tfile}-f{g,u}
5560         test_mkdir $DIR/${tfile}-dg
5561         test_mkdir $DIR/${tfile}-du
5562         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5563         chmod g+s $DIR/${tfile}-{f,d}g
5564         chmod u+s $DIR/${tfile}-{f,d}u
5565         for perm in 777 2777 4777; do
5566                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5567                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5568                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5569                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5570         done
5571         true
5572 }
5573 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5574
5575 # bug 3462 - multiple simultaneous MDC requests
5576 test_73() {
5577         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5578         test_mkdir $DIR/d73-1
5579         test_mkdir $DIR/d73-2
5580         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5581         pid1=$!
5582
5583         lctl set_param fail_loc=0x80000129
5584         $MULTIOP $DIR/d73-1/f73-2 Oc &
5585         sleep 1
5586         lctl set_param fail_loc=0
5587
5588         $MULTIOP $DIR/d73-2/f73-3 Oc &
5589         pid3=$!
5590
5591         kill -USR1 $pid1
5592         wait $pid1 || return 1
5593
5594         sleep 25
5595
5596         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5597         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5598         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5599
5600         rm -rf $DIR/d73-*
5601 }
5602 run_test 73 "multiple MDC requests (should not deadlock)"
5603
5604 test_74a() { # bug 6149, 6184
5605         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5606         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5607         #
5608         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5609         # will spin in a tight reconnection loop
5610         touch $DIR/f74a
5611         $LCTL set_param fail_loc=0x8000030e
5612         # get any lock that won't be difficult - lookup works.
5613         ls $DIR/f74a
5614         $LCTL set_param fail_loc=0
5615         rm -f $DIR/f74a
5616         true
5617 }
5618 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5619
5620 test_74b() { # bug 13310
5621         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5622         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5623         #
5624         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5625         # will spin in a tight reconnection loop
5626         $LCTL set_param fail_loc=0x8000030e
5627         # get a "difficult" lock
5628         touch $DIR/f74b
5629         $LCTL set_param fail_loc=0
5630         rm -f $DIR/f74b
5631         true
5632 }
5633 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5634
5635 test_74c() {
5636         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5637         #define OBD_FAIL_LDLM_NEW_LOCK
5638         $LCTL set_param fail_loc=0x319
5639         touch $DIR/$tfile && error "touch successful"
5640         $LCTL set_param fail_loc=0
5641         true
5642 }
5643 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5644
5645 num_inodes() {
5646         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5647 }
5648
5649 get_inode_slab_tunables() {
5650         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5651 }
5652
5653 set_inode_slab_tunables() {
5654         echo "lustre_inode_cache $1" > /proc/slabinfo
5655 }
5656
5657 test_76() { # Now for bug 20433, added originally in bug 1443
5658         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5659         local SLAB_SETTINGS=`get_inode_slab_tunables`
5660         local CPUS=`getconf _NPROCESSORS_ONLN`
5661         # we cannot set limit below 1 which means 1 inode in each
5662         # per-cpu cache is still allowed
5663         set_inode_slab_tunables "1 1 0"
5664         cancel_lru_locks osc
5665         BEFORE_INODES=$(num_inodes)
5666         echo "before inodes: $BEFORE_INODES"
5667         local COUNT=1000
5668         [ "$SLOW" = "no" ] && COUNT=100
5669         for i in $(seq $COUNT); do
5670                 touch $DIR/$tfile
5671                 rm -f $DIR/$tfile
5672         done
5673         cancel_lru_locks osc
5674         AFTER_INODES=$(num_inodes)
5675         echo "after inodes: $AFTER_INODES"
5676         local wait=0
5677         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5678                 sleep 2
5679                 AFTER_INODES=$(num_inodes)
5680                 wait=$((wait+2))
5681                 echo "wait $wait seconds inodes: $AFTER_INODES"
5682                 if [ $wait -gt 30 ]; then
5683                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5684                 fi
5685         done
5686         set_inode_slab_tunables "$SLAB_SETTINGS"
5687 }
5688 run_test 76 "confirm clients recycle inodes properly ===="
5689
5690
5691 export ORIG_CSUM=""
5692 set_checksums()
5693 {
5694         # Note: in sptlrpc modes which enable its own bulk checksum, the
5695         # original crc32_le bulk checksum will be automatically disabled,
5696         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5697         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5698         # In this case set_checksums() will not be no-op, because sptlrpc
5699         # bulk checksum will be enabled all through the test.
5700
5701         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5702         lctl set_param -n osc.*.checksums $1
5703         return 0
5704 }
5705
5706 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5707                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5708 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5709 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5710 set_checksum_type()
5711 {
5712         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5713         log "set checksum type to $1"
5714         return 0
5715 }
5716 F77_TMP=$TMP/f77-temp
5717 F77SZ=8
5718 setup_f77() {
5719         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5720                 error "error writing to $F77_TMP"
5721 }
5722
5723 test_77a() { # bug 10889
5724         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5725         $GSS && skip "could not run with gss" && return
5726         [ ! -f $F77_TMP ] && setup_f77
5727         set_checksums 1
5728         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5729         set_checksums 0
5730         rm -f $DIR/$tfile
5731 }
5732 run_test 77a "normal checksum read/write operation"
5733
5734 test_77b() { # bug 10889
5735         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5736         $GSS && skip "could not run with gss" && return
5737         [ ! -f $F77_TMP ] && setup_f77
5738         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5739         $LCTL set_param fail_loc=0x80000409
5740         set_checksums 1
5741
5742         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5743                 error "dd error: $?"
5744         $LCTL set_param fail_loc=0
5745
5746         for algo in $CKSUM_TYPES; do
5747                 cancel_lru_locks osc
5748                 set_checksum_type $algo
5749                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5750                 $LCTL set_param fail_loc=0x80000408
5751                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5752                 $LCTL set_param fail_loc=0
5753         done
5754         set_checksums 0
5755         set_checksum_type $ORIG_CSUM_TYPE
5756         rm -f $DIR/$tfile
5757 }
5758 run_test 77b "checksum error on client write, read"
5759
5760 test_77d() { # bug 10889
5761         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5762         $GSS && skip "could not run with gss" && return
5763         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5764         $LCTL set_param fail_loc=0x80000409
5765         set_checksums 1
5766         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5767                 error "direct write: rc=$?"
5768         $LCTL set_param fail_loc=0
5769         set_checksums 0
5770
5771         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5772         $LCTL set_param fail_loc=0x80000408
5773         set_checksums 1
5774         cancel_lru_locks osc
5775         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5776                 error "direct read: rc=$?"
5777         $LCTL set_param fail_loc=0
5778         set_checksums 0
5779 }
5780 run_test 77d "checksum error on OST direct write, read"
5781
5782 test_77f() { # bug 10889
5783         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5784         $GSS && skip "could not run with gss" && return
5785         set_checksums 1
5786         for algo in $CKSUM_TYPES; do
5787                 cancel_lru_locks osc
5788                 set_checksum_type $algo
5789                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5790                 $LCTL set_param fail_loc=0x409
5791                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5792                         error "direct write succeeded"
5793                 $LCTL set_param fail_loc=0
5794         done
5795         set_checksum_type $ORIG_CSUM_TYPE
5796         set_checksums 0
5797 }
5798 run_test 77f "repeat checksum error on write (expect error)"
5799
5800 test_77g() { # bug 10889
5801         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5802         $GSS && skip "could not run with gss" && return
5803         remote_ost_nodsh && skip "remote OST with nodsh" && return
5804
5805         [ ! -f $F77_TMP ] && setup_f77
5806
5807         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5808         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5809         do_facet ost1 lctl set_param fail_loc=0x8000021a
5810         set_checksums 1
5811         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5812                 error "write error: rc=$?"
5813         do_facet ost1 lctl set_param fail_loc=0
5814         set_checksums 0
5815
5816         cancel_lru_locks osc
5817         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5818         do_facet ost1 lctl set_param fail_loc=0x8000021b
5819         set_checksums 1
5820         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5821         do_facet ost1 lctl set_param fail_loc=0
5822         set_checksums 0
5823 }
5824 run_test 77g "checksum error on OST write, read"
5825
5826 test_77i() { # bug 13805
5827         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5828         $GSS && skip "could not run with gss" && return
5829         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5830         lctl set_param fail_loc=0x40b
5831         remount_client $MOUNT
5832         lctl set_param fail_loc=0
5833         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5834                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5835                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5836                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5837         done
5838         remount_client $MOUNT
5839 }
5840 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5841
5842 test_77j() { # bug 13805
5843         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5844         $GSS && skip "could not run with gss" && return
5845         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5846         lctl set_param fail_loc=0x40c
5847         remount_client $MOUNT
5848         lctl set_param fail_loc=0
5849         sleep 2 # wait async osc connect to finish
5850         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5851                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5852                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5853                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5854         done
5855         remount_client $MOUNT
5856 }
5857 run_test 77j "client only supporting ADLER32"
5858
5859 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5860 rm -f $F77_TMP
5861 unset F77_TMP
5862
5863 test_78() { # bug 10901
5864         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5865         remote_ost || { skip_env "local OST" && return; }
5866
5867         NSEQ=5
5868         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5869         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5870         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5871         echo "MemTotal: $MEMTOTAL"
5872
5873         # reserve 256MB of memory for the kernel and other running processes,
5874         # and then take 1/2 of the remaining memory for the read/write buffers.
5875         if [ $MEMTOTAL -gt 512 ] ;then
5876                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5877         else
5878                 # for those poor memory-starved high-end clusters...
5879                 MEMTOTAL=$((MEMTOTAL / 2))
5880         fi
5881         echo "Mem to use for directio: $MEMTOTAL"
5882
5883         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5884         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5885         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5886         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5887                 head -n1)
5888         echo "Smallest OST: $SMALLESTOST"
5889         [[ $SMALLESTOST -lt 10240 ]] &&
5890                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5891
5892         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5893                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5894
5895         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5896         echo "File size: $F78SIZE"
5897         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5898         for i in $(seq 1 $NSEQ); do
5899                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5900                 echo directIO rdwr round $i of $NSEQ
5901                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5902         done
5903
5904         rm -f $DIR/$tfile
5905 }
5906 run_test 78 "handle large O_DIRECT writes correctly ============"
5907
5908 test_79() { # bug 12743
5909         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5910         wait_delete_completed
5911
5912         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5913         BKFREE=$(calc_osc_kbytes kbytesfree)
5914         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5915
5916         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5917         DFTOTAL=`echo $STRING | cut -d, -f1`
5918         DFUSED=`echo $STRING  | cut -d, -f2`
5919         DFAVAIL=`echo $STRING | cut -d, -f3`
5920         DFFREE=$(($DFTOTAL - $DFUSED))
5921
5922         ALLOWANCE=$((64 * $OSTCOUNT))
5923
5924         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5925            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5926                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5927         fi
5928         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5929            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5930                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5931         fi
5932         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5933            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5934                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5935         fi
5936 }
5937 run_test 79 "df report consistency check ======================="
5938
5939 test_80() { # bug 10718
5940         remote_ost_nodsh && skip "remote OST with nodsh" && return
5941         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5942         # relax strong synchronous semantics for slow backends like ZFS
5943         local soc="obdfilter.*.sync_on_lock_cancel"
5944         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5945         local hosts=
5946         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5947                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5948                           facet_active_host $host; done | sort -u)
5949                 do_nodes $hosts lctl set_param $soc=never
5950         fi
5951
5952         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5953         sync; sleep 1; sync
5954         local BEFORE=`date +%s`
5955         cancel_lru_locks osc
5956         local AFTER=`date +%s`
5957         local DIFF=$((AFTER-BEFORE))
5958         if [ $DIFF -gt 1 ] ; then
5959                 error "elapsed for 1M@1T = $DIFF"
5960         fi
5961
5962         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5963
5964         rm -f $DIR/$tfile
5965 }
5966 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5967
5968 test_81a() { # LU-456
5969         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5970         remote_ost_nodsh && skip "remote OST with nodsh" && return
5971         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5972         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5973         do_facet ost1 lctl set_param fail_loc=0x80000228
5974
5975         # write should trigger a retry and success
5976         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5977         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5978         RC=$?
5979         if [ $RC -ne 0 ] ; then
5980                 error "write should success, but failed for $RC"
5981         fi
5982 }
5983 run_test 81a "OST should retry write when get -ENOSPC ==============="
5984
5985 test_81b() { # LU-456
5986         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5987         remote_ost_nodsh && skip "remote OST with nodsh" && return
5988         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5989         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5990         do_facet ost1 lctl set_param fail_loc=0x228
5991
5992         # write should retry several times and return -ENOSPC finally
5993         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5994         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5995         RC=$?
5996         ENOSPC=28
5997         if [ $RC -ne $ENOSPC ] ; then
5998                 error "dd should fail for -ENOSPC, but succeed."
5999         fi
6000 }
6001 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6002
6003 test_82() { # LU-1031
6004         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6005         local gid1=14091995
6006         local gid2=16022000
6007
6008         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6009         local MULTIPID1=$!
6010         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6011         local MULTIPID2=$!
6012         kill -USR1 $MULTIPID2
6013         sleep 2
6014         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6015                 error "First grouplock does not block second one"
6016         else
6017                 echo "Second grouplock blocks first one"
6018         fi
6019         kill -USR1 $MULTIPID1
6020         wait $MULTIPID1
6021         wait $MULTIPID2
6022 }
6023 run_test 82 "Basic grouplock test ==============================="
6024
6025 test_99a() {
6026         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6027                 return
6028         test_mkdir -p $DIR/d99cvsroot
6029         chown $RUNAS_ID $DIR/d99cvsroot
6030         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6031         cd $TMP
6032
6033         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6034         cd $oldPWD
6035 }
6036 run_test 99a "cvs init ========================================="
6037
6038 test_99b() {
6039         [ -z "$(which cvs 2>/dev/null)" ] &&
6040                 skip_env "could not find cvs" && return
6041         [ ! -d $DIR/d99cvsroot ] && test_99a
6042         cd /etc/init.d
6043         # some versions of cvs import exit(1) when asked to import links or
6044         # files they can't read.  ignore those files.
6045         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6046                         ! -perm +4 -printf '-I %f\n')
6047         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6048                 d99reposname vtag rtag
6049 }
6050 run_test 99b "cvs import ======================================="
6051
6052 test_99c() {
6053         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6054         [ ! -d $DIR/d99cvsroot ] && test_99b
6055         cd $DIR
6056         test_mkdir -p $DIR/d99reposname
6057         chown $RUNAS_ID $DIR/d99reposname
6058         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6059 }
6060 run_test 99c "cvs checkout ====================================="
6061
6062 test_99d() {
6063         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6064         [ ! -d $DIR/d99cvsroot ] && test_99c
6065         cd $DIR/d99reposname
6066         $RUNAS touch foo99
6067         $RUNAS cvs add -m 'addmsg' foo99
6068 }
6069 run_test 99d "cvs add =========================================="
6070
6071 test_99e() {
6072         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6073         [ ! -d $DIR/d99cvsroot ] && test_99c
6074         cd $DIR/d99reposname
6075         $RUNAS cvs update
6076 }
6077 run_test 99e "cvs update ======================================="
6078
6079 test_99f() {
6080         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6081         [ ! -d $DIR/d99cvsroot ] && test_99d
6082         cd $DIR/d99reposname
6083         $RUNAS cvs commit -m 'nomsg' foo99
6084     rm -fr $DIR/d99cvsroot
6085 }
6086 run_test 99f "cvs commit ======================================="
6087
6088 test_100() {
6089         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6090         [ "$NETTYPE" = tcp ] || \
6091                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6092                         return ; }
6093
6094         remote_ost_nodsh && skip "remote OST with nodsh" && return
6095         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6096         remote_servers || \
6097                 { skip "useless for local single node setup" && return; }
6098
6099         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6100                 [ "$PROT" != "tcp" ] && continue
6101                 RPORT=$(echo $REMOTE | cut -d: -f2)
6102                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6103
6104                 rc=0
6105                 LPORT=`echo $LOCAL | cut -d: -f2`
6106                 if [ $LPORT -ge 1024 ]; then
6107                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6108                         netstat -tna
6109                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6110                 fi
6111         done
6112         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6113 }
6114 run_test 100 "check local port using privileged port ==========="
6115
6116 function get_named_value()
6117 {
6118     local tag
6119
6120     tag=$1
6121     while read ;do
6122         line=$REPLY
6123         case $line in
6124         $tag*)
6125             echo $line | sed "s/^$tag[ ]*//"
6126             break
6127             ;;
6128         esac
6129     done
6130 }
6131
6132 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6133                    awk '/^max_cached_mb/ { print $2 }')
6134
6135 cleanup_101a() {
6136         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6137         trap 0
6138 }
6139
6140 test_101a() {
6141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6142         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6143         local s
6144         local discard
6145         local nreads=10000
6146         local cache_limit=32
6147
6148         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6149         trap cleanup_101a EXIT
6150         $LCTL set_param -n llite.*.read_ahead_stats 0
6151         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6152
6153         #
6154         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6155         #
6156         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6157         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6158
6159         discard=0
6160         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6161                 get_named_value 'read but discarded' | cut -d" " -f1); do
6162                         discard=$(($discard + $s))
6163         done
6164         cleanup_101a
6165
6166         if [[ $(($discard * 10)) -gt $nreads ]]; then
6167                 $LCTL get_param osc.*-osc*.rpc_stats
6168                 $LCTL get_param llite.*.read_ahead_stats
6169                 error "too many ($discard) discarded pages"
6170         fi
6171         rm -f $DIR/$tfile || true
6172 }
6173 run_test 101a "check read-ahead for random reads ================"
6174
6175 setup_test101bc() {
6176         test_mkdir -p $DIR/$tdir
6177         local STRIPE_SIZE=$1
6178         local FILE_LENGTH=$2
6179         STRIPE_OFFSET=0
6180
6181         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6182
6183         local list=$(comma_list $(osts_nodes))
6184         set_osd_param $list '' read_cache_enable 0
6185         set_osd_param $list '' writethrough_cache_enable 0
6186
6187         trap cleanup_test101bc EXIT
6188         # prepare the read-ahead file
6189         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6190
6191         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6192                                 count=$FILE_SIZE_MB 2> /dev/null
6193
6194 }
6195
6196 cleanup_test101bc() {
6197         trap 0
6198         rm -rf $DIR/$tdir
6199         rm -f $DIR/$tfile
6200
6201         local list=$(comma_list $(osts_nodes))
6202         set_osd_param $list '' read_cache_enable 1
6203         set_osd_param $list '' writethrough_cache_enable 1
6204 }
6205
6206 calc_total() {
6207         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6208 }
6209
6210 ra_check_101() {
6211         local READ_SIZE=$1
6212         local STRIPE_SIZE=$2
6213         local FILE_LENGTH=$3
6214         local RA_INC=1048576
6215         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6216         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6217                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6218         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6219                         get_named_value 'read but discarded' |
6220                         cut -d" " -f1 | calc_total)
6221         if [[ $DISCARD -gt $discard_limit ]]; then
6222                 $LCTL get_param llite.*.read_ahead_stats
6223                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6224         else
6225                 echo "Read-ahead success for size ${READ_SIZE}"
6226         fi
6227 }
6228
6229 test_101b() {
6230         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6231         [[ $OSTCOUNT -lt 2 ]] &&
6232                 skip_env "skipping stride IO stride-ahead test" && return
6233         local STRIPE_SIZE=1048576
6234         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6235         if [ $SLOW == "yes" ]; then
6236                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6237         else
6238                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6239         fi
6240
6241         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6242
6243         # prepare the read-ahead file
6244         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6245         cancel_lru_locks osc
6246         for BIDX in 2 4 8 16 32 64 128 256
6247         do
6248                 local BSIZE=$((BIDX*4096))
6249                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6250                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6251                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6252                 $LCTL set_param -n llite.*.read_ahead_stats 0
6253                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6254                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6255                 cancel_lru_locks osc
6256                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6257         done
6258         cleanup_test101bc
6259         true
6260 }
6261 run_test 101b "check stride-io mode read-ahead ================="
6262
6263 test_101c() {
6264         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6265         local STRIPE_SIZE=1048576
6266         local FILE_LENGTH=$((STRIPE_SIZE*100))
6267         local nreads=10000
6268         local osc_rpc_stats
6269
6270         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6271
6272         cancel_lru_locks osc
6273         $LCTL set_param osc.*.rpc_stats 0
6274         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6275         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6276                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6277                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6278                 local size
6279
6280                 if [ $lines -le 20 ]; then
6281                         continue
6282                 fi
6283                 for size in 1 2 4 8; do
6284                         local rpc=$(echo "$stats" |
6285                                     awk '($1 == "'$size':") {print $2; exit; }')
6286                         [ $rpc != 0 ] &&
6287                                 error "Small $((size*4))k read IO $rpc !"
6288                 done
6289                 echo "$osc_rpc_stats check passed!"
6290         done
6291         cleanup_test101bc
6292         true
6293 }
6294 run_test 101c "check stripe_size aligned read-ahead ================="
6295
6296 set_read_ahead() {
6297         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6298         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6299 }
6300
6301 test_101d() {
6302         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6303         local file=$DIR/$tfile
6304         local sz_MB=${FILESIZE_101d:-500}
6305         local ra_MB=${READAHEAD_MB:-40}
6306
6307         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6308         [ $free_MB -lt $sz_MB ] &&
6309                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6310
6311         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6312         $SETSTRIPE -c -1 $file || error "setstripe failed"
6313
6314         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6315         echo Cancel LRU locks on lustre client to flush the client cache
6316         cancel_lru_locks osc
6317
6318         echo Disable read-ahead
6319         local old_READAHEAD=$(set_read_ahead 0)
6320
6321         echo Reading the test file $file with read-ahead disabled
6322         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6323
6324         echo Cancel LRU locks on lustre client to flush the client cache
6325         cancel_lru_locks osc
6326         echo Enable read-ahead with ${ra_MB}MB
6327         set_read_ahead $ra_MB
6328
6329         echo Reading the test file $file with read-ahead enabled
6330         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6331
6332         echo "read-ahead disabled time read $raOFF"
6333         echo "read-ahead enabled  time read $raON"
6334
6335         set_read_ahead $old_READAHEAD
6336         rm -f $file
6337         wait_delete_completed
6338
6339         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6340                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6341 }
6342 run_test 101d "file read with and without read-ahead enabled"
6343
6344 test_101e() {
6345         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6346         local file=$DIR/$tfile
6347         local size_KB=500  #KB
6348         local count=100
6349         local bsize=1024
6350
6351         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6352         local need_KB=$((count * size_KB))
6353         [[ $free_KB -le $need_KB ]] &&
6354                 skip_env "Need free space $need_KB, have $free_KB" && return
6355
6356         echo "Creating $count ${size_KB}K test files"
6357         for ((i = 0; i < $count; i++)); do
6358                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6359         done
6360
6361         echo "Cancel LRU locks on lustre client to flush the client cache"
6362         cancel_lru_locks osc
6363
6364         echo "Reset readahead stats"
6365         $LCTL set_param -n llite.*.read_ahead_stats 0
6366
6367         for ((i = 0; i < $count; i++)); do
6368                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6369         done
6370
6371         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6372                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6373
6374         for ((i = 0; i < $count; i++)); do
6375                 rm -rf $file.$i 2>/dev/null
6376         done
6377
6378         #10000 means 20% reads are missing in readahead
6379         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6380 }
6381 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6382
6383 cleanup_test101f() {
6384     trap 0
6385     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6386     rm -rf $DIR/$tfile 2>/dev/null
6387 }
6388
6389 test_101f() {
6390         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6391     local file=$DIR/$tfile
6392     local nreads=1000
6393
6394     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6395     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6396     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6397     trap cleanup_test101f EXIT
6398
6399     echo Cancel LRU locks on lustre client to flush the client cache
6400     cancel_lru_locks osc
6401
6402     echo Reset readahead stats
6403     $LCTL set_param -n llite.*.read_ahead_stats 0
6404     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6405     # readahead should read in 2M file on second read, so only miss
6406     # 2 pages.
6407     echo Random 4K reads on 2M file for 1000 times
6408     $READS -f $file -s 2097152 -b 4096 -n $nreads
6409
6410     echo checking missing pages
6411     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6412           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6413
6414     [ $miss -lt 3 ] || error "misses too much pages!"
6415     cleanup_test101f
6416 }
6417 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6418
6419 setup_test102() {
6420         test_mkdir -p $DIR/$tdir
6421         chown $RUNAS_ID $DIR/$tdir
6422         STRIPE_SIZE=65536
6423         STRIPE_OFFSET=1
6424         STRIPE_COUNT=$OSTCOUNT
6425         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6426
6427         trap cleanup_test102 EXIT
6428         cd $DIR
6429         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6430         cd $DIR/$tdir
6431         for num in 1 2 3 4; do
6432                 for count in $(seq 1 $STRIPE_COUNT); do
6433                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6434                                 local size=`expr $STRIPE_SIZE \* $num`
6435                                 local file=file"$num-$idx-$count"
6436                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6437                         done
6438                 done
6439         done
6440
6441         cd $DIR
6442         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6443 }
6444
6445 cleanup_test102() {
6446         trap 0
6447         rm -f $TMP/f102.tar
6448         rm -rf $DIR/d0.sanity/d102
6449 }
6450
6451 test_102a() {
6452         local testfile=$DIR/$tfile
6453
6454         touch $testfile
6455
6456         [ "$UID" != 0 ] && skip_env "must run as root" && return
6457         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6458                 skip_env "must have user_xattr" && return
6459
6460         [ -z "$(which setfattr 2>/dev/null)" ] &&
6461                 skip_env "could not find setfattr" && return
6462
6463         echo "set/get xattr..."
6464         setfattr -n trusted.name1 -v value1 $testfile ||
6465                 error "setfattr -n trusted.name1=value1 $testfile failed"
6466         getfattr -n trusted.name1 $testfile 2> /dev/null |
6467           grep "trusted.name1=.value1" ||
6468                 error "$testfile missing trusted.name1=value1"
6469
6470         setfattr -n user.author1 -v author1 $testfile ||
6471                 error "setfattr -n user.author1=author1 $testfile failed"
6472         getfattr -n user.author1 $testfile 2> /dev/null |
6473           grep "user.author1=.author1" ||
6474                 error "$testfile missing trusted.author1=author1"
6475
6476         echo "listxattr..."
6477         setfattr -n trusted.name2 -v value2 $testfile ||
6478                 error "$testfile unable to set trusted.name2"
6479         setfattr -n trusted.name3 -v value3 $testfile ||
6480                 error "$testfile unable to set trusted.name3"
6481         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6482             grep "trusted.name" | wc -l) -eq 3 ] ||
6483                 error "$testfile missing 3 trusted.name xattrs"
6484
6485         setfattr -n user.author2 -v author2 $testfile ||
6486                 error "$testfile unable to set user.author2"
6487         setfattr -n user.author3 -v author3 $testfile ||
6488                 error "$testfile unable to set user.author3"
6489         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6490             grep "user.author" | wc -l) -eq 3 ] ||
6491                 error "$testfile missing 3 user.author xattrs"
6492
6493         echo "remove xattr..."
6494         setfattr -x trusted.name1 $testfile ||
6495                 error "$testfile error deleting trusted.name1"
6496         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6497                 error "$testfile did not delete trusted.name1 xattr"
6498
6499         setfattr -x user.author1 $testfile ||
6500                 error "$testfile error deleting user.author1"
6501         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6502                 error "$testfile did not delete trusted.name1 xattr"
6503
6504         # b10667: setting lustre special xattr be silently discarded
6505         echo "set lustre special xattr ..."
6506         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6507                 error "$testfile allowed setting trusted.lov"
6508 }
6509 run_test 102a "user xattr test =================================="
6510
6511 test_102b() {
6512         [ -z "$(which setfattr 2>/dev/null)" ] &&
6513                 skip_env "could not find setfattr" && return
6514
6515         # b10930: get/set/list trusted.lov xattr
6516         echo "get/set/list trusted.lov xattr ..."
6517         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6518         local testfile=$DIR/$tfile
6519         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6520                 error "setstripe failed"
6521         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6522                 error "getstripe failed"
6523         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6524                 error "can't get trusted.lov from $testfile"
6525
6526         local testfile2=${testfile}2
6527         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6528                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6529
6530         $MCREATE $testfile2
6531         setfattr -n trusted.lov -v $value $testfile2
6532         local stripe_size=$($GETSTRIPE -S $testfile2)
6533         local stripe_count=$($GETSTRIPE -c $testfile2)
6534         [[ $stripe_size -eq 65536 ]] ||
6535                 error "stripe size $stripe_size != 65536"
6536         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6537                 error "stripe count $stripe_count != $STRIPECOUNT"
6538         rm -f $DIR/$tfile
6539 }
6540 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6541
6542 test_102c() {
6543         [ -z "$(which setfattr 2>/dev/null)" ] &&
6544                 skip_env "could not find setfattr" && return
6545
6546         # b10930: get/set/list lustre.lov xattr
6547         echo "get/set/list lustre.lov xattr ..."
6548         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6549         test_mkdir -p $DIR/$tdir
6550         chown $RUNAS_ID $DIR/$tdir
6551         local testfile=$DIR/$tdir/$tfile
6552         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6553                 error "setstripe failed"
6554         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6555                 error "getstripe failed"
6556         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6557         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6558
6559         local testfile2=${testfile}2
6560         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6561                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6562
6563         $RUNAS $MCREATE $testfile2
6564         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6565         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6566         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6567         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6568         [ $stripe_count -eq $STRIPECOUNT ] ||
6569                 error "stripe count $stripe_count != $STRIPECOUNT"
6570 }
6571 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6572
6573 compare_stripe_info1() {
6574         local stripe_index_all_zero=true
6575
6576         for num in 1 2 3 4; do
6577                 for count in $(seq 1 $STRIPE_COUNT); do
6578                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6579                                 local size=$((STRIPE_SIZE * num))
6580                                 local file=file"$num-$offset-$count"
6581                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6582                                 [[ $stripe_size -ne $size ]] &&
6583                                     error "$file: size $stripe_size != $size"
6584                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6585                                 # allow fewer stripes to be created, ORI-601
6586                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6587                                     error "$file: count $stripe_count != $count"
6588                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6589                                 [[ $stripe_index -ne 0 ]] &&
6590                                         stripe_index_all_zero=false
6591                         done
6592                 done
6593         done
6594         $stripe_index_all_zero &&
6595                 error "all files are being extracted starting from OST index 0"
6596         return 0
6597 }
6598
6599 find_lustre_tar() {
6600         [ -n "$(which tar 2>/dev/null)" ] &&
6601                 strings $(which tar) | grep -q "lustre" && echo tar
6602 }
6603
6604 test_102d() {
6605         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6606         # b10930: tar test for trusted.lov xattr
6607         TAR=$(find_lustre_tar)
6608         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6609         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6610         setup_test102
6611         test_mkdir -p $DIR/d102d
6612         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6613         cd $DIR/d102d/$tdir
6614         compare_stripe_info1
6615 }
6616 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6617
6618 test_102f() {
6619         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6620         # b10930: tar test for trusted.lov xattr
6621         TAR=$(find_lustre_tar)
6622         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6623         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6624         setup_test102
6625         test_mkdir -p $DIR/d102f
6626         cd $DIR
6627         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6628         cd $DIR/d102f/$tdir
6629         compare_stripe_info1
6630 }
6631 run_test 102f "tar copy files, not keep osts ==========="
6632
6633 grow_xattr() {
6634         local xsize=${1:-1024}  # in bytes
6635         local file=$DIR/$tfile
6636
6637         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6638                 skip "must have user_xattr" && return 0
6639         [ -z "$(which setfattr 2>/dev/null)" ] &&
6640                 skip_env "could not find setfattr" && return 0
6641         [ -z "$(which getfattr 2>/dev/null)" ] &&
6642                 skip_env "could not find getfattr" && return 0
6643
6644         touch $file
6645
6646         local value="$(generate_string $xsize)"
6647
6648         local xbig=trusted.big
6649         log "save $xbig on $file"
6650         setfattr -n $xbig -v $value $file ||
6651                 error "saving $xbig on $file failed"
6652
6653         local orig=$(get_xattr_value $xbig $file)
6654         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6655
6656         local xsml=trusted.sml
6657         log "save $xsml on $file"
6658         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6659
6660         local new=$(get_xattr_value $xbig $file)
6661         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6662
6663         log "grow $xsml on $file"
6664         setfattr -n $xsml -v "$value" $file ||
6665                 error "growing $xsml on $file failed"
6666
6667         new=$(get_xattr_value $xbig $file)
6668         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6669         log "$xbig still valid after growing $xsml"
6670
6671         rm -f $file
6672 }
6673
6674 test_102h() { # bug 15777
6675         grow_xattr 1024
6676 }
6677 run_test 102h "grow xattr from inside inode to external block"
6678
6679 test_102ha() {
6680         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6681         grow_xattr $(max_xattr_size)
6682 }
6683 run_test 102ha "grow xattr from inside inode to external inode"
6684
6685 test_102i() { # bug 17038
6686         [ -z "$(which getfattr 2>/dev/null)" ] &&
6687                 skip "could not find getfattr" && return
6688         touch $DIR/$tfile
6689         ln -s $DIR/$tfile $DIR/${tfile}link
6690         getfattr -n trusted.lov $DIR/$tfile ||
6691                 error "lgetxattr on $DIR/$tfile failed"
6692         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6693                 grep -i "no such attr" ||
6694                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6695         rm -f $DIR/$tfile $DIR/${tfile}link
6696 }
6697 run_test 102i "lgetxattr test on symbolic link ============"
6698
6699 test_102j() {
6700         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6701         TAR=$(find_lustre_tar)
6702         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6703         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6704         setup_test102 "$RUNAS"
6705         test_mkdir -p $DIR/d102j
6706         chown $RUNAS_ID $DIR/d102j
6707         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6708         cd $DIR/d102j/$tdir
6709         compare_stripe_info1 "$RUNAS"
6710 }
6711 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6712
6713 test_102k() {
6714         [ -z "$(which setfattr 2>/dev/null)" ] &&
6715                 skip "could not find setfattr" && return
6716         touch $DIR/$tfile
6717         # b22187 just check that does not crash for regular file.
6718         setfattr -n trusted.lov $DIR/$tfile
6719         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6720         local test_kdir=$DIR/d102k
6721         test_mkdir $test_kdir
6722         local default_size=`$GETSTRIPE -S $test_kdir`
6723         local default_count=`$GETSTRIPE -c $test_kdir`
6724         local default_offset=`$GETSTRIPE -i $test_kdir`
6725         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6726                 error 'dir setstripe failed'
6727         setfattr -n trusted.lov $test_kdir
6728         local stripe_size=`$GETSTRIPE -S $test_kdir`
6729         local stripe_count=`$GETSTRIPE -c $test_kdir`
6730         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6731         [ $stripe_size -eq $default_size ] ||
6732                 error "stripe size $stripe_size != $default_size"
6733         [ $stripe_count -eq $default_count ] ||
6734                 error "stripe count $stripe_count != $default_count"
6735         [ $stripe_offset -eq $default_offset ] ||
6736                 error "stripe offset $stripe_offset != $default_offset"
6737         rm -rf $DIR/$tfile $test_kdir
6738 }
6739 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6740
6741 test_102l() {
6742         [ -z "$(which getfattr 2>/dev/null)" ] &&
6743                 skip "could not find getfattr" && return
6744
6745         # LU-532 trusted. xattr is invisible to non-root
6746         local testfile=$DIR/$tfile
6747
6748         touch $testfile
6749
6750         echo "listxattr as user..."
6751         chown $RUNAS_ID $testfile
6752         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6753             grep -q "trusted" &&
6754                 error "$testfile trusted xattrs are user visible"
6755
6756         return 0;
6757 }
6758 run_test 102l "listxattr size test =================================="
6759
6760 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6761         local path=$DIR/$tfile
6762         touch $path
6763
6764         listxattr_size_check $path || error "listattr_size_check $path failed"
6765 }
6766 run_test 102m "Ensure listxattr fails on small bufffer ========"
6767
6768 cleanup_test102
6769
6770 getxattr() { # getxattr path name
6771         # Return the base64 encoding of the value of xattr name on path.
6772         local path=$1
6773         local name=$2
6774
6775         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6776         # file: $path
6777         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6778         #
6779         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6780
6781         getfattr --absolute-names --encoding=base64 --name=$name $path |
6782                 awk -F= -v name=$name '$1 == name {
6783                         print substr($0, index($0, "=") + 1);
6784         }'
6785 }
6786
6787 test_102n() { # LU-4101 mdt: protect internal xattrs
6788         local file0=$DIR/$tfile.0
6789         local file1=$DIR/$tfile.1
6790         local xattr0=$TMP/$tfile.0
6791         local xattr1=$TMP/$tfile.1
6792         local name
6793         local value
6794
6795         [ -z "$(which setfattr 2>/dev/null)" ] &&
6796                 skip "could not find setfattr" && return
6797
6798         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6799         then
6800                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6801                 return
6802         fi
6803
6804         rm -rf $file0 $file1 $xattr0 $xattr1
6805         touch $file0 $file1
6806
6807         # Get 'before' xattrs of $file1.
6808         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6809
6810         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6811                 # Try to copy xattr from $file0 to $file1.
6812                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6813
6814                 setfattr --name=trusted.$name --value="$value" $file1 ||
6815                         error "setxattr 'trusted.$name' failed"
6816
6817                 # Try to set a garbage xattr.
6818                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6819
6820                 setfattr --name=trusted.$name --value="$value" $file1 ||
6821                         error "setxattr 'trusted.$name' failed"
6822
6823                 # Try to remove the xattr from $file1. We don't care if this
6824                 # appears to succeed or fail, we just don't want there to be
6825                 # any changes or crashes.
6826                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6827         done
6828
6829         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
6830         then
6831                 name="lfsck_ns"
6832                 # Try to copy xattr from $file0 to $file1.
6833                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6834
6835                 setfattr --name=trusted.$name --value="$value" $file1 ||
6836                         error "setxattr 'trusted.$name' failed"
6837
6838                 # Try to set a garbage xattr.
6839                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6840
6841                 setfattr --name=trusted.$name --value="$value" $file1 ||
6842                         error "setxattr 'trusted.$name' failed"
6843
6844                 # Try to remove the xattr from $file1. We don't care if this
6845                 # appears to succeed or fail, we just don't want there to be
6846                 # any changes or crashes.
6847                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6848         fi
6849
6850         # Get 'after' xattrs of file1.
6851         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6852
6853         if ! diff $xattr0 $xattr1; then
6854                 error "before and after xattrs of '$file1' differ"
6855         fi
6856
6857         rm -rf $file0 $file1 $xattr0 $xattr1
6858
6859         return 0
6860 }
6861 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6862
6863 test_102p() { # LU-4703 setxattr did not check ownership
6864         local testfile=$DIR/$tfile
6865
6866         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6867                 skip "MDS needs to be at least 2.5.56" && return
6868
6869         touch $testfile
6870
6871         echo "setfacl as user..."
6872         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6873         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6874
6875         echo "setfattr as user..."
6876         setfacl -m "u:$RUNAS_ID:---" $testfile
6877         $RUNAS setfattr -x system.posix_acl_access $testfile
6878         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6879 }
6880 run_test 102p "check setxattr(2) correctly fails without permission"
6881
6882 run_acl_subtest()
6883 {
6884     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6885     return $?
6886 }
6887
6888 test_103a() {
6889         [ "$UID" != 0 ] && skip_env "must run as root" && return
6890         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6891                 skip "must have acl enabled" && return
6892         [ -z "$(which setfacl 2>/dev/null)" ] &&
6893                 skip_env "could not find setfacl" && return
6894         $GSS && skip "could not run under gss" && return
6895
6896         gpasswd -a daemon bin                           # LU-5641
6897         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
6898
6899         declare -a identity_old
6900
6901         for num in $(seq $MDSCOUNT); do
6902                 switch_identity $num true || identity_old[$num]=$?
6903         done
6904
6905         SAVE_UMASK=$(umask)
6906         umask 0022
6907         cd $DIR
6908
6909         echo "performing cp ..."
6910         run_acl_subtest cp || error "run_acl_subtest cp failed"
6911         echo "performing getfacl-noacl..."
6912         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6913         echo "performing misc..."
6914         run_acl_subtest misc || error  "misc test failed"
6915         echo "performing permissions..."
6916         run_acl_subtest permissions || error "permissions failed"
6917         echo "performing setfacl..."
6918         run_acl_subtest setfacl || error  "setfacl test failed"
6919
6920         # inheritance test got from HP
6921         echo "performing inheritance..."
6922         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6923         chmod +x make-tree || error "chmod +x failed"
6924         run_acl_subtest inheritance || error "inheritance test failed"
6925         rm -f make-tree
6926
6927         echo "LU-974 ignore umask when acl is enabled..."
6928         run_acl_subtest 974 || error "LU-974 umask test failed"
6929         if [ $MDSCOUNT -ge 2 ]; then
6930                 run_acl_subtest 974_remote ||
6931                         error "LU-974 umask test failed under remote dir"
6932         fi
6933
6934         echo "LU-2561 newly created file is same size as directory..."
6935         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6936                 run_acl_subtest 2561 || error "LU-2561 test failed"
6937         else
6938                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6939         fi
6940
6941         run_acl_subtest 4924 || error "LU-4924 test failed"
6942
6943         cd $SAVE_PWD
6944         umask $SAVE_UMASK
6945
6946         for num in $(seq $MDSCOUNT); do
6947                 if [ "${identity_old[$num]}" = 1 ]; then
6948                         switch_identity $num false || identity_old[$num]=$?
6949                 fi
6950         done
6951 }
6952 run_test 103a "acl test ========================================="
6953
6954 test_103b() {
6955         local noacl=false
6956         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
6957         local mountopts=$MDS_MOUNT_OPTS
6958
6959         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
6960                 noacl=true
6961         else
6962                 # stop the MDT
6963                 stop $SINGLEMDS || error "failed to stop MDT."
6964                 # remount the MDT
6965                 if [ -z "$MDS_MOUNT_OPTS" ]; then
6966                         MDS_MOUNT_OPTS="-o noacl"
6967                 else
6968                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
6969                 fi
6970                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6971                         error "failed to start MDT."
6972                 MDS_MOUNT_OPTS=$mountopts
6973         fi
6974
6975         touch $DIR/$tfile
6976         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
6977
6978         if ! $noacl; then
6979                 # stop the MDT
6980                 stop $SINGLEMDS || error "failed to stop MDT."
6981                 # remount the MDT
6982                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6983                         error "failed to start MDT."
6984         fi
6985
6986         true
6987 }
6988 run_test 103b "MDS mount option 'noacl'"
6989
6990 test_103c() {
6991         mkdir -p $DIR/$tdir
6992         cp -rp $DIR/$tdir $DIR/$tdir.bak
6993
6994         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
6995                 error "$DIR/$tdir shouldn't contain default ACL"
6996         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
6997                 error "$DIR/$tdir.bak shouldn't contain default ACL"
6998         true
6999 }
7000 run_test 103c "'cp -rp' won't set empty acl"
7001
7002 test_104a() {
7003         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7004         touch $DIR/$tfile
7005         lfs df || error "lfs df failed"
7006         lfs df -ih || error "lfs df -ih failed"
7007         lfs df -h $DIR || error "lfs df -h $DIR failed"
7008         lfs df -i $DIR || error "lfs df -i $DIR failed"
7009         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7010         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7011
7012         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7013         lctl --device %$OSC deactivate
7014         lfs df || error "lfs df with deactivated OSC failed"
7015         lctl --device %$OSC activate
7016         # wait the osc back to normal
7017         wait_osc_import_state client ost FULL
7018
7019         lfs df || error "lfs df with reactivated OSC failed"
7020         rm -f $DIR/$tfile
7021 }
7022 run_test 104a "lfs df [-ih] [path] test ========================="
7023
7024 test_104b() {
7025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7026         [ $RUNAS_ID -eq $UID ] &&
7027                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7028         chmod 666 /dev/obd
7029         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7030                         grep "Permission denied" | wc -l)))
7031         if [ $denied_cnt -ne 0 ]; then
7032                 error "lfs check servers test failed"
7033         fi
7034 }
7035 run_test 104b "$RUNAS lfs check servers test ===================="
7036
7037 test_105a() {
7038         # doesn't work on 2.4 kernels
7039         touch $DIR/$tfile
7040         if $(flock_is_enabled); then
7041                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7042         else
7043                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7044         fi
7045         rm -f $DIR/$tfile
7046 }
7047 run_test 105a "flock when mounted without -o flock test ========"
7048
7049 test_105b() {
7050         touch $DIR/$tfile
7051         if $(flock_is_enabled); then
7052                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7053         else
7054                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7055         fi
7056         rm -f $DIR/$tfile
7057 }
7058 run_test 105b "fcntl when mounted without -o flock test ========"
7059
7060 test_105c() {
7061         touch $DIR/$tfile
7062         if $(flock_is_enabled); then
7063                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7064         else
7065                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7066         fi
7067         rm -f $DIR/$tfile
7068 }
7069 run_test 105c "lockf when mounted without -o flock test ========"
7070
7071 test_105d() { # bug 15924
7072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7073         test_mkdir -p $DIR/$tdir
7074         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7075         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7076         $LCTL set_param fail_loc=0x80000315
7077         flocks_test 2 $DIR/$tdir
7078 }
7079 run_test 105d "flock race (should not freeze) ========"
7080
7081 test_105e() { # bug 22660 && 22040
7082         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7083         touch $DIR/$tfile
7084         flocks_test 3 $DIR/$tfile
7085 }
7086 run_test 105e "Two conflicting flocks from same process ======="
7087
7088 test_106() { #bug 10921
7089         test_mkdir -p $DIR/$tdir
7090         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7091         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7092 }
7093 run_test 106 "attempt exec of dir followed by chown of that dir"
7094
7095 test_107() {
7096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7097         CDIR=`pwd`
7098         cd $DIR
7099
7100         local file=core
7101         rm -f $file
7102
7103         local save_pattern=$(sysctl -n kernel.core_pattern)
7104         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7105         sysctl -w kernel.core_pattern=$file
7106         sysctl -w kernel.core_uses_pid=0
7107
7108         ulimit -c unlimited
7109         sleep 60 &
7110         SLEEPPID=$!
7111
7112         sleep 1
7113
7114         kill -s 11 $SLEEPPID
7115         wait $SLEEPPID
7116         if [ -e $file ]; then
7117                 size=`stat -c%s $file`
7118                 [ $size -eq 0 ] && error "Fail to create core file $file"
7119         else
7120                 error "Fail to create core file $file"
7121         fi
7122         rm -f $file
7123         sysctl -w kernel.core_pattern=$save_pattern
7124         sysctl -w kernel.core_uses_pid=$save_uses_pid
7125         cd $CDIR
7126 }
7127 run_test 107 "Coredump on SIG"
7128
7129 test_110() {
7130         test_mkdir -p $DIR/$tdir
7131         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7132                 error "mkdir with 255 char failed"
7133         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7134                 error "mkdir with 256 char should fail, but did not"
7135         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7136                 error "create with 255 char failed"
7137         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7138                 error "create with 256 char should fail, but did not"
7139
7140         ls -l $DIR/$tdir
7141         rm -rf $DIR/$tdir
7142 }
7143 run_test 110 "filename length checking"
7144
7145 test_115() {
7146         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7147         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7148                 tail -1 | cut -c11-20)
7149         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7150         echo "Starting with $OSTIO_pre threads"
7151
7152         NUMTEST=20000
7153         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7154         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7155         echo "$NUMTEST creates/unlinks"
7156         test_mkdir -p $DIR/$tdir
7157         createmany -o $DIR/$tdir/$tfile $NUMTEST
7158         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7159
7160         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7161                 tail -1 | cut -c11-20)
7162
7163         # don't return an error
7164         [ $OSTIO_post == $OSTIO_pre ] && echo \
7165             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7166             echo "This may be fine, depending on what ran before this test" &&
7167             echo "and how fast this system is." && return
7168
7169         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7170 }
7171 run_test 115 "verify dynamic thread creation===================="
7172
7173 free_min_max () {
7174         wait_delete_completed
7175         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7176         echo OST kbytes available: ${AVAIL[@]}
7177         MAXI=0; MAXV=${AVAIL[0]}
7178         MINI=0; MINV=${AVAIL[0]}
7179         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7180                 #echo OST $i: ${AVAIL[i]}kb
7181                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7182                         MAXV=${AVAIL[i]}; MAXI=$i
7183                 fi
7184                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7185                         MINV=${AVAIL[i]}; MINI=$i
7186                 fi
7187         done
7188         echo Min free space: OST $MINI: $MINV
7189         echo Max free space: OST $MAXI: $MAXV
7190 }
7191
7192 test_116a() { # was previously test_116()
7193         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7194         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7195
7196         echo -n "Free space priority "
7197         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7198                 head -n1
7199         declare -a AVAIL
7200         free_min_max
7201
7202         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7203         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7204                 && return
7205         trap simple_cleanup_common EXIT
7206
7207
7208         # Check if we need to generate uneven OSTs
7209         test_mkdir -p $DIR/$tdir/OST${MINI}
7210         local FILL=$(($MINV / 4))
7211         local DIFF=$(($MAXV - $MINV))
7212         local DIFF2=$(($DIFF * 100 / $MINV))
7213
7214         local threshold=$(do_facet $SINGLEMDS \
7215                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7216         threshold=${threshold%%%}
7217         echo -n "Check for uneven OSTs: "
7218         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7219
7220         if [[ $DIFF2 -gt $threshold ]]; then
7221                 echo "ok"
7222                 echo "Don't need to fill OST$MINI"
7223         else
7224                 # generate uneven OSTs. Write 2% over the QOS threshold value
7225                 echo "no"
7226                 DIFF=$(($threshold - $DIFF2 + 2))
7227                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7228                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7229                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7230                         error "setstripe failed"
7231                 DIFF=$(($DIFF2 / 2048))
7232                 i=0
7233                 while [ $i -lt $DIFF ]; do
7234                         i=$(($i + 1))
7235                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7236                                 bs=2M count=1 2>/dev/null
7237                         echo -n .
7238                 done
7239                 echo .
7240                 sync
7241                 sleep_maxage
7242                 free_min_max
7243         fi
7244
7245         DIFF=$(($MAXV - $MINV))
7246         DIFF2=$(($DIFF * 100 / $MINV))
7247         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7248         if [[ $DIFF2 -gt $threshold ]]; then
7249                 echo "ok"
7250         else
7251                 echo "failed - QOS mode won't be used"
7252                 skip "QOS imbalance criteria not met"
7253                 simple_cleanup_common
7254                 return
7255         fi
7256
7257         MINI1=$MINI; MINV1=$MINV
7258         MAXI1=$MAXI; MAXV1=$MAXV
7259
7260         # now fill using QOS
7261         $SETSTRIPE -c 1 $DIR/$tdir
7262         FILL=$(($FILL / 200))
7263         if [ $FILL -gt 600 ]; then
7264                 FILL=600
7265         fi
7266         echo "writing $FILL files to QOS-assigned OSTs"
7267         i=0
7268         while [ $i -lt $FILL ]; do
7269                 i=$((i + 1))
7270                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7271                         count=1 2>/dev/null
7272                 echo -n .
7273         done
7274         echo "wrote $i 200k files"
7275         sync
7276         sleep_maxage
7277
7278         echo "Note: free space may not be updated, so measurements might be off"
7279         free_min_max
7280         DIFF2=$(($MAXV - $MINV))
7281         echo "free space delta: orig $DIFF final $DIFF2"
7282         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7283         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7284         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7285         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7286         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7287         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7288         [ $DIFF -gt 0 ] &&
7289                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7290
7291         # Figure out which files were written where
7292         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7293                   awk '/'$MINI1': / {print $2; exit}')
7294         echo $UUID
7295         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7296         echo "$MINC files created on smaller OST $MINI1"
7297         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7298                   awk '/'$MAXI1': / {print $2; exit}')
7299         echo $UUID
7300         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7301         echo "$MAXC files created on larger OST $MAXI1"
7302         FILL=$(($MAXC * 100 / $MINC - 100))
7303         [[ $MINC -gt 0 ]] &&
7304                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7305         [[ $MAXC -gt $MINC ]] ||
7306                 error_ignore LU-9 "stripe QOS didn't balance free space"
7307         simple_cleanup_common
7308 }
7309 run_test 116a "stripe QOS: free space balance ==================="
7310
7311 test_116b() { # LU-2093
7312         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7313         [ -z "$($LCTL get_param -n lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr |
7314                 head -1 2>/dev/null)" ] && skip "no QOS" && return
7315 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7316         local old_rr
7317         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7318                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7319         do_facet $SINGLEMDS lctl set_param \
7320                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7321         mkdir -p $DIR/$tdir
7322         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7323         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7324         do_facet $SINGLEMDS lctl set_param fail_loc=0
7325         rm -rf $DIR/$tdir
7326         do_facet $SINGLEMDS lctl set_param \
7327                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7328 }
7329 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7330
7331 test_117() # bug 10891
7332 {
7333         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7334         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7335         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7336         lctl set_param fail_loc=0x21e
7337         > $DIR/$tfile || error "truncate failed"
7338         lctl set_param fail_loc=0
7339         echo "Truncate succeeded."
7340         rm -f $DIR/$tfile
7341 }
7342 run_test 117 "verify osd extend =========="
7343
7344 NO_SLOW_RESENDCOUNT=4
7345 export OLD_RESENDCOUNT=""
7346 set_resend_count () {
7347         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7348         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7349         lctl set_param -n $PROC_RESENDCOUNT $1
7350         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7351 }
7352
7353 # for reduce test_118* time (b=14842)
7354 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7355
7356 # Reset async IO behavior after error case
7357 reset_async() {
7358         FILE=$DIR/reset_async
7359
7360         # Ensure all OSCs are cleared
7361         $SETSTRIPE -c -1 $FILE
7362         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7363         sync
7364         rm $FILE
7365 }
7366
7367 test_118a() #bug 11710
7368 {
7369         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7370         reset_async
7371
7372         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7373         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7374         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7375
7376         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7377                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7378                 return 1;
7379         fi
7380         rm -f $DIR/$tfile
7381 }
7382 run_test 118a "verify O_SYNC works =========="
7383
7384 test_118b()
7385 {
7386         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7387         remote_ost_nodsh && skip "remote OST with nodsh" && return
7388
7389         reset_async
7390
7391         #define OBD_FAIL_OST_ENOENT 0x217
7392         set_nodes_failloc "$(osts_nodes)" 0x217
7393         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7394         RC=$?
7395         set_nodes_failloc "$(osts_nodes)" 0
7396         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7397         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7398                     grep -c writeback)
7399
7400         if [[ $RC -eq 0 ]]; then
7401                 error "Must return error due to dropped pages, rc=$RC"
7402                 return 1;
7403         fi
7404
7405         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7406                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7407                 return 1;
7408         fi
7409
7410         echo "Dirty pages not leaked on ENOENT"
7411
7412         # Due to the above error the OSC will issue all RPCs syncronously
7413         # until a subsequent RPC completes successfully without error.
7414         $MULTIOP $DIR/$tfile Ow4096yc
7415         rm -f $DIR/$tfile
7416
7417         return 0
7418 }
7419 run_test 118b "Reclaim dirty pages on fatal error =========="
7420
7421 test_118c()
7422 {
7423         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7424
7425         # for 118c, restore the original resend count, LU-1940
7426         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7427                                 set_resend_count $OLD_RESENDCOUNT
7428         remote_ost_nodsh && skip "remote OST with nodsh" && return
7429
7430         reset_async
7431
7432         #define OBD_FAIL_OST_EROFS               0x216
7433         set_nodes_failloc "$(osts_nodes)" 0x216
7434
7435         # multiop should block due to fsync until pages are written
7436         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7437         MULTIPID=$!
7438         sleep 1
7439
7440         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7441                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7442         fi
7443
7444         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7445                     grep -c writeback)
7446         if [[ $WRITEBACK -eq 0 ]]; then
7447                 error "No page in writeback, writeback=$WRITEBACK"
7448         fi
7449
7450         set_nodes_failloc "$(osts_nodes)" 0
7451         wait $MULTIPID
7452         RC=$?
7453         if [[ $RC -ne 0 ]]; then
7454                 error "Multiop fsync failed, rc=$RC"
7455         fi
7456
7457         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7458         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7459                     grep -c writeback)
7460         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7461                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7462         fi
7463
7464         rm -f $DIR/$tfile
7465         echo "Dirty pages flushed via fsync on EROFS"
7466         return 0
7467 }
7468 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7469
7470 # continue to use small resend count to reduce test_118* time (b=14842)
7471 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7472
7473 test_118d()
7474 {
7475         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7476         remote_ost_nodsh && skip "remote OST with nodsh" && return
7477
7478         reset_async
7479
7480         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7481         set_nodes_failloc "$(osts_nodes)" 0x214
7482         # multiop should block due to fsync until pages are written
7483         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7484         MULTIPID=$!
7485         sleep 1
7486
7487         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7488                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7489         fi
7490
7491         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7492                     grep -c writeback)
7493         if [[ $WRITEBACK -eq 0 ]]; then
7494                 error "No page in writeback, writeback=$WRITEBACK"
7495         fi
7496
7497         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7498         set_nodes_failloc "$(osts_nodes)" 0
7499
7500         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7501         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7502                     grep -c writeback)
7503         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7504                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7505         fi
7506
7507         rm -f $DIR/$tfile
7508         echo "Dirty pages gaurenteed flushed via fsync"
7509         return 0
7510 }
7511 run_test 118d "Fsync validation inject a delay of the bulk =========="
7512
7513 test_118f() {
7514         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7515         reset_async
7516
7517         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7518         lctl set_param fail_loc=0x8000040a
7519
7520         # Should simulate EINVAL error which is fatal
7521         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7522         RC=$?
7523         if [[ $RC -eq 0 ]]; then
7524                 error "Must return error due to dropped pages, rc=$RC"
7525         fi
7526
7527         lctl set_param fail_loc=0x0
7528
7529         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7530         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7531         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7532                     grep -c writeback)
7533         if [[ $LOCKED -ne 0 ]]; then
7534                 error "Locked pages remain in cache, locked=$LOCKED"
7535         fi
7536
7537         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7538                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7539         fi
7540
7541         rm -f $DIR/$tfile
7542         echo "No pages locked after fsync"
7543
7544         reset_async
7545         return 0
7546 }
7547 run_test 118f "Simulate unrecoverable OSC side error =========="
7548
7549 test_118g() {
7550         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7551         reset_async
7552
7553         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7554         lctl set_param fail_loc=0x406
7555
7556         # simulate local -ENOMEM
7557         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7558         RC=$?
7559
7560         lctl set_param fail_loc=0
7561         if [[ $RC -eq 0 ]]; then
7562                 error "Must return error due to dropped pages, rc=$RC"
7563         fi
7564
7565         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7566         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7567         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7568                         grep -c writeback)
7569         if [[ $LOCKED -ne 0 ]]; then
7570                 error "Locked pages remain in cache, locked=$LOCKED"
7571         fi
7572
7573         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7574                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7575         fi
7576
7577         rm -f $DIR/$tfile
7578         echo "No pages locked after fsync"
7579
7580         reset_async
7581         return 0
7582 }
7583 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7584
7585 test_118h() {
7586         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7587         remote_ost_nodsh && skip "remote OST with nodsh" && return
7588
7589         reset_async
7590
7591         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7592         set_nodes_failloc "$(osts_nodes)" 0x20e
7593         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7594         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7595         RC=$?
7596
7597         set_nodes_failloc "$(osts_nodes)" 0
7598         if [[ $RC -eq 0 ]]; then
7599                 error "Must return error due to dropped pages, rc=$RC"
7600         fi
7601
7602         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7603         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7604         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7605                     grep -c writeback)
7606         if [[ $LOCKED -ne 0 ]]; then
7607                 error "Locked pages remain in cache, locked=$LOCKED"
7608         fi
7609
7610         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7611                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7612         fi
7613
7614         rm -f $DIR/$tfile
7615         echo "No pages locked after fsync"
7616
7617         return 0
7618 }
7619 run_test 118h "Verify timeout in handling recoverables errors  =========="
7620
7621 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7622
7623 test_118i() {
7624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7625         remote_ost_nodsh && skip "remote OST with nodsh" && return
7626
7627         reset_async
7628
7629         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7630         set_nodes_failloc "$(osts_nodes)" 0x20e
7631
7632         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7633         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7634         PID=$!
7635         sleep 5
7636         set_nodes_failloc "$(osts_nodes)" 0
7637
7638         wait $PID
7639         RC=$?
7640         if [[ $RC -ne 0 ]]; then
7641                 error "got error, but should be not, rc=$RC"
7642         fi
7643
7644         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7645         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7646         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7647         if [[ $LOCKED -ne 0 ]]; then
7648                 error "Locked pages remain in cache, locked=$LOCKED"
7649         fi
7650
7651         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7652                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7653         fi
7654
7655         rm -f $DIR/$tfile
7656         echo "No pages locked after fsync"
7657
7658         return 0
7659 }
7660 run_test 118i "Fix error before timeout in recoverable error  =========="
7661
7662 [ "$SLOW" = "no" ] && set_resend_count 4
7663
7664 test_118j() {
7665         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7666         remote_ost_nodsh && skip "remote OST with nodsh" && return
7667
7668         reset_async
7669
7670         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7671         set_nodes_failloc "$(osts_nodes)" 0x220
7672
7673         # return -EIO from OST
7674         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7675         RC=$?
7676         set_nodes_failloc "$(osts_nodes)" 0x0
7677         if [[ $RC -eq 0 ]]; then
7678                 error "Must return error due to dropped pages, rc=$RC"
7679         fi
7680
7681         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7682         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7683         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7684         if [[ $LOCKED -ne 0 ]]; then
7685                 error "Locked pages remain in cache, locked=$LOCKED"
7686         fi
7687
7688         # in recoverable error on OST we want resend and stay until it finished
7689         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7690                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7691         fi
7692
7693         rm -f $DIR/$tfile
7694         echo "No pages locked after fsync"
7695
7696         return 0
7697 }
7698 run_test 118j "Simulate unrecoverable OST side error =========="
7699
7700 test_118k()
7701 {
7702         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7703         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7704
7705         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7706         set_nodes_failloc "$(osts_nodes)" 0x20e
7707         test_mkdir -p $DIR/$tdir
7708
7709         for ((i=0;i<10;i++)); do
7710                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7711                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7712                 SLEEPPID=$!
7713                 sleep 0.500s
7714                 kill $SLEEPPID
7715                 wait $SLEEPPID
7716         done
7717
7718         set_nodes_failloc "$(osts_nodes)" 0
7719         rm -rf $DIR/$tdir
7720 }
7721 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7722
7723 test_118l()
7724 {
7725         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7726         # LU-646
7727         test_mkdir -p $DIR/$tdir
7728         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7729         rm -rf $DIR/$tdir
7730 }
7731 run_test 118l "fsync dir ========="
7732
7733 test_118m() # LU-3066
7734 {
7735         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7736         test_mkdir -p $DIR/$tdir
7737         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7738         rm -rf $DIR/$tdir
7739 }
7740 run_test 118m "fdatasync dir ========="
7741
7742 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7743
7744 test_119a() # bug 11737
7745 {
7746         BSIZE=$((512 * 1024))
7747         directio write $DIR/$tfile 0 1 $BSIZE
7748         # We ask to read two blocks, which is more than a file size.
7749         # directio will indicate an error when requested and actual
7750         # sizes aren't equeal (a normal situation in this case) and
7751         # print actual read amount.
7752         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7753         if [ "$NOB" != "$BSIZE" ]; then
7754                 error "read $NOB bytes instead of $BSIZE"
7755         fi
7756         rm -f $DIR/$tfile
7757 }
7758 run_test 119a "Short directIO read must return actual read amount"
7759
7760 test_119b() # bug 11737
7761 {
7762         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7763
7764         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7765         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7766         sync
7767         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7768                 error "direct read failed"
7769         rm -f $DIR/$tfile
7770 }
7771 run_test 119b "Sparse directIO read must return actual read amount"
7772
7773 test_119c() # bug 13099
7774 {
7775         BSIZE=1048576
7776         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7777         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7778         rm -f $DIR/$tfile
7779 }
7780 run_test 119c "Testing for direct read hitting hole"
7781
7782 test_119d() # bug 15950
7783 {
7784         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7785         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7786         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7787         BSIZE=1048576
7788         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7789         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7790         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7791         lctl set_param fail_loc=0x40d
7792         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7793         pid_dio=$!
7794         sleep 1
7795         cat $DIR/$tfile > /dev/null &
7796         lctl set_param fail_loc=0
7797         pid_reads=$!
7798         wait $pid_dio
7799         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7800         sleep 2
7801         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7802         error "the read rpcs have not completed in 2s"
7803         rm -f $DIR/$tfile
7804         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7805 }
7806 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7807
7808 test_120a() {
7809         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7810         test_mkdir -p $DIR/$tdir
7811         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7812                skip "no early lock cancel on server" && return 0
7813
7814         lru_resize_disable mdc
7815         lru_resize_disable osc
7816         cancel_lru_locks mdc
7817         # asynchronous object destroy at MDT could cause bl ast to client
7818         cancel_lru_locks osc
7819
7820         stat $DIR/$tdir > /dev/null
7821         can1=$(do_facet $SINGLEMDS \
7822                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7823                awk '/ldlm_cancel/ {print $2}')
7824         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7825                awk '/ldlm_bl_callback/ {print $2}')
7826         test_mkdir -c1 $DIR/$tdir/d1
7827         can2=$(do_facet $SINGLEMDS \
7828                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7829                awk '/ldlm_cancel/ {print $2}')
7830         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7831                awk '/ldlm_bl_callback/ {print $2}')
7832         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7833         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7834         lru_resize_enable mdc
7835         lru_resize_enable osc
7836 }
7837 run_test 120a "Early Lock Cancel: mkdir test"
7838
7839 test_120b() {
7840         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7841         test_mkdir $DIR/$tdir
7842         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7843                skip "no early lock cancel on server" && return 0
7844         lru_resize_disable mdc
7845         lru_resize_disable osc
7846         cancel_lru_locks mdc
7847         stat $DIR/$tdir > /dev/null
7848         can1=$(do_facet $SINGLEMDS \
7849                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7850                awk '/ldlm_cancel/ {print $2}')
7851         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7852                awk '/ldlm_bl_callback/ {print $2}')
7853         touch $DIR/$tdir/f1
7854         can2=$(do_facet $SINGLEMDS \
7855                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7856                awk '/ldlm_cancel/ {print $2}')
7857         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7858                awk '/ldlm_bl_callback/ {print $2}')
7859         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7860         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7861         lru_resize_enable mdc
7862         lru_resize_enable osc
7863 }
7864 run_test 120b "Early Lock Cancel: create test"
7865
7866 test_120c() {
7867         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7868         test_mkdir -c1 $DIR/$tdir
7869         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7870                skip "no early lock cancel on server" && return 0
7871         lru_resize_disable mdc
7872         lru_resize_disable osc
7873         test_mkdir -p -c1 $DIR/$tdir/d1
7874         test_mkdir -p -c1 $DIR/$tdir/d2
7875         touch $DIR/$tdir/d1/f1
7876         cancel_lru_locks mdc
7877         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7878         can1=$(do_facet $SINGLEMDS \
7879                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7880                awk '/ldlm_cancel/ {print $2}')
7881         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7882                awk '/ldlm_bl_callback/ {print $2}')
7883         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7884         can2=$(do_facet $SINGLEMDS \
7885                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7886                awk '/ldlm_cancel/ {print $2}')
7887         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7888                awk '/ldlm_bl_callback/ {print $2}')
7889         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7890         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7891         lru_resize_enable mdc
7892         lru_resize_enable osc
7893 }
7894 run_test 120c "Early Lock Cancel: link test"
7895
7896 test_120d() {
7897         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7898         test_mkdir -p -c1 $DIR/$tdir
7899         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7900                skip "no early lock cancel on server" && return 0
7901         lru_resize_disable mdc
7902         lru_resize_disable osc
7903         touch $DIR/$tdir
7904         cancel_lru_locks mdc
7905         stat $DIR/$tdir > /dev/null
7906         can1=$(do_facet $SINGLEMDS \
7907                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7908                awk '/ldlm_cancel/ {print $2}')
7909         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7910                awk '/ldlm_bl_callback/ {print $2}')
7911         chmod a+x $DIR/$tdir
7912         can2=$(do_facet $SINGLEMDS \
7913                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7914                awk '/ldlm_cancel/ {print $2}')
7915         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7916                awk '/ldlm_bl_callback/ {print $2}')
7917         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7918         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7919         lru_resize_enable mdc
7920         lru_resize_enable osc
7921 }
7922 run_test 120d "Early Lock Cancel: setattr test"
7923
7924 test_120e() {
7925         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7926         test_mkdir -p -c1 $DIR/$tdir
7927         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7928                skip "no early lock cancel on server" && return 0
7929         lru_resize_disable mdc
7930         lru_resize_disable osc
7931         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7932         cancel_lru_locks mdc
7933         cancel_lru_locks osc
7934         dd if=$DIR/$tdir/f1 of=/dev/null
7935         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7936         # XXX client can not do early lock cancel of OST lock
7937         # during unlink (LU-4206), so cancel osc lock now.
7938         cancel_lru_locks osc
7939         can1=$(do_facet $SINGLEMDS \
7940                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7941                awk '/ldlm_cancel/ {print $2}')
7942         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7943                awk '/ldlm_bl_callback/ {print $2}')
7944         unlink $DIR/$tdir/f1
7945         sleep 5
7946         can2=$(do_facet $SINGLEMDS \
7947                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7948                awk '/ldlm_cancel/ {print $2}')
7949         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7950                awk '/ldlm_bl_callback/ {print $2}')
7951         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7952         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7953         lru_resize_enable mdc
7954         lru_resize_enable osc
7955 }
7956 run_test 120e "Early Lock Cancel: unlink test"
7957
7958 test_120f() {
7959         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7960         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7961                skip "no early lock cancel on server" && return 0
7962         test_mkdir -p -c1 $DIR/$tdir
7963         lru_resize_disable mdc
7964         lru_resize_disable osc
7965         test_mkdir -p -c1 $DIR/$tdir/d1
7966         test_mkdir -p -c1 $DIR/$tdir/d2
7967         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7968         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7969         cancel_lru_locks mdc
7970         cancel_lru_locks osc
7971         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7972         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7973         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7974         # XXX client can not do early lock cancel of OST lock
7975         # during rename (LU-4206), so cancel osc lock now.
7976         cancel_lru_locks osc
7977         can1=$(do_facet $SINGLEMDS \
7978                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7979                awk '/ldlm_cancel/ {print $2}')
7980         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7981                awk '/ldlm_bl_callback/ {print $2}')
7982         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7983         sleep 5
7984         can2=$(do_facet $SINGLEMDS \
7985                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7986                awk '/ldlm_cancel/ {print $2}')
7987         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7988                awk '/ldlm_bl_callback/ {print $2}')
7989         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7990         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7991         lru_resize_enable mdc
7992         lru_resize_enable osc
7993 }
7994 run_test 120f "Early Lock Cancel: rename test"
7995
7996 test_120g() {
7997         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7998         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7999                skip "no early lock cancel on server" && return 0
8000         lru_resize_disable mdc
8001         lru_resize_disable osc
8002         count=10000
8003         echo create $count files
8004         test_mkdir -p $DIR/$tdir
8005         cancel_lru_locks mdc
8006         cancel_lru_locks osc
8007         t0=`date +%s`
8008
8009         can0=$(do_facet $SINGLEMDS \
8010                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8011                awk '/ldlm_cancel/ {print $2}')
8012         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8013                awk '/ldlm_bl_callback/ {print $2}')
8014         createmany -o $DIR/$tdir/f $count
8015         sync
8016         can1=$(do_facet $SINGLEMDS \
8017                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8018                awk '/ldlm_cancel/ {print $2}')
8019         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8020                awk '/ldlm_bl_callback/ {print $2}')
8021         t1=$(date +%s)
8022         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8023         echo rm $count files
8024         rm -r $DIR/$tdir
8025         sync
8026         can2=$(do_facet $SINGLEMDS \
8027                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8028                awk '/ldlm_cancel/ {print $2}')
8029         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8030                awk '/ldlm_bl_callback/ {print $2}')
8031         t2=$(date +%s)
8032         echo total: $count removes in $((t2-t1))
8033         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8034         sleep 2
8035         # wait for commitment of removal
8036         lru_resize_enable mdc
8037         lru_resize_enable osc
8038 }
8039 run_test 120g "Early Lock Cancel: performance test"
8040
8041 test_121() { #bug #10589
8042         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8043         rm -rf $DIR/$tfile
8044         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8045 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8046         lctl set_param fail_loc=0x310
8047         cancel_lru_locks osc > /dev/null
8048         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8049         lctl set_param fail_loc=0
8050         [[ $reads -eq $writes ]] ||
8051                 error "read $reads blocks, must be $writes blocks"
8052 }
8053 run_test 121 "read cancel race ========="
8054
8055 test_123a() { # was test 123, statahead(bug 11401)
8056         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8057         SLOWOK=0
8058         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8059             log "testing on UP system. Performance may be not as good as expected."
8060                         SLOWOK=1
8061         fi
8062
8063         rm -rf $DIR/$tdir
8064         test_mkdir -p $DIR/$tdir
8065         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8066         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8067         MULT=10
8068         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8069                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8070
8071                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8072                 lctl set_param -n llite.*.statahead_max 0
8073                 lctl get_param llite.*.statahead_max
8074                 cancel_lru_locks mdc
8075                 cancel_lru_locks osc
8076                 stime=`date +%s`
8077                 time ls -l $DIR/$tdir | wc -l
8078                 etime=`date +%s`
8079                 delta=$((etime - stime))
8080                 log "ls $i files without statahead: $delta sec"
8081                 lctl set_param llite.*.statahead_max=$max
8082
8083                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8084                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8085                 cancel_lru_locks mdc
8086                 cancel_lru_locks osc
8087                 stime=`date +%s`
8088                 time ls -l $DIR/$tdir | wc -l
8089                 etime=`date +%s`
8090                 delta_sa=$((etime - stime))
8091                 log "ls $i files with statahead: $delta_sa sec"
8092                 lctl get_param -n llite.*.statahead_stats
8093                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8094
8095                 [[ $swrong -lt $ewrong ]] &&
8096                         log "statahead was stopped, maybe too many locks held!"
8097                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8098
8099                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8100                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8101                     lctl set_param -n llite.*.statahead_max 0
8102                     lctl get_param llite.*.statahead_max
8103                     cancel_lru_locks mdc
8104                     cancel_lru_locks osc
8105                     stime=`date +%s`
8106                     time ls -l $DIR/$tdir | wc -l
8107                     etime=`date +%s`
8108                     delta=$((etime - stime))
8109                     log "ls $i files again without statahead: $delta sec"
8110                     lctl set_param llite.*.statahead_max=$max
8111                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8112                         if [  $SLOWOK -eq 0 ]; then
8113                                 error "ls $i files is slower with statahead!"
8114                         else
8115                                 log "ls $i files is slower with statahead!"
8116                         fi
8117                         break
8118                     fi
8119                 fi
8120
8121                 [ $delta -gt 20 ] && break
8122                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8123                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8124         done
8125         log "ls done"
8126
8127         stime=`date +%s`
8128         rm -r $DIR/$tdir
8129         sync
8130         etime=`date +%s`
8131         delta=$((etime - stime))
8132         log "rm -r $DIR/$tdir/: $delta seconds"
8133         log "rm done"
8134         lctl get_param -n llite.*.statahead_stats
8135 }
8136 run_test 123a "verify statahead work"
8137
8138 test_123b () { # statahead(bug 15027)
8139         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8140         test_mkdir -p $DIR/$tdir
8141         createmany -o $DIR/$tdir/$tfile-%d 1000
8142
8143         cancel_lru_locks mdc
8144         cancel_lru_locks osc
8145
8146 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8147         lctl set_param fail_loc=0x80000803
8148         ls -lR $DIR/$tdir > /dev/null
8149         log "ls done"
8150         lctl set_param fail_loc=0x0
8151         lctl get_param -n llite.*.statahead_stats
8152         rm -r $DIR/$tdir
8153         sync
8154
8155 }
8156 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8157
8158 test_124a() {
8159         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8160         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8161                 skip "no lru resize on server" && return 0
8162         local NR=2000
8163         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8164
8165         log "create $NR files at $DIR/$tdir"
8166         createmany -o $DIR/$tdir/f $NR ||
8167                 error "failed to create $NR files in $DIR/$tdir"
8168
8169         cancel_lru_locks mdc
8170         ls -l $DIR/$tdir > /dev/null
8171
8172         local NSDIR=""
8173         local LRU_SIZE=0
8174         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8175                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8176                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8177                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8178                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8179                         log "NSDIR=$NSDIR"
8180                         log "NS=$(basename $NSDIR)"
8181                         break
8182                 fi
8183         done
8184
8185         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8186                 skip "Not enough cached locks created!"
8187                 return 0
8188         fi
8189         log "LRU=$LRU_SIZE"
8190
8191         local SLEEP=30
8192
8193         # We know that lru resize allows one client to hold $LIMIT locks
8194         # for 10h. After that locks begin to be killed by client.
8195         local MAX_HRS=10
8196         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8197         log "LIMIT=$LIMIT"
8198
8199         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8200         # killing locks. Some time was spent for creating locks. This means
8201         # that up to the moment of sleep finish we must have killed some of
8202         # them (10-100 locks). This depends on how fast ther were created.
8203         # Many of them were touched in almost the same moment and thus will
8204         # be killed in groups.
8205         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8206
8207         # Use $LRU_SIZE_B here to take into account real number of locks
8208         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8209         local LRU_SIZE_B=$LRU_SIZE
8210         log "LVF=$LVF"
8211         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8212         log "OLD_LVF=$OLD_LVF"
8213         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8214
8215         # Let's make sure that we really have some margin. Client checks
8216         # cached locks every 10 sec.
8217         SLEEP=$((SLEEP+20))
8218         log "Sleep ${SLEEP} sec"
8219         local SEC=0
8220         while ((SEC<$SLEEP)); do
8221                 echo -n "..."
8222                 sleep 5
8223                 SEC=$((SEC+5))
8224                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8225                 echo -n "$LRU_SIZE"
8226         done
8227         echo ""
8228         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8229         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8230
8231         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8232                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8233                 unlinkmany $DIR/$tdir/f $NR
8234                 return
8235         }
8236
8237         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8238         log "unlink $NR files at $DIR/$tdir"
8239         unlinkmany $DIR/$tdir/f $NR
8240 }
8241 run_test 124a "lru resize ======================================="
8242
8243 get_max_pool_limit()
8244 {
8245         local limit=$($LCTL get_param \
8246                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8247         local max=0
8248         for l in $limit; do
8249                 if [[ $l -gt $max ]]; then
8250                         max=$l
8251                 fi
8252         done
8253         echo $max
8254 }
8255
8256 test_124b() {
8257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8258         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8259                 skip "no lru resize on server" && return 0
8260
8261         LIMIT=$(get_max_pool_limit)
8262
8263         NR=$(($(default_lru_size)*20))
8264         if [[ $NR -gt $LIMIT ]]; then
8265                 log "Limit lock number by $LIMIT locks"
8266                 NR=$LIMIT
8267         fi
8268         lru_resize_disable mdc
8269         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8270                 error "failed to create $DIR/$tdir/disable_lru_resize"
8271
8272         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8273         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8274         cancel_lru_locks mdc
8275         stime=`date +%s`
8276         PID=""
8277         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8278         PID="$PID $!"
8279         sleep 2
8280         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8281         PID="$PID $!"
8282         sleep 2
8283         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8284         PID="$PID $!"
8285         wait $PID
8286         etime=`date +%s`
8287         nolruresize_delta=$((etime-stime))
8288         log "ls -la time: $nolruresize_delta seconds"
8289         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8290         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8291
8292         lru_resize_enable mdc
8293         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8294                 error "failed to create $DIR/$tdir/enable_lru_resize"
8295
8296         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8297         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8298         cancel_lru_locks mdc
8299         stime=`date +%s`
8300         PID=""
8301         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8302         PID="$PID $!"
8303         sleep 2
8304         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8305         PID="$PID $!"
8306         sleep 2
8307         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8308         PID="$PID $!"
8309         wait $PID
8310         etime=`date +%s`
8311         lruresize_delta=$((etime-stime))
8312         log "ls -la time: $lruresize_delta seconds"
8313         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8314
8315         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8316                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8317         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8318                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8319         else
8320                 log "lru resize performs the same with no lru resize"
8321         fi
8322         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8323 }
8324 run_test 124b "lru resize (performance test) ======================="
8325
8326 test_125() { # 13358
8327         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8328         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8329         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8330         test_mkdir -p $DIR/d125 || error "mkdir failed"
8331         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8332         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8333         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8334 }
8335 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8336
8337 test_126() { # bug 12829/13455
8338         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8339         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8340         $GSS && skip "must run as gss disabled" && return
8341
8342         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8343         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8344         rm -f $DIR/$tfile
8345         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8346 }
8347 run_test 126 "check that the fsgid provided by the client is taken into account"
8348
8349 test_127a() { # bug 15521
8350         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8351         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8352         $LCTL set_param osc.*.stats=0
8353         FSIZE=$((2048 * 1024))
8354         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8355         cancel_lru_locks osc
8356         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8357
8358         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8359         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8360                 echo "got $COUNT $NAME"
8361                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8362                 eval $NAME=$COUNT || error "Wrong proc format"
8363
8364                 case $NAME in
8365                         read_bytes|write_bytes)
8366                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8367                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8368                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8369                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8370                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8371                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8372                                 error "sumsquare is too small: $SUMSQ"
8373                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8374                                 error "sumsquare is too big: $SUMSQ"
8375                         ;;
8376                         *) ;;
8377                 esac
8378         done < $DIR/${tfile}.tmp
8379
8380         #check that we actually got some stats
8381         [ "$read_bytes" ] || error "Missing read_bytes stats"
8382         [ "$write_bytes" ] || error "Missing write_bytes stats"
8383         [ "$read_bytes" != 0 ] || error "no read done"
8384         [ "$write_bytes" != 0 ] || error "no write done"
8385 }
8386 run_test 127a "verify the client stats are sane"
8387
8388 test_127b() { # bug LU-333
8389         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8390         $LCTL set_param llite.*.stats=0
8391         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8392         # perform 2 reads and writes so MAX is different from SUM.
8393         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8394         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8395         cancel_lru_locks osc
8396         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8397         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8398
8399         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8400         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8401                 echo "got $COUNT $NAME"
8402                 eval $NAME=$COUNT || error "Wrong proc format"
8403
8404         case $NAME in
8405                 read_bytes)
8406                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8407                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8408                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8409                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8410                         ;;
8411                 write_bytes)
8412                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8413                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8414                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8415                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8416                         ;;
8417                         *) ;;
8418                 esac
8419         done < $TMP/${tfile}.tmp
8420
8421         #check that we actually got some stats
8422         [ "$read_bytes" ] || error "Missing read_bytes stats"
8423         [ "$write_bytes" ] || error "Missing write_bytes stats"
8424         [ "$read_bytes" != 0 ] || error "no read done"
8425         [ "$write_bytes" != 0 ] || error "no write done"
8426 }
8427 run_test 127b "verify the llite client stats are sane"
8428
8429 test_128() { # bug 15212
8430         touch $DIR/$tfile
8431         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8432                 find $DIR/$tfile
8433                 find $DIR/$tfile
8434         EOF
8435
8436         result=$(grep error $TMP/$tfile.log)
8437         rm -f $DIR/$tfile
8438         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8439 }
8440 run_test 128 "interactive lfs for 2 consecutive find's"
8441
8442 set_dir_limits () {
8443         local mntdev
8444         local canondev
8445         local node
8446
8447         local LDPROC=/proc/fs/ldiskfs
8448         local facets=$(get_facets MDS)
8449
8450         for facet in ${facets//,/ }; do
8451                 canondev=$(ldiskfs_canon \
8452                            *.$(convert_facet2label $facet).mntdev $facet)
8453                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8454                                                 LDPROC=/sys/fs/ldiskfs
8455                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8456         done
8457 }
8458
8459 test_129() {
8460         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8461         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8462                 skip "Only applicable to ldiskfs-based MDTs"
8463                 return
8464         fi
8465         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8466         ENOSPC=28
8467         EFBIG=27
8468
8469         rm -rf $DIR/$tdir
8470         test_mkdir -p $DIR/$tdir
8471
8472         # block size of mds1
8473         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8474         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8475         local MAX=$((MDSBLOCKSIZE * 3))
8476         set_dir_limits $MAX
8477         local I=$(stat -c%s "$DIR/$tdir")
8478         local J=0
8479         local STRIPE_COUNT=1
8480         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8481         MAX=$((MAX*STRIPE_COUNT))
8482         while [[ $I -le $MAX ]]; do
8483                 $MULTIOP $DIR/$tdir/$J Oc
8484                 rc=$?
8485                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8486                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8487                 #and EFBIG for previous versions
8488                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8489                         set_dir_limits 0
8490                         echo "return code $rc received as expected"
8491                         multiop $DIR/$tdir/$J Oc ||
8492                                 error_exit "multiop failed w/o dir size limit"
8493
8494                         I=$(stat -c%s "$DIR/$tdir")
8495
8496                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8497                                         $(version_code 2.4.51) ]
8498                         then
8499                                 [[ $I -eq $MAX ]] && return 0
8500                         else
8501                                 [[ $I -gt $MAX ]] && return 0
8502                         fi
8503                         error_exit "current dir size $I, previous limit $MAX"
8504                 elif [ $rc -ne 0 ]; then
8505                         set_dir_limits 0
8506                         error_exit "return code $rc received instead of expected " \
8507                                    "$EFBIG or $ENOSPC, files in dir $I"
8508                 fi
8509                 J=$((J+1))
8510                 I=$(stat -c%s "$DIR/$tdir")
8511         done
8512
8513         set_dir_limits 0
8514         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8515 }
8516 run_test 129 "test directory size limit ========================"
8517
8518 OLDIFS="$IFS"
8519 cleanup_130() {
8520         trap 0
8521         IFS="$OLDIFS"
8522 }
8523
8524 test_130a() {
8525         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8526         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8527                 return
8528
8529         trap cleanup_130 EXIT RETURN
8530
8531         local fm_file=$DIR/$tfile
8532         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8533         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8534                 error "dd failed for $fm_file"
8535
8536         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8537         filefrag -ves $fm_file
8538         RC=$?
8539         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8540                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8541         [ $RC != 0 ] && error "filefrag $fm_file failed"
8542
8543         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8544                       grep -v "ext:" | grep -v "found")
8545         lun=$($GETSTRIPE -i $fm_file)
8546
8547         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8548         IFS=$'\n'
8549         tot_len=0
8550         for line in $filefrag_op
8551         do
8552                 frag_lun=`echo $line | cut -d: -f5`
8553                 ext_len=`echo $line | cut -d: -f4`
8554                 if (( $frag_lun != $lun )); then
8555                         cleanup_130
8556                         error "FIEMAP on 1-stripe file($fm_file) failed"
8557                         return
8558                 fi
8559                 (( tot_len += ext_len ))
8560         done
8561
8562         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8563                 cleanup_130
8564                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8565                 return
8566         fi
8567
8568         cleanup_130
8569
8570         echo "FIEMAP on single striped file succeeded"
8571 }
8572 run_test 130a "FIEMAP (1-stripe file)"
8573
8574 test_130b() {
8575         [ "$OSTCOUNT" -lt "2" ] &&
8576                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8577
8578         [ "$OSTCOUNT" -ge "10" ] &&
8579                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8580
8581         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8582         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8583                 return
8584
8585         trap cleanup_130 EXIT RETURN
8586
8587         local fm_file=$DIR/$tfile
8588         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8589         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8590                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8591
8592         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8593                 error "dd failed on $fm_file"
8594
8595         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8596         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8597                       grep -v "ext:" | grep -v "found")
8598
8599         last_lun=$(echo $filefrag_op | cut -d: -f5)
8600
8601         IFS=$'\n'
8602         tot_len=0
8603         num_luns=1
8604         for line in $filefrag_op
8605         do
8606                 frag_lun=`echo $line | cut -d: -f5`
8607                 ext_len=`echo $line | cut -d: -f4`
8608                 if (( $frag_lun != $last_lun )); then
8609                         if (( tot_len != 1024 )); then
8610                                 cleanup_130
8611                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8612                                 return
8613                         else
8614                                 (( num_luns += 1 ))
8615                                 tot_len=0
8616                         fi
8617                 fi
8618                 (( tot_len += ext_len ))
8619                 last_lun=$frag_lun
8620         done
8621         if (( num_luns != 2 || tot_len != 1024 )); then
8622                 cleanup_130
8623                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8624                 return
8625         fi
8626
8627         cleanup_130
8628
8629         echo "FIEMAP on 2-stripe file succeeded"
8630 }
8631 run_test 130b "FIEMAP (2-stripe file)"
8632
8633 test_130c() {
8634         [ "$OSTCOUNT" -lt "2" ] &&
8635                 skip_env "skipping FIEMAP on 2-stripe file" && return
8636
8637         [ "$OSTCOUNT" -ge "10" ] &&
8638                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8639
8640         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8641         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8642                 return
8643
8644         trap cleanup_130 EXIT RETURN
8645
8646         local fm_file=$DIR/$tfile
8647         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8648         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8649                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8650
8651         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8652
8653         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8654         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8655
8656         last_lun=`echo $filefrag_op | cut -d: -f5`
8657
8658         IFS=$'\n'
8659         tot_len=0
8660         num_luns=1
8661         for line in $filefrag_op
8662         do
8663                 frag_lun=`echo $line | cut -d: -f5`
8664                 ext_len=`echo $line | cut -d: -f4`
8665                 if (( $frag_lun != $last_lun )); then
8666                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8667                         if (( logical != 512 )); then
8668                                 cleanup_130
8669                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8670                                 return
8671                         fi
8672                         if (( tot_len != 512 )); then
8673                                 cleanup_130
8674                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8675                                 return
8676                         else
8677                                 (( num_luns += 1 ))
8678                                 tot_len=0
8679                         fi
8680                 fi
8681                 (( tot_len += ext_len ))
8682                 last_lun=$frag_lun
8683         done
8684         if (( num_luns != 2 || tot_len != 512 )); then
8685                 cleanup_130
8686                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8687                 return
8688         fi
8689
8690         cleanup_130
8691
8692         echo "FIEMAP on 2-stripe file with hole succeeded"
8693 }
8694 run_test 130c "FIEMAP (2-stripe file with hole)"
8695
8696 test_130d() {
8697         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8698
8699         [ "$OSTCOUNT" -ge "10" ] &&
8700                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8701
8702         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8703         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8704
8705         trap cleanup_130 EXIT RETURN
8706
8707         local fm_file=$DIR/$tfile
8708         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8709         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8710                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8711
8712         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8713         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8714                 error "dd failed on $fm_file"
8715
8716         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8717         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8718                 grep -v "ext:" | grep -v "found"`
8719
8720         last_lun=`echo $filefrag_op | cut -d: -f5`
8721
8722         IFS=$'\n'
8723         tot_len=0
8724         num_luns=1
8725         for line in $filefrag_op
8726         do
8727                 frag_lun=`echo $line | cut -d: -f5`
8728                 ext_len=`echo $line | cut -d: -f4`
8729                 if (( $frag_lun != $last_lun )); then
8730                         if (( tot_len != 1024 )); then
8731                                 cleanup_130
8732                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8733                                 return
8734                         else
8735                                 (( num_luns += 1 ))
8736                                 tot_len=0
8737                         fi
8738                 fi
8739                 (( tot_len += ext_len ))
8740                 last_lun=$frag_lun
8741         done
8742         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8743                 cleanup_130
8744                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8745                 return
8746         fi
8747
8748         cleanup_130
8749
8750         echo "FIEMAP on N-stripe file succeeded"
8751 }
8752 run_test 130d "FIEMAP (N-stripe file)"
8753
8754 test_130e() {
8755         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8756
8757         [ "$OSTCOUNT" -ge "10" ] &&
8758                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8759
8760         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8761         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8762
8763         trap cleanup_130 EXIT RETURN
8764
8765         local fm_file=$DIR/$tfile
8766         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8767         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8768                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8769
8770         NUM_BLKS=512
8771         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8772         for ((i = 0; i < $NUM_BLKS; i++))
8773         do
8774                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8775         done
8776
8777         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8778         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8779
8780         last_lun=`echo $filefrag_op | cut -d: -f5`
8781
8782         IFS=$'\n'
8783         tot_len=0
8784         num_luns=1
8785         for line in $filefrag_op
8786         do
8787                 frag_lun=`echo $line | cut -d: -f5`
8788                 ext_len=`echo $line | cut -d: -f4`
8789                 if (( $frag_lun != $last_lun )); then
8790                         if (( tot_len != $EXPECTED_LEN )); then
8791                                 cleanup_130
8792                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8793                                 return
8794                         else
8795                                 (( num_luns += 1 ))
8796                                 tot_len=0
8797                         fi
8798                 fi
8799                 (( tot_len += ext_len ))
8800                 last_lun=$frag_lun
8801         done
8802         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8803                 cleanup_130
8804                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8805                 return
8806         fi
8807
8808         cleanup_130
8809
8810         echo "FIEMAP with continuation calls succeeded"
8811 }
8812 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8813
8814 # Test for writev/readv
8815 test_131a() {
8816         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8817         error "writev test failed"
8818         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8819         error "readv failed"
8820         rm -f $DIR/$tfile
8821 }
8822 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8823
8824 test_131b() {
8825         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8826         error "append writev test failed"
8827         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8828         error "append writev test failed"
8829         rm -f $DIR/$tfile
8830 }
8831 run_test 131b "test append writev"
8832
8833 test_131c() {
8834         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8835         error "NOT PASS"
8836 }
8837 run_test 131c "test read/write on file w/o objects"
8838
8839 test_131d() {
8840         rwv -f $DIR/$tfile -w -n 1 1572864
8841         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8842         if [ "$NOB" != 1572864 ]; then
8843                 error "Short read filed: read $NOB bytes instead of 1572864"
8844         fi
8845         rm -f $DIR/$tfile
8846 }
8847 run_test 131d "test short read"
8848
8849 test_131e() {
8850         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8851         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8852         error "read hitting hole failed"
8853         rm -f $DIR/$tfile
8854 }
8855 run_test 131e "test read hitting hole"
8856
8857 get_ost_param() {
8858         local token=$1
8859         local gl_sum=0
8860         for node in $(osts_nodes); do
8861                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8862                 [ x$gl = x"" ] && gl=0
8863                 gl_sum=$((gl_sum + gl))
8864         done
8865         echo $gl_sum
8866 }
8867
8868 som_mode_switch() {
8869         local som=$1
8870         local gl1=$2
8871         local gl2=$3
8872
8873         if [ x$som = x"enabled" ]; then
8874                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8875                 MOUNT_OPTS=`echo $MOUNT_OPTS |
8876                     sed 's/som_preview,\|,som_preview\|som_preview//g'`
8877                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8878         else
8879                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8880                 MOUNT_OPTS="${MOUNT_OPTS:+$MOUNT_OPTS,}som_preview"
8881                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8882         fi
8883
8884         # do remount to make new mount-conf parameters actual
8885         echo remounting...
8886         sync
8887         stopall
8888         setupall
8889 }
8890
8891 test_132() { #1028, SOM
8892         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8893         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8894         local num=$(get_mds_dir $DIR)
8895         local mymds=mds${num}
8896         local MOUNT_OPTS_SAVE=$MOUNT_OPTS
8897
8898         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8899         cancel_lru_locks osc
8900
8901         som1=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8902
8903         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8904         stat $DIR/$tfile >/dev/null
8905         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8906         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8907         rm $DIR/$tfile
8908         som_mode_switch $som1 $gl1 $gl2
8909
8910         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8911         cancel_lru_locks osc
8912
8913         som2=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8914         if [ $som1 == $som2 ]; then
8915             error "som is still "$som2
8916             if [ x$som2 = x"enabled" ]; then
8917                 som2="disabled"
8918             else
8919                 som2="enabled"
8920             fi
8921         fi
8922
8923         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8924         stat $DIR/$tfile >/dev/null
8925         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8926         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8927         som_mode_switch $som2 $gl1 $gl2
8928         MOUNT_OPTS=$MOUNT_OPTS_SAVE
8929 }
8930 run_test 132 "som avoids glimpse rpc"
8931
8932 check_stats() {
8933         local res
8934         local count
8935         case $1 in
8936         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8937                  ;;
8938         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8939                  ;;
8940         *) error "Wrong argument $1" ;;
8941         esac
8942         echo $res
8943         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8944         # if the argument $3 is zero, it means any stat increment is ok.
8945         if [[ $3 -gt 0 ]]; then
8946                 count=$(echo $res | awk '{ print $2 }')
8947                 [[ $count -ne $3 ]] &&
8948                         error "The $2 counter on $1 is wrong - expected $3"
8949         fi
8950 }
8951
8952 test_133a() {
8953         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8954         remote_ost_nodsh && skip "remote OST with nodsh" && return
8955         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8956
8957         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8958                 { skip "MDS doesn't support rename stats"; return; }
8959         local testdir=$DIR/${tdir}/stats_testdir
8960         mkdir -p $DIR/${tdir}
8961
8962         # clear stats.
8963         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8964         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8965
8966         # verify mdt stats first.
8967         mkdir ${testdir} || error "mkdir failed"
8968         check_stats $SINGLEMDS "mkdir" 1
8969         touch ${testdir}/${tfile} || "touch failed"
8970         check_stats $SINGLEMDS "open" 1
8971         check_stats $SINGLEMDS "close" 1
8972         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8973         check_stats $SINGLEMDS "mknod" 1
8974         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8975         check_stats $SINGLEMDS "unlink" 1
8976         rm -f ${testdir}/${tfile} || error "file remove failed"
8977         check_stats $SINGLEMDS "unlink" 2
8978
8979         # remove working dir and check mdt stats again.
8980         rmdir ${testdir} || error "rmdir failed"
8981         check_stats $SINGLEMDS "rmdir" 1
8982
8983         local testdir1=$DIR/${tdir}/stats_testdir1
8984         mkdir -p ${testdir}
8985         mkdir -p ${testdir1}
8986         touch ${testdir1}/test1
8987         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8988         check_stats $SINGLEMDS "crossdir_rename" 1
8989
8990         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8991         check_stats $SINGLEMDS "samedir_rename" 1
8992
8993         rm -rf $DIR/${tdir}
8994 }
8995 run_test 133a "Verifying MDT stats ========================================"
8996
8997 test_133b() {
8998         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8999         remote_ost_nodsh && skip "remote OST with nodsh" && return
9000         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9001         local testdir=$DIR/${tdir}/stats_testdir
9002         mkdir -p ${testdir} || error "mkdir failed"
9003         touch ${testdir}/${tfile} || "touch failed"
9004         cancel_lru_locks mdc
9005
9006         # clear stats.
9007         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9008         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9009
9010         # extra mdt stats verification.
9011         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9012         check_stats $SINGLEMDS "setattr" 1
9013         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9014         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9015         then            # LU-1740
9016                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9017                 check_stats $SINGLEMDS "getattr" 1
9018         fi
9019         $LFS df || error "lfs failed"
9020         check_stats $SINGLEMDS "statfs" 1
9021
9022         rm -rf $DIR/${tdir}
9023 }
9024 run_test 133b "Verifying extra MDT stats =================================="
9025
9026 test_133c() {
9027         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9028         remote_ost_nodsh && skip "remote OST with nodsh" && return
9029         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9030         local testdir=$DIR/${tdir}/stats_testdir
9031         test_mkdir -p ${testdir} || error "mkdir failed"
9032
9033         # verify obdfilter stats.
9034         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9035         sync
9036         cancel_lru_locks osc
9037         wait_delete_completed
9038
9039         # clear stats.
9040         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9041         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9042
9043         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9044         sync
9045         cancel_lru_locks osc
9046         check_stats ost "write" 1
9047
9048         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9049         check_stats ost "read" 1
9050
9051         > ${testdir}/${tfile} || error "truncate failed"
9052         check_stats ost "punch" 1
9053
9054         rm -f ${testdir}/${tfile} || error "file remove failed"
9055         wait_delete_completed
9056         check_stats ost "destroy" 1
9057
9058         rm -rf $DIR/${tdir}
9059 }
9060 run_test 133c "Verifying OST stats ========================================"
9061
9062 order_2() {
9063         local value=$1
9064         local orig=$value
9065         local order=1
9066
9067         while [ $value -ge 2 ]; do
9068                 order=$((order*2))
9069                 value=$((value/2))
9070         done
9071
9072         if [ $orig -gt $order ]; then
9073                 order=$((order*2))
9074         fi
9075         echo $order
9076 }
9077
9078 size_in_KMGT() {
9079     local value=$1
9080     local size=('K' 'M' 'G' 'T');
9081     local i=0
9082     local size_string=$value
9083
9084     while [ $value -ge 1024 ]; do
9085         if [ $i -gt 3 ]; then
9086             #T is the biggest unit we get here, if that is bigger,
9087             #just return XXXT
9088             size_string=${value}T
9089             break
9090         fi
9091         value=$((value >> 10))
9092         if [ $value -lt 1024 ]; then
9093             size_string=${value}${size[$i]}
9094             break
9095         fi
9096         i=$((i + 1))
9097     done
9098
9099     echo $size_string
9100 }
9101
9102 get_rename_size() {
9103     local size=$1
9104     local context=${2:-.}
9105     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9106                 grep -A1 $context |
9107                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9108     echo $sample
9109 }
9110
9111 test_133d() {
9112         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9113         remote_ost_nodsh && skip "remote OST with nodsh" && return
9114         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9115         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9116         { skip "MDS doesn't support rename stats"; return; }
9117
9118         local testdir1=$DIR/${tdir}/stats_testdir1
9119         local testdir2=$DIR/${tdir}/stats_testdir2
9120
9121         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9122
9123         mkdir -p ${testdir1} || error "mkdir failed"
9124         mkdir -p ${testdir2} || error "mkdir failed"
9125
9126         createmany -o $testdir1/test 512 || error "createmany failed"
9127
9128         # check samedir rename size
9129         mv ${testdir1}/test0 ${testdir1}/test_0
9130
9131         local testdir1_size=$(ls -l $DIR/${tdir} |
9132                 awk '/stats_testdir1/ {print $5}')
9133         local testdir2_size=$(ls -l $DIR/${tdir} |
9134                 awk '/stats_testdir2/ {print $5}')
9135
9136         testdir1_size=$(order_2 $testdir1_size)
9137         testdir2_size=$(order_2 $testdir2_size)
9138
9139         testdir1_size=$(size_in_KMGT $testdir1_size)
9140         testdir2_size=$(size_in_KMGT $testdir2_size)
9141
9142         echo "source rename dir size: ${testdir1_size}"
9143         echo "target rename dir size: ${testdir2_size}"
9144
9145         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9146         eval $cmd || error "$cmd failed"
9147         local samedir=$($cmd | grep 'same_dir')
9148         local same_sample=$(get_rename_size $testdir1_size)
9149         [ -z "$samedir" ] && error "samedir_rename_size count error"
9150         [[ $same_sample -eq 1 ]] ||
9151                 error "samedir_rename_size error $same_sample"
9152         echo "Check same dir rename stats success"
9153
9154         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9155
9156         # check crossdir rename size
9157         mv ${testdir1}/test_0 ${testdir2}/test_0
9158
9159         testdir1_size=$(ls -l $DIR/${tdir} |
9160                 awk '/stats_testdir1/ {print $5}')
9161         testdir2_size=$(ls -l $DIR/${tdir} |
9162                 awk '/stats_testdir2/ {print $5}')
9163
9164         testdir1_size=$(order_2 $testdir1_size)
9165         testdir2_size=$(order_2 $testdir2_size)
9166
9167         testdir1_size=$(size_in_KMGT $testdir1_size)
9168         testdir2_size=$(size_in_KMGT $testdir2_size)
9169
9170         echo "source rename dir size: ${testdir1_size}"
9171         echo "target rename dir size: ${testdir2_size}"
9172
9173         eval $cmd || error "$cmd failed"
9174         local crossdir=$($cmd | grep 'crossdir')
9175         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9176         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9177         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9178         [[ $src_sample -eq 1 ]] ||
9179                 error "crossdir_rename_size error $src_sample"
9180         [[ $tgt_sample -eq 1 ]] ||
9181                 error "crossdir_rename_size error $tgt_sample"
9182         echo "Check cross dir rename stats success"
9183         rm -rf $DIR/${tdir}
9184 }
9185 run_test 133d "Verifying rename_stats ========================================"
9186
9187 test_133e() {
9188         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9189         remote_ost_nodsh && skip "remote OST with nodsh" && return
9190         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9191         local testdir=$DIR/${tdir}/stats_testdir
9192         local ctr f0 f1 bs=32768 count=42 sum
9193
9194         mkdir -p ${testdir} || error "mkdir failed"
9195
9196         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9197
9198         for ctr in {write,read}_bytes; do
9199                 sync
9200                 cancel_lru_locks osc
9201
9202                 do_facet ost1 $LCTL set_param -n \
9203                         "obdfilter.*.exports.clear=clear"
9204
9205                 if [ $ctr = write_bytes ]; then
9206                         f0=/dev/zero
9207                         f1=${testdir}/${tfile}
9208                 else
9209                         f0=${testdir}/${tfile}
9210                         f1=/dev/null
9211                 fi
9212
9213                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9214                         error "dd failed"
9215                 sync
9216                 cancel_lru_locks osc
9217
9218                 sum=$(do_facet ost1 $LCTL get_param \
9219                         "obdfilter.*.exports.*.stats" |
9220                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9221                                 $1 == ctr { sum += $7 }
9222                                 END { printf("%0.0f", sum) }')
9223
9224                 if ((sum != bs * count)); then
9225                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9226                 fi
9227         done
9228
9229         rm -rf $DIR/${tdir}
9230 }
9231 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9232
9233 test_133f() {
9234         local proc_dirs
9235
9236         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9237 /sys/fs/lustre/ /sys/fs/lnet/"
9238         local dir
9239         for dir in $dirs; do
9240                 if [ -d $dir ]; then
9241                         proc_dirs="$proc_dirs $dir"
9242                 fi
9243         done
9244
9245         local facet
9246
9247         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9248         remote_ost_nodsh && skip "remote OST with nodsh" && return
9249         # First without trusting modes.
9250         find $proc_dirs -exec cat '{}' \; &> /dev/null
9251
9252         # Second verifying readability.
9253         find $proc_dirs \
9254                 -type f \
9255                 -exec cat '{}' \; &> /dev/null ||
9256                         error "proc file read failed"
9257
9258         for facet in $SINGLEMDS ost1; do
9259                 do_facet $facet find $proc_dirs \
9260                         ! -name req_history \
9261                         -exec cat '{}' \\\; &> /dev/null
9262
9263                 do_facet $facet find $proc_dirs \
9264                         ! -name req_history \
9265                         -type f \
9266                         -exec cat '{}' \\\; &> /dev/null ||
9267                                 error "proc file read failed"
9268         done
9269 }
9270 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9271
9272 test_133g() {
9273         local proc_dirs
9274
9275         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9276 /sys/fs/lustre/ /sys/fs/lnet/"
9277         local dir
9278         for dir in $dirs; do
9279                 if [ -d $dir ]; then
9280                         proc_dirs="$proc_dirs $dir"
9281                 fi
9282         done
9283
9284         local facet
9285
9286         # Second verifying readability.
9287         find $proc_dirs \
9288                 -type f \
9289                 -not -name force_lbug \
9290                 -not -name changelog_mask \
9291                 -exec badarea_io '{}' \; &> /dev/null ||
9292                 error "find $proc_dirs failed"
9293
9294         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9295                 skip "Too old lustre on MDS"
9296
9297         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9298                 skip "Too old lustre on ost1"
9299
9300         for facet in $SINGLEMDS ost1; do
9301                 do_facet $facet find $proc_dirs \
9302                         -type f \
9303                         -not -name force_lbug \
9304                         -not -name changelog_mask \
9305                         -exec badarea_io '{}' \\\; &> /dev/null ||
9306                 error "$facet find $proc_dirs failed"
9307
9308         done
9309
9310         # remount the FS in case writes/reads /proc break the FS
9311         cleanup || error "failed to unmount"
9312         setup || error "failed to setup"
9313         true
9314 }
9315 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9316
9317 test_140() { #bug-17379
9318         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9319         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9320         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9321         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9322
9323         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9324         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9325         local i=0
9326         while i=`expr $i + 1`; do
9327                 test_mkdir -p $i || error "Creating dir $i"
9328                 cd $i || error "Changing to $i"
9329                 ln -s ../stat stat || error "Creating stat symlink"
9330                 # Read the symlink until ELOOP present,
9331                 # not LBUGing the system is considered success,
9332                 # we didn't overrun the stack.
9333                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9334                 [ $ret -ne 0 ] && {
9335                         if [ $ret -eq 40 ]; then
9336                                 break  # -ELOOP
9337                         else
9338                                 error "Open stat symlink"
9339                                 return
9340                         fi
9341                 }
9342         done
9343         i=`expr $i - 1`
9344         echo "The symlink depth = $i"
9345         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9346                                         error "Invalid symlink depth"
9347
9348         # Test recursive symlink
9349         ln -s symlink_self symlink_self
9350         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9351         echo "open symlink_self returns $ret"
9352         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9353 }
9354 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9355
9356 test_150() {
9357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9358         local TF="$TMP/$tfile"
9359
9360         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9361         cp $TF $DIR/$tfile
9362         cancel_lru_locks osc
9363         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9364         remount_client $MOUNT
9365         df -P $MOUNT
9366         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9367
9368         $TRUNCATE $TF 6000
9369         $TRUNCATE $DIR/$tfile 6000
9370         cancel_lru_locks osc
9371         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9372
9373         echo "12345" >>$TF
9374         echo "12345" >>$DIR/$tfile
9375         cancel_lru_locks osc
9376         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9377
9378         echo "12345" >>$TF
9379         echo "12345" >>$DIR/$tfile
9380         cancel_lru_locks osc
9381         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9382
9383         rm -f $TF
9384         true
9385 }
9386 run_test 150 "truncate/append tests"
9387
9388 #LU-2902 roc_hit was not able to read all values from lproc
9389 function roc_hit_init() {
9390         local list=$(comma_list $(osts_nodes))
9391         local dir=$DIR/$tdir-check
9392         local file=$dir/file
9393         local BEFORE
9394         local AFTER
9395         local idx
9396
9397         test_mkdir -p $dir
9398         #use setstripe to do a write to every ost
9399         for i in $(seq 0 $((OSTCOUNT-1))); do
9400                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9401                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9402                 idx=$(printf %04x $i)
9403                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9404                         awk '$1 == "cache_access" {sum += $7}
9405                                 END { printf("%0.0f", sum) }')
9406
9407                 cancel_lru_locks osc
9408                 cat $file >/dev/null
9409
9410                 AFTER=$(get_osd_param $list *OST*$idx stats |
9411                         awk '$1 == "cache_access" {sum += $7}
9412                                 END { printf("%0.0f", sum) }')
9413
9414                 echo BEFORE:$BEFORE AFTER:$AFTER
9415                 if ! let "AFTER - BEFORE == 4"; then
9416                         rm -rf $dir
9417                         error "roc_hit is not safe to use"
9418                 fi
9419                 rm $file
9420         done
9421
9422         rm -rf $dir
9423 }
9424
9425 function roc_hit() {
9426         local list=$(comma_list $(osts_nodes))
9427         echo $(get_osd_param $list '' stats |
9428                 awk '$1 == "cache_hit" {sum += $7}
9429                         END { printf("%0.0f", sum) }')
9430 }
9431
9432 function set_cache() {
9433         local on=1
9434
9435         if [ "$2" == "off" ]; then
9436                 on=0;
9437         fi
9438         local list=$(comma_list $(osts_nodes))
9439         set_osd_param $list '' $1_cache_enable $on
9440
9441         cancel_lru_locks osc
9442 }
9443
9444 test_151() {
9445         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9446         remote_ost_nodsh && skip "remote OST with nodsh" && return
9447
9448         local CPAGES=3
9449         local list=$(comma_list $(osts_nodes))
9450
9451         # check whether obdfilter is cache capable at all
9452         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9453                 echo "not cache-capable obdfilter"
9454                 return 0
9455         fi
9456
9457         # check cache is enabled on all obdfilters
9458         if get_osd_param $list '' read_cache_enable | grep 0; then
9459                 echo "oss cache is disabled"
9460                 return 0
9461         fi
9462
9463         set_osd_param $list '' writethrough_cache_enable 1
9464
9465         # check write cache is enabled on all obdfilters
9466         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9467                 echo "oss write cache is NOT enabled"
9468                 return 0
9469         fi
9470
9471         roc_hit_init
9472
9473         #define OBD_FAIL_OBD_NO_LRU  0x609
9474         do_nodes $list $LCTL set_param fail_loc=0x609
9475
9476         # pages should be in the case right after write
9477         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9478                 error "dd failed"
9479
9480         local BEFORE=$(roc_hit)
9481         cancel_lru_locks osc
9482         cat $DIR/$tfile >/dev/null
9483         local AFTER=$(roc_hit)
9484
9485         do_nodes $list $LCTL set_param fail_loc=0
9486
9487         if ! let "AFTER - BEFORE == CPAGES"; then
9488                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9489         fi
9490
9491         # the following read invalidates the cache
9492         cancel_lru_locks osc
9493         set_osd_param $list '' read_cache_enable 0
9494         cat $DIR/$tfile >/dev/null
9495
9496         # now data shouldn't be found in the cache
9497         BEFORE=$(roc_hit)
9498         cancel_lru_locks osc
9499         cat $DIR/$tfile >/dev/null
9500         AFTER=$(roc_hit)
9501         if let "AFTER - BEFORE != 0"; then
9502                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9503         fi
9504
9505         set_osd_param $list '' read_cache_enable 1
9506         rm -f $DIR/$tfile
9507 }
9508 run_test 151 "test cache on oss and controls ==============================="
9509
9510 test_152() {
9511         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9512         local TF="$TMP/$tfile"
9513
9514         # simulate ENOMEM during write
9515 #define OBD_FAIL_OST_NOMEM      0x226
9516         lctl set_param fail_loc=0x80000226
9517         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9518         cp $TF $DIR/$tfile
9519         sync || error "sync failed"
9520         lctl set_param fail_loc=0
9521
9522         # discard client's cache
9523         cancel_lru_locks osc
9524
9525         # simulate ENOMEM during read
9526         lctl set_param fail_loc=0x80000226
9527         cmp $TF $DIR/$tfile || error "cmp failed"
9528         lctl set_param fail_loc=0
9529
9530         rm -f $TF
9531 }
9532 run_test 152 "test read/write with enomem ============================"
9533
9534 test_153() {
9535         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9536 }
9537 run_test 153 "test if fdatasync does not crash ======================="
9538
9539 dot_lustre_fid_permission_check() {
9540         local fid=$1
9541         local ffid=$MOUNT/.lustre/fid/$fid
9542         local test_dir=$2
9543
9544         echo "stat fid $fid"
9545         stat $ffid > /dev/null || error "stat $ffid failed."
9546         echo "touch fid $fid"
9547         touch $ffid || error "touch $ffid failed."
9548         echo "write to fid $fid"
9549         cat /etc/hosts > $ffid || error "write $ffid failed."
9550         echo "read fid $fid"
9551         diff /etc/hosts $ffid || error "read $ffid failed."
9552         echo "append write to fid $fid"
9553         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9554         echo "rename fid $fid"
9555         mv $ffid $test_dir/$tfile.1 &&
9556                 error "rename $ffid to $tfile.1 should fail."
9557         touch $test_dir/$tfile.1
9558         mv $test_dir/$tfile.1 $ffid &&
9559                 error "rename $tfile.1 to $ffid should fail."
9560         rm -f $test_dir/$tfile.1
9561         echo "truncate fid $fid"
9562         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9563         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9564                 echo "link fid $fid"
9565                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9566         fi
9567         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9568                 echo "setfacl fid $fid"
9569                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9570                 echo "getfacl fid $fid"
9571                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9572         fi
9573         echo "unlink fid $fid"
9574         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9575         echo "mknod fid $fid"
9576         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9577
9578         fid=[0xf00000400:0x1:0x0]
9579         ffid=$MOUNT/.lustre/fid/$fid
9580
9581         echo "stat non-exist fid $fid"
9582         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9583         echo "write to non-exist fid $fid"
9584         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9585         echo "link new fid $fid"
9586         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9587
9588         mkdir -p $test_dir/$tdir
9589         touch $test_dir/$tdir/$tfile
9590         fid=$($LFS path2fid $test_dir/$tdir)
9591         rc=$?
9592         [ $rc -ne 0 ] &&
9593                 error "error: could not get fid for $test_dir/$dir/$tfile."
9594
9595         ffid=$MOUNT/.lustre/fid/$fid
9596
9597         echo "ls $fid"
9598         ls $ffid > /dev/null || error "ls $ffid failed."
9599         echo "touch $fid/$tfile.1"
9600         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9601
9602         echo "touch $MOUNT/.lustre/fid/$tfile"
9603         touch $MOUNT/.lustre/fid/$tfile && \
9604                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9605
9606         echo "setxattr to $MOUNT/.lustre/fid"
9607         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9608
9609         echo "listxattr for $MOUNT/.lustre/fid"
9610         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9611
9612         echo "delxattr from $MOUNT/.lustre/fid"
9613         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9614
9615         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9616         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9617                 error "touch invalid fid should fail."
9618
9619         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9620         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9621                 error "touch non-normal fid should fail."
9622
9623         echo "rename $tdir to $MOUNT/.lustre/fid"
9624         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9625                 error "rename to $MOUNT/.lustre/fid should fail."
9626
9627         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9628         then            # LU-3547
9629                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9630                 local new_obf_mode=777
9631
9632                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9633                 chmod $new_obf_mode $DIR/.lustre/fid ||
9634                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9635
9636                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9637                 [ $obf_mode -eq $new_obf_mode ] ||
9638                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9639
9640                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9641                 chmod $old_obf_mode $DIR/.lustre/fid ||
9642                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9643         fi
9644
9645         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9646         fid=$($LFS path2fid $test_dir/$tfile-2)
9647
9648         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9649         then # LU-5424
9650                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9651                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9652                         error "create lov data thru .lustre failed"
9653         fi
9654         echo "cp /etc/passwd $test_dir/$tfile-2"
9655         cp /etc/passwd $test_dir/$tfile-2 ||
9656                 error "copy to $test_dir/$tfile-2 failed."
9657         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9658         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9659                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9660
9661         rm -rf $test_dir/tfile.lnk
9662         rm -rf $test_dir/$tfile-2
9663 }
9664
9665 test_154A() {
9666         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9667                 skip "Need MDS version at least 2.4.1" && return
9668
9669         touch $DIR/$tfile
9670         local FID=$($LFS path2fid $DIR/$tfile)
9671         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9672
9673         # check that we get the same pathname back
9674         local FOUND=$($LFS fid2path $MOUNT $FID)
9675         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9676         [ "$FOUND" != "$DIR/$tfile" ] &&
9677                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9678
9679         rm -rf $DIR/$tfile
9680 }
9681 run_test 154A "lfs path2fid and fid2path basic checks"
9682
9683 test_154a() {
9684         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9685         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9686                 { skip "Need MDS version at least 2.2.51"; return 0; }
9687         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9688
9689         cp /etc/hosts $DIR/$tfile
9690
9691         fid=$($LFS path2fid $DIR/$tfile)
9692         rc=$?
9693         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9694
9695         dot_lustre_fid_permission_check "$fid" $DIR ||
9696                 error "dot lustre permission check $fid failed"
9697
9698         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9699
9700         touch $MOUNT/.lustre/file &&
9701                 error "creation is not allowed under .lustre"
9702
9703         mkdir $MOUNT/.lustre/dir &&
9704                 error "mkdir is not allowed under .lustre"
9705
9706         rm -rf $DIR/$tfile
9707 }
9708 run_test 154a "Open-by-FID"
9709
9710 test_154b() {
9711         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9712         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9713                 { skip "Need MDS version at least 2.2.51"; return 0; }
9714
9715         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9716
9717         local remote_dir=$DIR/$tdir/remote_dir
9718         local MDTIDX=1
9719         local rc=0
9720
9721         mkdir -p $DIR/$tdir
9722         $LFS mkdir -i $MDTIDX $remote_dir ||
9723                 error "create remote directory failed"
9724
9725         cp /etc/hosts $remote_dir/$tfile
9726
9727         fid=$($LFS path2fid $remote_dir/$tfile)
9728         rc=$?
9729         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9730
9731         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9732                 error "dot lustre permission check $fid failed"
9733         rm -rf $DIR/$tdir
9734 }
9735 run_test 154b "Open-by-FID for remote directory"
9736
9737 test_154c() {
9738         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9739                 skip "Need MDS version at least 2.4.1" && return
9740
9741         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9742         local FID1=$($LFS path2fid $DIR/$tfile.1)
9743         local FID2=$($LFS path2fid $DIR/$tfile.2)
9744         local FID3=$($LFS path2fid $DIR/$tfile.3)
9745
9746         local N=1
9747         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9748                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9749                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9750                 local want=FID$N
9751                 [ "$FID" = "${!want}" ] ||
9752                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9753                 N=$((N + 1))
9754         done
9755
9756         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9757                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9758                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9759                 N=$((N + 1))
9760         done
9761 }
9762 run_test 154c "lfs path2fid and fid2path multiple arguments"
9763
9764 test_154d() {
9765         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9766                 skip "Need MDS version at least 2.5.53" && return
9767
9768         if remote_mds; then
9769                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9770         else
9771                 nid="0@lo"
9772         fi
9773         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9774         local fd
9775         local cmd
9776
9777         rm -f $DIR/$tfile
9778         touch $DIR/$tfile
9779
9780         fid=$($LFS path2fid $DIR/$tfile)
9781         # Open the file
9782         fd=$(free_fd)
9783         cmd="exec $fd<$DIR/$tfile"
9784         eval $cmd
9785         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9786         echo $fid_list | grep $fid
9787         rc=$?
9788
9789         cmd="exec $fd>/dev/null"
9790         eval $cmd
9791         if [ $rc -ne 0 ]; then
9792                 error "FID $fid not found in open files list $fid_list"
9793         fi
9794 }
9795 run_test 154d "Verify open file fid"
9796
9797 test_154e()
9798 {
9799         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
9800                 skip "Need MDS version at least 2.6.50" && return
9801
9802         if ls -a $MOUNT | grep -q '^\.lustre$'; then
9803                 error ".lustre returned by readdir"
9804         fi
9805 }
9806 run_test 154e ".lustre is not returned by readdir"
9807
9808 test_154f() {
9809         # create parent directory on a single MDT to avoid cross-MDT hardlinks
9810         test_mkdir -p -c1 $DIR/$tdir/d
9811         # test dirs inherit from its stripe
9812         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
9813         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
9814         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
9815         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
9816         touch $DIR/f
9817
9818         # get fid of parents
9819         local FID0=$($LFS path2fid $DIR/$tdir/d)
9820         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
9821         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
9822         local FID3=$($LFS path2fid $DIR)
9823
9824         # check that path2fid --parents returns expected <parent_fid>/name
9825         # 1) test for a directory (single parent)
9826         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
9827         [ "$parent" == "$FID0/foo1" ] ||
9828                 error "expected parent: $FID0/foo1, got: $parent"
9829
9830         # 2) test for a file with nlink > 1 (multiple parents)
9831         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
9832         echo "$parent" | grep -F "$FID1/$tfile" ||
9833                 error "$FID1/$tfile not returned in parent list"
9834         echo "$parent" | grep -F "$FID2/link" ||
9835                 error "$FID2/link not returned in parent list"
9836
9837         # 3) get parent by fid
9838         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
9839         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9840         echo "$parent" | grep -F "$FID1/$tfile" ||
9841                 error "$FID1/$tfile not returned in parent list (by fid)"
9842         echo "$parent" | grep -F "$FID2/link" ||
9843                 error "$FID2/link not returned in parent list (by fid)"
9844
9845         # 4) test for entry in root directory
9846         parent=$($LFS path2fid --parents $DIR/f)
9847         echo "$parent" | grep -F "$FID3/f" ||
9848                 error "$FID3/f not returned in parent list"
9849
9850         # 5) test it on root directory
9851         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
9852                 error "$MOUNT should not have parents"
9853
9854         # enable xattr caching and check that linkea is correctly updated
9855         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
9856         save_lustre_params client "llite.*.xattr_cache" > $save
9857         lctl set_param llite.*.xattr_cache 1
9858
9859         # 6.1) linkea update on rename
9860         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
9861
9862         # get parents by fid
9863         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9864         # foo1 should no longer be returned in parent list
9865         echo "$parent" | grep -F "$FID1" &&
9866                 error "$FID1 should no longer be in parent list"
9867         # the new path should appear
9868         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
9869                 error "$FID2/$tfile.moved is not in parent list"
9870
9871         # 6.2) linkea update on unlink
9872         rm -f $DIR/$tdir/d/foo2/link
9873         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9874         # foo2/link should no longer be returned in parent list
9875         echo "$parent" | grep -F "$FID2/link" &&
9876                 error "$FID2/link should no longer be in parent list"
9877         true
9878
9879         rm -f $DIR/f
9880         restore_lustre_params < $save
9881 }
9882 run_test 154f "get parent fids by reading link ea"
9883
9884 test_155_small_load() {
9885     local temp=$TMP/$tfile
9886     local file=$DIR/$tfile
9887
9888     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9889         error "dd of=$temp bs=6096 count=1 failed"
9890     cp $temp $file
9891     cancel_lru_locks osc
9892     cmp $temp $file || error "$temp $file differ"
9893
9894     $TRUNCATE $temp 6000
9895     $TRUNCATE $file 6000
9896     cmp $temp $file || error "$temp $file differ (truncate1)"
9897
9898     echo "12345" >>$temp
9899     echo "12345" >>$file
9900     cmp $temp $file || error "$temp $file differ (append1)"
9901
9902     echo "12345" >>$temp
9903     echo "12345" >>$file
9904     cmp $temp $file || error "$temp $file differ (append2)"
9905
9906     rm -f $temp $file
9907     true
9908 }
9909
9910 test_155_big_load() {
9911     remote_ost_nodsh && skip "remote OST with nodsh" && return
9912     local temp=$TMP/$tfile
9913     local file=$DIR/$tfile
9914
9915     free_min_max
9916     local cache_size=$(do_facet ost$((MAXI+1)) \
9917         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9918     local large_file_size=$((cache_size * 2))
9919
9920     echo "OSS cache size: $cache_size KB"
9921     echo "Large file size: $large_file_size KB"
9922
9923     [ $MAXV -le $large_file_size ] && \
9924         skip_env "max available OST size needs > $large_file_size KB" && \
9925         return 0
9926
9927     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9928
9929     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9930         error "dd of=$temp bs=$large_file_size count=1k failed"
9931     cp $temp $file
9932     ls -lh $temp $file
9933     cancel_lru_locks osc
9934     cmp $temp $file || error "$temp $file differ"
9935
9936     rm -f $temp $file
9937     true
9938 }
9939
9940 test_155a() {
9941         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9942         set_cache read on
9943         set_cache writethrough on
9944         test_155_small_load
9945 }
9946 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9947
9948 test_155b() {
9949         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9950         set_cache read on
9951         set_cache writethrough off
9952         test_155_small_load
9953 }
9954 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9955
9956 test_155c() {
9957         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9958         set_cache read off
9959         set_cache writethrough on
9960         test_155_small_load
9961 }
9962 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9963
9964 test_155d() {
9965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9966         set_cache read off
9967         set_cache writethrough off
9968         test_155_small_load
9969 }
9970 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9971
9972 test_155e() {
9973         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9974         set_cache read on
9975         set_cache writethrough on
9976         test_155_big_load
9977 }
9978 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9979
9980 test_155f() {
9981         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9982         set_cache read on
9983         set_cache writethrough off
9984         test_155_big_load
9985 }
9986 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9987
9988 test_155g() {
9989         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9990         set_cache read off
9991         set_cache writethrough on
9992         test_155_big_load
9993 }
9994 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9995
9996 test_155h() {
9997         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9998         set_cache read off
9999         set_cache writethrough off
10000         test_155_big_load
10001 }
10002 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10003
10004 test_156() {
10005         remote_ost_nodsh && skip "remote OST with nodsh" && return
10006         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10007         local CPAGES=3
10008         local BEFORE
10009         local AFTER
10010         local file="$DIR/$tfile"
10011
10012         [ "$(facet_fstype ost1)" = "zfs" ] &&
10013                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
10014                 return
10015
10016         roc_hit_init
10017
10018     log "Turn on read and write cache"
10019     set_cache read on
10020     set_cache writethrough on
10021
10022     log "Write data and read it back."
10023     log "Read should be satisfied from the cache."
10024     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10025     BEFORE=`roc_hit`
10026     cancel_lru_locks osc
10027     cat $file >/dev/null
10028     AFTER=`roc_hit`
10029     if ! let "AFTER - BEFORE == CPAGES"; then
10030         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10031     else
10032         log "cache hits:: before: $BEFORE, after: $AFTER"
10033     fi
10034
10035     log "Read again; it should be satisfied from the cache."
10036     BEFORE=$AFTER
10037     cancel_lru_locks osc
10038     cat $file >/dev/null
10039     AFTER=`roc_hit`
10040     if ! let "AFTER - BEFORE == CPAGES"; then
10041         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10042     else
10043         log "cache hits:: before: $BEFORE, after: $AFTER"
10044     fi
10045
10046
10047     log "Turn off the read cache and turn on the write cache"
10048     set_cache read off
10049     set_cache writethrough on
10050
10051     log "Read again; it should be satisfied from the cache."
10052     BEFORE=`roc_hit`
10053     cancel_lru_locks osc
10054     cat $file >/dev/null
10055     AFTER=`roc_hit`
10056     if ! let "AFTER - BEFORE == CPAGES"; then
10057         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10058     else
10059         log "cache hits:: before: $BEFORE, after: $AFTER"
10060     fi
10061
10062     log "Read again; it should not be satisfied from the cache."
10063     BEFORE=$AFTER
10064     cancel_lru_locks osc
10065     cat $file >/dev/null
10066     AFTER=`roc_hit`
10067     if ! let "AFTER - BEFORE == 0"; then
10068         error "IN CACHE: before: $BEFORE, after: $AFTER"
10069     else
10070         log "cache hits:: before: $BEFORE, after: $AFTER"
10071     fi
10072
10073     log "Write data and read it back."
10074     log "Read should be satisfied from the cache."
10075     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10076     BEFORE=`roc_hit`
10077     cancel_lru_locks osc
10078     cat $file >/dev/null
10079     AFTER=`roc_hit`
10080     if ! let "AFTER - BEFORE == CPAGES"; then
10081         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10082     else
10083         log "cache hits:: before: $BEFORE, after: $AFTER"
10084     fi
10085
10086     log "Read again; it should not be satisfied from the cache."
10087     BEFORE=$AFTER
10088     cancel_lru_locks osc
10089     cat $file >/dev/null
10090     AFTER=`roc_hit`
10091     if ! let "AFTER - BEFORE == 0"; then
10092         error "IN CACHE: before: $BEFORE, after: $AFTER"
10093     else
10094         log "cache hits:: before: $BEFORE, after: $AFTER"
10095     fi
10096
10097
10098     log "Turn off read and write cache"
10099     set_cache read off
10100     set_cache writethrough off
10101
10102     log "Write data and read it back"
10103     log "It should not be satisfied from the cache."
10104     rm -f $file
10105     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10106     cancel_lru_locks osc
10107     BEFORE=`roc_hit`
10108     cat $file >/dev/null
10109     AFTER=`roc_hit`
10110         if ! let "AFTER - BEFORE == 0"; then
10111                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10112         else
10113                 log "cache hits:: before: $BEFORE, after: $AFTER"
10114         fi
10115
10116     log "Turn on the read cache and turn off the write cache"
10117     set_cache read on
10118     set_cache writethrough off
10119
10120     log "Write data and read it back"
10121     log "It should not be satisfied from the cache."
10122     rm -f $file
10123     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10124     BEFORE=`roc_hit`
10125     cancel_lru_locks osc
10126     cat $file >/dev/null
10127     AFTER=`roc_hit`
10128         if ! let "AFTER - BEFORE == 0"; then
10129                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10130         else
10131                 log "cache hits:: before: $BEFORE, after: $AFTER"
10132         fi
10133
10134     log "Read again; it should be satisfied from the cache."
10135     BEFORE=`roc_hit`
10136     cancel_lru_locks osc
10137     cat $file >/dev/null
10138     AFTER=`roc_hit`
10139     if ! let "AFTER - BEFORE == CPAGES"; then
10140         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10141     else
10142         log "cache hits:: before: $BEFORE, after: $AFTER"
10143     fi
10144
10145     rm -f $file
10146 }
10147 run_test 156 "Verification of tunables ============================"
10148
10149 #Changelogs
10150 err17935 () {
10151         if [[ $MDSCOUNT -gt 1 ]]; then
10152                 error_ignore bz17935 $*
10153         else
10154                 error $*
10155         fi
10156 }
10157
10158 changelog_chmask()
10159 {
10160         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10161
10162         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10163
10164         if [ $MASK -eq 1 ]; then
10165                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10166         else
10167                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10168         fi
10169 }
10170
10171 changelog_extract_field() {
10172         local mdt=$1
10173         local cltype=$2
10174         local file=$3
10175         local identifier=$4
10176
10177         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10178                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10179                 tail -1
10180 }
10181
10182 test_160a() {
10183         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10184         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10185         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10186                 { skip "Need MDS version at least 2.2.0"; return; }
10187
10188         local CL_USERS="mdd.$MDT0.changelog_users"
10189         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10190         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10191         echo "Registered as changelog user $USER"
10192         $GET_CL_USERS | grep -q $USER ||
10193                 error "User $USER not found in changelog_users"
10194
10195         # change something
10196         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10197         touch $DIR/$tdir/pics/2008/zachy/timestamp
10198         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10199         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10200         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10201         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10202         rm $DIR/$tdir/pics/desktop.jpg
10203
10204         $LFS changelog $MDT0 | tail -5
10205
10206         echo "verifying changelog mask"
10207         changelog_chmask "MKDIR"
10208         changelog_chmask "CLOSE"
10209
10210         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10211         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10212
10213         changelog_chmask "MKDIR"
10214         changelog_chmask "CLOSE"
10215
10216         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10217         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10218
10219         $LFS changelog $MDT0
10220         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10221         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10222         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10223         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10224
10225         # verify contents
10226         echo "verifying target fid"
10227         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10228         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10229         [ "$fidc" == "$fidf" ] ||
10230                 err17935 "fid in changelog $fidc != file fid $fidf"
10231         echo "verifying parent fid"
10232         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10233         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10234         [ "$fidc" == "$fidf" ] ||
10235                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10236
10237         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10238         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10239         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10240         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10241         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10242                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10243
10244         MIN_REC=$($GET_CL_USERS |
10245                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10246         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10247         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10248         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10249                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10250
10251         # LU-3446 changelog index reset on MDT restart
10252         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10253         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10254         $LFS changelog_clear $MDT0 $USER 0
10255         stop $SINGLEMDS || error "Fail to stop MDT."
10256         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10257         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10258         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10259         [ $CUR_REC1 == $CUR_REC2 ] ||
10260                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10261
10262         echo "verifying user deregister"
10263         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10264         $GET_CL_USERS | grep -q $USER &&
10265                 error "User $USER still in changelog_users"
10266
10267         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10268         if [ $USERS -eq 0 ]; then
10269                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10270                 touch $DIR/$tdir/chloe
10271                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10272                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10273                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10274         else
10275                 echo "$USERS other changelog users; can't verify off"
10276         fi
10277 }
10278 run_test 160a "changelog sanity"
10279
10280 test_160b() { # LU-3587
10281         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10282         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10283         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10284                 { skip "Need MDS version at least 2.2.0"; return; }
10285
10286         local CL_USERS="mdd.$MDT0.changelog_users"
10287         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10288         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10289         echo "Registered as changelog user $USER"
10290         $GET_CL_USERS | grep -q $USER ||
10291                 error "User $USER not found in changelog_users"
10292
10293         local LONGNAME1=$(str_repeat a 255)
10294         local LONGNAME2=$(str_repeat b 255)
10295
10296         cd $DIR
10297         echo "creating very long named file"
10298         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10299         echo "moving very long named file"
10300         mv $LONGNAME1 $LONGNAME2
10301
10302         $LFS changelog $MDT0 | grep RENME
10303
10304         echo "deregistering $USER"
10305         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10306
10307         rm -f $LONGNAME2
10308 }
10309 run_test 160b "Verify that very long rename doesn't crash in changelog"
10310
10311 test_160c() {
10312         local rc=0
10313         local server_version=$(lustre_version_code $SINGLEMDS)
10314
10315         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10316                 [[ $server_version -gt $(version_code 2.5.1) &&
10317                    $server_version -lt $(version_code 2.5.50) ]] ||
10318                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10319         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10320
10321         # Registration step
10322         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10323                 changelog_register -n)
10324
10325         rm -rf $DIR/$tdir
10326         mkdir -p $DIR/$tdir
10327         $MCREATE $DIR/$tdir/foo_160c
10328         changelog_chmask "TRUNC"
10329         $TRUNCATE $DIR/$tdir/foo_160c 200
10330         changelog_chmask "TRUNC"
10331         $TRUNCATE $DIR/$tdir/foo_160c 199
10332         $LFS changelog $MDT0
10333         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10334         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10335         $LFS changelog_clear $MDT0 $USER 0
10336
10337         # Deregistration step
10338         echo "deregistering $USER"
10339         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10340 }
10341 run_test 160c "verify that changelog log catch the truncate event"
10342
10343 test_161a() {
10344         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10345         test_mkdir -p -c1 $DIR/$tdir
10346         cp /etc/hosts $DIR/$tdir/$tfile
10347         test_mkdir -c1 $DIR/$tdir/foo1
10348         test_mkdir -c1 $DIR/$tdir/foo2
10349         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10350         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10351         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10352         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10353         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10354         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10355                 $LFS fid2path $DIR $FID
10356                 err17935 "bad link ea"
10357         fi
10358     # middle
10359     rm $DIR/$tdir/foo2/zachary
10360     # last
10361     rm $DIR/$tdir/foo2/thor
10362     # first
10363     rm $DIR/$tdir/$tfile
10364     # rename
10365     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10366     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10367         then
10368         $LFS fid2path $DIR $FID
10369         err17935 "bad link rename"
10370     fi
10371     rm $DIR/$tdir/foo2/maggie
10372
10373         # overflow the EA
10374         local longname=filename_avg_len_is_thirty_two_
10375         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10376                 error "failed to hardlink many files"
10377         links=$($LFS fid2path $DIR $FID | wc -l)
10378         echo -n "${links}/1000 links in link EA"
10379         [[ $links -gt 60 ]] ||
10380                 err17935 "expected at least 60 links in link EA"
10381         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10382                 error "failed to unlink many hardlinks"
10383 }
10384 run_test 161a "link ea sanity"
10385
10386 test_161b() {
10387         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10388         [ $MDSCOUNT -lt 2 ] &&
10389                 skip "skipping remote directory test" && return
10390         local MDTIDX=1
10391         local remote_dir=$DIR/$tdir/remote_dir
10392
10393         mkdir -p $DIR/$tdir
10394         $LFS mkdir -i $MDTIDX $remote_dir ||
10395                 error "create remote directory failed"
10396
10397         cp /etc/hosts $remote_dir/$tfile
10398         mkdir -p $remote_dir/foo1
10399         mkdir -p $remote_dir/foo2
10400         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10401         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10402         ln $remote_dir/$tfile $remote_dir/foo1/luna
10403         ln $remote_dir/$tfile $remote_dir/foo2/thor
10404
10405         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10406                      tr -d ']')
10407         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10408                 $LFS fid2path $DIR $FID
10409                 err17935 "bad link ea"
10410         fi
10411         # middle
10412         rm $remote_dir/foo2/zachary
10413         # last
10414         rm $remote_dir/foo2/thor
10415         # first
10416         rm $remote_dir/$tfile
10417         # rename
10418         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10419         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10420         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10421                 $LFS fid2path $DIR $FID
10422                 err17935 "bad link rename"
10423         fi
10424         rm $remote_dir/foo2/maggie
10425
10426         # overflow the EA
10427         local longname=filename_avg_len_is_thirty_two_
10428         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10429                 error "failed to hardlink many files"
10430         links=$($LFS fid2path $DIR $FID | wc -l)
10431         echo -n "${links}/1000 links in link EA"
10432         [[ ${links} -gt 60 ]] ||
10433                 err17935 "expected at least 60 links in link EA"
10434         unlinkmany $remote_dir/foo2/$longname 1000 ||
10435         error "failed to unlink many hardlinks"
10436 }
10437 run_test 161b "link ea sanity under remote directory"
10438
10439 test_161c() {
10440         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10441         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10442         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10443                 skip "Need MDS version at least 2.1.5" && return
10444
10445         # define CLF_RENAME_LAST 0x0001
10446         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10447         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10448                 changelog_register -n)
10449         rm -rf $DIR/$tdir
10450         mkdir -p $DIR/$tdir
10451         touch $DIR/$tdir/foo_161c
10452         touch $DIR/$tdir/bar_161c
10453         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10454         $LFS changelog $MDT0 | grep RENME
10455         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10456                 cut -f5 -d' ')
10457         $LFS changelog_clear $MDT0 $USER 0
10458         if [ x$flags != "x0x1" ]; then
10459                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10460                         $USER
10461                 error "flag $flags is not 0x1"
10462         fi
10463         echo "rename overwrite a target having nlink = 1," \
10464                 "changelog record has flags of $flags"
10465
10466         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10467         touch $DIR/$tdir/foo_161c
10468         touch $DIR/$tdir/bar_161c
10469         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10470         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10471         $LFS changelog $MDT0 | grep RENME
10472         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10473         $LFS changelog_clear $MDT0 $USER 0
10474         if [ x$flags != "x0x0" ]; then
10475                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10476                         $USER
10477                 error "flag $flags is not 0x0"
10478         fi
10479         echo "rename overwrite a target having nlink > 1," \
10480                 "changelog record has flags of $flags"
10481
10482         # rename doesn't overwrite a target (changelog flag 0x0)
10483         touch $DIR/$tdir/foo_161c
10484         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10485         $LFS changelog $MDT0 | grep RENME
10486         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10487         $LFS changelog_clear $MDT0 $USER 0
10488         if [ x$flags != "x0x0" ]; then
10489                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10490                         $USER
10491                 error "flag $flags is not 0x0"
10492         fi
10493         echo "rename doesn't overwrite a target," \
10494                 "changelog record has flags of $flags"
10495
10496         # define CLF_UNLINK_LAST 0x0001
10497         # unlink a file having nlink = 1 (changelog flag 0x1)
10498         rm -f $DIR/$tdir/foo2_161c
10499         $LFS changelog $MDT0 | grep UNLNK
10500         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10501         $LFS changelog_clear $MDT0 $USER 0
10502         if [ x$flags != "x0x1" ]; then
10503                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10504                         $USER
10505                 error "flag $flags is not 0x1"
10506         fi
10507         echo "unlink a file having nlink = 1," \
10508                 "changelog record has flags of $flags"
10509
10510         # unlink a file having nlink > 1 (changelog flag 0x0)
10511         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10512         rm -f $DIR/$tdir/foobar_161c
10513         $LFS changelog $MDT0 | grep UNLNK
10514         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10515         $LFS changelog_clear $MDT0 $USER 0
10516         if [ x$flags != "x0x0" ]; then
10517                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10518                         $USER
10519                 error "flag $flags is not 0x0"
10520         fi
10521         echo "unlink a file having nlink > 1," \
10522                 "changelog record has flags of $flags"
10523         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10524 }
10525 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10526
10527 check_path() {
10528     local expected=$1
10529     shift
10530     local fid=$2
10531
10532     local path=$(${LFS} fid2path $*)
10533     RC=$?
10534
10535     if [ $RC -ne 0 ]; then
10536         err17935 "path looked up of $expected failed. Error $RC"
10537         return $RC
10538     elif [ "${path}" != "${expected}" ]; then
10539         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10540         return 2
10541     fi
10542     echo "fid $fid resolves to path $path (expected $expected)"
10543 }
10544
10545 test_162() {
10546         # Make changes to filesystem
10547         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10548         test_mkdir -p -c1 $DIR/$tdir/d2
10549         touch $DIR/$tdir/d2/$tfile
10550         touch $DIR/$tdir/d2/x1
10551         touch $DIR/$tdir/d2/x2
10552         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10553         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10554         # regular file
10555         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10556         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10557                 error "check path $tdir/d2/$tfile failed"
10558
10559         # softlink
10560         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10561         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10562         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10563                 error "check path $tdir/d2/p/q/r/slink failed"
10564
10565         # softlink to wrong file
10566         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10567         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10568         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10569                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10570
10571         # hardlink
10572         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10573         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10574         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10575         # fid2path dir/fsname should both work
10576         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10577                 error "check path $tdir/d2/a/b/c/new_file failed"
10578         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10579                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10580
10581         # hardlink count: check that there are 2 links
10582         # Doesnt work with CMD yet: 17935
10583         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10584                 err17935 "expected 2 links"
10585
10586         # hardlink indexing: remove the first link
10587         rm $DIR/$tdir/d2/p/q/r/hlink
10588         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10589                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10590
10591         return 0
10592 }
10593 run_test 162 "path lookup sanity"
10594
10595 test_162b() {
10596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10597         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10598
10599         mkdir $DIR/$tdir
10600         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10601                                 error "create striped dir failed"
10602
10603         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10604                                         tail -n 1 | awk '{print $2}')
10605         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10606
10607         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10608         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10609
10610         # regular file
10611         for ((i=0;i<5;i++)); do
10612                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10613                         error "get fid for f$i failed"
10614                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10615                         error "check path $tdir/striped_dir/f$i failed"
10616
10617                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10618                         error "get fid for d$i failed"
10619                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10620                         error "check path $tdir/striped_dir/d$i failed"
10621         done
10622
10623         return 0
10624 }
10625 run_test 162b "striped directory path lookup sanity"
10626
10627 test_169() {
10628         # do directio so as not to populate the page cache
10629         log "creating a 10 Mb file"
10630         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10631         log "starting reads"
10632         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10633         log "truncating the file"
10634         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10635         log "killing dd"
10636         kill %+ || true # reads might have finished
10637         echo "wait until dd is finished"
10638         wait
10639         log "removing the temporary file"
10640         rm -rf $DIR/$tfile || error "tmp file removal failed"
10641 }
10642 run_test 169 "parallel read and truncate should not deadlock"
10643
10644 test_170() {
10645         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10646         $LCTL clear     # bug 18514
10647         $LCTL debug_daemon start $TMP/${tfile}_log_good
10648         touch $DIR/$tfile
10649         $LCTL debug_daemon stop
10650         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10651                error "sed failed to read log_good"
10652
10653         $LCTL debug_daemon start $TMP/${tfile}_log_good
10654         rm -rf $DIR/$tfile
10655         $LCTL debug_daemon stop
10656
10657         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10658                error "lctl df log_bad failed"
10659
10660         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10661         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10662
10663         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10664         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10665
10666         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10667                 error "bad_line good_line1 good_line2 are empty"
10668
10669         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10670         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10671         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10672
10673         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10674         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10675         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10676
10677         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10678                 error "bad_line_new good_line_new are empty"
10679
10680         local expected_good=$((good_line1 + good_line2*2))
10681
10682         rm -f $TMP/${tfile}*
10683         # LU-231, short malformed line may not be counted into bad lines
10684         if [ $bad_line -ne $bad_line_new ] &&
10685                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10686                 error "expected $bad_line bad lines, but got $bad_line_new"
10687                 return 1
10688         fi
10689
10690         if [ $expected_good -ne $good_line_new ]; then
10691                 error "expected $expected_good good lines, but got $good_line_new"
10692                 return 2
10693         fi
10694         true
10695 }
10696 run_test 170 "test lctl df to handle corrupted log ====================="
10697
10698 test_171() { # bug20592
10699         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10700 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10701         $LCTL set_param fail_loc=0x50e
10702         $LCTL set_param fail_val=3000
10703         multiop_bg_pause $DIR/$tfile O_s || true
10704         local MULTIPID=$!
10705         kill -USR1 $MULTIPID
10706         # cause log dump
10707         sleep 3
10708         wait $MULTIPID
10709         if dmesg | grep "recursive fault"; then
10710                 error "caught a recursive fault"
10711         fi
10712         $LCTL set_param fail_loc=0
10713         true
10714 }
10715 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10716
10717 # it would be good to share it with obdfilter-survey/iokit-libecho code
10718 setup_obdecho_osc () {
10719         local rc=0
10720         local ost_nid=$1
10721         local obdfilter_name=$2
10722         echo "Creating new osc for $obdfilter_name on $ost_nid"
10723         # make sure we can find loopback nid
10724         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10725
10726         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10727                            ${obdfilter_name}_osc_UUID || rc=2; }
10728         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10729                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10730         return $rc
10731 }
10732
10733 cleanup_obdecho_osc () {
10734         local obdfilter_name=$1
10735         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10736         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10737         return 0
10738 }
10739
10740 obdecho_test() {
10741         local OBD=$1
10742         local node=$2
10743         local pages=${3:-64}
10744         local rc=0
10745         local id
10746
10747         local count=10
10748         local obd_size=$(get_obd_size $node $OBD)
10749         local page_size=$(get_page_size $node)
10750         if [[ -n "$obd_size" ]]; then
10751                 local new_count=$((obd_size / (pages * page_size / 1024)))
10752                 [[ $new_count -ge $count ]] || count=$new_count
10753         fi
10754
10755         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10756         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10757                            rc=2; }
10758         if [ $rc -eq 0 ]; then
10759             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10760             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10761         fi
10762         echo "New object id is $id"
10763         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10764                            rc=4; }
10765         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10766                            "test_brw $count w v $pages $id" || rc=4; }
10767         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10768                            rc=4; }
10769         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10770                                         "cleanup" || rc=5; }
10771         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10772                                         "detach" || rc=6; }
10773         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10774         return $rc
10775 }
10776
10777 test_180a() {
10778         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10779         remote_ost_nodsh && skip "remote OST with nodsh" && return
10780         local rc=0
10781         local rmmod_local=0
10782
10783         if ! module_loaded obdecho; then
10784             load_module obdecho/obdecho
10785             rmmod_local=1
10786         fi
10787
10788         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10789         local host=$(lctl get_param -n osc.$osc.import |
10790                              awk '/current_connection:/ {print $2}' )
10791         local target=$(lctl get_param -n osc.$osc.import |
10792                              awk '/target:/ {print $2}' )
10793         target=${target%_UUID}
10794
10795         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10796         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10797         [[ -n $target ]] && cleanup_obdecho_osc $target
10798         [ $rmmod_local -eq 1 ] && rmmod obdecho
10799         return $rc
10800 }
10801 run_test 180a "test obdecho on osc"
10802
10803 test_180b() {
10804         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10805         remote_ost_nodsh && skip "remote OST with nodsh" && return
10806         local rc=0
10807         local rmmod_remote=0
10808
10809         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10810                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10811                       "modprobe obdecho; }" && rmmod_remote=1
10812         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10813         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10814         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10815         return $rc
10816 }
10817 run_test 180b "test obdecho directly on obdfilter"
10818
10819 test_180c() { # LU-2598
10820         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10821         remote_ost_nodsh && skip "remote OST with nodsh" && return
10822         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10823                 skip "Need MDS version at least 2.4.0" && return
10824
10825         local rc=0
10826         local rmmod_remote=false
10827         local pages=16384 # 64MB bulk I/O RPC size
10828         local target
10829
10830         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10831                 rmmod_remote=true || error "failed to load module obdecho"
10832
10833         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10834                 head -n1)
10835         if [ -n "$target" ]; then
10836                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10837         else
10838                 echo "there is no obdfilter target on ost1"
10839                 rc=2
10840         fi
10841         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10842         return $rc
10843 }
10844 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10845
10846 test_181() { # bug 22177
10847         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10848         # create enough files to index the directory
10849         createmany -o $DIR/$tdir/foobar 4000
10850         # print attributes for debug purpose
10851         lsattr -d .
10852         # open dir
10853         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10854         MULTIPID=$!
10855         # remove the files & current working dir
10856         unlinkmany $DIR/$tdir/foobar 4000
10857         rmdir $DIR/$tdir
10858         kill -USR1 $MULTIPID
10859         wait $MULTIPID
10860         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10861         return 0
10862 }
10863 run_test 181 "Test open-unlinked dir ========================"
10864
10865 test_182() {
10866         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10867         # disable MDC RPC lock wouldn't crash client
10868         local fcount=1000
10869         local tcount=4
10870
10871         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10872 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10873         $LCTL set_param fail_loc=0x804
10874
10875         for (( i=0; i < $tcount; i++ )) ; do
10876                 mkdir $DIR/$tdir/$i
10877                 createmany -o $DIR/$tdir/$i/f- $fcount &
10878         done
10879         wait
10880
10881         for (( i=0; i < $tcount; i++ )) ; do
10882                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10883         done
10884         wait
10885
10886         rm -rf $DIR/$tdir
10887
10888         $LCTL set_param fail_loc=0
10889 }
10890 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10891
10892 test_183() { # LU-2275
10893         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10894         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10895                 skip "Need MDS version at least 2.3.56" && return
10896
10897         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10898         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10899         echo aaa > $DIR/$tdir/$tfile
10900
10901 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10902         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10903
10904         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10905         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10906
10907         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10908
10909         # Flush negative dentry cache
10910         touch $DIR/$tdir/$tfile
10911
10912         # We are not checking for any leaked references here, they'll
10913         # become evident next time we do cleanup with module unload.
10914         rm -rf $DIR/$tdir
10915 }
10916 run_test 183 "No crash or request leak in case of strange dispositions ========"
10917
10918 # test suite 184 is for LU-2016, LU-2017
10919 test_184a() {
10920         check_swap_layouts_support && return 0
10921
10922         dir0=$DIR/$tdir/$testnum
10923         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
10924         ref1=/etc/passwd
10925         ref2=/etc/group
10926         file1=$dir0/f1
10927         file2=$dir0/f2
10928         $SETSTRIPE -c1 $file1
10929         cp $ref1 $file1
10930         $SETSTRIPE -c2 $file2
10931         cp $ref2 $file2
10932         gen1=$($GETSTRIPE -g $file1)
10933         gen2=$($GETSTRIPE -g $file2)
10934
10935         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10936         gen=$($GETSTRIPE -g $file1)
10937         [[ $gen1 != $gen ]] ||
10938                 "Layout generation on $file1 does not change"
10939         gen=$($GETSTRIPE -g $file2)
10940         [[ $gen2 != $gen ]] ||
10941                 "Layout generation on $file2 does not change"
10942
10943         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10944         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10945 }
10946 run_test 184a "Basic layout swap"
10947
10948 test_184b() {
10949         check_swap_layouts_support && return 0
10950
10951         dir0=$DIR/$tdir/$testnum
10952         mkdir -p $dir0 || error "creating dir $dir0"
10953         file1=$dir0/f1
10954         file2=$dir0/f2
10955         file3=$dir0/f3
10956         dir1=$dir0/d1
10957         dir2=$dir0/d2
10958         mkdir $dir1 $dir2
10959         $SETSTRIPE -c1 $file1
10960         $SETSTRIPE -c2 $file2
10961         $SETSTRIPE -c1 $file3
10962         chown $RUNAS_ID $file3
10963         gen1=$($GETSTRIPE -g $file1)
10964         gen2=$($GETSTRIPE -g $file2)
10965
10966         $LFS swap_layouts $dir1 $dir2 &&
10967                 error "swap of directories layouts should fail"
10968         $LFS swap_layouts $dir1 $file1 &&
10969                 error "swap of directory and file layouts should fail"
10970         $RUNAS $LFS swap_layouts $file1 $file2 &&
10971                 error "swap of file we cannot write should fail"
10972         $LFS swap_layouts $file1 $file3 &&
10973                 error "swap of file with different owner should fail"
10974         /bin/true # to clear error code
10975 }
10976 run_test 184b "Forbidden layout swap (will generate errors)"
10977
10978 test_184c() {
10979         check_swap_layouts_support && return 0
10980
10981         local dir0=$DIR/$tdir/$testnum
10982         mkdir -p $dir0 || error "creating dir $dir0"
10983
10984         local ref1=$dir0/ref1
10985         local ref2=$dir0/ref2
10986         local file1=$dir0/file1
10987         local file2=$dir0/file2
10988         # create a file large enough for the concurent test
10989         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10990         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10991         echo "ref file size: ref1($(stat -c %s $ref1))," \
10992              "ref2($(stat -c %s $ref2))"
10993
10994         cp $ref2 $file2
10995         dd if=$ref1 of=$file1 bs=16k &
10996         local DD_PID=$!
10997
10998         # Make sure dd starts to copy file
10999         while [ ! -f $file1 ]; do sleep 0.1; done
11000
11001         $LFS swap_layouts $file1 $file2
11002         local rc=$?
11003         wait $DD_PID
11004         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
11005         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
11006
11007         # how many bytes copied before swapping layout
11008         local copied=$(stat -c %s $file2)
11009         local remaining=$(stat -c %s $ref1)
11010         remaining=$((remaining - copied))
11011         echo "Copied $copied bytes before swapping layout..."
11012
11013         cmp -n $copied $file1 $ref2 | grep differ &&
11014                 error "Content mismatch [0, $copied) of ref2 and file1"
11015         cmp -n $copied $file2 $ref1 ||
11016                 error "Content mismatch [0, $copied) of ref1 and file2"
11017         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
11018                 error "Content mismatch [$copied, EOF) of ref1 and file1"
11019
11020         # clean up
11021         rm -f $ref1 $ref2 $file1 $file2
11022 }
11023 run_test 184c "Concurrent write and layout swap"
11024
11025 test_184d() {
11026         check_swap_layouts_support && return 0
11027         [ -z "$(which getfattr 2>/dev/null)" ] &&
11028                 skip "no getfattr command" && return 0
11029
11030         local file1=$DIR/$tdir/$tfile-1
11031         local file2=$DIR/$tdir/$tfile-2
11032         local file3=$DIR/$tdir/$tfile-3
11033         local lovea1
11034         local lovea2
11035
11036         mkdir -p $DIR/$tdir
11037         touch $file1 || error "create $file1 failed"
11038         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11039                 error "create $file2 failed"
11040         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11041                 error "create $file3 failed"
11042         lovea1=$($LFS getstripe $file1 | sed 1d)
11043
11044         $LFS swap_layouts $file2 $file3 ||
11045                 error "swap $file2 $file3 layouts failed"
11046         $LFS swap_layouts $file1 $file2 ||
11047                 error "swap $file1 $file2 layouts failed"
11048
11049         lovea2=$($LFS getstripe $file2 | sed 1d)
11050         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
11051
11052         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11053         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
11054 }
11055 run_test 184d "allow stripeless layouts swap"
11056
11057
11058 test_185() { # LU-2441
11059         # LU-3553 - no volatile file support in old servers
11060         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
11061                 { skip "Need MDS version at least 2.3.60"; return 0; }
11062
11063         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11064         touch $DIR/$tdir/spoo
11065         local mtime1=$(stat -c "%Y" $DIR/$tdir)
11066         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
11067                 error "cannot create/write a volatile file"
11068         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
11069                 error "FID is still valid after close"
11070
11071         multiop_bg_pause $DIR/$tdir vVw4096_c
11072         local multi_pid=$!
11073
11074         local OLD_IFS=$IFS
11075         IFS=":"
11076         local fidv=($fid)
11077         IFS=$OLD_IFS
11078         # assume that the next FID for this client is sequential, since stdout
11079         # is unfortunately eaten by multiop_bg_pause
11080         local n=$((${fidv[1]} + 1))
11081         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
11082         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
11083                 error "FID is missing before close"
11084         kill -USR1 $multi_pid
11085         # 1 second delay, so if mtime change we will see it
11086         sleep 1
11087         local mtime2=$(stat -c "%Y" $DIR/$tdir)
11088         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
11089 }
11090 run_test 185 "Volatile file support"
11091
11092 test_187a() {
11093         local dir0=$DIR/$tdir/$testnum
11094         mkdir -p $dir0 || error "creating dir $dir0"
11095
11096         local file=$dir0/file1
11097         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
11098         local dv1=$($LFS data_version $file)
11099         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
11100         local dv2=$($LFS data_version $file)
11101         [[ $dv1 != $dv2 ]] ||
11102                 error "data version did not change on write $dv1 == $dv2"
11103
11104         # clean up
11105         rm -f $file1
11106 }
11107 run_test 187a "Test data version change"
11108
11109 test_187b() {
11110         local dir0=$DIR/$tdir/$testnum
11111         mkdir -p $dir0 || error "creating dir $dir0"
11112
11113         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
11114         [[ ${DV[0]} != ${DV[1]} ]] ||
11115                 error "data version did not change on write"\
11116                       " ${DV[0]} == ${DV[1]}"
11117
11118         # clean up
11119         rm -f $file1
11120 }
11121 run_test 187b "Test data version change on volatile file"
11122
11123 test_200() {
11124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11125         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11126
11127         local POOL=${POOL:-cea1}
11128         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11129         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11130         # Pool OST targets
11131         local first_ost=0
11132         local last_ost=$(($OSTCOUNT - 1))
11133         local ost_step=2
11134         local ost_list=$(seq $first_ost $ost_step $last_ost)
11135         local ost_range="$first_ost $last_ost $ost_step"
11136         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11137         local file_dir=$POOL_ROOT/file_tst
11138
11139         local rc=0
11140         while : ; do
11141                 # former test_200a test_200b
11142                 pool_add $POOL                          || { rc=$? ; break; }
11143                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11144                 # former test_200c test_200d
11145                 mkdir -p $test_path
11146                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11147                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11148                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11149                                                         || { rc=$? ; break; }
11150                 # former test_200e test_200f
11151                 local files=$((OSTCOUNT*3))
11152                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11153                                                         || { rc=$? ; break; }
11154                 pool_create_files $POOL $file_dir $files "$ost_list" \
11155                                                         || { rc=$? ; break; }
11156                 # former test_200g test_200h
11157                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11158                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11159
11160                 # former test_201a test_201b test_201c
11161                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11162
11163                 local f=$test_path/$tfile
11164                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11165                 pool_remove $POOL $f                    || { rc=$? ; break; }
11166                 break
11167         done
11168
11169         cleanup_pools
11170         return $rc
11171 }
11172 run_test 200 "OST pools"
11173
11174 # usage: default_attr <count | size | offset>
11175 default_attr() {
11176         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11177 }
11178
11179 # usage: check_default_stripe_attr
11180 check_default_stripe_attr() {
11181         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11182         case $1 in
11183         --stripe-count|--count)
11184                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11185         --stripe-size|--size)
11186                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11187         --stripe-index|--index)
11188                 EXPECTED=-1;;
11189         *)
11190                 error "unknown getstripe attr '$1'"
11191         esac
11192
11193         [ $ACTUAL != $EXPECTED ] &&
11194                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11195 }
11196
11197 test_204a() {
11198         test_mkdir -p $DIR/$tdir
11199         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11200
11201         check_default_stripe_attr --stripe-count
11202         check_default_stripe_attr --stripe-size
11203         check_default_stripe_attr --stripe-index
11204
11205         return 0
11206 }
11207 run_test 204a "Print default stripe attributes ================="
11208
11209 test_204b() {
11210         test_mkdir -p $DIR/$tdir
11211         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11212
11213         check_default_stripe_attr --stripe-size
11214         check_default_stripe_attr --stripe-index
11215
11216         return 0
11217 }
11218 run_test 204b "Print default stripe size and offset  ==========="
11219
11220 test_204c() {
11221         test_mkdir -p $DIR/$tdir
11222         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11223
11224         check_default_stripe_attr --stripe-count
11225         check_default_stripe_attr --stripe-index
11226
11227         return 0
11228 }
11229 run_test 204c "Print default stripe count and offset ==========="
11230
11231 test_204d() {
11232         test_mkdir -p $DIR/$tdir
11233         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11234
11235         check_default_stripe_attr --stripe-count
11236         check_default_stripe_attr --stripe-size
11237
11238         return 0
11239 }
11240 run_test 204d "Print default stripe count and size ============="
11241
11242 test_204e() {
11243         test_mkdir -p $DIR/$tdir
11244         $SETSTRIPE -d $DIR/$tdir
11245
11246         check_default_stripe_attr --stripe-count --raw
11247         check_default_stripe_attr --stripe-size --raw
11248         check_default_stripe_attr --stripe-index --raw
11249
11250         return 0
11251 }
11252 run_test 204e "Print raw stripe attributes ================="
11253
11254 test_204f() {
11255         test_mkdir -p $DIR/$tdir
11256         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11257
11258         check_default_stripe_attr --stripe-size --raw
11259         check_default_stripe_attr --stripe-index --raw
11260
11261         return 0
11262 }
11263 run_test 204f "Print raw stripe size and offset  ==========="
11264
11265 test_204g() {
11266         test_mkdir -p $DIR/$tdir
11267         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11268
11269         check_default_stripe_attr --stripe-count --raw
11270         check_default_stripe_attr --stripe-index --raw
11271
11272         return 0
11273 }
11274 run_test 204g "Print raw stripe count and offset ==========="
11275
11276 test_204h() {
11277         test_mkdir -p $DIR/$tdir
11278         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11279
11280         check_default_stripe_attr --stripe-count --raw
11281         check_default_stripe_attr --stripe-size --raw
11282
11283         return 0
11284 }
11285 run_test 204h "Print raw stripe count and size ============="
11286
11287 # Figure out which job scheduler is being used, if any,
11288 # or use a fake one
11289 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11290         JOBENV=SLURM_JOB_ID
11291 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11292         JOBENV=LSB_JOBID
11293 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11294         JOBENV=PBS_JOBID
11295 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11296         JOBENV=LOADL_STEP_ID
11297 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11298         JOBENV=JOB_ID
11299 else
11300         JOBENV=FAKE_JOBID
11301 fi
11302
11303 verify_jobstats() {
11304         local cmd=$1
11305         local target=$2
11306
11307         # clear old jobstats
11308         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11309         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11310
11311         # use a new JobID for this test, or we might see an old one
11312         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11313
11314         JOBVAL=${!JOBENV}
11315         log "Test: $cmd"
11316         log "Using JobID environment variable $JOBENV=$JOBVAL"
11317
11318         if [ $JOBENV = "FAKE_JOBID" ]; then
11319                 FAKE_JOBID=$JOBVAL $cmd
11320         else
11321                 $cmd
11322         fi
11323
11324         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11325                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11326                 do_facet $FACET lctl get_param mdt.*.job_stats |
11327                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11328         fi
11329         if [ "$target" = "ost" -o "$target" = "both" ]; then
11330                 FACET=ost1
11331                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11332                         grep $JOBVAL || error "No job stats found on OST $FACET"
11333         fi
11334 }
11335
11336 jobstats_set() {
11337         trap 0
11338         NEW_JOBENV=${1:-$OLD_JOBENV}
11339         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11340         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11341 }
11342
11343 test_205() { # Job stats
11344         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11345         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11346         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11347                 skip "Server doesn't support jobstats" && return 0
11348         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11349
11350         local cmd
11351         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11352         if [ $OLD_JOBENV != $JOBENV ]; then
11353                 jobstats_set $JOBENV
11354                 trap jobstats_set EXIT
11355         fi
11356
11357         local user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11358                      changelog_register -n)
11359         echo "Registered as changelog user $user"
11360
11361         # mkdir
11362         cmd="mkdir $DIR/$tfile"
11363         verify_jobstats "$cmd" "mdt"
11364         # rmdir
11365         cmd="rm -fr $DIR/$tfile"
11366         verify_jobstats "$cmd" "mdt"
11367         # mknod
11368         cmd="mknod $DIR/$tfile c 1 3"
11369         verify_jobstats "$cmd" "mdt"
11370         # unlink
11371         cmd="rm -f $DIR/$tfile"
11372         verify_jobstats "$cmd" "mdt"
11373         # open & close
11374         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11375         verify_jobstats "$cmd" "mdt"
11376         # setattr
11377         cmd="touch $DIR/$tfile"
11378         verify_jobstats "$cmd" "both"
11379         # write
11380         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11381         verify_jobstats "$cmd" "ost"
11382         # read
11383         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11384         verify_jobstats "$cmd" "ost"
11385         # truncate
11386         cmd="$TRUNCATE $DIR/$tfile 0"
11387         verify_jobstats "$cmd" "both"
11388         # rename
11389         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11390         verify_jobstats "$cmd" "mdt"
11391
11392         # Ensure that jobid are present in changelog (if supported by MDS)
11393         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
11394         then
11395                 $LFS changelog $MDT0 | tail -9
11396                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
11397                 [ $jobids -eq 9 ] ||
11398                         error "Wrong changelog jobid count $jobids != 9"
11399
11400                 # LU-5862
11401                 JOBENV="disable"
11402                 jobstats_set $JOBENV
11403                 touch $DIR/$tfile
11404                 $LFS changelog $MDT0 | tail -1
11405                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
11406                 [ $jobids -eq 0 ] ||
11407                         error "Unexpected jobids when jobid_var=$JOBENV"
11408         fi
11409
11410         # cleanup
11411         rm -f $DIR/jobstats_test_rename
11412
11413         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11414 }
11415 run_test 205 "Verify job stats"
11416
11417 # LU-1480, LU-1773 and LU-1657
11418 test_206() {
11419         mkdir -p $DIR/$tdir
11420         $SETSTRIPE -c -1 $DIR/$tdir
11421 #define OBD_FAIL_LOV_INIT 0x1403
11422         $LCTL set_param fail_loc=0xa0001403
11423         $LCTL set_param fail_val=1
11424         touch $DIR/$tdir/$tfile || true
11425 }
11426 run_test 206 "fail lov_init_raid0() doesn't lbug"
11427
11428 test_207a() {
11429         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11430         local fsz=`stat -c %s $DIR/$tfile`
11431         cancel_lru_locks mdc
11432
11433         # do not return layout in getattr intent
11434 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11435         $LCTL set_param fail_loc=0x170
11436         local sz=`stat -c %s $DIR/$tfile`
11437
11438         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11439
11440         rm -rf $DIR/$tfile
11441 }
11442 run_test 207a "can refresh layout at glimpse"
11443
11444 test_207b() {
11445         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11446         local cksum=`md5sum $DIR/$tfile`
11447         local fsz=`stat -c %s $DIR/$tfile`
11448         cancel_lru_locks mdc
11449         cancel_lru_locks osc
11450
11451         # do not return layout in getattr intent
11452 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11453         $LCTL set_param fail_loc=0x171
11454
11455         # it will refresh layout after the file is opened but before read issues
11456         echo checksum is "$cksum"
11457         echo "$cksum" |md5sum -c --quiet || error "file differs"
11458
11459         rm -rf $DIR/$tfile
11460 }
11461 run_test 207b "can refresh layout at open"
11462
11463 test_208() {
11464         # FIXME: in this test suite, only RD lease is used. This is okay
11465         # for now as only exclusive open is supported. After generic lease
11466         # is done, this test suite should be revised. - Jinshan
11467
11468         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11469                 { skip "Need MDS version at least 2.4.52"; return 0; }
11470         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11471
11472         echo "==== test 1: verify get lease work"
11473         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11474
11475         echo "==== test 2: verify lease can be broken by upcoming open"
11476         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11477         local PID=$!
11478         sleep 1
11479
11480         $MULTIOP $DIR/$tfile oO_RDONLY:c
11481         kill -USR1 $PID && wait $PID || error "break lease error"
11482
11483         echo "==== test 3: verify lease can't be granted if an open already exists"
11484         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11485         local PID=$!
11486         sleep 1
11487
11488         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11489         kill -USR1 $PID && wait $PID || error "open file error"
11490
11491         echo "==== test 4: lease can sustain over recovery"
11492         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11493         PID=$!
11494         sleep 1
11495
11496         fail mds1
11497
11498         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11499
11500         echo "==== test 5: lease broken can't be regained by replay"
11501         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11502         PID=$!
11503         sleep 1
11504
11505         # open file to break lease and then recovery
11506         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11507         fail mds1
11508
11509         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11510
11511         rm -f $DIR/$tfile
11512 }
11513 run_test 208 "Exclusive open"
11514
11515 test_209() {
11516         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11517                 skip_env "must have disp_stripe" && return
11518
11519         touch $DIR/$tfile
11520         sync; sleep 5; sync;
11521
11522         echo 3 > /proc/sys/vm/drop_caches
11523         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11524
11525         # open/close 500 times
11526         for i in $(seq 500); do
11527                 cat $DIR/$tfile
11528         done
11529
11530         echo 3 > /proc/sys/vm/drop_caches
11531         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11532
11533         echo "before: $req_before, after: $req_after"
11534         [ $((req_after - req_before)) -ge 300 ] &&
11535                 error "open/close requests are not freed"
11536         return 0
11537 }
11538 run_test 209 "read-only open/close requests should be freed promptly"
11539
11540 test_212() {
11541         size=`date +%s`
11542         size=$((size % 8192 + 1))
11543         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11544         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11545         rm -f $DIR/f212 $DIR/f212.xyz
11546 }
11547 run_test 212 "Sendfile test ============================================"
11548
11549 test_213() {
11550         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11551         cancel_lru_locks osc
11552         lctl set_param fail_loc=0x8000040f
11553         # generate a read lock
11554         cat $DIR/$tfile > /dev/null
11555         # write to the file, it will try to cancel the above read lock.
11556         cat /etc/hosts >> $DIR/$tfile
11557 }
11558 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11559
11560 test_214() { # for bug 20133
11561         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11562         for (( i=0; i < 340; i++ )) ; do
11563                 touch $DIR/$tdir/d214c/a$i
11564         done
11565
11566         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11567         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11568         ls $DIR/d214c || error "ls $DIR/d214c failed"
11569         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11570         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11571 }
11572 run_test 214 "hash-indexed directory test - bug 20133"
11573
11574 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11575 create_lnet_proc_files() {
11576         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11577         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11578
11579         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11580         rm -f "$TMP/lnet_$1.sys_tmp"
11581 }
11582
11583 # counterpart of create_lnet_proc_files
11584 remove_lnet_proc_files() {
11585         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11586 }
11587
11588 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11589 # 3rd arg as regexp for body
11590 check_lnet_proc_stats() {
11591         local l=$(cat "$TMP/lnet_$1" |wc -l)
11592         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11593
11594         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11595 }
11596
11597 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11598 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11599 # optional and can be regexp for 2nd line (lnet.routes case)
11600 check_lnet_proc_entry() {
11601         local blp=2          # blp stands for 'position of 1st line of body'
11602         [ -z "$5" ] || blp=3 # lnet.routes case
11603
11604         local l=$(cat "$TMP/lnet_$1" |wc -l)
11605         # subtracting one from $blp because the body can be empty
11606         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11607
11608         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11609                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11610
11611         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11612                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11613
11614         # bail out if any unexpected line happened
11615         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11616         [ "$?" != 0 ] || error "$2 misformatted"
11617 }
11618
11619 test_215() { # for bugs 18102, 21079, 21517
11620         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11621         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11622         local P='[1-9][0-9]*'           # positive numeric
11623         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11624         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11625         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11626         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11627
11628         local L1 # regexp for 1st line
11629         local L2 # regexp for 2nd line (optional)
11630         local BR # regexp for the rest (body)
11631
11632         # lnet.stats should look as 11 space-separated non-negative numerics
11633         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11634         create_lnet_proc_files "stats"
11635         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11636         remove_lnet_proc_files "stats"
11637
11638         # lnet.routes should look like this:
11639         # Routing disabled/enabled
11640         # net hops priority state router
11641         # where net is a string like tcp0, hops > 0, priority >= 0,
11642         # state is up/down,
11643         # router is a string like 192.168.1.1@tcp2
11644         L1="^Routing (disabled|enabled)$"
11645         L2="^net +hops +priority +state +router$"
11646         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11647         create_lnet_proc_files "routes"
11648         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11649         remove_lnet_proc_files "routes"
11650
11651         # lnet.routers should look like this:
11652         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11653         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11654         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11655         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11656         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11657         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11658         create_lnet_proc_files "routers"
11659         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11660         remove_lnet_proc_files "routers"
11661
11662         # lnet.peers should look like this:
11663         # nid refs state last max rtr min tx min queue
11664         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11665         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11666         # numeric (0 or >0 or <0), queue >= 0.
11667         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11668         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11669         create_lnet_proc_files "peers"
11670         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11671         remove_lnet_proc_files "peers"
11672
11673         # lnet.buffers  should look like this:
11674         # pages count credits min
11675         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11676         L1="^pages +count +credits +min$"
11677         BR="^ +$N +$N +$I +$I$"
11678         create_lnet_proc_files "buffers"
11679         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11680         remove_lnet_proc_files "buffers"
11681
11682         # lnet.nis should look like this:
11683         # nid status alive refs peer rtr max tx min
11684         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11685         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11686         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11687         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11688         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11689         create_lnet_proc_files "nis"
11690         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11691         remove_lnet_proc_files "nis"
11692
11693         # can we successfully write to lnet.stats?
11694         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
11695         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11696 }
11697 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
11698
11699 test_216() { # bug 20317
11700         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11701         remote_ost_nodsh && skip "remote OST with nodsh" && return
11702
11703         local node
11704         local facets=$(get_facets OST)
11705         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11706
11707         save_lustre_params client "osc.*.contention_seconds" > $p
11708         save_lustre_params $facets \
11709                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11710         save_lustre_params $facets \
11711                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11712         save_lustre_params $facets \
11713                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11714         clear_osc_stats
11715
11716         # agressive lockless i/o settings
11717         for node in $(osts_nodes); do
11718                 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'
11719         done
11720         lctl set_param -n osc.*.contention_seconds 60
11721
11722         $DIRECTIO write $DIR/$tfile 0 10 4096
11723         $CHECKSTAT -s 40960 $DIR/$tfile
11724
11725         # disable lockless i/o
11726         for node in $(osts_nodes); do
11727                 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'
11728         done
11729         lctl set_param -n osc.*.contention_seconds 0
11730         clear_osc_stats
11731
11732         dd if=/dev/zero of=$DIR/$tfile count=0
11733         $CHECKSTAT -s 0 $DIR/$tfile
11734
11735         restore_lustre_params <$p
11736         rm -f $p
11737         rm $DIR/$tfile
11738 }
11739 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11740
11741 test_217() { # bug 22430
11742         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11743         local node
11744         local nid
11745
11746         for node in $(nodes_list); do
11747                 nid=$(host_nids_address $node $NETTYPE)
11748                 if [[ $nid = *-* ]] ; then
11749                         echo "lctl ping $nid@$NETTYPE"
11750                         lctl ping $nid@$NETTYPE
11751                 else
11752                         echo "skipping $node (no hyphen detected)"
11753                 fi
11754         done
11755 }
11756 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11757
11758 test_218() {
11759        # do directio so as not to populate the page cache
11760        log "creating a 10 Mb file"
11761        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11762        log "starting reads"
11763        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11764        log "truncating the file"
11765        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11766        log "killing dd"
11767        kill %+ || true # reads might have finished
11768        echo "wait until dd is finished"
11769        wait
11770        log "removing the temporary file"
11771        rm -rf $DIR/$tfile || error "tmp file removal failed"
11772 }
11773 run_test 218 "parallel read and truncate should not deadlock ======================="
11774
11775 test_219() {
11776         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11777         # write one partial page
11778         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11779         # set no grant so vvp_io_commit_write will do sync write
11780         $LCTL set_param fail_loc=0x411
11781         # write a full page at the end of file
11782         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11783
11784         $LCTL set_param fail_loc=0
11785         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11786         $LCTL set_param fail_loc=0x411
11787         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11788
11789         # LU-4201
11790         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11791         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11792 }
11793 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11794
11795 test_220() { #LU-325
11796         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11797         remote_ost_nodsh && skip "remote OST with nodsh" && return
11798         local OSTIDX=0
11799
11800         test_mkdir -p $DIR/$tdir
11801         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11802                 awk '{print $2}' | sed -e 's/_UUID$//')
11803
11804         # on the mdt's osc
11805         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11806         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11807                         osc.$mdtosc_proc1.prealloc_last_id)
11808         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11809                         osc.$mdtosc_proc1.prealloc_next_id)
11810
11811         $LFS df -i
11812
11813         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11814         #define OBD_FAIL_OST_ENOINO              0x229
11815         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11816         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11817         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11818
11819         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11820
11821         MDSOBJS=$((last_id - next_id))
11822         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11823
11824         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11825         echo "OST still has $count kbytes free"
11826
11827         echo "create $MDSOBJS files @next_id..."
11828         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11829
11830         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11831                         osc.$mdtosc_proc1.prealloc_last_id)
11832         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11833                         osc.$mdtosc_proc1.prealloc_next_id)
11834
11835         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11836         $LFS df -i
11837
11838         echo "cleanup..."
11839
11840         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11841         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11842
11843         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11844         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11845         echo "unlink $MDSOBJS files @$next_id..."
11846         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11847 }
11848 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11849
11850 test_221() {
11851         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11852         dd if=`which date` of=$MOUNT/date oflag=sync
11853         chmod +x $MOUNT/date
11854
11855         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11856         $LCTL set_param fail_loc=0x80001401
11857
11858         $MOUNT/date > /dev/null
11859         rm -f $MOUNT/date
11860 }
11861 run_test 221 "make sure fault and truncate race to not cause OOM"
11862
11863 test_222a () {
11864         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11865        rm -rf $DIR/$tdir
11866        test_mkdir -p $DIR/$tdir
11867        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11868        createmany -o $DIR/$tdir/$tfile 10
11869        cancel_lru_locks mdc
11870        cancel_lru_locks osc
11871        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11872        $LCTL set_param fail_loc=0x31a
11873        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11874        $LCTL set_param fail_loc=0
11875        rm -r $DIR/$tdir
11876 }
11877 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11878
11879 test_222b () {
11880         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11881        rm -rf $DIR/$tdir
11882        test_mkdir -p $DIR/$tdir
11883        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11884        createmany -o $DIR/$tdir/$tfile 10
11885        cancel_lru_locks mdc
11886        cancel_lru_locks osc
11887        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11888        $LCTL set_param fail_loc=0x31a
11889        rm -r $DIR/$tdir || "AGL for rmdir failed"
11890        $LCTL set_param fail_loc=0
11891 }
11892 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11893
11894 test_223 () {
11895         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11896        rm -rf $DIR/$tdir
11897        test_mkdir -p $DIR/$tdir
11898        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11899        createmany -o $DIR/$tdir/$tfile 10
11900        cancel_lru_locks mdc
11901        cancel_lru_locks osc
11902        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11903        $LCTL set_param fail_loc=0x31b
11904        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11905        $LCTL set_param fail_loc=0
11906        rm -r $DIR/$tdir
11907 }
11908 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11909
11910 test_224a() { # LU-1039, MRP-303
11911         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11912         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11913         $LCTL set_param fail_loc=0x508
11914         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11915         $LCTL set_param fail_loc=0
11916         df $DIR
11917 }
11918 run_test 224a "Don't panic on bulk IO failure"
11919
11920 test_224b() { # LU-1039, MRP-303
11921         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11922         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11923         cancel_lru_locks osc
11924         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11925         $LCTL set_param fail_loc=0x515
11926         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11927         $LCTL set_param fail_loc=0
11928         df $DIR
11929 }
11930 run_test 224b "Don't panic on bulk IO failure"
11931
11932 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11933 test_225a () {
11934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11935         if [ -z ${MDSSURVEY} ]; then
11936               skip_env "mds-survey not found" && return
11937         fi
11938
11939         [ $MDSCOUNT -ge 2 ] &&
11940                 skip "skipping now for more than one MDT" && return
11941
11942        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11943             { skip "Need MDS version at least 2.2.51"; return; }
11944
11945        local mds=$(facet_host $SINGLEMDS)
11946        local target=$(do_nodes $mds 'lctl dl' | \
11947                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11948
11949        local cmd1="file_count=1000 thrhi=4"
11950        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11951        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11952        local cmd="$cmd1 $cmd2 $cmd3"
11953
11954        rm -f ${TMP}/mds_survey*
11955        echo + $cmd
11956        eval $cmd || error "mds-survey with zero-stripe failed"
11957        cat ${TMP}/mds_survey*
11958        rm -f ${TMP}/mds_survey*
11959 }
11960 run_test 225a "Metadata survey sanity with zero-stripe"
11961
11962 test_225b () {
11963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11964
11965         if [ -z ${MDSSURVEY} ]; then
11966               skip_env "mds-survey not found" && return
11967         fi
11968         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11969             { skip "Need MDS version at least 2.2.51"; return; }
11970
11971         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11972               skip_env "Need to mount OST to test" && return
11973         fi
11974
11975         [ $MDSCOUNT -ge 2 ] &&
11976                 skip "skipping now for more than one MDT" && return
11977        local mds=$(facet_host $SINGLEMDS)
11978        local target=$(do_nodes $mds 'lctl dl' | \
11979                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11980
11981        local cmd1="file_count=1000 thrhi=4"
11982        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11983        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11984        local cmd="$cmd1 $cmd2 $cmd3"
11985
11986        rm -f ${TMP}/mds_survey*
11987        echo + $cmd
11988        eval $cmd || error "mds-survey with stripe_count failed"
11989        cat ${TMP}/mds_survey*
11990        rm -f ${TMP}/mds_survey*
11991 }
11992 run_test 225b "Metadata survey sanity with stripe_count = 1"
11993
11994 mcreate_path2fid () {
11995         local mode=$1
11996         local major=$2
11997         local minor=$3
11998         local name=$4
11999         local desc=$5
12000         local path=$DIR/$tdir/$name
12001         local fid
12002         local rc
12003         local fid_path
12004
12005         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
12006                 error "cannot create $desc"
12007
12008         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
12009         rc=$?
12010         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
12011
12012         fid_path=$($LFS fid2path $MOUNT $fid)
12013         rc=$?
12014         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
12015
12016         [ "$path" == "$fid_path" ] ||
12017                 error "fid2path returned $fid_path, expected $path"
12018
12019         echo "pass with $path and $fid"
12020 }
12021
12022 test_226a () {
12023         rm -rf $DIR/$tdir
12024         mkdir -p $DIR/$tdir
12025
12026         mcreate_path2fid 0010666 0 0 fifo "FIFO"
12027         mcreate_path2fid 0020666 1 3 null "character special file (null)"
12028         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
12029         mcreate_path2fid 0040666 0 0 dir "directory"
12030         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
12031         mcreate_path2fid 0100666 0 0 file "regular file"
12032         mcreate_path2fid 0120666 0 0 link "symbolic link"
12033         mcreate_path2fid 0140666 0 0 sock "socket"
12034 }
12035 run_test 226a "call path2fid and fid2path on files of all type"
12036
12037 test_226b () {
12038         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12039         rm -rf $DIR/$tdir
12040         local MDTIDX=1
12041
12042         mkdir -p $DIR/$tdir
12043         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
12044                 error "create remote directory failed"
12045         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
12046         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
12047                                 "character special file (null)"
12048         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
12049                                 "character special file (no device)"
12050         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
12051         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
12052                                 "block special file (loop)"
12053         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
12054         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
12055         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
12056 }
12057 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
12058
12059 # LU-1299 Executing or running ldd on a truncated executable does not
12060 # cause an out-of-memory condition.
12061 test_227() {
12062         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12063         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
12064         dd if=$(which date) of=$MOUNT/date bs=1k count=1
12065         chmod +x $MOUNT/date
12066
12067         $MOUNT/date > /dev/null
12068         ldd $MOUNT/date > /dev/null
12069         rm -f $MOUNT/date
12070 }
12071 run_test 227 "running truncated executable does not cause OOM"
12072
12073 # LU-1512 try to reuse idle OI blocks
12074 test_228a() {
12075         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12076         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12077         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12078                 skip "non-ldiskfs backend" && return
12079
12080         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12081         local myDIR=$DIR/$tdir
12082
12083         mkdir -p $myDIR
12084         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12085         $LCTL set_param fail_loc=0x80001002
12086         createmany -o $myDIR/t- 10000
12087         $LCTL set_param fail_loc=0
12088         # The guard is current the largest FID holder
12089         touch $myDIR/guard
12090         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12091                     tr -d '[')
12092         local IDX=$(($SEQ % 64))
12093
12094         do_facet $SINGLEMDS sync
12095         # Make sure journal flushed.
12096         sleep 6
12097         local blk1=$(do_facet $SINGLEMDS \
12098                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12099                      grep Blockcount | awk '{print $4}')
12100
12101         # Remove old files, some OI blocks will become idle.
12102         unlinkmany $myDIR/t- 10000
12103         # Create new files, idle OI blocks should be reused.
12104         createmany -o $myDIR/t- 2000
12105         do_facet $SINGLEMDS sync
12106         # Make sure journal flushed.
12107         sleep 6
12108         local blk2=$(do_facet $SINGLEMDS \
12109                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12110                      grep Blockcount | awk '{print $4}')
12111
12112         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12113 }
12114 run_test 228a "try to reuse idle OI blocks"
12115
12116 test_228b() {
12117         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12118         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12119         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12120                 skip "non-ldiskfs backend" && return
12121
12122         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12123         local myDIR=$DIR/$tdir
12124
12125         mkdir -p $myDIR
12126         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12127         $LCTL set_param fail_loc=0x80001002
12128         createmany -o $myDIR/t- 10000
12129         $LCTL set_param fail_loc=0
12130         # The guard is current the largest FID holder
12131         touch $myDIR/guard
12132         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12133                     tr -d '[')
12134         local IDX=$(($SEQ % 64))
12135
12136         do_facet $SINGLEMDS sync
12137         # Make sure journal flushed.
12138         sleep 6
12139         local blk1=$(do_facet $SINGLEMDS \
12140                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12141                      grep Blockcount | awk '{print $4}')
12142
12143         # Remove old files, some OI blocks will become idle.
12144         unlinkmany $myDIR/t- 10000
12145
12146         # stop the MDT
12147         stop $SINGLEMDS || error "Fail to stop MDT."
12148         # remount the MDT
12149         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12150
12151         df $MOUNT || error "Fail to df."
12152         # Create new files, idle OI blocks should be reused.
12153         createmany -o $myDIR/t- 2000
12154         do_facet $SINGLEMDS sync
12155         # Make sure journal flushed.
12156         sleep 6
12157         local blk2=$(do_facet $SINGLEMDS \
12158                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12159                      grep Blockcount | awk '{print $4}')
12160
12161         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12162 }
12163 run_test 228b "idle OI blocks can be reused after MDT restart"
12164
12165 #LU-1881
12166 test_228c() {
12167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12168         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12169         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12170                 skip "non-ldiskfs backend" && return
12171
12172         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12173         local myDIR=$DIR/$tdir
12174
12175         mkdir -p $myDIR
12176         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12177         $LCTL set_param fail_loc=0x80001002
12178         # 20000 files can guarantee there are index nodes in the OI file
12179         createmany -o $myDIR/t- 20000
12180         $LCTL set_param fail_loc=0
12181         # The guard is current the largest FID holder
12182         touch $myDIR/guard
12183         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12184                     tr -d '[')
12185         local IDX=$(($SEQ % 64))
12186
12187         do_facet $SINGLEMDS sync
12188         # Make sure journal flushed.
12189         sleep 6
12190         local blk1=$(do_facet $SINGLEMDS \
12191                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12192                      grep Blockcount | awk '{print $4}')
12193
12194         # Remove old files, some OI blocks will become idle.
12195         unlinkmany $myDIR/t- 20000
12196         rm -f $myDIR/guard
12197         # The OI file should become empty now
12198
12199         # Create new files, idle OI blocks should be reused.
12200         createmany -o $myDIR/t- 2000
12201         do_facet $SINGLEMDS sync
12202         # Make sure journal flushed.
12203         sleep 6
12204         local blk2=$(do_facet $SINGLEMDS \
12205                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12206                      grep Blockcount | awk '{print $4}')
12207
12208         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12209 }
12210 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12211
12212 test_229() { # LU-2482, LU-3448
12213         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12214                 skip "No HSM support on MDS of $(get_lustre_version)," \
12215                          "need 2.4.53 at least" && return
12216         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12217         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12218
12219         rm -f $DIR/$tfile
12220
12221         # Create a file with a released layout and stripe count 2.
12222         $MULTIOP $DIR/$tfile H2c ||
12223                 error "failed to create file with released layout"
12224
12225         $GETSTRIPE -v $DIR/$tfile
12226
12227         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12228         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12229
12230         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12231         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12232         stat $DIR/$tfile || error "failed to stat released file"
12233
12234         chown $RUNAS_ID $DIR/$tfile ||
12235                 error "chown $RUNAS_ID $DIR/$tfile failed"
12236
12237         chgrp $RUNAS_ID $DIR/$tfile ||
12238                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12239
12240         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12241         rm $DIR/$tfile || error "failed to remove released file"
12242 }
12243 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12244
12245 test_230a() {
12246         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12247         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12248         local MDTIDX=1
12249
12250         mkdir -p $DIR/$tdir/test_230_local
12251         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12252         [ $mdt_idx -ne 0 ] &&
12253                 error "create local directory on wrong MDT $mdt_idx"
12254
12255         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12256                         error "create remote directory failed"
12257         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12258         [ $mdt_idx -ne $MDTIDX ] &&
12259                 error "create remote directory on wrong MDT $mdt_idx"
12260
12261         createmany -o $DIR/$tdir/test_230/t- 10 ||
12262                 error "create files on remote directory failed"
12263         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12264         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12265         rm -r $DIR/$tdir || error "unlink remote directory failed"
12266 }
12267 run_test 230a "Create remote directory and files under the remote directory"
12268
12269 test_230b() {
12270         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12271         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12272         local MDTIDX=1
12273         local mdt_index
12274         local i
12275         local file
12276         local pid
12277         local stripe_count
12278         local migrate_dir=$DIR/$tdir/migrate_dir
12279         local other_dir=$DIR/$tdir/other_dir
12280
12281         mkdir -p $migrate_dir
12282         mkdir -p $other_dir
12283         for ((i=0; i<10; i++)); do
12284                 mkdir -p $migrate_dir/dir_${i}
12285                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12286                         error "create files under remote dir failed $i"
12287         done
12288
12289         cp /etc/passwd $migrate_dir/$tfile
12290         cp /etc/passwd $other_dir/$tfile
12291         chattr +SAD $migrate_dir
12292         chattr +SAD $migrate_dir/$tfile
12293
12294         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12295         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12296         local old_dir_mode=$(stat -c%f $migrate_dir)
12297         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12298
12299         mkdir -p $migrate_dir/dir_default_stripe2
12300         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12301         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12302
12303         mkdir -p $other_dir
12304         ln $migrate_dir/$tfile $other_dir/luna
12305         ln $migrate_dir/$tfile $migrate_dir/sofia
12306         ln $other_dir/$tfile $migrate_dir/david
12307         ln -s $migrate_dir/$tfile $other_dir/zachary
12308         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12309         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12310
12311         $LFS mv -v -M $MDTIDX $migrate_dir ||
12312                         error "migrate remote dir error"
12313
12314         echo "migratate to MDT1, then checking.."
12315         for ((i=0; i<10; i++)); do
12316                 for file in $(find $migrate_dir/dir_${i}); do
12317                         mdt_index=$($LFS getstripe -M $file)
12318                         [ $mdt_index == $MDTIDX ] ||
12319                                 error "$file is not on MDT${MDTIDX}"
12320                 done
12321         done
12322
12323         # the multiple link file should still in MDT0
12324         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12325         [ $mdt_index == 0 ] ||
12326                 error "$file is not on MDT${MDTIDX}"
12327
12328         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12329         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12330                 error " expect $old_dir_flag get $new_dir_flag"
12331
12332         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12333         [ "$old_file_flag" = "$new_file_flag" ] ||
12334                 error " expect $old_file_flag get $new_file_flag"
12335
12336         local new_dir_mode=$(stat -c%f $migrate_dir)
12337         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12338                 error "expect mode $old_dir_mode get $new_dir_mode"
12339
12340         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12341         [ "$old_file_mode" = "$new_file_mode" ] ||
12342                 error "expect mode $old_file_mode get $new_file_mode"
12343
12344         diff /etc/passwd $migrate_dir/$tfile ||
12345                 error "$tfile different after migration"
12346
12347         diff /etc/passwd $other_dir/luna ||
12348                 error "luna different after migration"
12349
12350         diff /etc/passwd $migrate_dir/sofia ||
12351                 error "sofia different after migration"
12352
12353         diff /etc/passwd $migrate_dir/david ||
12354                 error "david different after migration"
12355
12356         diff /etc/passwd $other_dir/zachary ||
12357                 error "zachary different after migration"
12358
12359         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12360                 error "${tfile}_ln different after migration"
12361
12362         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12363                 error "${tfile}_ln_other different after migration"
12364
12365         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12366         [ $stripe_count = 2 ] ||
12367                         error "dir strpe_count $d != 2 after migration."
12368
12369         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12370         [ $stripe_count = 2 ] ||
12371                         error "file strpe_count $d != 2 after migration."
12372
12373         #migrate back to MDT0
12374         MDTIDX=0
12375         $LFS mv -v -M $MDTIDX $migrate_dir ||
12376                         error "migrate remote dir error"
12377
12378         echo "migrate back to MDT0, checking.."
12379         for file in $(find $migrate_dir); do
12380                 mdt_index=$($LFS getstripe -M $file)
12381                 [ $mdt_index == $MDTIDX ] ||
12382                         error "$file is not on MDT${MDTIDX}"
12383         done
12384
12385         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12386         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12387                 error " expect $old_dir_flag get $new_dir_flag"
12388
12389         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12390         [ "$old_file_flag" = "$new_file_flag" ] ||
12391                 error " expect $old_file_flag get $new_file_flag"
12392
12393         local new_dir_mode=$(stat -c%f $migrate_dir)
12394         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12395                 error "expect mode $old_dir_mode get $new_dir_mode"
12396
12397         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12398         [ "$old_file_mode" = "$new_file_mode" ] ||
12399                 error "expect mode $old_file_mode get $new_file_mode"
12400
12401         diff /etc/passwd ${migrate_dir}/$tfile ||
12402                 error "$tfile different after migration"
12403
12404         diff /etc/passwd ${other_dir}/luna ||
12405                 error "luna different after migration"
12406
12407         diff /etc/passwd ${migrate_dir}/sofia ||
12408                 error "sofia different after migration"
12409
12410         diff /etc/passwd ${other_dir}/zachary ||
12411                 error "zachary different after migration"
12412
12413         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12414                 error "${tfile}_ln different after migration"
12415
12416         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12417                 error "${tfile}_ln_other different after migration"
12418
12419         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12420         [ $stripe_count = 2 ] ||
12421                 error "dir strpe_count $d != 2 after migration."
12422
12423         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12424         [ $stripe_count = 2 ] ||
12425                 error "file strpe_count $d != 2 after migration."
12426
12427         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12428 }
12429 run_test 230b "migrate directory"
12430
12431 test_230c() {
12432         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12433         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12434         local MDTIDX=1
12435         local mdt_index
12436         local file
12437
12438         #If migrating directory fails in the middle, all entries of
12439         #the directory is still accessiable.
12440         mkdir -p $DIR/$tdir
12441         stat $DIR/$tdir
12442         createmany -o $DIR/$tdir/f 10 ||
12443                 error "create files under ${tdir} failed"
12444
12445         #failed after migrating 5 entries
12446         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12447         do_facet mds1 lctl set_param fail_loc=0x20001801
12448         do_facet mds1 lctl  set_param fail_val=5
12449         local t=`ls $DIR/$tdir | wc -l`
12450         $LFS mv -M $MDTIDX $DIR/$tdir &&
12451                 error "migrate should failed after 5 entries"
12452         local u=`ls $DIR/$tdir | wc -l`
12453         [ "$u" == "$t" ] || error "$u != $t during migration"
12454
12455         for file in $(find $DIR/$tdir); do
12456                 stat $file || error "stat $file failed"
12457         done
12458
12459         do_facet mds1 lctl set_param fail_loc=0
12460         do_facet mds1 lctl set_param fail_val=0
12461
12462         $LFS mv -M $MDTIDX $DIR/$tdir ||
12463                 error "migrate open files should failed with open files"
12464
12465         echo "Finish migration, then checking.."
12466         for file in $(find $DIR/$tdir); do
12467                 mdt_index=$($LFS getstripe -M $file)
12468                 [ $mdt_index == $MDTIDX ] ||
12469                         error "$file is not on MDT${MDTIDX}"
12470         done
12471
12472         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12473 }
12474 run_test 230c "check directory accessiblity if migration is failed"
12475
12476 test_230d() {
12477         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12478         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12479         local MDTIDX=1
12480         local mdt_index
12481         local i
12482         local j
12483
12484         mkdir -p $DIR/$tdir
12485
12486         for ((i=0; i<100; i++)); do
12487                 mkdir -p $DIR/$tdir/dir_${i}
12488                 createmany -o $DIR/$tdir/dir_${i}/f 100 ||
12489                         error "create files under remote dir failed $i"
12490         done
12491
12492         $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
12493
12494         echo "Finish migration, then checking.."
12495         for file in $(find $DIR/$tdir); do
12496                 mdt_index=$($LFS getstripe -M $file)
12497                 [ $mdt_index == $MDTIDX ] ||
12498                         error "$file is not on MDT${MDTIDX}"
12499         done
12500
12501         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12502 }
12503 run_test 230d "check migrate big directory"
12504
12505 test_231a()
12506 {
12507         # For simplicity this test assumes that max_pages_per_rpc
12508         # is the same across all OSCs
12509         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12510         local bulk_size=$((max_pages * 4096))
12511
12512         mkdir -p $DIR/$tdir
12513
12514         # clear the OSC stats
12515         $LCTL set_param osc.*.stats=0 &>/dev/null
12516
12517         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12518         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12519                 oflag=direct &>/dev/null || error "dd failed"
12520
12521         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12522         if [ x$nrpcs != "x1" ]; then
12523                 error "found $nrpc ost_write RPCs, not 1 as expected"
12524         fi
12525
12526         # Drop the OSC cache, otherwise we will read from it
12527         cancel_lru_locks osc
12528
12529         # clear the OSC stats
12530         $LCTL set_param osc.*.stats=0 &>/dev/null
12531
12532         # Client reads $bulk_size.
12533         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12534                 iflag=direct &>/dev/null || error "dd failed"
12535
12536         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12537         if [ x$nrpcs != "x1" ]; then
12538                 error "found $nrpc ost_read RPCs, not 1 as expected"
12539         fi
12540 }
12541 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12542
12543 test_231b() {
12544         mkdir -p $DIR/$tdir
12545         local i
12546         for i in {0..1023}; do
12547                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12548                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12549                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12550         done
12551         sync
12552 }
12553 run_test 231b "must not assert on fully utilized OST request buffer"
12554
12555 test_232() {
12556         mkdir -p $DIR/$tdir
12557         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12558         $LCTL set_param fail_loc=0x31c
12559
12560         # ignore dd failure
12561         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12562
12563         $LCTL set_param fail_loc=0
12564         umount_client $MOUNT || error "umount failed"
12565         mount_client $MOUNT || error "mount failed"
12566 }
12567 run_test 232 "failed lock should not block umount"
12568
12569 test_233a() {
12570         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12571         { skip "Need MDS version at least 2.3.64"; return; }
12572
12573         local fid=$($LFS path2fid $MOUNT)
12574         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12575                 error "cannot access $MOUNT using its FID '$fid'"
12576 }
12577 run_test 233a "checking that OBF of the FS root succeeds"
12578
12579 test_233b() {
12580         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12581         { skip "Need MDS version at least 2.5.90"; return; }
12582
12583         local fid=$($LFS path2fid $MOUNT/.lustre)
12584         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12585                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12586
12587         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12588         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12589                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12590 }
12591 run_test 233b "checking that OBF of the FS .lustre succeeds"
12592
12593 test_234() {
12594         local p="$TMP/sanityN-$TESTNAME.parameters"
12595         save_lustre_params client "llite.*.xattr_cache" > $p
12596         lctl set_param llite.*.xattr_cache 1 ||
12597                 { skip "xattr cache is not supported"; return 0; }
12598
12599         mkdir -p $DIR/$tdir || error "mkdir failed"
12600         touch $DIR/$tdir/$tfile || error "touch failed"
12601         # OBD_FAIL_LLITE_XATTR_ENOMEM
12602         $LCTL set_param fail_loc=0x1405
12603         # output of the form: attr 2 4 44 3 fc13 x86_64
12604         V=($(IFS=".-" rpm -q attr))
12605         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
12606               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
12607                 # attr pre-2.4.44-7 had a bug with rc
12608                 # LU-3703 - SLES 11 and FC13 clients have older attr
12609                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12610                         error "getfattr should have failed with ENOMEM"
12611         else
12612                 skip "LU-3703: attr version $(getfattr --version) too old"
12613         fi
12614         $LCTL set_param fail_loc=0x0
12615         rm -rf $DIR/$tdir
12616
12617         restore_lustre_params < $p
12618         rm -f $p
12619 }
12620 run_test 234 "xattr cache should not crash on ENOMEM"
12621
12622 test_235() {
12623         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12624                 skip "Need MDS version at least 2.4.52" && return
12625         flock_deadlock $DIR/$tfile
12626         local RC=$?
12627         case $RC in
12628                 0)
12629                 ;;
12630                 124) error "process hangs on a deadlock"
12631                 ;;
12632                 *) error "error executing flock_deadlock $DIR/$tfile"
12633                 ;;
12634         esac
12635 }
12636 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12637
12638 #LU-2935
12639 test_236() {
12640         check_swap_layouts_support && return 0
12641         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12642
12643         local ref1=/etc/passwd
12644         local ref2=/etc/group
12645         local file1=$DIR/$tdir/f1
12646         local file2=$DIR/$tdir/f2
12647
12648         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12649         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12650         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12651         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12652         local fd=$(free_fd)
12653         local cmd="exec $fd<>$file2"
12654         eval $cmd
12655         rm $file2
12656         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12657                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12658         cmd="exec $fd>&-"
12659         eval $cmd
12660         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12661
12662         #cleanup
12663         rm -rf $DIR/$tdir
12664 }
12665 run_test 236 "Layout swap on open unlinked file"
12666
12667 # test to verify file handle related system calls
12668 # (name_to_handle_at/open_by_handle_at)
12669 # The new system calls are supported in glibc >= 2.14.
12670
12671 test_237() {
12672         echo "Test file_handle syscalls" > $DIR/$tfile ||
12673                 error "write failed"
12674         check_fhandle_syscalls $DIR/$tfile ||
12675                 error "check_fhandle_syscalls failed"
12676 }
12677 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12678
12679 # LU-4659 linkea consistency
12680 test_238() {
12681         local server_version=$(lustre_version_code $SINGLEMDS)
12682
12683         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12684                 [[ $server_version -gt $(version_code 2.5.1) &&
12685                    $server_version -lt $(version_code 2.5.50) ]] ||
12686                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
12687
12688         touch $DIR/$tfile
12689         ln $DIR/$tfile $DIR/$tfile.lnk
12690         touch $DIR/$tfile.new
12691         mv $DIR/$tfile.new $DIR/$tfile
12692         local fid1=$(lfs path2fid $DIR/$tfile)
12693         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12694         local path1=$(lfs fid2path $FSNAME $fid1)
12695         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12696         local path2=$(lfs fid2path $FSNAME $fid2)
12697         [ $tfile.lnk == $path2 ] ||
12698                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12699         rm -f $DIR/$tfile*
12700 }
12701 run_test 238 "Verify linkea consistency"
12702
12703 test_239() {
12704         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
12705                 skip "Need MDS version at least 2.5.60" && return
12706         local list=$(comma_list $(mdts_nodes))
12707
12708         mkdir -p $DIR/$tdir
12709         createmany -o $DIR/$tdir/f- 5000
12710         unlinkmany $DIR/$tdir/f- 5000
12711         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
12712         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
12713                         osc.*MDT*.sync_in_flight" | calc_sum)
12714         [ "$changes" -eq 0 ] || error "$changes not synced"
12715 }
12716 run_test 239 "osp_sync test"
12717
12718 test_240() {
12719         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12720
12721         mkdir -p $DIR/$tdir
12722
12723         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
12724                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
12725         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
12726                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
12727
12728         umount_client $MOUNT || error "umount failed"
12729         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
12730         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
12731         mount_client $MOUNT || error "failed to mount client"
12732
12733         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
12734         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
12735 }
12736 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
12737
12738 test_241_bio() {
12739         for LOOP in $(seq $1); do
12740                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
12741                 cancel_lru_locks osc
12742         done
12743 }
12744
12745 test_241_dio() {
12746         for LOOP in $(seq $1); do
12747                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
12748                                                 iflag=direct 2>/dev/null
12749         done
12750 }
12751
12752 test_241() {
12753         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12754         ls -la $DIR/$tfile
12755         cancel_lru_locks osc
12756         test_241_bio 1000 &
12757         PID=$!
12758         test_241_dio 1000
12759         wait $PID
12760 }
12761 run_test 241 "bio vs dio"
12762
12763 cleanup_test_300() {
12764         trap 0
12765         umask $SAVE_UMASK
12766 }
12767 test_striped_dir() {
12768         local mdt_index=$1
12769         local stripe_count
12770         local stripe_index
12771
12772         mkdir -p $DIR/$tdir
12773
12774         SAVE_UMASK=$(umask)
12775         trap cleanup_test_300 RETURN EXIT
12776
12777         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
12778                                                 $DIR/$tdir/striped_dir ||
12779                 error "set striped dir error"
12780
12781         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
12782         [ "$mode" = "755" ] || error "expect 755 got $mode"
12783
12784         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
12785         if [ "$stripe_count" != "2" ]; then
12786                 error "stripe_count is $stripe_count, expect 2"
12787         fi
12788
12789         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
12790         if [ "$stripe_index" != "$mdt_index" ]; then
12791                 error "stripe_index is $stripe_index, expect $mdt_index"
12792         fi
12793
12794         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12795                 error "nlink error after create striped dir"
12796
12797         mkdir $DIR/$tdir/striped_dir/a
12798         mkdir $DIR/$tdir/striped_dir/b
12799
12800         stat $DIR/$tdir/striped_dir/a ||
12801                 error "create dir under striped dir failed"
12802         stat $DIR/$tdir/striped_dir/b ||
12803                 error "create dir under striped dir failed"
12804
12805         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
12806                 error "nlink error after mkdir"
12807
12808         rmdir $DIR/$tdir/striped_dir/a
12809         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
12810                 error "nlink error after rmdir"
12811
12812         rmdir $DIR/$tdir/striped_dir/b
12813         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12814                 error "nlink error after rmdir"
12815
12816         rmdir $DIR/$tdir/striped_dir ||
12817                 error "rmdir striped dir error"
12818
12819         cleanup_test_300
12820
12821         true
12822 }
12823
12824 test_300a() {
12825         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12826         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12827
12828         test_striped_dir 0 || error "failed on striped dir on MDT0"
12829         test_striped_dir 1 || error "failed on striped dir on MDT0"
12830 }
12831 run_test 300a "basic striped dir sanity test"
12832
12833 test_300b() {
12834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12835         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12836         local i
12837         local mtime1
12838         local mtime2
12839         local mtime3
12840
12841         test_mkdir $DIR/$tdir || error "mkdir fail"
12842         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12843                 error "set striped dir error"
12844         for ((i=0; i<10; i++)); do
12845                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
12846                 sleep 1
12847                 touch $DIR/$tdir/striped_dir/file_$i ||
12848                                         error "touch error $i"
12849                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
12850                 [ $mtime1 -eq $mtime2 ] &&
12851                         error "mtime not change after create"
12852                 sleep 1
12853                 rm -f $DIR/$tdir/striped_dir/file_$i ||
12854                                         error "unlink error $i"
12855                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
12856                 [ $mtime2 -eq $mtime3 ] &&
12857                         error "mtime did not change after unlink"
12858         done
12859         true
12860 }
12861 run_test 300b "check ctime/mtime for striped dir"
12862
12863 test_300c() {
12864         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12865         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12866         local file_count
12867
12868         mkdir -p $DIR/$tdir
12869         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
12870                 error "set striped dir error"
12871
12872         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
12873                 error "chown striped dir failed"
12874
12875         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
12876                 error "create 5k files failed"
12877
12878         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
12879
12880         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
12881
12882         rm -rf $DIR/$tdir
12883 }
12884 run_test 300c "chown && check ls under striped directory"
12885
12886 test_300d() {
12887         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12888         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12889         local stripe_count
12890         local file
12891
12892         mkdir -p $DIR/$tdir
12893         $SETSTRIPE -c 2 $DIR/$tdir
12894
12895         #local striped directory
12896         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12897                 error "set striped dir error"
12898         createmany -o $DIR/$tdir/striped_dir/f 10 ||
12899                 error "create 10 files failed"
12900
12901         #remote striped directory
12902         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
12903                 error "set striped dir error"
12904         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
12905                 error "create 10 files failed"
12906
12907         for file in $(find $DIR/$tdir); do
12908                 stripe_count=$($GETSTRIPE -c $file)
12909                 [ $stripe_count -eq 2 ] ||
12910                         error "wrong stripe $stripe_count for $file"
12911         done
12912
12913         rm -rf $DIR/$tdir
12914 }
12915 run_test 300d "check default stripe under striped directory"
12916
12917 test_300e() {
12918         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12919         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12920         local stripe_count
12921         local file
12922
12923         mkdir -p $DIR/$tdir
12924
12925         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12926                 error "set striped dir error"
12927
12928         touch $DIR/$tdir/striped_dir/a
12929         touch $DIR/$tdir/striped_dir/b
12930         touch $DIR/$tdir/striped_dir/c
12931
12932         mkdir $DIR/$tdir/striped_dir/dir_a
12933         mkdir $DIR/$tdir/striped_dir/dir_b
12934         mkdir $DIR/$tdir/striped_dir/dir_c
12935
12936         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
12937                 error "set striped dir under striped dir error"
12938
12939         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
12940                 error "set striped dir under striped dir error"
12941
12942         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
12943                 error "set striped dir under striped dir error"
12944
12945         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
12946                 error "rename file under striped dir should fail"
12947
12948         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
12949                 error "rename dir under striped dir should fail"
12950
12951         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
12952                 error "rename dir under different stripes should fail"
12953
12954         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
12955                 error "rename file under striped dir should succeed"
12956
12957         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
12958                 error "rename dir under striped dir should succeed"
12959
12960         rm -rf $DIR/$tdir
12961 }
12962 run_test 300e "check rename under striped directory"
12963
12964 test_300f() {
12965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12966         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12967         local stripe_count
12968         local file
12969
12970         rm -rf $DIR/$tdir
12971         mkdir -p $DIR/$tdir
12972
12973         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12974                 error "set striped dir error"
12975
12976         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
12977                 error "set striped dir error"
12978
12979         touch $DIR/$tdir/striped_dir/a
12980         mkdir $DIR/$tdir/striped_dir/dir_a
12981         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
12982                 error "create striped dir under striped dir fails"
12983
12984         touch $DIR/$tdir/striped_dir1/b
12985         mkdir $DIR/$tdir/striped_dir1/dir_b
12986         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
12987                 error "create striped dir under striped dir fails"
12988
12989         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
12990                 error "rename file under different striped dir should fail"
12991
12992         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
12993                 error "rename dir under different striped dir should fail"
12994
12995         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
12996                 error "rename striped dir under diff striped dir should fail"
12997
12998         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
12999                 error "rename file under diff striped dirs fails"
13000
13001         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
13002                 error "rename dir under diff striped dirs fails"
13003
13004         rm -rf $DIR/$tdir
13005 }
13006 run_test 300f "check rename cross striped directory"
13007
13008 test_300g() {
13009         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13010         local stripe_count
13011         local dir
13012
13013         mkdir $DIR/$tdir
13014         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
13015                                         $DIR/$tdir/striped_dir ||
13016                 error "set striped dir error"
13017
13018         $LFS setdirstripe -D -c $MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13019                 error "set default stripe on striped dir error"
13020
13021         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/striped_dir)
13022         [ $stripe_count -eq $MDSCOUNT ] ||
13023                 error "default stripe wrong expect $MDSCOUNT get $stripe_count"
13024
13025         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
13026
13027         for dir in $(find $DIR/$tdir/striped_dir/*); do
13028                 stripe_count=$($LFS getdirstripe -c $dir)
13029                 [ $stripe_count -eq $MDSCOUNT ] ||
13030                         error "expect $MDSCOUNT get $stripe_count for $dir"
13031         done
13032
13033         rmdir $DIR/$tdir/striped_dir/* || error "rmdir1 failed"
13034         #change default stripe count to 2
13035         $LFS setdirstripe -D -c 2 -t all_char $DIR/$tdir/striped_dir ||
13036                 error "set default stripe on striped dir error"
13037
13038         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
13039
13040         rmdir $DIR/$tdir/striped_dir/* || error "rmdir2 failed"
13041
13042         #change default stripe count to 1
13043         $LFS setdirstripe -D -c 1 -t all_char $DIR/$tdir/striped_dir ||
13044                 error "set default stripe on striped dir error"
13045
13046         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
13047         for dir in $(find $DIR/$tdir/striped_dir/*); do
13048                 stripe_count=$($LFS getdirstripe -c $dir)
13049                 [ $stripe_count -eq 1 ] ||
13050                         error "expect 1 get $stripe_count for $dir"
13051         done
13052         rmdir $DIR/$tdir/striped_dir/* || error "rmdir3 failed"
13053 }
13054 run_test 300g "check default striped directory for striped directory"
13055
13056 test_300h() {
13057         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13058         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13059         local stripe_count
13060         local file
13061
13062         mkdir $DIR/$tdir
13063
13064         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13065                 error "set striped dir error"
13066
13067         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
13068                 error "create files under striped dir failed"
13069
13070         # unfortunately, we need to umount to clear dir layout cache for now
13071         # once we fully implement dir layout, we can drop this
13072         umount_client $MOUNT || error "umount failed"
13073         mount_client $MOUNT || error "mount failed"
13074
13075         #set the stripe to be unknown hash type
13076         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
13077         $LCTL set_param fail_loc=0x1901
13078         for ((i = 0; i < 10; i++)); do
13079                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
13080                         error "stat f-$i failed"
13081                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
13082         done
13083
13084         touch $DIR/$tdir/striped_dir/f0 &&
13085                 error "create under striped dir with unknown hash should fail"
13086
13087         $LCTL set_param fail_loc=0
13088
13089         umount_client $MOUNT || error "umount failed"
13090         mount_client $MOUNT || error "mount failed"
13091
13092         return 0
13093 }
13094 run_test 300h "client handle unknown hash type striped directory"
13095
13096 test_400a() { # LU-1606, was conf-sanity test_74
13097         local extra_flags=''
13098         local out=$TMP/$tfile
13099         local prefix=/usr/include/lustre
13100         local prog
13101
13102         if ! which $CC > /dev/null 2>&1; then
13103                 skip_env "$CC is not installed"
13104                 return 0
13105         fi
13106
13107         if ! [[ -d $prefix ]]; then
13108                 # Assume we're running in tree and fixup the include path.
13109                 extra_flags+=" -I$LUSTRE/../libcfs/include"
13110                 extra_flags+=" -I$LUSTRE/include"
13111                 extra_flags+=" -L$LUSTRE/utils"
13112         fi
13113
13114         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
13115                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
13116                         error "client api broken"
13117         done
13118 }
13119 run_test 400a "Lustre client api program can compile and link"
13120
13121 test_400b() { # LU-1606, LU-5011
13122         local header
13123         local out=$TMP/$tfile
13124         local prefix=/usr/include/lustre
13125
13126         # We use a hard coded prefix so that this test will not fail
13127         # when run in tree. There are headers in lustre/include/lustre/
13128         # that are not packaged (like lustre_idl.h) and have more
13129         # complicated include dependencies (like config.h and lnet/types.h).
13130         # Since this test about correct packaging we just skip them when
13131         # they don't exist (see below) rather than try to fixup cppflags.
13132
13133         if ! which $CC > /dev/null 2>&1; then
13134                 skip_env "$CC is not installed"
13135                 return 0
13136         fi
13137
13138         for header in $prefix/*.h; do
13139                 if ! [[ -f "$header" ]]; then
13140                         continue
13141                 fi
13142
13143                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
13144                         continue # liblustreapi.h is deprecated.
13145                 fi
13146
13147                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
13148                         error "cannot compile '$header'"
13149         done
13150 }
13151 run_test 400b "packaged headers can be compiled"
13152
13153 #
13154 # tests that do cleanup/setup should be run at the end
13155 #
13156
13157 test_900() {
13158         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13159         local ls
13160         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
13161         $LCTL set_param fail_loc=0x903
13162
13163         cancel_lru_locks MGC
13164
13165         FAIL_ON_ERROR=true cleanup
13166         FAIL_ON_ERROR=true setup
13167 }
13168 run_test 900 "umount should not race with any mgc requeue thread"
13169
13170 complete $SECONDS
13171 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
13172 check_and_cleanup_lustre
13173 if [ "$I_MOUNTED" != "yes" ]; then
13174         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
13175 fi
13176 exit_status