Whamcloud - gitweb
d81cf53fde538db12d01694bdb1ebc0dad5e9ee1
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 8; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
12 ALWAYS_EXCEPT="                42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # with LOD/OSP landing
16 # bug number for skipped tests: LU-2036
17 ALWAYS_EXCEPT="                 76     $ALWAYS_EXCEPT"
18
19 is_sles11()                                             # LU-4351
20 {
21         if [ -r /etc/SuSE-release ]
22         then
23                 local vers=`grep VERSION /etc/SuSE-release | awk '{print $3}'`
24                 if [ $vers -eq 11 ]
25                 then
26                         return 0
27                 fi
28         fi
29         return 1
30 }
31
32 if is_sles11; then                                      # LU-4351
33         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 54c"
34 fi
35
36 SRCDIR=$(cd $(dirname $0); echo $PWD)
37 export PATH=$PATH:/sbin
38
39 TMP=${TMP:-/tmp}
40
41 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
42 CREATETEST=${CREATETEST:-createtest}
43 LFS=${LFS:-lfs}
44 LFIND=${LFIND:-"$LFS find"}
45 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
46 LCTL=${LCTL:-lctl}
47 MCREATE=${MCREATE:-mcreate}
48 OPENFILE=${OPENFILE:-openfile}
49 OPENUNLINK=${OPENUNLINK:-openunlink}
50 export MULTIOP=${MULTIOP:-multiop}
51 READS=${READS:-"reads"}
52 MUNLINK=${MUNLINK:-munlink}
53 SOCKETSERVER=${SOCKETSERVER:-socketserver}
54 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
55 MEMHOG=${MEMHOG:-memhog}
56 DIRECTIO=${DIRECTIO:-directio}
57 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
58 UMOUNT=${UMOUNT:-"umount -d"}
59 STRIPES_PER_OBJ=-1
60 CHECK_GRANT=${CHECK_GRANT:-"yes"}
61 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
62 export PARALLEL=${PARALLEL:-"no"}
63
64 export NAME=${NAME:-local}
65
66 SAVE_PWD=$PWD
67
68 CLEANUP=${CLEANUP:-:}
69 SETUP=${SETUP:-:}
70 TRACE=${TRACE:-""}
71 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
72 . $LUSTRE/tests/test-framework.sh
73 init_test_env $@
74 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
75 init_logging
76
77 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 64b 68 71 77f 78 115 124b 230d"
78
79 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
80 # bug number for skipped test:        LU-1593 LU-2610 LU-2833 LU-1957 LU-2805
81         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h     40      48a     180     184c"
82
83 FAIL_ON_ERROR=false
84
85 cleanup() {
86         echo -n "cln.."
87         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
88         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
89 }
90 setup() {
91         echo -n "mnt.."
92         load_modules
93         setupall || exit 10
94         echo "done"
95 }
96
97 check_kernel_version() {
98         WANT_VER=$1
99         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
100         case $GOT_VER in
101         patchless|patchless_client) return 0;;
102         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
103         esac
104         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
105         return 1
106 }
107
108 check_swap_layouts_support()
109 {
110         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
111                 { skip "Does not support layout lock."; return 0; }
112         return 1
113 }
114
115 if [ "$ONLY" == "cleanup" ]; then
116        sh llmountcleanup.sh
117        exit 0
118 fi
119
120 check_and_setup_lustre
121
122 DIR=${DIR:-$MOUNT}
123 assert_DIR
124
125 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
126         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
127 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
128 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
129 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
130 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
131 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
132 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
133
134 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
135 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
136 rm -rf $DIR/[Rdfs][0-9]*
137
138 # $RUNAS_ID may get set incorrectly somewhere else
139 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
140
141 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
142
143 build_test_filter
144
145 if [ "${ONLY}" = "MOUNT" ] ; then
146         echo "Lustre is up, please go on"
147         exit
148 fi
149
150 echo "preparing for tests involving mounts"
151 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
152 touch $EXT2_DEV
153 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
154 echo # add a newline after mke2fs.
155
156 umask 077
157
158 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
159 lctl set_param debug=-1 2> /dev/null || true
160 test_0a() {
161         touch $DIR/$tfile
162         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
163         rm $DIR/$tfile
164         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
165 }
166 run_test 0a "touch; rm ====================="
167
168 test_0b() {
169         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
170         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
171 }
172 run_test 0b "chmod 0755 $DIR ============================="
173
174 test_0c() {
175         $LCTL get_param mdc.*.import | grep "state: FULL" ||
176                 error "import not FULL"
177         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
178                 error "bad target"
179 }
180 run_test 0c "check import proc ============================="
181
182 test_1() {
183         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
184         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
185         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
186         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
187         rmdir $DIR/$tdir/d2
188         rmdir $DIR/$tdir
189         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
190 }
191 run_test 1 "mkdir; remkdir; rmdir =============================="
192
193 test_2() {
194         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
195         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
196         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
197         rm -r $DIR/$tdir
198         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
199 }
200 run_test 2 "mkdir; touch; rmdir; check file ===================="
201
202 test_3() {
203         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
204         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
205         touch $DIR/$tdir/$tfile
206         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
207         rm -r $DIR/$tdir
208         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
209 }
210 run_test 3 "mkdir; touch; rmdir; check dir ====================="
211
212 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
213 test_4() {
214         local MDTIDX=1
215         local remote_dir=remote_dir
216
217         [ $MDSCOUNT -ge 2 ] && skip "skip now for LU-4690" && return #LU-4690
218         test_mkdir $DIR/$remote_dir ||
219                 error "Create remote directory failed"
220
221         touch $DIR/$remote_dir/$tfile ||
222                 error "Create file under remote directory failed"
223
224         rmdir $DIR/$remote_dir &&
225                 error "Expect error removing in-use dir $DIR/$remote_dir"
226
227         test -d $DIR/$remote_dir || error "Remote directory disappeared"
228 }
229 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
230
231 test_5() {
232         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
233         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
234         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
235         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
236         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
237 }
238 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
239
240 test_6a() {
241         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
242         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
243         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
244                 error "$tfile does not have perm 0666 or UID $UID"
245         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
246         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
247                 error "$tfile should be 0666 and owned by UID $UID"
248 }
249 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
250
251 test_6c() {
252         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
253         touch $DIR/$tfile
254         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
255         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
256                 error "$tfile should be owned by UID $RUNAS_ID"
257         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
258         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
259                 error "$tfile should be owned by UID $RUNAS_ID"
260 }
261 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
262
263 test_6e() {
264         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
265         touch $DIR/$tfile
266         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
267         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
268                 error "$tfile should be owned by GID $UID"
269         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
270         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
271                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
272 }
273 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
274
275 test_6g() {
276         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
277         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
278         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
279         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
280         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
281         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
282         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
283                 error "$tdir/d/subdir should be GID $RUNAS_GID"
284 }
285 run_test 6g "Is new dir in sgid dir inheriting group?"
286
287 test_6h() { # bug 7331
288         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
289         touch $DIR/$tfile || error "touch failed"
290         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
291         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
292                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
293         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
294                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
295 }
296 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
297
298 test_7a() {
299         test_mkdir $DIR/$tdir
300         $MCREATE $DIR/$tdir/$tfile
301         chmod 0666 $DIR/$tdir/$tfile
302         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
303                 error "$tdir/$tfile should be mode 0666"
304 }
305 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
306
307 test_7b() {
308         if [ ! -d $DIR/$tdir ]; then
309                 mkdir $DIR/$tdir
310         fi
311         $MCREATE $DIR/$tdir/$tfile
312         echo -n foo > $DIR/$tdir/$tfile
313         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
314         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
315 }
316 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
317
318 test_8() {
319         test_mkdir $DIR/$tdir
320         touch $DIR/$tdir/$tfile
321         chmod 0666 $DIR/$tdir/$tfile
322         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
323                 error "$tfile mode not 0666"
324 }
325 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
326
327 test_9() {
328         test_mkdir $DIR/$tdir
329         test_mkdir $DIR/$tdir/d2
330         test_mkdir $DIR/$tdir/d2/d3
331         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
332 }
333 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
334
335 test_10() {
336         test_mkdir $DIR/$tdir
337         test_mkdir $DIR/$tdir/d2
338         touch $DIR/$tdir/d2/$tfile
339         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
340                 error "$tdir/d2/$tfile not a file"
341 }
342 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
343
344 test_11() {
345         test_mkdir $DIR/$tdir
346         test_mkdir $DIR/$tdir/d2
347         chmod 0666 $DIR/$tdir/d2
348         chmod 0705 $DIR/$tdir/d2
349         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
350                 error "$tdir/d2 mode not 0705"
351 }
352 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
353
354 test_12() {
355         test_mkdir $DIR/$tdir
356         touch $DIR/$tdir/$tfile
357         chmod 0666 $DIR/$tdir/$tfile
358         chmod 0654 $DIR/$tdir/$tfile
359         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
360                 error "$tdir/d2 mode not 0654"
361 }
362 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
363
364 test_13() {
365         test_mkdir $DIR/$tdir
366         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
367         >  $DIR/$tdir/$tfile
368         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
369                 error "$tdir/$tfile size not 0 after truncate"
370 }
371 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
372
373 test_14() {
374         test_mkdir $DIR/$tdir
375         touch $DIR/$tdir/$tfile
376         rm $DIR/$tdir/$tfile
377         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
378 }
379 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
380
381 test_15() {
382         test_mkdir $DIR/$tdir
383         touch $DIR/$tdir/$tfile
384         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
385         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
386                 error "$tdir/${tfile_2} not a file after rename"
387 }
388 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
389
390 test_16() {
391         test_mkdir $DIR/$tdir
392         touch $DIR/$tdir/$tfile
393         rm -rf $DIR/$tdir/$tfile
394         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
395 }
396 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
397
398 test_17a() {
399         test_mkdir -p $DIR/$tdir
400         touch $DIR/$tdir/$tfile
401         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
402         ls -l $DIR/$tdir
403         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
404                 error "$tdir/l-exist not a symlink"
405         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
406                 error "$tdir/l-exist not referencing a file"
407         rm -f $DIR/$tdir/l-exist
408         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
409 }
410 run_test 17a "symlinks: create, remove (real) =================="
411
412 test_17b() {
413         test_mkdir -p $DIR/$tdir
414         ln -s no-such-file $DIR/$tdir/l-dangle
415         ls -l $DIR/$tdir
416         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
417                 error "$tdir/l-dangle not referencing no-such-file"
418         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
419                 error "$tdir/l-dangle not referencing non-existent file"
420         rm -f $DIR/$tdir/l-dangle
421         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
422 }
423 run_test 17b "symlinks: create, remove (dangling) =============="
424
425 test_17c() { # bug 3440 - don't save failed open RPC for replay
426         test_mkdir -p $DIR/$tdir
427         ln -s foo $DIR/$tdir/$tfile
428         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
429 }
430 run_test 17c "symlinks: open dangling (should return error) ===="
431
432 test_17d() {
433         test_mkdir -p $DIR/$tdir
434         ln -s foo $DIR/$tdir/$tfile
435         touch $DIR/$tdir/$tfile || error "creating to new symlink"
436 }
437 run_test 17d "symlinks: create dangling ========================"
438
439 test_17e() {
440         test_mkdir -p $DIR/$tdir
441         local foo=$DIR/$tdir/$tfile
442         ln -s $foo $foo || error "create symlink failed"
443         ls -l $foo || error "ls -l failed"
444         ls $foo && error "ls not failed" || true
445 }
446 run_test 17e "symlinks: create recursive symlink (should return error) ===="
447
448 test_17f() {
449         test_mkdir -p $DIR/d17f
450         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/d17f/111
451         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/d17f/222
452         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/d17f/333
453         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/d17f/444
454         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/d17f/555
455         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890/aaaaaaaaaa/bbbbbbbbbb/cccccccccc/dddddddddd/eeeeeeeeee/ffffffffff/ $DIR/d17f/666
456         ls -l  $DIR/d17f
457 }
458 run_test 17f "symlinks: long and very long symlink name ========================"
459
460 # str_repeat(S, N) generate a string that is string S repeated N times
461 str_repeat() {
462         local s=$1
463         local n=$2
464         local ret=''
465         while [ $((n -= 1)) -ge 0 ]; do
466                 ret=$ret$s
467         done
468         echo $ret
469 }
470
471 # Long symlinks and LU-2241
472 test_17g() {
473         test_mkdir -p $DIR/$tdir
474         local TESTS="59 60 61 4094 4095"
475
476         # Fix for inode size boundary in 2.1.4
477         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
478                 TESTS="4094 4095"
479
480         # Patch not applied to 2.2 or 2.3 branches
481         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
482         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
483                 TESTS="4094 4095"
484
485         # skip long symlink name for rhel6.5.
486         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
487         grep -q '6.5' /etc/redhat-release &>/dev/null &&
488                 TESTS="59 60 61 4062 4063"
489
490         for i in $TESTS; do
491                 local SYMNAME=$(str_repeat 'x' $i)
492                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
493                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
494         done
495 }
496 run_test 17g "symlinks: really long symlink name and inode boundaries"
497
498 test_17h() { #bug 17378
499         remote_mds_nodsh && skip "remote MDS with nodsh" && return
500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
501         local mdt_idx
502         test_mkdir -p $DIR/$tdir
503         if [[ $MDSCOUNT -gt 1 ]]; then
504                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
505         else
506                 mdt_idx=0
507         fi
508         $SETSTRIPE -c -1 $DIR/$tdir
509 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
510         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
511         touch $DIR/$tdir/$tfile || true
512 }
513 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
514
515 test_17i() { #bug 20018
516         remote_mds_nodsh && skip "remote MDS with nodsh" && return
517         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
518         test_mkdir -p $DIR/$tdir
519         local foo=$DIR/$tdir/$tfile
520         local mdt_idx
521         if [[ $MDSCOUNT -gt 1 ]]; then
522                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
523         else
524                 mdt_idx=0
525         fi
526         ln -s $foo $foo || error "create symlink failed"
527 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
528         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
529         ls -l $foo && error "error not detected"
530         return 0
531 }
532 run_test 17i "don't panic on short symlink"
533
534 test_17k() { #bug 22301
535         [[ -z "$(which rsync 2>/dev/null)" ]] &&
536                 skip "no rsync command" && return 0
537         rsync --help | grep -q xattr ||
538                 skip_env "$(rsync --version | head -n1) does not support xattrs"
539         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
540         test_mkdir -p $DIR/$tdir
541         test_mkdir -p $DIR/$tdir.new
542         touch $DIR/$tdir/$tfile
543         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
544         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
545                 error "rsync failed with xattrs enabled"
546 }
547 run_test 17k "symlinks: rsync with xattrs enabled ========================="
548
549 test_17l() { # LU-279
550         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
551                 skip "no getfattr command" && return 0
552         mkdir -p $DIR/$tdir
553         touch $DIR/$tdir/$tfile
554         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
555         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
556                 # -h to not follow symlinks. -m '' to list all the xattrs.
557                 # grep to remove first line: '# file: $path'.
558                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
559                 do
560                         lgetxattr_size_check $path $xattr ||
561                                 error "lgetxattr_size_check $path $xattr failed"
562                 done
563         done
564 }
565 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
566
567 # LU-1540
568 test_17m() {
569         local short_sym="0123456789"
570         local WDIR=$DIR/${tdir}m
571         local mds_index
572         local devname
573         local cmd
574         local i
575         local rc=0
576
577         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
578         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
579                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
580
581         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
582                 skip "only for ldiskfs MDT" && return 0
583
584         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
585
586         mkdir -p $WDIR
587         long_sym=$short_sym
588         # create a long symlink file
589         for ((i = 0; i < 4; ++i)); do
590                 long_sym=${long_sym}${long_sym}
591         done
592
593         echo "create 512 short and long symlink files under $WDIR"
594         for ((i = 0; i < 256; ++i)); do
595                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
596                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
597         done
598
599         echo "erase them"
600         rm -f $WDIR/*
601         sync
602         wait_delete_completed
603
604         echo "recreate the 512 symlink files with a shorter string"
605         for ((i = 0; i < 512; ++i)); do
606                 # rewrite the symlink file with a shorter string
607                 ln -sf ${long_sym} $WDIR/long-$i
608                 ln -sf ${short_sym} $WDIR/short-$i
609         done
610
611         mds_index=$($LFS getstripe -M $WDIR)
612         mds_index=$((mds_index+1))
613         devname=$(mdsdevname $mds_index)
614         cmd="$E2FSCK -fnvd $devname"
615
616         echo "stop and checking mds${mds_index}: $cmd"
617         # e2fsck should not return error
618         stop mds${mds_index}
619         do_facet mds${mds_index} $cmd || rc=$?
620
621         start mds${mds_index} $devname $MDS_MOUNT_OPTS
622         df $MOUNT > /dev/null 2>&1
623         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
624                 "short/long symlink MDT: rc=$rc"
625         return $rc
626 }
627 run_test 17m "run e2fsck against MDT which contains short/long symlink"
628
629 check_fs_consistency_17n() {
630         local mdt_index
631         local devname
632         local cmd
633         local rc=0
634
635         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
636         # so it only check MDT1/MDT2 instead of all of MDTs.
637         for mdt_index in $(seq 1 2); do
638                 devname=$(mdsdevname $mdt_index)
639                 cmd="$E2FSCK -fnvd $devname"
640
641                 echo "stop and checking mds${mdt_index}: $cmd"
642                 # e2fsck should not return error
643                 stop mds${mdt_index}
644                 do_facet mds${mdt_index} $cmd || rc=$?
645
646                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
647                 df $MOUNT > /dev/null 2>&1
648                 [ $rc -ne 0 ] && break
649         done
650         return $rc
651 }
652
653 test_17n() {
654         local i
655
656         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
657         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
658                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
659
660         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
661                 skip "only for ldiskfs MDT" && return 0
662
663         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
664
665         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
666
667         mkdir -p $DIR/$tdir
668         for ((i=0; i<10; i++)); do
669                 $LFS mkdir -i 1 $DIR/$tdir/remote_dir_${i} ||
670                         error "create remote dir error $i"
671                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
672                         error "create files under remote dir failed $i"
673         done
674
675         check_fs_consistency_17n ||
676                 error "e2fsck report error after create files under remote dir"
677
678         for ((i=0;i<10;i++)); do
679                 rm -rf $DIR/$tdir/remote_dir_${i} ||
680                         error "destroy remote dir error $i"
681         done
682
683         check_fs_consistency_17n ||
684                 error "e2fsck report error after unlink files under remote dir"
685
686         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
687                 skip "lustre < 2.4.50 does not support migrate mv " && return
688
689         for ((i=0; i<10; i++)); do
690                 mkdir -p $DIR/$tdir/remote_dir_${i}
691                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
692                         error "create files under remote dir failed $i"
693                 $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} ||
694                         error "migrate remote dir error $i"
695         done
696         check_fs_consistency_17n || error "e2fsck report error after migration"
697
698         for ((i=0;i<10;i++)); do
699                 rm -rf $DIR/$tdir/remote_dir_${i} ||
700                         error "destroy remote dir error $i"
701         done
702
703         check_fs_consistency_17n || error "e2fsck report error after unlink"
704 }
705 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
706
707 test_17o() {
708         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
709                 skip "Need MDS version at least 2.3.64" && return
710
711         local WDIR=$DIR/${tdir}o
712         local mdt_index
713         local mdtdevname
714         local rc=0
715
716         mkdir -p $WDIR
717         mdt_index=$($LFS getstripe -M $WDIR)
718         mdt_index=$((mdt_index+1))
719         mdtdevname=$(mdsdevname $mdt_index)
720
721         touch $WDIR/$tfile
722         stop mds${mdt_index}
723         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS
724
725         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
726         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
727         ls -l $WDIR/$tfile && rc=1
728         do_facet mds${mdt_index} lctl set_param fail_loc=0
729         [[ $rc -ne 0 ]] && error "stat file should fail"
730         true
731 }
732 run_test 17o "stat file with incompat LMA feature"
733
734 test_18() {
735         touch $DIR/f || error "Failed to touch $DIR/f: $?"
736         ls $DIR || error "Failed to ls $DIR: $?"
737 }
738 run_test 18 "touch .../f ; ls ... =============================="
739
740 test_19a() {
741         touch $DIR/$tfile
742         ls -l $DIR
743         rm $DIR/$tfile
744         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
745 }
746 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
747
748 test_19b() {
749         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
750 }
751 run_test 19b "ls -l .../f19 (should return error) =============="
752
753 test_19c() {
754         [ $RUNAS_ID -eq $UID ] &&
755                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
756         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
757 }
758 run_test 19c "$RUNAS touch .../f19 (should return error) =="
759
760 test_19d() {
761         cat $DIR/f19 && error || true
762 }
763 run_test 19d "cat .../f19 (should return error) =============="
764
765 test_20() {
766         touch $DIR/$tfile
767         rm $DIR/$tfile
768         log "1 done"
769         touch $DIR/$tfile
770         rm $DIR/$tfile
771         log "2 done"
772         touch $DIR/$tfile
773         rm $DIR/$tfile
774         log "3 done"
775         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
776 }
777 run_test 20 "touch .../f ; ls -l ... ==========================="
778
779 test_21() {
780         test_mkdir -p $DIR/$tdir
781         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
782         ln -s dangle $DIR/$tdir/link
783         echo foo >> $DIR/$tdir/link
784         cat $DIR/$tdir/dangle
785         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
786         $CHECKSTAT -f -t file $DIR/$tdir/link ||
787                 error "$tdir/link not linked to a file"
788 }
789 run_test 21 "write to dangling link ============================"
790
791 test_22() {
792         WDIR=$DIR/$tdir
793         test_mkdir -p $DIR/$tdir
794         chown $RUNAS_ID:$RUNAS_GID $WDIR
795         (cd $WDIR || error "cd $WDIR failed";
796         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
797         $RUNAS tar xf -)
798         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
799         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
800         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
801 }
802 run_test 22 "unpack tar archive as non-root user ==============="
803
804 # was test_23
805 test_23a() {
806         test_mkdir -p $DIR/$tdir
807         local file=$DIR/$tdir/$tfile
808
809         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
810         openfile -f O_CREAT:O_EXCL $file &&
811                 error "$file recreate succeeded" || true
812 }
813 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
814
815 test_23b() { # bug 18988
816         test_mkdir -p $DIR/$tdir
817         local file=$DIR/$tdir/$tfile
818
819         rm -f $file
820         echo foo > $file || error "write filed"
821         echo bar >> $file || error "append filed"
822         $CHECKSTAT -s 8 $file || error "wrong size"
823         rm $file
824 }
825 run_test 23b "O_APPEND check =========================="
826
827 # rename sanity
828 test_24a() {
829         echo '-- same directory rename'
830         test_mkdir $DIR/$tdir
831         touch $DIR/$tdir/$tfile.1
832         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
833         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
834 }
835 run_test 24a "rename file to non-existent target"
836
837 test_24b() {
838         test_mkdir $DIR/$tdir
839         touch $DIR/$tdir/$tfile.{1,2}
840         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
841         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
842         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
843 }
844 run_test 24b "rename file to existing target"
845
846 test_24c() {
847         test_mkdir $DIR/$tdir
848         test_mkdir $DIR/$tdir/d$testnum.1
849         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
850         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
851         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
852 }
853 run_test 24c "rename directory to non-existent target"
854
855 test_24d() {
856         test_mkdir -c1 $DIR/$tdir
857         test_mkdir -c1 $DIR/$tdir/d$testnum.1
858         test_mkdir -c1 $DIR/$tdir/d$testnum.2
859         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
860         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
861         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
862 }
863 run_test 24d "rename directory to existing target"
864
865 test_24e() {
866         echo '-- cross directory renames --'
867         test_mkdir $DIR/R5a
868         test_mkdir $DIR/R5b
869         touch $DIR/R5a/f
870         mv $DIR/R5a/f $DIR/R5b/g
871         $CHECKSTAT -a $DIR/R5a/f || error
872         $CHECKSTAT -t file $DIR/R5b/g || error
873 }
874 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
875
876 test_24f() {
877         test_mkdir $DIR/R6a
878         test_mkdir $DIR/R6b
879         touch $DIR/R6a/f $DIR/R6b/g
880         mv $DIR/R6a/f $DIR/R6b/g
881         $CHECKSTAT -a $DIR/R6a/f || error
882         $CHECKSTAT -t file $DIR/R6b/g || error
883 }
884 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
885
886 test_24g() {
887         test_mkdir $DIR/R7a
888         test_mkdir $DIR/R7b
889         test_mkdir $DIR/R7a/d
890         mv $DIR/R7a/d $DIR/R7b/e
891         $CHECKSTAT -a $DIR/R7a/d || error
892         $CHECKSTAT -t dir $DIR/R7b/e || error
893 }
894 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
895
896 test_24h() {
897         test_mkdir -c1 $DIR/R8a
898         test_mkdir -c1 $DIR/R8b
899         test_mkdir -c1 $DIR/R8a/d
900         test_mkdir -c1 $DIR/R8b/e
901         mrename $DIR/R8a/d $DIR/R8b/e
902         $CHECKSTAT -a $DIR/R8a/d || error
903         $CHECKSTAT -t dir $DIR/R8b/e || error
904 }
905 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
906
907 test_24i() {
908         echo "-- rename error cases"
909         test_mkdir $DIR/R9
910         test_mkdir $DIR/R9/a
911         touch $DIR/R9/f
912         mrename $DIR/R9/f $DIR/R9/a
913         $CHECKSTAT -t file $DIR/R9/f || error
914         $CHECKSTAT -t dir  $DIR/R9/a || error
915         $CHECKSTAT -a $DIR/R9/a/f || error
916 }
917 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
918
919 test_24j() {
920         test_mkdir $DIR/R10
921         mrename $DIR/R10/f $DIR/R10/g
922         $CHECKSTAT -t dir $DIR/R10 || error
923         $CHECKSTAT -a $DIR/R10/f || error
924         $CHECKSTAT -a $DIR/R10/g || error
925 }
926 run_test 24j "source does not exist ============================"
927
928 test_24k() {
929         test_mkdir $DIR/R11a
930         test_mkdir $DIR/R11a/d
931         touch $DIR/R11a/f
932         mv $DIR/R11a/f $DIR/R11a/d
933         $CHECKSTAT -a $DIR/R11a/f || error
934         $CHECKSTAT -t file $DIR/R11a/d/f || error
935 }
936 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
937
938 # bug 2429 - rename foo foo foo creates invalid file
939 test_24l() {
940         f="$DIR/f24l"
941         $MULTIOP $f OcNs || error
942 }
943 run_test 24l "Renaming a file to itself ========================"
944
945 test_24m() {
946         f="$DIR/f24m"
947         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
948         # on ext3 this does not remove either the source or target files
949         # though the "expected" operation would be to remove the source
950         $CHECKSTAT -t file ${f} || error "${f} missing"
951         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
952 }
953 run_test 24m "Renaming a file to a hard link to itself ========="
954
955 test_24n() {
956     f="$DIR/f24n"
957     # this stats the old file after it was renamed, so it should fail
958     touch ${f}
959     $CHECKSTAT ${f}
960     mv ${f} ${f}.rename
961     $CHECKSTAT ${f}.rename
962     $CHECKSTAT -a ${f}
963 }
964 run_test 24n "Statting the old file after renaming (Posix rename 2)"
965
966 test_24o() {
967         check_kernel_version 37 || return 0
968         test_mkdir -p $DIR/d24o
969         rename_many -s random -v -n 10 $DIR/d24o
970 }
971 run_test 24o "rename of files during htree split ==============="
972
973 test_24p() {
974         test_mkdir $DIR/R12a
975         test_mkdir $DIR/R12b
976         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
977         mrename $DIR/R12a $DIR/R12b
978         $CHECKSTAT -a $DIR/R12a || error
979         $CHECKSTAT -t dir $DIR/R12b || error
980         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
981         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
982 }
983 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
984
985 cleanup_multiop_pause() {
986         trap 0
987         kill -USR1 $MULTIPID
988 }
989
990 test_24q() {
991         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
992         test_mkdir $DIR/R13a
993         test_mkdir $DIR/R13b
994         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
995         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
996         MULTIPID=$!
997
998         trap cleanup_multiop_pause EXIT
999         mrename $DIR/R13a $DIR/R13b
1000         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
1001         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
1002         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
1003         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
1004         cleanup_multiop_pause
1005         wait $MULTIPID || error "multiop close failed"
1006 }
1007 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
1008
1009 test_24r() { #bug 3789
1010         test_mkdir $DIR/R14a
1011         test_mkdir $DIR/R14a/b
1012         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1013         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1014         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1015 }
1016 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1017
1018 test_24s() {
1019         test_mkdir $DIR/R15a
1020         test_mkdir $DIR/R15a/b
1021         test_mkdir $DIR/R15a/b/c
1022         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1023         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1024         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1025 }
1026 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1027 test_24t() {
1028         test_mkdir $DIR/R16a
1029         test_mkdir $DIR/R16a/b
1030         test_mkdir $DIR/R16a/b/c
1031         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1032         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1033         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1034 }
1035 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1036
1037 test_24u() { # bug12192
1038         rm -rf $DIR/$tfile
1039         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1040         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1041 }
1042 run_test 24u "create stripe file"
1043
1044 page_size() {
1045         getconf PAGE_SIZE
1046 }
1047
1048 simple_cleanup_common() {
1049         trap 0
1050         rm -rf $DIR/$tdir
1051         wait_delete_completed
1052 }
1053
1054 max_pages_per_rpc() {
1055         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1056 }
1057
1058 test_24v() {
1059         local NRFILES=100000
1060         local FREE_INODES=$(mdt_free_inodes 0)
1061         [[ $FREE_INODES -lt $NRFILES ]] &&
1062                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1063                 return
1064
1065         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1066         trap simple_cleanup_common EXIT
1067
1068         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1069         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1070
1071         mkdir -p $DIR/$tdir
1072         createmany -m $DIR/$tdir/$tfile $NRFILES
1073
1074         cancel_lru_locks mdc
1075         lctl set_param mdc.*.stats clear
1076
1077         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1078
1079         # LU-5 large readdir
1080         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1081         #               8 bytes for name(filename is mostly 5 in this test) +
1082         #               8 bytes for luda_type
1083         # take into account of overhead in lu_dirpage header and end mark in
1084         # each page, plus one in RPC_NUM calculation.
1085         DIRENT_SIZE=48
1086         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1087         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1088         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1089                                 awk '/^mds_readpage/ {print $2}')
1090         [[ $mds_readpage -gt $RPC_NUM ]] &&
1091                 error "large readdir doesn't take effect"
1092
1093         simple_cleanup_common
1094 }
1095 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1096
1097 test_24w() { # bug21506
1098         SZ1=234852
1099         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1100         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1101         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1102         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1103         [ "$SZ1" = "$SZ2" ] || \
1104                 error "Error reading at the end of the file $tfile"
1105 }
1106 run_test 24w "Reading a file larger than 4Gb"
1107
1108 test_24x() {
1109         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1110         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1111         local MDTIDX=1
1112         local remote_dir=$DIR/$tdir/remote_dir
1113
1114         mkdir -p $DIR/$tdir
1115         $LFS mkdir -i $MDTIDX $remote_dir ||
1116                 error "create remote directory failed"
1117
1118         mkdir -p $DIR/$tdir/src_dir
1119         touch $DIR/$tdir/src_file
1120         mkdir -p $remote_dir/tgt_dir
1121         touch $remote_dir/tgt_file
1122
1123         mrename $remote_dir $DIR/ &&
1124                 error "rename dir cross MDT works!"
1125
1126         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1127                 error "rename dir cross MDT works!"
1128
1129         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1130                 error "rename file cross MDT works!"
1131
1132         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1133                 error "ln file cross MDT should not work!"
1134
1135         rm -rf $DIR/$tdir || error "Can not delete directories"
1136 }
1137 run_test 24x "cross rename/link should be failed"
1138
1139 test_24y() {
1140         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1142         local MDTIDX=1
1143         local remote_dir=$DIR/$tdir/remote_dir
1144
1145         mkdir -p $DIR/$tdir
1146         $LFS mkdir -i $MDTIDX $remote_dir ||
1147                    error "create remote directory failed"
1148
1149         mkdir -p $remote_dir/src_dir
1150         touch $remote_dir/src_file
1151         mkdir -p $remote_dir/tgt_dir
1152         touch $remote_dir/tgt_file
1153
1154         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1155                 error "rename subdir in the same remote dir failed!"
1156
1157         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1158                 error "rename files in the same remote dir failed!"
1159
1160         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1161                 error "link files in the same remote dir failed!"
1162
1163         rm -rf $DIR/$tdir || error "Can not delete directories"
1164 }
1165 run_test 24y "rename/link on the same dir should succeed"
1166
1167 test_24z() {
1168         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1169         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1170         local MDTIDX=1
1171         local remote_src=$DIR/$tdir/remote_dir
1172         local remote_tgt=$DIR/$tdir/remote_tgt
1173
1174         mkdir -p $DIR/$tdir
1175         $LFS mkdir -i $MDTIDX $remote_src ||
1176                    error "create remote directory failed"
1177
1178         $LFS mkdir -i $MDTIDX $remote_tgt ||
1179                    error "create remote directory failed"
1180
1181         mrename $remote_src $remote_tgt &&
1182                 error "rename remote dirs should not work!"
1183
1184         # If target dir does not exists, it should succeed
1185         rm -rf $remote_tgt
1186         mrename $remote_src $remote_tgt ||
1187                 error "rename remote dirs(tgt dir does not exists) failed!"
1188
1189         rm -rf $DIR/$tdir || error "Can not delete directories"
1190 }
1191 run_test 24z "rename one remote dir to another remote dir should fail"
1192
1193 test_24A() { # LU-3182
1194         local NFILES=5000
1195
1196         rm -rf $DIR/$tdir
1197         mkdir -p $DIR/$tdir
1198         createmany -m $DIR/$tdir/$tfile $NFILES
1199         local t=`ls $DIR/$tdir | wc -l`
1200         local u=`ls $DIR/$tdir | sort -u | wc -l`
1201         if [ $t -ne $NFILES -o $u -ne $NFILES ] ; then
1202                 error "Expected $NFILES files, got $t ($u unique)"
1203         fi
1204
1205         rm -rf $DIR/$tdir || error "Can not delete directories"
1206 }
1207 run_test 24A "readdir() returns correct number of entries."
1208
1209 test_25a() {
1210         echo '== symlink sanity ============================================='
1211
1212         test_mkdir $DIR/d25
1213         ln -s d25 $DIR/s25
1214         touch $DIR/s25/foo || error
1215 }
1216 run_test 25a "create file in symlinked directory ==============="
1217
1218 test_25b() {
1219         [ ! -d $DIR/d25 ] && test_25a
1220         $CHECKSTAT -t file $DIR/s25/foo || error
1221 }
1222 run_test 25b "lookup file in symlinked directory ==============="
1223
1224 test_26a() {
1225         test_mkdir $DIR/d26
1226         test_mkdir $DIR/d26/d26-2
1227         ln -s d26/d26-2 $DIR/s26
1228         touch $DIR/s26/foo || error
1229 }
1230 run_test 26a "multiple component symlink ======================="
1231
1232 test_26b() {
1233         test_mkdir -p $DIR/d26b/d26-2
1234         ln -s d26b/d26-2/foo $DIR/s26-2
1235         touch $DIR/s26-2 || error
1236 }
1237 run_test 26b "multiple component symlink at end of lookup ======"
1238
1239 test_26c() {
1240         test_mkdir $DIR/d26.2
1241         touch $DIR/d26.2/foo
1242         ln -s d26.2 $DIR/s26.2-1
1243         ln -s s26.2-1 $DIR/s26.2-2
1244         ln -s s26.2-2 $DIR/s26.2-3
1245         chmod 0666 $DIR/s26.2-3/foo
1246 }
1247 run_test 26c "chain of symlinks ================================"
1248
1249 # recursive symlinks (bug 439)
1250 test_26d() {
1251         ln -s d26-3/foo $DIR/d26-3
1252 }
1253 run_test 26d "create multiple component recursive symlink ======"
1254
1255 test_26e() {
1256         [ ! -h $DIR/d26-3 ] && test_26d
1257         rm $DIR/d26-3
1258 }
1259 run_test 26e "unlink multiple component recursive symlink ======"
1260
1261 # recursive symlinks (bug 7022)
1262 test_26f() {
1263         test_mkdir -p $DIR/$tdir
1264         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1265         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1266         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1267         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1268         cd $tfile                || error "cd $tfile failed"
1269         ln -s .. dotdot          || error "ln dotdot failed"
1270         ln -s dotdot/lndir lndir || error "ln lndir failed"
1271         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1272         output=`ls $tfile/$tfile/lndir/bar1`
1273         [ "$output" = bar1 ] && error "unexpected output"
1274         rm -r $tfile             || error "rm $tfile failed"
1275         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1276 }
1277 run_test 26f "rm -r of a directory which has recursive symlink ="
1278
1279 test_27a() {
1280         echo '== stripe sanity =============================================='
1281         test_mkdir -p $DIR/d27 || error "mkdir failed"
1282         $GETSTRIPE $DIR/d27
1283         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1284         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1285         log "== test_27a: write to one stripe file ========================="
1286         cp /etc/hosts $DIR/d27/f0 || error
1287 }
1288 run_test 27a "one stripe file =================================="
1289
1290 test_27b() {
1291         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1292         test_mkdir -p $DIR/d27
1293         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1294         $GETSTRIPE -c $DIR/d27/f01
1295         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1296                 error "two-stripe file doesn't have two stripes"
1297
1298         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1299 }
1300 run_test 27b "create and write to two stripe file"
1301
1302 test_27d() {
1303         test_mkdir -p $DIR/d27
1304         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1305         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1306         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1307 }
1308 run_test 27d "create file with default settings ================"
1309
1310 test_27e() {
1311         test_mkdir -p $DIR/d27
1312         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1313         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1314         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1315 }
1316 run_test 27e "setstripe existing file (should return error) ======"
1317
1318 test_27f() {
1319         test_mkdir -p $DIR/d27
1320         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1321         dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed"
1322         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1323 }
1324 run_test 27f "setstripe with bad stripe size (should return error)"
1325
1326 test_27g() {
1327         test_mkdir -p $DIR/d27
1328         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1329         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1330                 error "$DIR/d27/fnone has object"
1331 }
1332 run_test 27g "$GETSTRIPE with no objects"
1333
1334 test_27i() {
1335         touch $DIR/d27/fsome || error "touch failed"
1336         [[ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ]] || error "missing objects"
1337 }
1338 run_test 27i "$GETSTRIPE with some objects"
1339
1340 test_27j() {
1341         test_mkdir -p $DIR/d27
1342         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1343 }
1344 run_test 27j "setstripe with bad stripe offset (should return error)"
1345
1346 test_27k() { # bug 2844
1347         test_mkdir -p $DIR/d27
1348         FILE=$DIR/d27/f27k
1349         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1350         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1351         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1352         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1353         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1354         dd if=/dev/zero of=$FILE bs=4k count=1
1355         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1356         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1357 }
1358 run_test 27k "limit i_blksize for broken user apps ============="
1359
1360 test_27l() {
1361         test_mkdir -p $DIR/d27
1362         mcreate $DIR/f27l || error "creating file"
1363         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1364                 error "setstripe should have failed" || true
1365 }
1366 run_test 27l "check setstripe permissions (should return error)"
1367
1368 test_27m() {
1369         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1370                 return
1371         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1372                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1373                 return
1374         fi
1375         trap simple_cleanup_common EXIT
1376         test_mkdir -p $DIR/$tdir
1377         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1378         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1379                 error "dd should fill OST0"
1380         i=2
1381         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1382                 i=$((i + 1))
1383                 [ $i -gt 256 ] && break
1384         done
1385         i=$((i + 1))
1386         touch $DIR/$tdir/f27m_$i
1387         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1388                 error "OST0 was full but new created file still use it"
1389         i=$((i + 1))
1390         touch $DIR/$tdir/f27m_$i
1391         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1392                 error "OST0 was full but new created file still use it"
1393         simple_cleanup_common
1394 }
1395 run_test 27m "create file while OST0 was full =================="
1396
1397 sleep_maxage() {
1398         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1399         sleep $DELAY
1400 }
1401
1402 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1403 # if the OST isn't full anymore.
1404 reset_enospc() {
1405         local OSTIDX=${1:-""}
1406
1407         local list=$(comma_list $(osts_nodes))
1408         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1409
1410         do_nodes $list lctl set_param fail_loc=0
1411         sync    # initiate all OST_DESTROYs from MDS to OST
1412         sleep_maxage
1413 }
1414
1415 exhaust_precreations() {
1416         local OSTIDX=$1
1417         local FAILLOC=$2
1418         local FAILIDX=${3:-$OSTIDX}
1419
1420         test_mkdir -p $DIR/$tdir
1421         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1422         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1423
1424         local OST=$(ostname_from_index $OSTIDX)
1425         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1426                           sed -e 's/_UUID$//;s/^.*-//')
1427
1428         # on the mdt's osc
1429         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1430         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1431                         osc.$mdtosc_proc1.prealloc_last_id)
1432         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1433                         osc.$mdtosc_proc1.prealloc_next_id)
1434
1435         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1436         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1437
1438         test_mkdir -p $DIR/$tdir/${OST}
1439         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1440 #define OBD_FAIL_OST_ENOSPC              0x215
1441         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1442         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1443         echo "Creating to objid $last_id on ost $OST..."
1444         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1445         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1446         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1447         sleep_maxage
1448 }
1449
1450 exhaust_all_precreations() {
1451         local i
1452         for (( i=0; i < OSTCOUNT; i++ )) ; do
1453                 exhaust_precreations $i $1 -1
1454         done
1455 }
1456
1457 test_27n() {
1458         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1459         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1460         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1461         remote_ost_nodsh && skip "remote OST with nodsh" && return
1462
1463         reset_enospc
1464         rm -f $DIR/$tdir/$tfile
1465         exhaust_precreations 0 0x80000215
1466         $SETSTRIPE -c -1 $DIR/$tdir
1467         touch $DIR/$tdir/$tfile || error
1468         $GETSTRIPE $DIR/$tdir/$tfile
1469         reset_enospc
1470 }
1471 run_test 27n "create file with some full OSTs =================="
1472
1473 test_27o() {
1474         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1475         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1476         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1477         remote_ost_nodsh && skip "remote OST with nodsh" && return
1478
1479         reset_enospc
1480         rm -f $DIR/$tdir/$tfile
1481         exhaust_all_precreations 0x215
1482
1483         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1484
1485         reset_enospc
1486         rm -rf $DIR/$tdir/*
1487 }
1488 run_test 27o "create file with all full OSTs (should error) ===="
1489
1490 test_27p() {
1491         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1492         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1493         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1494         remote_ost_nodsh && skip "remote OST with nodsh" && return
1495
1496         reset_enospc
1497         rm -f $DIR/$tdir/$tfile
1498         test_mkdir -p $DIR/$tdir
1499
1500         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1501         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1502         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1503
1504         exhaust_precreations 0 0x80000215
1505         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1506         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1507         $GETSTRIPE $DIR/$tdir/$tfile
1508
1509         reset_enospc
1510 }
1511 run_test 27p "append to a truncated file with some full OSTs ==="
1512
1513 test_27q() {
1514         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1515         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1516         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1517         remote_ost_nodsh && skip "remote OST with nodsh" && return
1518
1519         reset_enospc
1520         rm -f $DIR/$tdir/$tfile
1521
1522         test_mkdir -p $DIR/$tdir
1523         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1524         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1525         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1526
1527         exhaust_all_precreations 0x215
1528
1529         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1530         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1531
1532         reset_enospc
1533 }
1534 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1535
1536 test_27r() {
1537         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1539         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1540         remote_ost_nodsh && skip "remote OST with nodsh" && return
1541
1542         reset_enospc
1543         rm -f $DIR/$tdir/$tfile
1544         exhaust_precreations 0 0x80000215
1545
1546         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1547
1548         reset_enospc
1549 }
1550 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1551
1552 test_27s() { # bug 10725
1553         test_mkdir -p $DIR/$tdir
1554         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1555         local stripe_count=0
1556         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1557         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1558                 error "stripe width >= 2^32 succeeded" || true
1559
1560 }
1561 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1562
1563 test_27t() { # bug 10864
1564         WDIR=$(pwd)
1565         WLFS=$(which lfs)
1566         cd $DIR
1567         touch $tfile
1568         $WLFS getstripe $tfile
1569         cd $WDIR
1570 }
1571 run_test 27t "check that utils parse path correctly"
1572
1573 test_27u() { # bug 4900
1574         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1575         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1576         local index
1577         local list=$(comma_list $(mdts_nodes))
1578
1579 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1580         do_nodes $list $LCTL set_param fail_loc=0x139
1581         test_mkdir -p $DIR/$tdir
1582         rm -rf $DIR/$tdir/*
1583         createmany -o $DIR/$tdir/t- 1000
1584         do_nodes $list $LCTL set_param fail_loc=0
1585
1586         TLOG=$DIR/$tfile.getstripe
1587         $GETSTRIPE $DIR/$tdir > $TLOG
1588         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1589         unlinkmany $DIR/$tdir/t- 1000
1590         [[ $OBJS -gt 0 ]] &&
1591                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1592 }
1593 run_test 27u "skip object creation on OSC w/o objects =========="
1594
1595 test_27v() { # bug 4900
1596         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1597         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1598         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1599         remote_ost_nodsh && skip "remote OST with nodsh" && return
1600
1601         exhaust_all_precreations 0x215
1602         reset_enospc
1603
1604         test_mkdir -p $DIR/$tdir
1605         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1606
1607         touch $DIR/$tdir/$tfile
1608         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1609         # all except ost1
1610         for (( i=1; i < OSTCOUNT; i++ )); do
1611                 do_facet ost$i lctl set_param fail_loc=0x705
1612         done
1613         local START=`date +%s`
1614         createmany -o $DIR/$tdir/$tfile 32
1615
1616         local FINISH=`date +%s`
1617         local TIMEOUT=`lctl get_param -n timeout`
1618         local PROCESS=$((FINISH - START))
1619         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1620                error "$FINISH - $START >= $TIMEOUT / 2"
1621         sleep $((TIMEOUT / 2 - PROCESS))
1622         reset_enospc
1623 }
1624 run_test 27v "skip object creation on slow OST ================="
1625
1626 test_27w() { # bug 10997
1627         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1628         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1629         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1630                 error "stripe size $size != 65536" || true
1631         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1632                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1633 }
1634 run_test 27w "check $SETSTRIPE -S option"
1635
1636 test_27wa() {
1637         [[ $OSTCOUNT -lt 2 ]] &&
1638                 skip_env "skipping multiple stripe count/offset test" && return
1639
1640         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1641         for i in $(seq 1 $OSTCOUNT); do
1642                 offset=$((i - 1))
1643                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1644                         error "setstripe -c $i -i $offset failed"
1645                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1646                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1647                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1648                 [ $index -ne $offset ] &&
1649                         error "stripe offset $index != $offset" || true
1650         done
1651 }
1652 run_test 27wa "check $SETSTRIPE -c -i options"
1653
1654 test_27x() {
1655         remote_ost_nodsh && skip "remote OST with nodsh" && return
1656         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1657         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1658         OFFSET=$(($OSTCOUNT - 1))
1659         OSTIDX=0
1660         local OST=$(ostname_from_index $OSTIDX)
1661
1662         test_mkdir -p $DIR/$tdir
1663         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1664         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1665         sleep_maxage
1666         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1667         for i in `seq 0 $OFFSET`; do
1668                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1669                 error "OST0 was degraded but new created file still use it"
1670         done
1671         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1672 }
1673 run_test 27x "create files while OST0 is degraded"
1674
1675 test_27y() {
1676         [[ $OSTCOUNT -lt 2 ]] &&
1677                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1678         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1679         remote_ost_nodsh && skip "remote OST with nodsh" && return
1680         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1681
1682         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1683         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1684             osc.$mdtosc.prealloc_last_id)
1685         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1686             osc.$mdtosc.prealloc_next_id)
1687         local fcount=$((last_id - next_id))
1688         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1689         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1690
1691         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1692                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1693         local OST_DEACTIVE_IDX=-1
1694         local OSC
1695         local OSTIDX
1696         local OST
1697
1698         for OSC in $MDS_OSCS; do
1699                 OST=$(osc_to_ost $OSC)
1700                 OSTIDX=$(index_from_ostuuid $OST)
1701                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1702                         OST_DEACTIVE_IDX=$OSTIDX
1703                 fi
1704                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1705                         echo $OSC "is Deactivated:"
1706                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1707                 fi
1708         done
1709
1710         OSTIDX=$(index_from_ostuuid $OST)
1711         mkdir -p $DIR/$tdir
1712         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1713
1714         for OSC in $MDS_OSCS; do
1715                 OST=$(osc_to_ost $OSC)
1716                 OSTIDX=$(index_from_ostuuid $OST)
1717                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1718                         echo $OST "is degraded:"
1719                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1720                                                 obdfilter.$OST.degraded=1
1721                 fi
1722         done
1723
1724         sleep_maxage
1725         createmany -o $DIR/$tdir/$tfile $fcount
1726
1727         for OSC in $MDS_OSCS; do
1728                 OST=$(osc_to_ost $OSC)
1729                 OSTIDX=$(index_from_ostuuid $OST)
1730                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1731                         echo $OST "is recovered from degraded:"
1732                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1733                                                 obdfilter.$OST.degraded=0
1734                 else
1735                         do_facet $SINGLEMDS lctl --device %$OSC activate
1736                 fi
1737         done
1738
1739         # all osp devices get activated, hence -1 stripe count restored
1740         local stripecnt=0
1741
1742         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1743         # devices get activated.
1744         sleep_maxage
1745         $SETSTRIPE -c -1 $DIR/$tfile
1746         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1747         rm -f $DIR/$tfile
1748         [ $stripecnt -ne $OSTCOUNT ] &&
1749                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1750         return 0
1751 }
1752 run_test 27y "create files while OST0 is degraded and the rest inactive"
1753
1754 check_seq_oid()
1755 {
1756         log "check file $1"
1757
1758         lmm_count=$($GETSTRIPE -c $1)
1759         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1760         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1761
1762         local old_ifs="$IFS"
1763         IFS=$'[:]'
1764         fid=($($LFS path2fid $1))
1765         IFS="$old_ifs"
1766
1767         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1768         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1769
1770         # compare lmm_seq and lu_fid->f_seq
1771         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1772         # compare lmm_object_id and lu_fid->oid
1773         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1774
1775         # check the trusted.fid attribute of the OST objects of the file
1776         local have_obdidx=false
1777         local stripe_nr=0
1778         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1779                 # skip lines up to and including "obdidx"
1780                 [ -z "$obdidx" ] && break
1781                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1782                 $have_obdidx || continue
1783
1784                 local ost=$((obdidx + 1))
1785                 local dev=$(ostdevname $ost)
1786                 local oid_hex
1787
1788                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1789
1790                 seq=$(echo $seq | sed -e "s/^0x//g")
1791                 if [ $seq == 0 ]; then
1792                         oid_hex=$(echo $oid)
1793                 else
1794                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1795                 fi
1796                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1797
1798                 local ff
1799                 #
1800                 # Don't unmount/remount the OSTs if we don't need to do that.
1801                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1802                 # update too, until that use mount/ll_decode_filter_fid/mount.
1803                 # Re-enable when debugfs will understand new filter_fid.
1804                 #
1805                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1806                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1807                                 $dev 2>/dev/null" | grep "parent=")
1808                 else
1809                         stop ost$ost
1810                         mount_fstype ost$ost
1811                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1812                                 $(facet_mntpt ost$ost)/$obj_file)
1813                         unmount_fstype ost$ost
1814                         start ost$ost $dev $OST_MOUNT_OPTS
1815                 fi
1816
1817                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1818
1819                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1820
1821                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1822                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1823                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1824                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1825                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1826                 local ff_pstripe
1827                 if echo $ff_parent | grep -q 'stripe='; then
1828                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1829                 else
1830                         #
1831                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1832                         # into f_ver in this case.  See the comment on
1833                         # ff_parent.
1834                         #
1835                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1836                                 sed -e 's/\]//')
1837                 fi
1838
1839                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1840                 [ $ff_pseq = $lmm_seq ] ||
1841                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1842                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1843                 [ $ff_poid = $lmm_oid ] ||
1844                         error "FF parent OID $ff_poid != $lmm_oid"
1845                 (($ff_pstripe == $stripe_nr)) ||
1846                         error "FF stripe $ff_pstripe != $stripe_nr"
1847
1848                 stripe_nr=$((stripe_nr + 1))
1849         done
1850 }
1851
1852 test_27z() {
1853         remote_ost_nodsh && skip "remote OST with nodsh" && return
1854         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1855         test_mkdir -p $DIR/$tdir
1856
1857         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1858                 { error "setstripe -c -1 failed"; return 1; }
1859         # We need to send a write to every object to get parent FID info set.
1860         # This _should_ also work for setattr, but does not currently.
1861         # touch $DIR/$tdir/$tfile-1 ||
1862         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1863                 { error "dd $tfile-1 failed"; return 2; }
1864         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1865                 { error "setstripe -c -1 failed"; return 3; }
1866         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1867                 { error "dd $tfile-2 failed"; return 4; }
1868
1869         # make sure write RPCs have been sent to OSTs
1870         sync; sleep 5; sync
1871
1872         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1873         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1874 }
1875 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1876
1877 test_27A() { # b=19102
1878         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1879         local restore_size=$($GETSTRIPE -S $MOUNT)
1880         local restore_count=$($GETSTRIPE -c $MOUNT)
1881         local restore_offset=$($GETSTRIPE -i $MOUNT)
1882         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1883         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1884                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1885         local default_size=$($GETSTRIPE -S $MOUNT)
1886         local default_offset=$($GETSTRIPE -i $MOUNT)
1887         local dsize=$((1024 * 1024))
1888         [ $default_size -eq $dsize ] ||
1889                 error "stripe size $default_size != $dsize"
1890         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1891         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1892 }
1893 run_test 27A "check filesystem-wide default LOV EA values"
1894
1895 test_27B() { # LU-2523
1896         test_mkdir -p $DIR/$tdir
1897         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1898         touch $DIR/$tdir/f0
1899         # open f1 with O_LOV_DELAY_CREATE
1900         # rename f0 onto f1
1901         # call setstripe ioctl on open file descriptor for f1
1902         # close
1903         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1904                 $DIR/$tdir/f0
1905
1906         rm -f $DIR/$tdir/f1
1907         # open f1 with O_LOV_DELAY_CREATE
1908         # unlink f1
1909         # call setstripe ioctl on open file descriptor for f1
1910         # close
1911         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1912
1913         # Allow multiop to fail in imitation of NFS's busted semantics.
1914         true
1915 }
1916 run_test 27B "call setstripe on open unlinked file/rename victim"
1917
1918 test_27C() { #LU-2871
1919         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1920
1921         declare -a ost_idx
1922         local index
1923         local found
1924         local i
1925         local j
1926
1927         test_mkdir -p $DIR/$tdir
1928         cd $DIR/$tdir
1929         for i in $(seq 0 $((OSTCOUNT - 1))); do
1930                 # set stripe across all OSTs starting from OST$i
1931                 $SETSTRIPE -i $i -c -1 $tfile$i
1932                 # get striping information
1933                 ost_idx=($($GETSTRIPE $tfile$i |
1934                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1935                 echo ${ost_idx[@]}
1936
1937                 # check the layout
1938                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1939                         error "${#ost_idx[@]} != $OSTCOUNT"
1940
1941                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1942                         found=0
1943                         for j in $(echo ${ost_idx[@]}); do
1944                                 if [ $index -eq $j ]; then
1945                                         found=1
1946                                         break
1947                                 fi
1948                         done
1949                         [ $found = 1 ] ||
1950                                 error "Can not find $index in ${ost_idx[@]}"
1951                 done
1952         done
1953 }
1954 run_test 27C "check full striping across all OSTs"
1955
1956 # createtest also checks that device nodes are created and
1957 # then visible correctly (#2091)
1958 test_28() { # bug 2091
1959         test_mkdir $DIR/d28
1960         $CREATETEST $DIR/d28/ct || error
1961 }
1962 run_test 28 "create/mknod/mkdir with bad file types ============"
1963
1964 test_29() {
1965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1966         cancel_lru_locks mdc
1967         test_mkdir $DIR/d29
1968         touch $DIR/d29/foo
1969         log 'first d29'
1970         ls -l $DIR/d29
1971
1972         declare -i LOCKCOUNTORIG=0
1973         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1974                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1975         done
1976         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1977
1978         declare -i LOCKUNUSEDCOUNTORIG=0
1979         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1980                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1981         done
1982
1983         log 'second d29'
1984         ls -l $DIR/d29
1985         log 'done'
1986
1987         declare -i LOCKCOUNTCURRENT=0
1988         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1989                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1990         done
1991
1992         declare -i LOCKUNUSEDCOUNTCURRENT=0
1993         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1994                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1995         done
1996
1997         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
1998                 $LCTL set_param -n ldlm.dump_namespaces ""
1999                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2000                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2001                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2002                 return 2
2003         fi
2004         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2005                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2006                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2007                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2008                 return 3
2009         fi
2010 }
2011 run_test 29 "IT_GETATTR regression  ============================"
2012
2013 test_30a() { # was test_30
2014         cp $(which ls) $DIR || cp /bin/ls $DIR
2015         $DIR/ls / || error
2016         rm $DIR/ls
2017 }
2018 run_test 30a "execute binary from Lustre (execve) =============="
2019
2020 test_30b() {
2021         cp `which ls` $DIR || cp /bin/ls $DIR
2022         chmod go+rx $DIR/ls
2023         $RUNAS $DIR/ls / || error
2024         rm $DIR/ls
2025 }
2026 run_test 30b "execute binary from Lustre as non-root ==========="
2027
2028 test_30c() { # b=22376
2029         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2030         cp `which ls` $DIR || cp /bin/ls $DIR
2031         chmod a-rw $DIR/ls
2032         cancel_lru_locks mdc
2033         cancel_lru_locks osc
2034         $RUNAS $DIR/ls / || error
2035         rm -f $DIR/ls
2036 }
2037 run_test 30c "execute binary from Lustre without read perms ===="
2038
2039 test_31a() {
2040         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2041         $CHECKSTAT -a $DIR/f31 || error
2042 }
2043 run_test 31a "open-unlink file =================================="
2044
2045 test_31b() {
2046         touch $DIR/f31 || error
2047         ln $DIR/f31 $DIR/f31b || error
2048         $MULTIOP $DIR/f31b Ouc || error
2049         $CHECKSTAT -t file $DIR/f31 || error
2050 }
2051 run_test 31b "unlink file with multiple links while open ======="
2052
2053 test_31c() {
2054         touch $DIR/f31 || error
2055         ln $DIR/f31 $DIR/f31c || error
2056         multiop_bg_pause $DIR/f31 O_uc || return 1
2057         MULTIPID=$!
2058         $MULTIOP $DIR/f31c Ouc
2059         kill -USR1 $MULTIPID
2060         wait $MULTIPID
2061 }
2062 run_test 31c "open-unlink file with multiple links ============="
2063
2064 test_31d() {
2065         opendirunlink $DIR/d31d $DIR/d31d || error
2066         $CHECKSTAT -a $DIR/d31d || error
2067 }
2068 run_test 31d "remove of open directory ========================="
2069
2070 test_31e() { # bug 2904
2071         check_kernel_version 34 || return 0
2072         openfilleddirunlink $DIR/d31e || error
2073 }
2074 run_test 31e "remove of open non-empty directory ==============="
2075
2076 test_31f() { # bug 4554
2077         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2078         set -vx
2079         test_mkdir $DIR/d31f
2080         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2081         cp /etc/hosts $DIR/d31f
2082         ls -l $DIR/d31f
2083         $GETSTRIPE $DIR/d31f/hosts
2084         multiop_bg_pause $DIR/d31f D_c || return 1
2085         MULTIPID=$!
2086
2087         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2088         test_mkdir $DIR/d31f
2089         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2090         cp /etc/hosts $DIR/d31f
2091         ls -l $DIR/d31f
2092         $GETSTRIPE $DIR/d31f/hosts
2093         multiop_bg_pause $DIR/d31f D_c || return 1
2094         MULTIPID2=$!
2095
2096         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2097         wait $MULTIPID || error "first opendir $MULTIPID failed"
2098
2099         sleep 6
2100
2101         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2102         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2103         set +vx
2104 }
2105 run_test 31f "remove of open directory with open-unlink file ==="
2106
2107 test_31g() {
2108         echo "-- cross directory link --"
2109         test_mkdir -c1 $DIR/${tdir}ga
2110         test_mkdir -c1 $DIR/${tdir}gb
2111         touch $DIR/${tdir}ga/f
2112         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2113         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2114         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2115         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2116         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2117 }
2118 run_test 31g "cross directory link==============="
2119
2120 test_31h() {
2121         echo "-- cross directory link --"
2122         test_mkdir -c1 $DIR/${tdir}
2123         test_mkdir -c1 $DIR/${tdir}/dir
2124         touch $DIR/${tdir}/f
2125         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2126         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2127         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2128         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2129         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2130 }
2131 run_test 31h "cross directory link under child==============="
2132
2133 test_31i() {
2134         echo "-- cross directory link --"
2135         test_mkdir -c1 $DIR/$tdir
2136         test_mkdir -c1 $DIR/$tdir/dir
2137         touch $DIR/$tdir/dir/f
2138         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2139         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2140         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2141         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2142         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2143 }
2144 run_test 31i "cross directory link under parent==============="
2145
2146 test_31j() {
2147         test_mkdir -c1 -p $DIR/$tdir
2148         test_mkdir -c1 -p $DIR/$tdir/dir1
2149         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2150         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2151         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2152         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2153         return 0
2154 }
2155 run_test 31j "link for directory==============="
2156
2157 test_31k() {
2158         test_mkdir -c1 -p $DIR/$tdir
2159         touch $DIR/$tdir/s
2160         touch $DIR/$tdir/exist
2161         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2162         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2163         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2164         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2165         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2166         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2167         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2168         return 0
2169 }
2170 run_test 31k "link to file: the same, non-existing, dir==============="
2171
2172 test_31m() {
2173         mkdir $DIR/d31m
2174         touch $DIR/d31m/s
2175         mkdir $DIR/d31m2
2176         touch $DIR/d31m2/exist
2177         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2178         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2179         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2180         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2181         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2182         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2183         return 0
2184 }
2185 run_test 31m "link to file: the same, non-existing, dir==============="
2186
2187 test_31n() {
2188         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2189         nlink=$(stat --format=%h $DIR/$tfile)
2190         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2191         local fd=$(free_fd)
2192         local cmd="exec $fd<$DIR/$tfile"
2193         eval $cmd
2194         cmd="exec $fd<&-"
2195         trap "eval $cmd" EXIT
2196         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2197         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2198         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2199         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2200         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2201         eval $cmd
2202 }
2203 run_test 31n "check link count of unlinked file"
2204
2205 link_one() {
2206         local TEMPNAME=$(mktemp $1_XXXXXX)
2207         mlink $TEMPNAME $1 2> /dev/null &&
2208                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2209         munlink $TEMPNAME
2210 }
2211
2212 test_31o() { # LU-2901
2213         mkdir -p $DIR/$tdir
2214         for LOOP in $(seq 100); do
2215                 rm -f $DIR/$tdir/$tfile*
2216                 for THREAD in $(seq 8); do
2217                         link_one $DIR/$tdir/$tfile.$LOOP &
2218                 done
2219                 wait
2220                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2221                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2222                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2223                         break || true
2224         done
2225 }
2226 run_test 31o "duplicate hard links with same filename"
2227
2228 cleanup_test32_mount() {
2229         trap 0
2230         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2231 }
2232
2233 test_32a() {
2234         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2235         echo "== more mountpoints and symlinks ================="
2236         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2237         trap cleanup_test32_mount EXIT
2238         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2239         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2240         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2241         cleanup_test32_mount
2242 }
2243 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2244
2245 test_32b() {
2246         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2247         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2248         trap cleanup_test32_mount EXIT
2249         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2250         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2251         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2252         cleanup_test32_mount
2253 }
2254 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2255
2256 test_32c() {
2257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2258         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2259         trap cleanup_test32_mount EXIT
2260         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2261         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2262         test_mkdir -p $DIR/$tdir/d2/test_dir
2263         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2264         cleanup_test32_mount
2265 }
2266 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2267
2268 test_32d() {
2269         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2270         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2271         trap cleanup_test32_mount EXIT
2272         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2273         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2274         test_mkdir -p $DIR/$tdir/d2/test_dir
2275         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2276         cleanup_test32_mount
2277 }
2278 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2279
2280 test_32e() {
2281         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2282         test_mkdir -p $DIR/d32e/tmp
2283         TMP_DIR=$DIR/d32e/tmp
2284         ln -s $DIR/d32e $TMP_DIR/symlink11
2285         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2286         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2287         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2288 }
2289 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2290
2291 test_32f() {
2292         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2293         test_mkdir -p $DIR/d32f/tmp
2294         TMP_DIR=$DIR/d32f/tmp
2295         ln -s $DIR/d32f $TMP_DIR/symlink11
2296         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2297         ls $DIR/d32f/tmp/symlink11  || error
2298         ls $DIR/d32f/symlink01 || error
2299 }
2300 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2301
2302 test_32g() {
2303         TMP_DIR=$DIR/$tdir/tmp
2304         test_mkdir -p $DIR/$tdir/tmp
2305         test_mkdir $DIR/${tdir}2
2306         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2307         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2308         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2309         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2310         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2311         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2312 }
2313 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2314
2315 test_32h() {
2316         rm -fr $DIR/$tdir $DIR/${tdir}2
2317         TMP_DIR=$DIR/$tdir/tmp
2318         test_mkdir -p $DIR/$tdir/tmp
2319         test_mkdir $DIR/${tdir}2
2320         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2321         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2322         ls $TMP_DIR/symlink12 || error
2323         ls $DIR/$tdir/symlink02  || error
2324 }
2325 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2326
2327 test_32i() {
2328         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2329         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2330         trap cleanup_test32_mount EXIT
2331         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2332         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2333         touch $DIR/$tdir/test_file
2334         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2335         cleanup_test32_mount
2336 }
2337 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2338
2339 test_32j() {
2340         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2341         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2342         trap cleanup_test32_mount EXIT
2343         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2344         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2345         touch $DIR/$tdir/test_file
2346         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2347         cleanup_test32_mount
2348 }
2349 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2350
2351 test_32k() {
2352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2353         rm -fr $DIR/$tdir
2354         trap cleanup_test32_mount EXIT
2355         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2356         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2357         test_mkdir -p $DIR/$tdir/d2
2358         touch $DIR/$tdir/d2/test_file || error
2359         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2360         cleanup_test32_mount
2361 }
2362 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2363
2364 test_32l() {
2365         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2366         rm -fr $DIR/$tdir
2367         trap cleanup_test32_mount EXIT
2368         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2369         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2370         test_mkdir -p $DIR/$tdir/d2
2371         touch $DIR/$tdir/d2/test_file
2372         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2373         cleanup_test32_mount
2374 }
2375 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2376
2377 test_32m() {
2378         rm -fr $DIR/d32m
2379         test_mkdir -p $DIR/d32m/tmp
2380         TMP_DIR=$DIR/d32m/tmp
2381         ln -s $DIR $TMP_DIR/symlink11
2382         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2383         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2384         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2385 }
2386 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2387
2388 test_32n() {
2389         rm -fr $DIR/d32n
2390         test_mkdir -p $DIR/d32n/tmp
2391         TMP_DIR=$DIR/d32n/tmp
2392         ln -s $DIR $TMP_DIR/symlink11
2393         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2394         ls -l $DIR/d32n/tmp/symlink11  || error
2395         ls -l $DIR/d32n/symlink01 || error
2396 }
2397 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2398
2399 test_32o() {
2400         rm -fr $DIR/d32o $DIR/$tfile
2401         touch $DIR/$tfile
2402         test_mkdir -p $DIR/d32o/tmp
2403         TMP_DIR=$DIR/d32o/tmp
2404         ln -s $DIR/$tfile $TMP_DIR/symlink12
2405         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2406         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2407         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2408         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2409         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2410 }
2411 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2412
2413 test_32p() {
2414     log 32p_1
2415         rm -fr $DIR/d32p
2416     log 32p_2
2417         rm -f $DIR/$tfile
2418     log 32p_3
2419         touch $DIR/$tfile
2420     log 32p_4
2421         test_mkdir -p $DIR/d32p/tmp
2422     log 32p_5
2423         TMP_DIR=$DIR/d32p/tmp
2424     log 32p_6
2425         ln -s $DIR/$tfile $TMP_DIR/symlink12
2426     log 32p_7
2427         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2428     log 32p_8
2429         cat $DIR/d32p/tmp/symlink12 || error
2430     log 32p_9
2431         cat $DIR/d32p/symlink02 || error
2432     log 32p_10
2433 }
2434 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2435
2436 cleanup_testdir_mount() {
2437         trap 0
2438         $UMOUNT -d $DIR/$tdir
2439 }
2440
2441 test_32q() {
2442         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2443         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2444         trap cleanup_testdir_mount EXIT
2445         test_mkdir -p $DIR/$tdir
2446         touch $DIR/$tdir/under_the_mount
2447         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2448         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2449         cleanup_testdir_mount
2450 }
2451 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2452
2453 test_32r() {
2454         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2455         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2456         trap cleanup_testdir_mount EXIT
2457         test_mkdir -p $DIR/$tdir
2458         touch $DIR/$tdir/under_the_mount
2459         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2460         ls $DIR/$tdir | grep -q under_the_mount && error || true
2461         cleanup_testdir_mount
2462 }
2463 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2464
2465 test_33aa() {
2466         rm -f $DIR/$tfile
2467         touch $DIR/$tfile
2468         chmod 444 $DIR/$tfile
2469         chown $RUNAS_ID $DIR/$tfile
2470         log 33_1
2471         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2472         log 33_2
2473 }
2474 run_test 33aa "write file with mode 444 (should return error) ===="
2475
2476 test_33a() {
2477         rm -fr $DIR/d33
2478         test_mkdir -p $DIR/d33
2479         chown $RUNAS_ID $DIR/d33
2480         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2481         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2482                 error "open RDWR" || true
2483 }
2484 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2485
2486 test_33b() {
2487         rm -fr $DIR/d33
2488         test_mkdir -p $DIR/d33
2489         chown $RUNAS_ID $DIR/d33
2490         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
2491 }
2492 run_test 33b "test open file with malformed flags (No panic and return error)"
2493
2494 test_33c() {
2495         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2496         local ostnum
2497         local ostname
2498         local write_bytes
2499         local all_zeros
2500
2501         remote_ost_nodsh && skip "remote OST with nodsh" && return
2502         all_zeros=:
2503         rm -fr $DIR/d33
2504         test_mkdir -p $DIR/d33
2505         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2506
2507         sync
2508         for ostnum in $(seq $OSTCOUNT); do
2509                 # test-framework's OST numbering is one-based, while Lustre's
2510                 # is zero-based
2511                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2512                 # Parsing llobdstat's output sucks; we could grep the /proc
2513                 # path, but that's likely to not be as portable as using the
2514                 # llobdstat utility.  So we parse lctl output instead.
2515                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2516                         obdfilter/$ostname/stats |
2517                         awk '/^write_bytes/ {print $7}' )
2518                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2519                 if (( ${write_bytes:-0} > 0 ))
2520                 then
2521                         all_zeros=false
2522                         break;
2523                 fi
2524         done
2525
2526         $all_zeros || return 0
2527
2528         # Write four bytes
2529         echo foo > $DIR/d33/bar
2530         # Really write them
2531         sync
2532
2533         # Total up write_bytes after writing.  We'd better find non-zeros.
2534         for ostnum in $(seq $OSTCOUNT); do
2535                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2536                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2537                         obdfilter/$ostname/stats |
2538                         awk '/^write_bytes/ {print $7}' )
2539                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2540                 if (( ${write_bytes:-0} > 0 ))
2541                 then
2542                         all_zeros=false
2543                         break;
2544                 fi
2545         done
2546
2547         if $all_zeros
2548         then
2549                 for ostnum in $(seq $OSTCOUNT); do
2550                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2551                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2552                         do_facet ost$ostnum lctl get_param -n \
2553                                 obdfilter/$ostname/stats
2554                 done
2555                 error "OST not keeping write_bytes stats (b22312)"
2556         fi
2557 }
2558 run_test 33c "test llobdstat and write_bytes"
2559
2560 test_33d() {
2561         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2562         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2563         local MDTIDX=1
2564         local remote_dir=$DIR/$tdir/remote_dir
2565
2566         mkdir -p $DIR/$tdir
2567         $LFS mkdir -i $MDTIDX $remote_dir ||
2568                 error "create remote directory failed"
2569
2570         touch $remote_dir/$tfile
2571         chmod 444 $remote_dir/$tfile
2572         chown $RUNAS_ID $remote_dir/$tfile
2573
2574         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2575
2576         chown $RUNAS_ID $remote_dir
2577         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2578                                         error "create" || true
2579         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2580                                     error "open RDWR" || true
2581         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2582                                     error "create" || true
2583 }
2584 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2585
2586 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2587 test_34a() {
2588         rm -f $DIR/f34
2589         $MCREATE $DIR/f34 || error
2590         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2591         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2592         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2593         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2594 }
2595 run_test 34a "truncate file that has not been opened ==========="
2596
2597 test_34b() {
2598         [ ! -f $DIR/f34 ] && test_34a
2599         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2600         $OPENFILE -f O_RDONLY $DIR/f34
2601         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2602         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2603 }
2604 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2605
2606 test_34c() {
2607         [ ! -f $DIR/f34 ] && test_34a
2608         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2609         $OPENFILE -f O_RDWR $DIR/f34
2610         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2611         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2612 }
2613 run_test 34c "O_RDWR opening file-with-size works =============="
2614
2615 test_34d() {
2616         [ ! -f $DIR/f34 ] && test_34a
2617         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2618         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2619         rm $DIR/f34
2620 }
2621 run_test 34d "write to sparse file ============================="
2622
2623 test_34e() {
2624         rm -f $DIR/f34e
2625         $MCREATE $DIR/f34e || error
2626         $TRUNCATE $DIR/f34e 1000 || error
2627         $CHECKSTAT -s 1000 $DIR/f34e || error
2628         $OPENFILE -f O_RDWR $DIR/f34e
2629         $CHECKSTAT -s 1000 $DIR/f34e || error
2630 }
2631 run_test 34e "create objects, some with size and some without =="
2632
2633 test_34f() { # bug 6242, 6243
2634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2635         SIZE34F=48000
2636         rm -f $DIR/f34f
2637         $MCREATE $DIR/f34f || error
2638         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2639         dd if=$DIR/f34f of=$TMP/f34f
2640         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2641         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2642         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2643         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2644         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2645 }
2646 run_test 34f "read from a file with no objects until EOF ======="
2647
2648 test_34g() {
2649         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2650         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2651         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2652         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2653         cancel_lru_locks osc
2654         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2655                 error "wrong size after lock cancel"
2656
2657         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2658         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2659                 error "expanding truncate failed"
2660         cancel_lru_locks osc
2661         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2662                 error "wrong expanded size after lock cancel"
2663 }
2664 run_test 34g "truncate long file ==============================="
2665
2666 test_34h() {
2667         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2668         local gid=10
2669         local sz=1000
2670
2671         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2672         sync # Flush the cache so that multiop below does not block on cache
2673              # flush when getting the group lock
2674         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2675         MULTIPID=$!
2676
2677         # Since just timed wait is not good enough, let's do a sync write
2678         # that way we are sure enough time for a roundtrip + processing
2679         # passed + 2 seconds of extra margin.
2680         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2681         rm $DIR/${tfile}-1
2682         sleep 2
2683
2684         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2685                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2686                 kill -9 $MULTIPID
2687         fi
2688         wait $MULTIPID
2689         local nsz=`stat -c %s $DIR/$tfile`
2690         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2691 }
2692 run_test 34h "ftruncate file under grouplock should not block"
2693
2694 test_35a() {
2695         cp /bin/sh $DIR/f35a
2696         chmod 444 $DIR/f35a
2697         chown $RUNAS_ID $DIR/f35a
2698         $RUNAS $DIR/f35a && error || true
2699         rm $DIR/f35a
2700 }
2701 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2702
2703 test_36a() {
2704         rm -f $DIR/f36
2705         utime $DIR/f36 || error
2706 }
2707 run_test 36a "MDS utime check (mknod, utime) ==================="
2708
2709 test_36b() {
2710         echo "" > $DIR/f36
2711         utime $DIR/f36 || error
2712 }
2713 run_test 36b "OST utime check (open, utime) ===================="
2714
2715 test_36c() {
2716         rm -f $DIR/d36/f36
2717         test_mkdir $DIR/d36
2718         chown $RUNAS_ID $DIR/d36
2719         $RUNAS utime $DIR/d36/f36 || error
2720 }
2721 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2722
2723 test_36d() {
2724         [ ! -d $DIR/d36 ] && test_36c
2725         echo "" > $DIR/d36/f36
2726         $RUNAS utime $DIR/d36/f36 || error
2727 }
2728 run_test 36d "non-root OST utime check (open, utime) ==========="
2729
2730 test_36e() {
2731         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2732         test_mkdir -p $DIR/$tdir
2733         touch $DIR/$tdir/$tfile
2734         $RUNAS utime $DIR/$tdir/$tfile && \
2735                 error "utime worked, expected failure" || true
2736 }
2737 run_test 36e "utime on non-owned file (should return error) ===="
2738
2739 subr_36fh() {
2740         local fl="$1"
2741         local LANG_SAVE=$LANG
2742         local LC_LANG_SAVE=$LC_LANG
2743         export LANG=C LC_LANG=C # for date language
2744
2745         DATESTR="Dec 20  2000"
2746         test_mkdir -p $DIR/$tdir
2747         lctl set_param fail_loc=$fl
2748         date; date +%s
2749         cp /etc/hosts $DIR/$tdir/$tfile
2750         sync & # write RPC generated with "current" inode timestamp, but delayed
2751         sleep 1
2752         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2753         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2754         cancel_lru_locks osc
2755         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2756         date; date +%s
2757         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2758                 echo "BEFORE: $LS_BEFORE" && \
2759                 echo "AFTER : $LS_AFTER" && \
2760                 echo "WANT  : $DATESTR" && \
2761                 error "$DIR/$tdir/$tfile timestamps changed" || true
2762
2763         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2764 }
2765
2766 test_36f() {
2767         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2768         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2769         subr_36fh "0x80000214"
2770 }
2771 run_test 36f "utime on file racing with OST BRW write =========="
2772
2773 test_36g() {
2774         remote_ost_nodsh && skip "remote OST with nodsh" && return
2775         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2776         local fmd_max_age
2777         local fmd_before
2778         local fmd_after
2779
2780         test_mkdir -p $DIR/$tdir
2781         fmd_max_age=$(do_facet ost1 \
2782                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2783                 head -n 1")
2784
2785         fmd_before=$(do_facet ost1 \
2786                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2787         touch $DIR/$tdir/$tfile
2788         sleep $((fmd_max_age + 12))
2789         fmd_after=$(do_facet ost1 \
2790                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2791
2792         echo "fmd_before: $fmd_before"
2793         echo "fmd_after: $fmd_after"
2794         [[ $fmd_after -gt $fmd_before ]] &&
2795                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2796                 error "fmd didn't expire after ping" || true
2797 }
2798 run_test 36g "filter mod data cache expiry ====================="
2799
2800 test_36h() {
2801         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2802         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2803         subr_36fh "0x80000227"
2804 }
2805 run_test 36h "utime on file racing with OST BRW write =========="
2806
2807 # test_37 - duplicate with tests 32q 32r
2808
2809 test_38() {
2810         local file=$DIR/$tfile
2811         touch $file
2812         openfile -f O_DIRECTORY $file
2813         local RC=$?
2814         local ENOTDIR=20
2815         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2816         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2817 }
2818 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2819
2820 test_39() {
2821         touch $DIR/$tfile
2822         touch $DIR/${tfile}2
2823 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2824 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2825 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2826         sleep 2
2827         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2828         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2829                 echo "mtime"
2830                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2831                 echo "atime"
2832                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2833                 echo "ctime"
2834                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2835                 error "O_TRUNC didn't change timestamps"
2836         fi
2837 }
2838 run_test 39 "mtime changed on create ==========================="
2839
2840 test_39b() {
2841         test_mkdir -p $DIR/$tdir
2842         cp -p /etc/passwd $DIR/$tdir/fopen
2843         cp -p /etc/passwd $DIR/$tdir/flink
2844         cp -p /etc/passwd $DIR/$tdir/funlink
2845         cp -p /etc/passwd $DIR/$tdir/frename
2846         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2847
2848         sleep 1
2849         echo "aaaaaa" >> $DIR/$tdir/fopen
2850         echo "aaaaaa" >> $DIR/$tdir/flink
2851         echo "aaaaaa" >> $DIR/$tdir/funlink
2852         echo "aaaaaa" >> $DIR/$tdir/frename
2853
2854         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2855         local link_new=`stat -c %Y $DIR/$tdir/flink`
2856         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2857         local rename_new=`stat -c %Y $DIR/$tdir/frename`
2858
2859         cat $DIR/$tdir/fopen > /dev/null
2860         ln $DIR/$tdir/flink $DIR/$tdir/flink2
2861         rm -f $DIR/$tdir/funlink2
2862         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
2863
2864         for (( i=0; i < 2; i++ )) ; do
2865                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
2866                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
2867                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
2868                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
2869
2870                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
2871                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
2872                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
2873                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
2874
2875                 cancel_lru_locks osc
2876                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2877         done
2878 }
2879 run_test 39b "mtime change on open, link, unlink, rename  ======"
2880
2881 # this should be set to past
2882 TEST_39_MTIME=`date -d "1 year ago" +%s`
2883
2884 # bug 11063
2885 test_39c() {
2886         touch $DIR1/$tfile
2887         sleep 2
2888         local mtime0=`stat -c %Y $DIR1/$tfile`
2889
2890         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2891         local mtime1=`stat -c %Y $DIR1/$tfile`
2892         [ "$mtime1" = $TEST_39_MTIME ] || \
2893                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
2894
2895         local d1=`date +%s`
2896         echo hello >> $DIR1/$tfile
2897         local d2=`date +%s`
2898         local mtime2=`stat -c %Y $DIR1/$tfile`
2899         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
2900                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
2901
2902         mv $DIR1/$tfile $DIR1/$tfile-1
2903
2904         for (( i=0; i < 2; i++ )) ; do
2905                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
2906                 [ "$mtime2" = "$mtime3" ] || \
2907                         error "mtime ($mtime2) changed (to $mtime3) on rename"
2908
2909                 cancel_lru_locks osc
2910                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2911         done
2912 }
2913 run_test 39c "mtime change on rename ==========================="
2914
2915 # bug 21114
2916 test_39d() {
2917         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2918         touch $DIR1/$tfile
2919
2920         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2921
2922         for (( i=0; i < 2; i++ )) ; do
2923                 local mtime=`stat -c %Y $DIR1/$tfile`
2924                 [ $mtime = $TEST_39_MTIME ] || \
2925                         error "mtime($mtime) is not set to $TEST_39_MTIME"
2926
2927                 cancel_lru_locks osc
2928                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2929         done
2930 }
2931 run_test 39d "create, utime, stat =============================="
2932
2933 # bug 21114
2934 test_39e() {
2935         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2936         touch $DIR1/$tfile
2937         local mtime1=`stat -c %Y $DIR1/$tfile`
2938
2939         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2940
2941         for (( i=0; i < 2; i++ )) ; do
2942                 local mtime2=`stat -c %Y $DIR1/$tfile`
2943                 [ $mtime2 = $TEST_39_MTIME ] || \
2944                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2945
2946                 cancel_lru_locks osc
2947                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2948         done
2949 }
2950 run_test 39e "create, stat, utime, stat ========================"
2951
2952 # bug 21114
2953 test_39f() {
2954         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2955         touch $DIR1/$tfile
2956         mtime1=`stat -c %Y $DIR1/$tfile`
2957
2958         sleep 2
2959         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2960
2961         for (( i=0; i < 2; i++ )) ; do
2962                 local mtime2=`stat -c %Y $DIR1/$tfile`
2963                 [ $mtime2 = $TEST_39_MTIME ] || \
2964                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2965
2966                 cancel_lru_locks osc
2967                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2968         done
2969 }
2970 run_test 39f "create, stat, sleep, utime, stat ================="
2971
2972 # bug 11063
2973 test_39g() {
2974         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2975         echo hello >> $DIR1/$tfile
2976         local mtime1=`stat -c %Y $DIR1/$tfile`
2977
2978         sleep 2
2979         chmod o+r $DIR1/$tfile
2980
2981         for (( i=0; i < 2; i++ )) ; do
2982                 local mtime2=`stat -c %Y $DIR1/$tfile`
2983                 [ "$mtime1" = "$mtime2" ] || \
2984                         error "lost mtime: $mtime2, should be $mtime1"
2985
2986                 cancel_lru_locks osc
2987                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2988         done
2989 }
2990 run_test 39g "write, chmod, stat ==============================="
2991
2992 # bug 11063
2993 test_39h() {
2994         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2995         touch $DIR1/$tfile
2996         sleep 1
2997
2998         local d1=`date`
2999         echo hello >> $DIR1/$tfile
3000         local mtime1=`stat -c %Y $DIR1/$tfile`
3001
3002         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3003         local d2=`date`
3004         if [ "$d1" != "$d2" ]; then
3005                 echo "write and touch not within one second"
3006         else
3007                 for (( i=0; i < 2; i++ )) ; do
3008                         local mtime2=`stat -c %Y $DIR1/$tfile`
3009                         [ "$mtime2" = $TEST_39_MTIME ] || \
3010                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3011
3012                         cancel_lru_locks osc
3013                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3014                 done
3015         fi
3016 }
3017 run_test 39h "write, utime within one second, stat ============="
3018
3019 test_39i() {
3020         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3021         touch $DIR1/$tfile
3022         sleep 1
3023
3024         echo hello >> $DIR1/$tfile
3025         local mtime1=`stat -c %Y $DIR1/$tfile`
3026
3027         mv $DIR1/$tfile $DIR1/$tfile-1
3028
3029         for (( i=0; i < 2; i++ )) ; do
3030                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3031
3032                 [ "$mtime1" = "$mtime2" ] || \
3033                         error "lost mtime: $mtime2, should be $mtime1"
3034
3035                 cancel_lru_locks osc
3036                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3037         done
3038 }
3039 run_test 39i "write, rename, stat =============================="
3040
3041 test_39j() {
3042         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3043         start_full_debug_logging
3044         touch $DIR1/$tfile
3045         sleep 1
3046
3047         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3048         lctl set_param fail_loc=0x80000412
3049         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3050                 error "multiop failed"
3051         local multipid=$!
3052         local mtime1=`stat -c %Y $DIR1/$tfile`
3053
3054         mv $DIR1/$tfile $DIR1/$tfile-1
3055
3056         kill -USR1 $multipid
3057         wait $multipid || error "multiop close failed"
3058
3059         for (( i=0; i < 2; i++ )) ; do
3060                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3061                 [ "$mtime1" = "$mtime2" ] ||
3062                         error "mtime is lost on close: $mtime2, " \
3063                               "should be $mtime1"
3064
3065                 cancel_lru_locks osc
3066                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3067         done
3068         lctl set_param fail_loc=0
3069         stop_full_debug_logging
3070 }
3071 run_test 39j "write, rename, close, stat ======================="
3072
3073 test_39k() {
3074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3075         touch $DIR1/$tfile
3076         sleep 1
3077
3078         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3079         local multipid=$!
3080         local mtime1=`stat -c %Y $DIR1/$tfile`
3081
3082         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3083
3084         kill -USR1 $multipid
3085         wait $multipid || error "multiop close failed"
3086
3087         for (( i=0; i < 2; i++ )) ; do
3088                 local mtime2=`stat -c %Y $DIR1/$tfile`
3089
3090                 [ "$mtime2" = $TEST_39_MTIME ] || \
3091                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3092
3093                 cancel_lru_locks osc
3094                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3095         done
3096 }
3097 run_test 39k "write, utime, close, stat ========================"
3098
3099 # this should be set to future
3100 TEST_39_ATIME=`date -d "1 year" +%s`
3101
3102 test_39l() {
3103         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3104         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3105         local atime_diff=$(do_facet $SINGLEMDS \
3106                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3107         rm -rf $DIR/$tdir
3108         mkdir -p $DIR/$tdir
3109
3110         # test setting directory atime to future
3111         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3112         local atime=$(stat -c %X $DIR/$tdir)
3113         [ "$atime" = $TEST_39_ATIME ] || \
3114                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3115
3116         # test setting directory atime from future to now
3117         local d1=$(date +%s)
3118         ls $DIR/$tdir
3119         local d2=$(date +%s)
3120
3121         cancel_lru_locks mdc
3122         atime=$(stat -c %X $DIR/$tdir)
3123         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3124                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3125
3126         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3127         sleep 3
3128
3129         # test setting directory atime when now > dir atime + atime_diff
3130         d1=$(date +%s)
3131         ls $DIR/$tdir
3132         d2=$(date +%s)
3133         cancel_lru_locks mdc
3134         atime=$(stat -c %X $DIR/$tdir)
3135         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3136                 error "atime is not updated  : $atime, should be $d2"
3137
3138         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3139         sleep 3
3140
3141         # test not setting directory atime when now < dir atime + atime_diff
3142         ls $DIR/$tdir
3143         cancel_lru_locks mdc
3144         atime=$(stat -c %X $DIR/$tdir)
3145         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3146                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3147
3148         do_facet $SINGLEMDS \
3149                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3150 }
3151 run_test 39l "directory atime update ==========================="
3152
3153 test_39m() {
3154         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3155         touch $DIR1/$tfile
3156         sleep 2
3157         local far_past_mtime=$(date -d "May 29 1953" +%s)
3158         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3159
3160         touch -m -d @$far_past_mtime $DIR1/$tfile
3161         touch -a -d @$far_past_atime $DIR1/$tfile
3162
3163         for (( i=0; i < 2; i++ )) ; do
3164                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3165                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3166                         error "atime or mtime set incorrectly"
3167
3168                 cancel_lru_locks osc
3169                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3170         done
3171 }
3172 run_test 39m "test atime and mtime before 1970"
3173
3174 test_39n() { # LU-3832
3175         local atime_diff=$(do_facet $SINGLEMDS \
3176                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3177         local atime0
3178         local atime1
3179         local atime2
3180
3181         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3182
3183         rm -rf $DIR/$tfile
3184         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3185         atime0=$(stat -c %X $DIR/$tfile)
3186
3187         sleep 5
3188         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3189         atime1=$(stat -c %X $DIR/$tfile)
3190
3191         sleep 5
3192         cancel_lru_locks mdc
3193         cancel_lru_locks osc
3194         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3195         atime2=$(stat -c %X $DIR/$tfile)
3196
3197         do_facet $SINGLEMDS \
3198                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3199
3200         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3201         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3202 }
3203 run_test 39n "check that O_NOATIME is honored"
3204
3205 test_39o() {
3206         TESTDIR=$DIR/$tdir/$tfile
3207         [ -e $TESTDIR ] && rm -rf $TESTDIR
3208         test_mkdir -p $TESTDIR
3209         cd $TESTDIR
3210         links1=2
3211         ls
3212         mkdir a b
3213         ls
3214         links2=$(stat -c %h .)
3215         [ $(($links1 + 2)) != $links2 ] &&
3216                 error "wrong links count $(($links1 + 2)) != $links2"
3217         rmdir b
3218         links3=$(stat -c %h .)
3219         [ $(($links1 + 1)) != $links3 ] &&
3220                 error "wrong links count $links1 != $links3"
3221         return 0
3222 }
3223 run_test 39o "directory cached attributes updated after create ========"
3224
3225 test_39p() {
3226         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3227         local MDTIDX=1
3228         TESTDIR=$DIR/$tdir/$tfile
3229         [ -e $TESTDIR ] && rm -rf $TESTDIR
3230         mkdir -p $TESTDIR
3231         cd $TESTDIR
3232         links1=2
3233         ls
3234         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3235         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3236         ls
3237         links2=$(stat -c %h .)
3238         [ $(($links1 + 2)) != $links2 ] &&
3239                 error "wrong links count $(($links1 + 2)) != $links2"
3240         rmdir remote_dir2
3241         links3=$(stat -c %h .)
3242         [ $(($links1 + 1)) != $links3 ] &&
3243                 error "wrong links count $links1 != $links3"
3244         return 0
3245 }
3246 run_test 39p "remote directory cached attributes updated after create ========"
3247
3248
3249 test_40() {
3250         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3251         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3252                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3253         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3254                 error "$tfile is not 4096 bytes in size"
3255 }
3256 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3257
3258 test_41() {
3259         # bug 1553
3260         small_write $DIR/f41 18
3261 }
3262 run_test 41 "test small file write + fstat ====================="
3263
3264 count_ost_writes() {
3265         lctl get_param -n osc.*.stats |
3266                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3267                         END { printf("%0.0f", writes) }'
3268 }
3269
3270 # decent default
3271 WRITEBACK_SAVE=500
3272 DIRTY_RATIO_SAVE=40
3273 MAX_DIRTY_RATIO=50
3274 BG_DIRTY_RATIO_SAVE=10
3275 MAX_BG_DIRTY_RATIO=25
3276
3277 start_writeback() {
3278         trap 0
3279         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3280         # dirty_ratio, dirty_background_ratio
3281         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3282                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3283                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3284                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3285         else
3286                 # if file not here, we are a 2.4 kernel
3287                 kill -CONT `pidof kupdated`
3288         fi
3289 }
3290
3291 stop_writeback() {
3292         # setup the trap first, so someone cannot exit the test at the
3293         # exact wrong time and mess up a machine
3294         trap start_writeback EXIT
3295         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3296         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3297                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3298                 sysctl -w vm.dirty_writeback_centisecs=0
3299                 sysctl -w vm.dirty_writeback_centisecs=0
3300                 # save and increase /proc/sys/vm/dirty_ratio
3301                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3302                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3303                 # save and increase /proc/sys/vm/dirty_background_ratio
3304                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3305                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3306         else
3307                 # if file not here, we are a 2.4 kernel
3308                 kill -STOP `pidof kupdated`
3309         fi
3310 }
3311
3312 # ensure that all stripes have some grant before we test client-side cache
3313 setup_test42() {
3314         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3315                 dd if=/dev/zero of=$i bs=4k count=1
3316                 rm $i
3317         done
3318 }
3319
3320 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3321 # file truncation, and file removal.
3322 test_42a() {
3323         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3324         setup_test42
3325         cancel_lru_locks osc
3326         stop_writeback
3327         sync; sleep 1; sync # just to be safe
3328         BEFOREWRITES=`count_ost_writes`
3329         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3330         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3331         AFTERWRITES=`count_ost_writes`
3332         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3333                 error "$BEFOREWRITES < $AFTERWRITES"
3334         start_writeback
3335 }
3336 run_test 42a "ensure that we don't flush on close =============="
3337
3338 test_42b() {
3339         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3340         setup_test42
3341         cancel_lru_locks osc
3342         stop_writeback
3343         sync
3344         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3345         BEFOREWRITES=$(count_ost_writes)
3346         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3347         AFTERWRITES=$(count_ost_writes)
3348         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3349                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3350         fi
3351         BEFOREWRITES=$(count_ost_writes)
3352         sync || error "sync: $?"
3353         AFTERWRITES=$(count_ost_writes)
3354         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3355                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3356         fi
3357         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3358         start_writeback
3359         return 0
3360 }
3361 run_test 42b "test destroy of file with cached dirty data ======"
3362
3363 # if these tests just want to test the effect of truncation,
3364 # they have to be very careful.  consider:
3365 # - the first open gets a {0,EOF}PR lock
3366 # - the first write conflicts and gets a {0, count-1}PW
3367 # - the rest of the writes are under {count,EOF}PW
3368 # - the open for truncate tries to match a {0,EOF}PR
3369 #   for the filesize and cancels the PWs.
3370 # any number of fixes (don't get {0,EOF} on open, match
3371 # composite locks, do smarter file size management) fix
3372 # this, but for now we want these tests to verify that
3373 # the cancellation with truncate intent works, so we
3374 # start the file with a full-file pw lock to match against
3375 # until the truncate.
3376 trunc_test() {
3377         test=$1
3378         file=$DIR/$test
3379         offset=$2
3380         cancel_lru_locks osc
3381         stop_writeback
3382         # prime the file with 0,EOF PW to match
3383         touch $file
3384         $TRUNCATE $file 0
3385         sync; sync
3386         # now the real test..
3387         dd if=/dev/zero of=$file bs=1024 count=100
3388         BEFOREWRITES=`count_ost_writes`
3389         $TRUNCATE $file $offset
3390         cancel_lru_locks osc
3391         AFTERWRITES=`count_ost_writes`
3392         start_writeback
3393 }
3394
3395 test_42c() {
3396         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3397         trunc_test 42c 1024
3398         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3399             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3400         rm $file
3401 }
3402 run_test 42c "test partial truncate of file with cached dirty data"
3403
3404 test_42d() {
3405         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3406         trunc_test 42d 0
3407         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3408             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3409         rm $file
3410 }
3411 run_test 42d "test complete truncate of file with cached dirty data"
3412
3413 test_42e() { # bug22074
3414         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3415         local TDIR=$DIR/${tdir}e
3416         local pagesz=$(page_size)
3417         local pages=16 # hardcoded 16 pages, don't change it.
3418         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3419         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3420         local max_dirty_mb
3421         local warmup_files
3422
3423         test_mkdir -p $DIR/${tdir}e
3424         $SETSTRIPE -c 1 $TDIR
3425         createmany -o $TDIR/f $files
3426
3427         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3428
3429         # we assume that with $OSTCOUNT files, at least one of them will
3430         # be allocated on OST0.
3431         warmup_files=$((OSTCOUNT * max_dirty_mb))
3432         createmany -o $TDIR/w $warmup_files
3433
3434         # write a large amount of data into one file and sync, to get good
3435         # avail_grant number from OST.
3436         for ((i=0; i<$warmup_files; i++)); do
3437                 idx=$($GETSTRIPE -i $TDIR/w$i)
3438                 [ $idx -ne 0 ] && continue
3439                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3440                 break
3441         done
3442         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3443         sync
3444         $LCTL get_param $proc_osc0/cur_dirty_bytes
3445         $LCTL get_param $proc_osc0/cur_grant_bytes
3446
3447         # create as much dirty pages as we can while not to trigger the actual
3448         # RPCs directly. but depends on the env, VFS may trigger flush during this
3449         # period, hopefully we are good.
3450         for ((i=0; i<$warmup_files; i++)); do
3451                 idx=$($GETSTRIPE -i $TDIR/w$i)
3452                 [ $idx -ne 0 ] && continue
3453                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3454         done
3455         $LCTL get_param $proc_osc0/cur_dirty_bytes
3456         $LCTL get_param $proc_osc0/cur_grant_bytes
3457
3458         # perform the real test
3459         $LCTL set_param $proc_osc0/rpc_stats 0
3460         for ((;i<$files; i++)); do
3461                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3462                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3463         done
3464         sync
3465         $LCTL get_param $proc_osc0/rpc_stats
3466
3467         local percent=0
3468         local have_ppr=false
3469         $LCTL get_param $proc_osc0/rpc_stats |
3470                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3471                         # skip lines until we are at the RPC histogram data
3472                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3473                         $have_ppr || continue
3474
3475                         # we only want the percent stat for < 16 pages
3476                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3477
3478                         percent=$((percent + WPCT))
3479                         if [[ $percent -gt 15 ]]; then
3480                                 error "less than 16-pages write RPCs" \
3481                                       "$percent% > 15%"
3482                                 break
3483                         fi
3484                 done
3485         rm -rf $TDIR
3486 }
3487 run_test 42e "verify sub-RPC writes are not done synchronously"
3488
3489 test_43() {
3490         test_mkdir -p $DIR/$tdir
3491         cp -p /bin/ls $DIR/$tdir/$tfile
3492         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3493         pid=$!
3494         # give multiop a chance to open
3495         sleep 1
3496
3497         $DIR/$tdir/$tfile && error || true
3498         kill -USR1 $pid
3499 }
3500 run_test 43 "execution of file opened for write should return -ETXTBSY"
3501
3502 test_43a() {
3503         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3504         test_mkdir -p $DIR/$tdir
3505         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3506                         cp -p multiop $DIR/$tdir/multiop
3507         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3508                         return 1
3509         MULTIOP_PID=$!
3510         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3511         kill -USR1 $MULTIOP_PID || return 2
3512         wait $MULTIOP_PID || return 3
3513         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3514 }
3515 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3516
3517 test_43b() {
3518         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3519         test_mkdir -p $DIR/$tdir
3520         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3521                         cp -p multiop $DIR/$tdir/multiop
3522         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3523                         return 1
3524         MULTIOP_PID=$!
3525         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3526         kill -USR1 $MULTIOP_PID || return 2
3527         wait $MULTIOP_PID || return 3
3528         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3529 }
3530 run_test 43b "truncate of file being executed should return -ETXTBSY"
3531
3532 test_43c() {
3533         local testdir="$DIR/$tdir"
3534         test_mkdir -p $DIR/$tdir
3535         cp $SHELL $testdir/
3536         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3537                 ( cd $testdir && md5sum -c)
3538 }
3539 run_test 43c "md5sum of copy into lustre========================"
3540
3541 test_44() {
3542         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3543         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3544         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3545 }
3546 run_test 44 "zero length read from a sparse stripe ============="
3547
3548 test_44a() {
3549         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3550                 awk '{ print $2 }')
3551         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3552         [[ $nstripe -gt $OSTCOUNT ]] &&
3553             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3554             return
3555         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3556                 awk '{ print $2 }')
3557         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3558                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3559                         awk '{ print $2 }')
3560         fi
3561
3562         OFFSETS="0 $((stride/2)) $((stride-1))"
3563         for offset in $OFFSETS; do
3564                 for i in $(seq 0 $((nstripe-1))); do
3565                         local GLOBALOFFSETS=""
3566                         # size in Bytes
3567                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3568                         local myfn=$DIR/d44a-$size
3569                         echo "--------writing $myfn at $size"
3570                         ll_sparseness_write $myfn $size ||
3571                                 error "ll_sparseness_write"
3572                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3573                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3574                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3575
3576                         for j in $(seq 0 $((nstripe-1))); do
3577                                 # size in Bytes
3578                                 size=$((((j + $nstripe )*$stride + $offset)))
3579                                 ll_sparseness_write $myfn $size ||
3580                                         error "ll_sparseness_write"
3581                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3582                         done
3583                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3584                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3585                         rm -f $myfn
3586                 done
3587         done
3588 }
3589 run_test 44a "test sparse pwrite ==============================="
3590
3591 dirty_osc_total() {
3592         tot=0
3593         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3594                 tot=$(($tot + $d))
3595         done
3596         echo $tot
3597 }
3598 do_dirty_record() {
3599         before=`dirty_osc_total`
3600         echo executing "\"$*\""
3601         eval $*
3602         after=`dirty_osc_total`
3603         echo before $before, after $after
3604 }
3605 test_45() {
3606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3607         f="$DIR/f45"
3608         # Obtain grants from OST if it supports it
3609         echo blah > ${f}_grant
3610         stop_writeback
3611         sync
3612         do_dirty_record "echo blah > $f"
3613         [[ $before -eq $after ]] && error "write wasn't cached"
3614         do_dirty_record "> $f"
3615         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3616         do_dirty_record "echo blah > $f"
3617         [[ $before -eq $after ]] && error "write wasn't cached"
3618         do_dirty_record "sync"
3619         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3620         do_dirty_record "echo blah > $f"
3621         [[ $before -eq $after ]] && error "write wasn't cached"
3622         do_dirty_record "cancel_lru_locks osc"
3623         [[ $before -gt $after ]] ||
3624                 error "lock cancellation didn't lower dirty count"
3625         start_writeback
3626 }
3627 run_test 45 "osc io page accounting ============================"
3628
3629 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3630 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3631 # objects offset and an assert hit when an rpc was built with 1023's mapped
3632 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3633 test_46() {
3634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3635         f="$DIR/f46"
3636         stop_writeback
3637         sync
3638         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3639         sync
3640         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3641         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3642         sync
3643         start_writeback
3644 }
3645 run_test 46 "dirtying a previously written page ================"
3646
3647 # test_47 is removed "Device nodes check" is moved to test_28
3648
3649 test_48a() { # bug 2399
3650         check_kernel_version 34 || return 0
3651         test_mkdir -p $DIR/$tdir
3652         cd $DIR/$tdir
3653         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3654         test_mkdir $DIR/$tdir || error "recreate directory failed"
3655         touch foo || error "'touch foo' failed after recreating cwd"
3656         test_mkdir $DIR/$tdir/bar ||
3657                      error "'mkdir foo' failed after recreating cwd"
3658         if check_kernel_version 44; then
3659                 touch .foo || error "'touch .foo' failed after recreating cwd"
3660                 test_mkdir $DIR/$tdir/.bar ||
3661                               error "'mkdir .foo' failed after recreating cwd"
3662         fi
3663         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3664         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3665         cd . || error "'cd .' failed after recreating cwd"
3666         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3667         rmdir . && error "'rmdir .' worked after recreating cwd"
3668         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3669         cd .. || error "'cd ..' failed after recreating cwd"
3670 }
3671 run_test 48a "Access renamed working dir (should return errors)="
3672
3673 test_48b() { # bug 2399
3674         check_kernel_version 34 || return 0
3675         rm -rf $DIR/$tdir
3676         test_mkdir -p $DIR/$tdir
3677         cd $DIR/$tdir
3678         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3679         touch foo && error "'touch foo' worked after removing cwd"
3680         test_mkdir $DIR/$tdir/foo &&
3681                      error "'mkdir foo' worked after removing cwd"
3682         if check_kernel_version 44; then
3683                 touch .foo && error "'touch .foo' worked after removing cwd"
3684                 test_mkdir $DIR/$tdir/.foo &&
3685                               error "'mkdir .foo' worked after removing cwd"
3686         fi
3687         ls . > /dev/null && error "'ls .' worked after removing cwd"
3688         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3689         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3690         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3691         rmdir . && error "'rmdir .' worked after removing cwd"
3692         ln -s . foo && error "'ln -s .' worked after removing cwd"
3693         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3694 }
3695 run_test 48b "Access removed working dir (should return errors)="
3696
3697 test_48c() { # bug 2350
3698         check_kernel_version 36 || return 0
3699         #lctl set_param debug=-1
3700         #set -vx
3701         rm -rf $DIR/$tdir
3702         test_mkdir -p $DIR/$tdir/dir
3703         cd $DIR/$tdir/dir
3704         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3705         $TRACE touch foo && error "touch foo worked after removing cwd"
3706         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3707         if check_kernel_version 44; then
3708                 touch .foo && error "touch .foo worked after removing cwd"
3709                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3710         fi
3711         $TRACE ls . && error "'ls .' worked after removing cwd"
3712         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3713         is_patchless || ( $TRACE cd . &&
3714                         error "'cd .' worked after removing cwd" )
3715         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3716         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3717         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3718         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3719 }
3720 run_test 48c "Access removed working subdir (should return errors)"
3721
3722 test_48d() { # bug 2350
3723         check_kernel_version 36 || return 0
3724         #lctl set_param debug=-1
3725         #set -vx
3726         rm -rf $DIR/$tdir
3727         test_mkdir -p $DIR/$tdir/dir
3728         cd $DIR/$tdir/dir
3729         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3730         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3731         $TRACE touch foo && error "'touch foo' worked after removing parent"
3732         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3733         if check_kernel_version 44; then
3734                 touch .foo && error "'touch .foo' worked after removing parent"
3735                 test_mkdir .foo &&
3736                               error "mkdir .foo worked after removing parent"
3737         fi
3738         $TRACE ls . && error "'ls .' worked after removing parent"
3739         $TRACE ls .. && error "'ls ..' worked after removing parent"
3740         is_patchless || ( $TRACE cd . &&
3741                         error "'cd .' worked after recreate parent" )
3742         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3743         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3744         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3745         is_patchless || ( $TRACE cd .. &&
3746                         error "'cd ..' worked after removing parent" || true )
3747 }
3748 run_test 48d "Access removed parent subdir (should return errors)"
3749
3750 test_48e() { # bug 4134
3751         check_kernel_version 41 || return 0
3752         #lctl set_param debug=-1
3753         #set -vx
3754         rm -rf $DIR/$tdir
3755         test_mkdir -p $DIR/$tdir/dir
3756         cd $DIR/$tdir/dir
3757         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3758         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3759         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3760         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3761         # On a buggy kernel addition of "touch foo" after cd .. will
3762         # produce kernel oops in lookup_hash_it
3763         touch ../foo && error "'cd ..' worked after recreate parent"
3764         cd $DIR
3765         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3766 }
3767 run_test 48e "Access to recreated parent subdir (should return errors)"
3768
3769 test_49() { # LU-1030
3770         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3771         # get ost1 size - lustre-OST0000
3772         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3773                 awk '{ print $4 }')
3774         # write 800M at maximum
3775         [[ $ost1_size -lt 2 ]] && ost1_size=2
3776         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3777
3778         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3779         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3780         local dd_pid=$!
3781
3782         # change max_pages_per_rpc while writing the file
3783         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3784         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3785         # loop until dd process exits
3786         while ps ax -opid | grep -wq $dd_pid; do
3787                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3788                 sleep $((RANDOM % 5 + 1))
3789         done
3790         # restore original max_pages_per_rpc
3791         $LCTL set_param $osc1_mppc=$orig_mppc
3792         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3793 }
3794 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3795
3796 test_50() {
3797         # bug 1485
3798         test_mkdir $DIR/$tdir
3799         cd $DIR/$tdir
3800         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3801 }
3802 run_test 50 "special situations: /proc symlinks  ==============="
3803
3804 test_51a() {    # was test_51
3805         # bug 1516 - create an empty entry right after ".." then split dir
3806         test_mkdir -p $DIR/$tdir
3807         touch $DIR/$tdir/foo
3808         $MCREATE $DIR/$tdir/bar
3809         rm $DIR/$tdir/foo
3810         createmany -m $DIR/$tdir/longfile 201
3811         FNUM=202
3812         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
3813                 $MCREATE $DIR/$tdir/longfile$FNUM
3814                 FNUM=$(($FNUM + 1))
3815                 echo -n "+"
3816         done
3817         echo
3818         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3819 }
3820 run_test 51a "special situations: split htree with empty entry =="
3821
3822 export NUMTEST=70000
3823 test_51b() {
3824         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3825         local BASE=$DIR/d${base}.${TESTSUITE}
3826
3827         # cleanup the directory
3828         rm -fr $BASE
3829
3830         test_mkdir -p $BASE
3831
3832         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3833         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3834         [[ $numfree -lt 21000 ]] && skip "not enough free inodes ($numfree)" &&
3835                 return
3836
3837         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3838                 echo "reduced count to $NUMTEST due to inodes"
3839
3840         # need to check free space for the directories as well
3841         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3842         numfree=$((blkfree / 4))
3843         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3844                 echo "reduced count to $NUMTEST due to blocks"
3845
3846         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3847                 echo "failed" > $BASE/fnum
3848 }
3849 run_test 51b "exceed 64k subdirectory nlink limit"
3850
3851 test_51ba() { # LU-993
3852         local BASE=$DIR/d${base}.${TESTSUITE}
3853         # unlink all but 100 subdirectories, then check it still works
3854         local LEFT=100
3855         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3856
3857         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
3858         local DELETE=$((NUMTEST - LEFT))
3859
3860         # continue on to run this test even if 51b didn't finish,
3861         # just to delete the many subdirectories created.
3862         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
3863
3864         # for ldiskfs the nlink count should be 1, but this is OSD specific
3865         # and so this is listed for informational purposes only
3866         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
3867         unlinkmany -d $BASE/d $DELETE
3868         RC=$?
3869
3870         if [ $RC -ne 0 ]; then
3871                 if [ "$NUMPREV" == "failed" ]; then
3872                         skip "previous setup failed"
3873                         return 0
3874                 else
3875                         error "unlink of first $DELETE subdirs failed"
3876                         return $RC
3877                 fi
3878         fi
3879
3880         echo "nlink between: $(stat -c %h $BASE)"
3881         # trim the first line of ls output
3882         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
3883         [ $FOUND -ne $LEFT ] &&
3884                 error "can't find subdirs: found only $FOUND/$LEFT"
3885
3886         unlinkmany -d $BASE/d $DELETE $LEFT ||
3887                 error "unlink of second $LEFT subdirs failed"
3888         # regardless of whether the backing filesystem tracks nlink accurately
3889         # or not, the nlink count shouldn't be more than "." and ".." here
3890         local AFTER=$(stat -c %h $BASE)
3891         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
3892                 echo "nlink after: $AFTER"
3893 }
3894 run_test 51ba "verify nlink for many subdirectory cleanup"
3895
3896 test_51d() {
3897         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3898         [[ $OSTCOUNT -lt 3 ]] &&
3899                 skip_env "skipping test with few OSTs" && return
3900         test_mkdir -p $DIR/$tdir
3901         createmany -o $DIR/$tdir/t- 1000
3902         $GETSTRIPE $DIR/$tdir > $TMP/files
3903         for N in $(seq 0 $((OSTCOUNT - 1))); do
3904                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
3905                         END { printf("%0.0f", objs) }' $TMP/files)
3906                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
3907                         '($1 == '$N') { objs += 1 } \
3908                         END { printf("%0.0f", objs) }')
3909                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
3910         done
3911         unlinkmany $DIR/$tdir/t- 1000
3912
3913         NLAST=0
3914         for N in $(seq 1 $((OSTCOUNT - 1))); do
3915                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
3916                         error "OST $N has less objects vs OST $NLAST" \
3917                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
3918                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
3919                         error "OST $N has less objects vs OST $NLAST" \
3920                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
3921
3922                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
3923                         error "OST $N has less #0 objects vs OST $NLAST" \
3924                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3925                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
3926                         error "OST $N has less #0 objects vs OST $NLAST" \
3927                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3928                 NLAST=$N
3929         done
3930 }
3931 run_test 51d "check object distribution ===================="
3932
3933 test_52a() {
3934         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
3935         test_mkdir -p $DIR/$tdir
3936         touch $DIR/$tdir/foo
3937         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
3938         echo bar >> $DIR/$tdir/foo || error "append bar failed"
3939         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3940         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3941         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3942                                         error "link worked"
3943         echo foo >> $DIR/$tdir/foo || error "append foo failed"
3944         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3945         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
3946                                                      error "lsattr"
3947         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
3948         cp -r $DIR/$tdir /tmp/
3949         rm -fr $DIR/$tdir || error "cleanup rm failed"
3950 }
3951 run_test 52a "append-only flag test (should return errors) ====="
3952
3953 test_52b() {
3954         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
3955         test_mkdir -p $DIR/$tdir
3956         touch $DIR/$tdir/foo
3957         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
3958         cat test > $DIR/$tdir/foo && error "cat test worked"
3959         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3960         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3961         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3962                                         error "link worked"
3963         echo foo >> $DIR/$tdir/foo && error "echo worked"
3964         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3965         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
3966         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
3967         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
3968                                                         error "lsattr"
3969         chattr -i $DIR/$tdir/foo || error "chattr failed"
3970
3971         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
3972 }
3973 run_test 52b "immutable flag test (should return errors) ======="
3974
3975 test_53() {
3976         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3977         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3978         remote_ost_nodsh && skip "remote OST with nodsh" && return
3979
3980         local param
3981         local param_seq
3982         local ostname
3983         local mds_last
3984         local mds_last_seq
3985         local ost_last
3986         local ost_last_seq
3987         local ost_last_id
3988         local ostnum
3989         local node
3990         local found=false
3991         local support_last_seq=true
3992
3993         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
3994                 support_last_seq=false
3995
3996         # only test MDT0000
3997         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
3998         local value
3999         for value in $(do_facet $SINGLEMDS \
4000                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4001                 param=$(echo ${value[0]} | cut -d "=" -f1)
4002                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4003
4004                 if $support_last_seq; then
4005                         param_seq=$(echo $param |
4006                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4007                         mds_last_seq=$(do_facet $SINGLEMDS \
4008                                        $LCTL get_param -n $param_seq)
4009                 fi
4010                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4011
4012                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4013                 node=$(facet_active_host ost$((ostnum+1)))
4014                 param="obdfilter.$ostname.last_id"
4015                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4016                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4017                         ost_last_id=$ost_last
4018
4019                         if $support_last_seq; then
4020                                 ost_last_id=$(echo $ost_last |
4021                                               awk -F':' '{print $2}' |
4022                                               sed -e "s/^0x//g")
4023                                 ost_last_seq=$(echo $ost_last |
4024                                                awk -F':' '{print $1}')
4025                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4026                         fi
4027
4028                         if [[ $ost_last_id != $mds_last ]]; then
4029                                 error "$ost_last_id != $mds_last"
4030                         else
4031                                 found=true
4032                                 break
4033                         fi
4034                 done
4035         done
4036         $found || error "can not match last_seq/last_id for $mdtosc"
4037         return 0
4038 }
4039 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4040
4041 test_54a() {
4042         $SOCKETSERVER $DIR/socket ||
4043                 error "$SOCKETSERVER $DIR/socket failed: $?"
4044         $SOCKETCLIENT $DIR/socket ||
4045                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4046         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4047 }
4048 run_test 54a "unix domain socket test =========================="
4049
4050 test_54b() {
4051         f="$DIR/f54b"
4052         mknod $f c 1 3
4053         chmod 0666 $f
4054         dd if=/dev/zero of=$f bs=$(page_size) count=1
4055 }
4056 run_test 54b "char device works in lustre ======================"
4057
4058 find_loop_dev() {
4059         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4060         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4061         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4062
4063         for i in $(seq 3 7); do
4064                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4065                 LOOPDEV=$LOOPBASE$i
4066                 LOOPNUM=$i
4067                 break
4068         done
4069 }
4070
4071 cleanup_54c() {
4072         loopdev="$DIR/loop54c"
4073
4074         trap 0
4075         $UMOUNT -d $tdir || rc=$?
4076         losetup -d $loopdev || true
4077         rm $loopdev
4078         return $rc
4079 }
4080
4081 test_54c() {
4082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4083         tfile="$DIR/f54c"
4084         tdir="$DIR/d54c"
4085         loopdev="$DIR/loop54c"
4086
4087         find_loop_dev
4088         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4089         mknod $loopdev b 7 $LOOPNUM
4090         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
4091         dd if=/dev/zero of=$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4092         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
4093         trap cleanup_54c EXIT
4094         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4095         test_mkdir -p $tdir
4096         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
4097         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
4098         df $tdir
4099         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
4100         cleanup_54c
4101 }
4102 run_test 54c "block device works in lustre ====================="
4103
4104 test_54d() {
4105         f="$DIR/f54d"
4106         string="aaaaaa"
4107         mknod $f p
4108         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4109 }
4110 run_test 54d "fifo device works in lustre ======================"
4111
4112 test_54e() {
4113         check_kernel_version 46 || return 0
4114         f="$DIR/f54e"
4115         string="aaaaaa"
4116         cp -aL /dev/console $f
4117         echo $string > $f || error "echo $string to $f failed"
4118 }
4119 run_test 54e "console/tty device works in lustre ======================"
4120
4121 #The test_55 used to be iopen test and it was removed by bz#24037.
4122 #run_test 55 "check iopen_connect_dentry() ======================"
4123
4124 test_56a() {    # was test_56
4125         rm -rf $DIR/$tdir
4126         $SETSTRIPE -d $DIR
4127         test_mkdir -p $DIR/$tdir/dir
4128         NUMFILES=3
4129         NUMFILESx2=$(($NUMFILES * 2))
4130         for i in $(seq 1 $NUMFILES); do
4131                 touch $DIR/$tdir/file$i
4132                 touch $DIR/$tdir/dir/file$i
4133         done
4134
4135         # test lfs getstripe with --recursive
4136         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4137         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4138                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4139         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4140         [[ $FILENUM -eq $NUMFILES ]] ||
4141                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4142         echo "$GETSTRIPE --recursive passed."
4143
4144         # test lfs getstripe with file instead of dir
4145         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4146         [[ $FILENUM -eq 1 ]] ||
4147                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4148         echo "$GETSTRIPE file1 passed."
4149
4150         #test lfs getstripe with --verbose
4151         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4152                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4153                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4154         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4155                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4156         echo "$GETSTRIPE --verbose passed."
4157
4158         #test lfs getstripe with --obd
4159         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4160                 grep -q "unknown obduuid" ||
4161                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4162
4163         [[ $OSTCOUNT -lt 2 ]] &&
4164                 skip_env "skipping other $GETSTRIPE --obd test" && return
4165
4166         OSTIDX=1
4167         OBDUUID=$(ostuuid_from_index $OSTIDX)
4168         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4169         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4170         [[ $FOUND -eq $FILENUM ]] ||
4171                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4172         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4173                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4174                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4175                 error "$GETSTRIPE --obd: should not show file on other obd"
4176         echo "$GETSTRIPE --obd passed"
4177 }
4178 run_test 56a "check $GETSTRIPE"
4179
4180 NUMFILES=3
4181 NUMDIRS=3
4182 setup_56() {
4183         local LOCAL_NUMFILES="$1"
4184         local LOCAL_NUMDIRS="$2"
4185         local MKDIR_PARAMS="$3"
4186         local DIR_STRIPE_PARAMS="$4"
4187
4188         if [ ! -d "$TDIR" ] ; then
4189                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4190                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4191                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4192                         touch $TDIR/file$i
4193                 done
4194                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4195                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4196                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4197                                 touch $TDIR/dir$i/file$j
4198                         done
4199                 done
4200         fi
4201 }
4202
4203 setup_56_special() {
4204         LOCAL_NUMFILES=$1
4205         LOCAL_NUMDIRS=$2
4206         setup_56 $1 $2
4207         if [ ! -e "$TDIR/loop1b" ] ; then
4208                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4209                         mknod $TDIR/loop${i}b b 7 $i
4210                         mknod $TDIR/null${i}c c 1 3
4211                         ln -s $TDIR/file1 $TDIR/link${i}l
4212                 done
4213                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4214                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4215                         mknod $TDIR/dir$i/null${i}c c 1 3
4216                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4217                 done
4218         fi
4219 }
4220
4221 test_56g() {
4222         $SETSTRIPE -d $DIR
4223
4224         TDIR=$DIR/${tdir}g
4225         setup_56 $NUMFILES $NUMDIRS
4226
4227         EXPECTED=$(($NUMDIRS + 2))
4228         # test lfs find with -name
4229         for i in $(seq 1 $NUMFILES) ; do
4230                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4231                 [ $NUMS -eq $EXPECTED ] ||
4232                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4233                               "found $NUMS, expected $EXPECTED"
4234         done
4235 }
4236 run_test 56g "check lfs find -name ============================="
4237
4238 test_56h() {
4239         $SETSTRIPE -d $DIR
4240
4241         TDIR=$DIR/${tdir}g
4242         setup_56 $NUMFILES $NUMDIRS
4243
4244         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4245         # test lfs find with ! -name
4246         for i in $(seq 1 $NUMFILES) ; do
4247                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4248                 [ $NUMS -eq $EXPECTED ] ||
4249                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4250                               "found $NUMS, expected $EXPECTED"
4251         done
4252 }
4253 run_test 56h "check lfs find ! -name ============================="
4254
4255 test_56i() {
4256        tdir=${tdir}i
4257        test_mkdir -p $DIR/$tdir
4258        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4259        CMD="$LFIND -ost $UUID $DIR/$tdir"
4260        OUT=$($CMD)
4261        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4262 }
4263 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4264
4265 test_56j() {
4266         TDIR=$DIR/${tdir}g
4267         setup_56_special $NUMFILES $NUMDIRS
4268
4269         EXPECTED=$((NUMDIRS + 1))
4270         CMD="$LFIND -type d $TDIR"
4271         NUMS=$($CMD | wc -l)
4272         [ $NUMS -eq $EXPECTED ] ||
4273                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4274 }
4275 run_test 56j "check lfs find -type d ============================="
4276
4277 test_56k() {
4278         TDIR=$DIR/${tdir}g
4279         setup_56_special $NUMFILES $NUMDIRS
4280
4281         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4282         CMD="$LFIND -type f $TDIR"
4283         NUMS=$($CMD | wc -l)
4284         [ $NUMS -eq $EXPECTED ] ||
4285                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4286 }
4287 run_test 56k "check lfs find -type f ============================="
4288
4289 test_56l() {
4290         TDIR=$DIR/${tdir}g
4291         setup_56_special $NUMFILES $NUMDIRS
4292
4293         EXPECTED=$((NUMDIRS + NUMFILES))
4294         CMD="$LFIND -type b $TDIR"
4295         NUMS=$($CMD | wc -l)
4296         [ $NUMS -eq $EXPECTED ] ||
4297                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4298 }
4299 run_test 56l "check lfs find -type b ============================="
4300
4301 test_56m() {
4302         TDIR=$DIR/${tdir}g
4303         setup_56_special $NUMFILES $NUMDIRS
4304
4305         EXPECTED=$((NUMDIRS + NUMFILES))
4306         CMD="$LFIND -type c $TDIR"
4307         NUMS=$($CMD | wc -l)
4308         [ $NUMS -eq $EXPECTED ] ||
4309                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4310 }
4311 run_test 56m "check lfs find -type c ============================="
4312
4313 test_56n() {
4314         TDIR=$DIR/${tdir}g
4315         setup_56_special $NUMFILES $NUMDIRS
4316
4317         EXPECTED=$((NUMDIRS + NUMFILES))
4318         CMD="$LFIND -type l $TDIR"
4319         NUMS=$($CMD | wc -l)
4320         [ $NUMS -eq $EXPECTED ] ||
4321                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4322 }
4323 run_test 56n "check lfs find -type l ============================="
4324
4325 test_56o() {
4326         TDIR=$DIR/${tdir}o
4327         setup_56 $NUMFILES $NUMDIRS
4328         utime $TDIR/file1 > /dev/null || error "utime (1)"
4329         utime $TDIR/file2 > /dev/null || error "utime (2)"
4330         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4331         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4332         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4333         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4334
4335         EXPECTED=4
4336         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4337         [ $NUMS -eq $EXPECTED ] || \
4338                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4339
4340         EXPECTED=12
4341         CMD="$LFIND -mtime 0 $TDIR"
4342         NUMS=$($CMD | wc -l)
4343         [ $NUMS -eq $EXPECTED ] ||
4344                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4345 }
4346 run_test 56o "check lfs find -mtime for old files =========================="
4347
4348 test_56p() {
4349         [ $RUNAS_ID -eq $UID ] &&
4350                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4351
4352         TDIR=$DIR/${tdir}p
4353         setup_56 $NUMFILES $NUMDIRS
4354
4355         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4356         EXPECTED=$NUMFILES
4357         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4358         NUMS=$($CMD | wc -l)
4359         [ $NUMS -eq $EXPECTED ] || \
4360                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4361
4362         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4363         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4364         NUMS=$($CMD | wc -l)
4365         [ $NUMS -eq $EXPECTED ] || \
4366                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4367 }
4368 run_test 56p "check lfs find -uid and ! -uid ==============================="
4369
4370 test_56q() {
4371         [ $RUNAS_ID -eq $UID ] &&
4372                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4373
4374         TDIR=$DIR/${tdir}q
4375         setup_56 $NUMFILES $NUMDIRS
4376
4377         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4378
4379         EXPECTED=$NUMFILES
4380         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4381         NUMS=$($CMD | wc -l)
4382         [ $NUMS -eq $EXPECTED ] ||
4383                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4384
4385         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4386         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4387         NUMS=$($CMD | wc -l)
4388         [ $NUMS -eq $EXPECTED ] ||
4389                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4390 }
4391 run_test 56q "check lfs find -gid and ! -gid ==============================="
4392
4393 test_56r() {
4394         TDIR=$DIR/${tdir}r
4395         setup_56 $NUMFILES $NUMDIRS
4396
4397         EXPECTED=12
4398         CMD="$LFIND -size 0 -type f $TDIR"
4399         NUMS=$($CMD | wc -l)
4400         [ $NUMS -eq $EXPECTED ] ||
4401                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4402         EXPECTED=0
4403         CMD="$LFIND ! -size 0 -type f $TDIR"
4404         NUMS=$($CMD | wc -l)
4405         [ $NUMS -eq $EXPECTED ] ||
4406                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4407         echo "test" > $TDIR/$tfile
4408         echo "test2" > $TDIR/$tfile.2 && sync
4409         EXPECTED=1
4410         CMD="$LFIND -size 5 -type f $TDIR"
4411         NUMS=$($CMD | wc -l)
4412         [ $NUMS -eq $EXPECTED ] ||
4413                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4414         EXPECTED=1
4415         CMD="$LFIND -size +5 -type f $TDIR"
4416         NUMS=$($CMD | wc -l)
4417         [ $NUMS -eq $EXPECTED ] ||
4418                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4419         EXPECTED=2
4420         CMD="$LFIND -size +0 -type f $TDIR"
4421         NUMS=$($CMD | wc -l)
4422         [ $NUMS -eq $EXPECTED ] ||
4423                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4424         EXPECTED=2
4425         CMD="$LFIND ! -size -5 -type f $TDIR"
4426         NUMS=$($CMD | wc -l)
4427         [ $NUMS -eq $EXPECTED ] ||
4428                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4429         EXPECTED=12
4430         CMD="$LFIND -size -5 -type f $TDIR"
4431         NUMS=$($CMD | wc -l)
4432         [ $NUMS -eq $EXPECTED ] ||
4433                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4434 }
4435 run_test 56r "check lfs find -size works =========================="
4436
4437 test_56s() { # LU-611
4438         TDIR=$DIR/${tdir}s
4439         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4440
4441         if [[ $OSTCOUNT -gt 1 ]]; then
4442                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4443                 ONESTRIPE=4
4444                 EXTRA=4
4445         else
4446                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4447                 EXTRA=0
4448         fi
4449
4450         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4451         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4452         NUMS=$($CMD | wc -l)
4453         [ $NUMS -eq $EXPECTED ] ||
4454                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4455
4456         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4457         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4458         NUMS=$($CMD | wc -l)
4459         [ $NUMS -eq $EXPECTED ] ||
4460                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4461
4462         EXPECTED=$ONESTRIPE
4463         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4464         NUMS=$($CMD | wc -l)
4465         [ $NUMS -eq $EXPECTED ] ||
4466                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4467
4468         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4469         NUMS=$($CMD | wc -l)
4470         [ $NUMS -eq $EXPECTED ] ||
4471                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4472
4473         EXPECTED=0
4474         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4475         NUMS=$($CMD | wc -l)
4476         [ $NUMS -eq $EXPECTED ] ||
4477                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4478 }
4479 run_test 56s "check lfs find -stripe-count works"
4480
4481 test_56t() { # LU-611
4482         TDIR=$DIR/${tdir}t
4483         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4484
4485         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4486
4487         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4488         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4489         NUMS=$($CMD | wc -l)
4490         [ $NUMS -eq $EXPECTED ] ||
4491                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4492
4493         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4494         NUMS=$($CMD | wc -l)
4495         [ $NUMS -eq $EXPECTED ] ||
4496                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4497
4498         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4499         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4500         NUMS=$($CMD | wc -l)
4501         [ $NUMS -eq $EXPECTED ] ||
4502                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4503
4504         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4505         NUMS=$($CMD | wc -l)
4506         [ $NUMS -eq $EXPECTED ] ||
4507                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4508
4509         EXPECTED=4
4510         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4511         NUMS=$($CMD | wc -l)
4512         [ $NUMS -eq $EXPECTED ] ||
4513                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4514
4515         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4516         NUMS=$($CMD | wc -l)
4517         [ $NUMS -eq $EXPECTED ] ||
4518                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4519
4520         EXPECTED=0
4521         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4522         NUMS=$($CMD | wc -l)
4523         [ $NUMS -eq $EXPECTED ] ||
4524                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4525 }
4526 run_test 56t "check lfs find -stripe-size works"
4527
4528 test_56u() { # LU-611
4529         TDIR=$DIR/${tdir}u
4530         setup_56 $NUMFILES $NUMDIRS "-i 0"
4531
4532         if [[ $OSTCOUNT -gt 1 ]]; then
4533                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4534                 ONESTRIPE=4
4535         else
4536                 ONESTRIPE=0
4537         fi
4538
4539         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4540         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4541         NUMS=$($CMD | wc -l)
4542         [ $NUMS -eq $EXPECTED ] ||
4543                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4544
4545         EXPECTED=$ONESTRIPE
4546         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4547         NUMS=$($CMD | wc -l)
4548         [ $NUMS -eq $EXPECTED ] ||
4549                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4550
4551         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4552         NUMS=$($CMD | wc -l)
4553         [ $NUMS -eq $EXPECTED ] ||
4554                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4555
4556         EXPECTED=0
4557         # This should produce an error and not return any files
4558         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4559         NUMS=$($CMD 2>/dev/null | wc -l)
4560         [ $NUMS -eq $EXPECTED ] ||
4561                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4562
4563         if [[ $OSTCOUNT -gt 1 ]]; then
4564                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4565                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4566                 NUMS=$($CMD | wc -l)
4567                 [ $NUMS -eq $EXPECTED ] ||
4568                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4569         fi
4570 }
4571 run_test 56u "check lfs find -stripe-index works"
4572
4573 test_56v() {
4574     local MDT_IDX=0
4575
4576     TDIR=$DIR/${tdir}v
4577     rm -rf $TDIR
4578     setup_56 $NUMFILES $NUMDIRS
4579
4580     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4581     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4582
4583     for file in $($LFIND -mdt $UUID $TDIR); do
4584         file_mdt_idx=$($GETSTRIPE -M $file)
4585         [ $file_mdt_idx -eq $MDT_IDX ] ||
4586             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4587     done
4588 }
4589 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4590
4591 # Get and check the actual stripe count of one file.
4592 # Usage: check_stripe_count <file> <expected_stripe_count>
4593 check_stripe_count() {
4594     local file=$1
4595     local expected=$2
4596     local actual
4597
4598     [[ -z "$file" || -z "$expected" ]] &&
4599         error "check_stripe_count: invalid argument!"
4600
4601     local cmd="$GETSTRIPE -c $file"
4602     actual=$($cmd) || error "$cmd failed"
4603     actual=${actual%% *}
4604
4605     if [[ $actual -ne $expected ]]; then
4606         [[ $expected -eq -1 ]] ||
4607             error "$cmd wrong: found $actual, expected $expected"
4608         [[ $actual -eq $OSTCOUNT ]] ||
4609             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4610     fi
4611 }
4612
4613 test_56w() {
4614         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4615         TDIR=$DIR/${tdir}w
4616
4617     rm -rf $TDIR || error "remove $TDIR failed"
4618     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4619
4620     local stripe_size
4621     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4622         error "$GETSTRIPE -S -d $TDIR failed"
4623     stripe_size=${stripe_size%% *}
4624
4625     local file_size=$((stripe_size * OSTCOUNT))
4626     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4627     local required_space=$((file_num * file_size))
4628     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4629     [[ $free_space -le $((required_space / 1024)) ]] &&
4630         skip_env "need at least $required_space bytes free space," \
4631                  "have $free_space kbytes" && return
4632
4633     local dd_bs=65536
4634     local dd_count=$((file_size / dd_bs))
4635
4636     # write data into the files
4637     local i
4638     local j
4639     local file
4640     for i in $(seq 1 $NUMFILES); do
4641         file=$TDIR/file$i
4642         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4643             error "write data into $file failed"
4644     done
4645     for i in $(seq 1 $NUMDIRS); do
4646         for j in $(seq 1 $NUMFILES); do
4647             file=$TDIR/dir$i/file$j
4648             yes | dd bs=$dd_bs count=$dd_count of=$file \
4649                 >/dev/null 2>&1 ||
4650                 error "write data into $file failed"
4651         done
4652     done
4653
4654     local expected=-1
4655     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4656
4657     # lfs_migrate file
4658     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4659     echo "$cmd"
4660     eval $cmd || error "$cmd failed"
4661
4662     check_stripe_count $TDIR/file1 $expected
4663
4664     # lfs_migrate dir
4665     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4666     echo "$cmd"
4667     eval $cmd || error "$cmd failed"
4668
4669     for j in $(seq 1 $NUMFILES); do
4670         check_stripe_count $TDIR/dir1/file$j $expected
4671     done
4672
4673     # lfs_migrate works with lfs find
4674     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4675          $LFS_MIGRATE -y -c $expected"
4676     echo "$cmd"
4677     eval $cmd || error "$cmd failed"
4678
4679     for i in $(seq 2 $NUMFILES); do
4680         check_stripe_count $TDIR/file$i $expected
4681     done
4682     for i in $(seq 2 $NUMDIRS); do
4683         for j in $(seq 1 $NUMFILES); do
4684             check_stripe_count $TDIR/dir$i/file$j $expected
4685         done
4686     done
4687 }
4688 run_test 56w "check lfs_migrate -c stripe_count works"
4689
4690 test_56x() {
4691         check_swap_layouts_support && return 0
4692         [[ $OSTCOUNT -lt 2 ]] &&
4693                 skip_env "need 2 OST, skipping test" && return
4694
4695         local dir0=$DIR/$tdir/$testnum
4696         mkdir -p $dir0 || error "creating dir $dir0"
4697
4698         local ref1=/etc/passwd
4699         local file1=$dir0/file1
4700
4701         $SETSTRIPE -c 2 $file1
4702         cp $ref1 $file1
4703         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4704         stripe=$($GETSTRIPE -c $file1)
4705         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4706         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4707
4708         # clean up
4709         rm -f $file1
4710 }
4711 run_test 56x "lfs migration support"
4712
4713 test_56y() {
4714         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4715                 skip "No HSM support on MDS of $(get_lustre_version)," \
4716                          "need 2.4.53 at least" && return
4717         local res=""
4718
4719         local dir0=$DIR/$tdir/$testnum
4720         mkdir -p $dir0 || error "creating dir $dir0"
4721         local f1=$dir0/file1
4722         local f2=$dir0/file2
4723
4724         touch $f1 || error "creating std file $f1"
4725         $MULTIOP $f2 H2c || error "creating released file $f2"
4726
4727         # a directory can be raid0, so ask only for files
4728         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4729         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4730
4731         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4732         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4733
4734         # only files can be released, so no need to force file search
4735         res=$($LFIND $dir0 -L released)
4736         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4737
4738         res=$($LFIND $dir0 \! -L released)
4739         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4740
4741 }
4742 run_test 56y "lfs find -L raid0|released"
4743
4744 test_57a() {
4745         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4746         # note test will not do anything if MDS is not local
4747         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4748                 skip "Only applicable to ldiskfs-based MDTs"
4749                 return
4750         fi
4751
4752         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4753         local MNTDEV="osd*.*MDT*.mntdev"
4754         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4755         [ -z "$DEV" ] && error "can't access $MNTDEV"
4756         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4757                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4758                         error "can't access $DEV"
4759                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
4760                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
4761                 rm $TMP/t57a.dump
4762         done
4763 }
4764 run_test 57a "verify MDS filesystem created with large inodes =="
4765
4766 test_57b() {
4767         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4768         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4769                 skip "Only applicable to ldiskfs-based MDTs"
4770                 return
4771         fi
4772
4773         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4774         local dir=$DIR/d57b
4775
4776         local FILECOUNT=100
4777         local FILE1=$dir/f1
4778         local FILEN=$dir/f$FILECOUNT
4779
4780         rm -rf $dir || error "removing $dir"
4781         test_mkdir -p $dir || error "creating $dir"
4782         local num=$(get_mds_dir $dir)
4783         local mymds=mds$num
4784
4785         echo "mcreating $FILECOUNT files"
4786         createmany -m $dir/f 1 $FILECOUNT || \
4787                 error "creating files in $dir"
4788
4789         # verify that files do not have EAs yet
4790         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4791         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4792
4793         sync
4794         sleep 1
4795         df $dir  #make sure we get new statfs data
4796         local MDSFREE=$(do_facet $mymds \
4797                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4798         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4799         echo "opening files to create objects/EAs"
4800         local FILE
4801         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4802                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4803         done
4804
4805         # verify that files have EAs now
4806         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
4807         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
4808
4809         sleep 1  #make sure we get new statfs data
4810         df $dir
4811         local MDSFREE2=$(do_facet $mymds \
4812                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4813         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4814         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
4815                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
4816                         error "MDC before $MDCFREE != after $MDCFREE2"
4817                 else
4818                         echo "MDC before $MDCFREE != after $MDCFREE2"
4819                         echo "unable to confirm if MDS has large inodes"
4820                 fi
4821         fi
4822         rm -rf $dir
4823 }
4824 run_test 57b "default LOV EAs are stored inside large inodes ==="
4825
4826 test_58() {
4827         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4828         [ -z "$(which wiretest 2>/dev/null)" ] &&
4829                         skip_env "could not find wiretest" && return
4830         wiretest
4831 }
4832 run_test 58 "verify cross-platform wire constants =============="
4833
4834 test_59() {
4835         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4836         echo "touch 130 files"
4837         createmany -o $DIR/f59- 130
4838         echo "rm 130 files"
4839         unlinkmany $DIR/f59- 130
4840         sync
4841         # wait for commitment of removal
4842         wait_delete_completed
4843 }
4844 run_test 59 "verify cancellation of llog records async ========="
4845
4846 TEST60_HEAD="test_60 run $RANDOM"
4847 test_60a() {
4848         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4849         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
4850         do_facet mgs "! which run-llog.sh &> /dev/null" &&
4851                 skip_env "missing subtest run-llog.sh" && return
4852         log "$TEST60_HEAD - from kernel mode"
4853         do_facet mgs sh run-llog.sh
4854 }
4855 run_test 60a "llog sanity tests run from kernel module =========="
4856
4857 test_60b() { # bug 6411
4858         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4859         dmesg > $DIR/$tfile
4860         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
4861                                  /llog.test/ {
4862                                          if (marker)
4863                                                  from_marker++
4864                                          from_begin++
4865                                  }
4866                                  END {
4867                                          if (marker)
4868                                                  print from_marker
4869                                          else
4870                                                  print from_begin
4871                                  }"`
4872         [[ $LLOG_COUNT -gt 50 ]] &&
4873                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
4874 }
4875 run_test 60b "limit repeated messages from CERROR/CWARN ========"
4876
4877 test_60c() {
4878         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4879         echo "create 5000 files"
4880         createmany -o $DIR/f60c- 5000
4881 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
4882         lctl set_param fail_loc=0x80000137
4883         unlinkmany $DIR/f60c- 5000
4884         lctl set_param fail_loc=0
4885 }
4886 run_test 60c "unlink file when mds full"
4887
4888 test_60d() {
4889         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4890         SAVEPRINTK=$(lctl get_param -n printk)
4891
4892         # verify "lctl mark" is even working"
4893         MESSAGE="test message ID $RANDOM $$"
4894         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4895         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
4896
4897         lctl set_param printk=0 || error "set lnet.printk failed"
4898         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
4899         MESSAGE="new test message ID $RANDOM $$"
4900         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
4901         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4902         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
4903
4904         lctl set_param -n printk="$SAVEPRINTK"
4905 }
4906 run_test 60d "test printk console message masking"
4907
4908 test_61() {
4909         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4910         f="$DIR/f61"
4911         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
4912         cancel_lru_locks osc
4913         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
4914         sync
4915 }
4916 run_test 61 "mmap() writes don't make sync hang ================"
4917
4918 # bug 2330 - insufficient obd_match error checking causes LBUG
4919 test_62() {
4920         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4921         f="$DIR/f62"
4922         echo foo > $f
4923         cancel_lru_locks osc
4924         lctl set_param fail_loc=0x405
4925         cat $f && error "cat succeeded, expect -EIO"
4926         lctl set_param fail_loc=0
4927 }
4928 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
4929 # match every page all of the time.
4930 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
4931
4932 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
4933 # Though this test is irrelevant anymore, it helped to reveal some
4934 # other grant bugs (LU-4482), let's keep it.
4935 test_63a() {   # was test_63
4936         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4937         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
4938         for i in `seq 10` ; do
4939                 dd if=/dev/zero of=$DIR/f63 bs=8k &
4940                 sleep 5
4941                 kill $!
4942                 sleep 1
4943         done
4944
4945         rm -f $DIR/f63 || true
4946 }
4947 run_test 63a "Verify oig_wait interruption does not crash ======="
4948
4949 # bug 2248 - async write errors didn't return to application on sync
4950 # bug 3677 - async write errors left page locked
4951 test_63b() {
4952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4953         debugsave
4954         lctl set_param debug=-1
4955
4956         # ensure we have a grant to do async writes
4957         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
4958         rm $DIR/$tfile
4959
4960         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4961         lctl set_param fail_loc=0x80000406
4962         $MULTIOP $DIR/$tfile Owy && \
4963                 error "sync didn't return ENOMEM"
4964         sync; sleep 2; sync     # do a real sync this time to flush page
4965         lctl get_param -n llite.*.dump_page_cache | grep locked && \
4966                 error "locked page left in cache after async error" || true
4967         debugrestore
4968 }
4969 run_test 63b "async write errors should be returned to fsync ==="
4970
4971 test_64a () {
4972         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4973         df $DIR
4974         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
4975 }
4976 run_test 64a "verify filter grant calculations (in kernel) ====="
4977
4978 test_64b () {
4979         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4980         sh oos.sh $MOUNT || error "oos.sh failed: $?"
4981 }
4982 run_test 64b "check out-of-space detection on client ==========="
4983
4984 test_64c() {
4985         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
4986 }
4987 run_test 64c "verify grant shrink ========================------"
4988
4989 # bug 1414 - set/get directories' stripe info
4990 test_65a() {
4991         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4992         test_mkdir -p $DIR/$tdir
4993         touch $DIR/$tdir/f1
4994         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
4995 }
4996 run_test 65a "directory with no stripe info ===================="
4997
4998 test_65b() {
4999         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5000         test_mkdir -p $DIR/$tdir
5001         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5002                                                 error "setstripe"
5003         touch $DIR/$tdir/f2
5004         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5005 }
5006 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5007
5008 test_65c() {
5009         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5010         if [[ $OSTCOUNT -gt 1 ]]; then
5011                 test_mkdir -p $DIR/$tdir
5012                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5013                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5014                 touch $DIR/$tdir/f3
5015                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5016         fi
5017 }
5018 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5019
5020 test_65d() {
5021         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5022         test_mkdir -p $DIR/$tdir
5023         if [[ $STRIPECOUNT -le 0 ]]; then
5024                 sc=1
5025         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5026 #LOV_MAX_STRIPE_COUNT is 2000
5027                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5028         else
5029                 sc=$(($STRIPECOUNT - 1))
5030         fi
5031         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5032         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5033         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5034                 error "lverify failed"
5035 }
5036 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5037
5038 test_65e() {
5039         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5040         test_mkdir -p $DIR/$tdir
5041
5042         $SETSTRIPE $DIR/$tdir || error "setstripe"
5043         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5044                                         error "no stripe info failed"
5045         touch $DIR/$tdir/f6
5046         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5047 }
5048 run_test 65e "directory setstripe defaults ======================="
5049
5050 test_65f() {
5051         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5052         test_mkdir -p $DIR/${tdir}f
5053         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5054 }
5055 run_test 65f "dir setstripe permission (should return error) ==="
5056
5057 test_65g() {
5058         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5059         test_mkdir -p $DIR/$tdir
5060         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5061                                                         error "setstripe"
5062         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5063         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5064                 error "delete default stripe failed"
5065 }
5066 run_test 65g "directory setstripe -d ==========================="
5067
5068 test_65h() {
5069         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5070         test_mkdir -p $DIR/$tdir
5071         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5072                                                         error "setstripe"
5073         test_mkdir -p $DIR/$tdir/dd1
5074         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5075                 error "stripe info inherit failed"
5076 }
5077 run_test 65h "directory stripe info inherit ===================="
5078
5079 test_65i() { # bug6367
5080         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5081         $SETSTRIPE -S 65536 -c -1 $MOUNT
5082 }
5083 run_test 65i "set non-default striping on root directory (bug 6367)="
5084
5085 test_65ia() { # bug12836
5086         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5087         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5088 }
5089 run_test 65ia "getstripe on -1 default directory striping"
5090
5091 test_65ib() { # bug12836
5092         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5093         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5094 }
5095 run_test 65ib "getstripe -v on -1 default directory striping"
5096
5097 test_65ic() { # bug12836
5098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5099         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5100 }
5101 run_test 65ic "new find on -1 default directory striping"
5102
5103 test_65j() { # bug6367
5104         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5105         sync; sleep 1
5106         # if we aren't already remounting for each test, do so for this test
5107         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5108                 cleanup || error "failed to unmount"
5109                 setup
5110         fi
5111         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5112 }
5113 run_test 65j "set default striping on root directory (bug 6367)="
5114
5115 test_65k() { # bug11679
5116         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5117         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5118         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5119
5120     echo "Check OST status: "
5121     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5122               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5123
5124     for OSC in $MDS_OSCS; do
5125         echo $OSC "is activate"
5126         do_facet $SINGLEMDS lctl --device %$OSC activate
5127     done
5128
5129     mkdir -p $DIR/$tdir
5130     for INACTIVE_OSC in $MDS_OSCS; do
5131         echo "Deactivate: " $INACTIVE_OSC
5132         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5133         for STRIPE_OSC in $MDS_OSCS; do
5134             OST=`osc_to_ost $STRIPE_OSC`
5135             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5136                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5137
5138             [ -f $DIR/$tdir/$IDX ] && continue
5139             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5140             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5141             RC=$?
5142             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5143         done
5144         rm -f $DIR/$tdir/*
5145         echo $INACTIVE_OSC "is Activate."
5146         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5147     done
5148 }
5149 run_test 65k "validate manual striping works properly with deactivated OSCs"
5150
5151 test_65l() { # bug 12836
5152         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5153         test_mkdir -p $DIR/$tdir/test_dir
5154         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5155         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5156 }
5157 run_test 65l "lfs find on -1 stripe dir ========================"
5158
5159 # bug 2543 - update blocks count on client
5160 test_66() {
5161         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5162         COUNT=${COUNT:-8}
5163         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5164         sync; sync_all_data; sync; sync_all_data
5165         cancel_lru_locks osc
5166         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5167         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5168 }
5169 run_test 66 "update inode blocks count on client ==============="
5170
5171 LLOOP=
5172 LLITELOOPLOAD=
5173 cleanup_68() {
5174         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5175         trap 0
5176         if [ ! -z "$LLOOP" ]; then
5177                 if swapon -s | grep -q $LLOOP; then
5178                         swapoff $LLOOP || error "swapoff failed"
5179                 fi
5180
5181                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5182                 rm -f $LLOOP
5183                 unset LLOOP
5184         fi
5185         if [ ! -z "$LLITELOOPLOAD" ]; then
5186                 rmmod llite_lloop
5187                 unset LLITELOOPLOAD
5188         fi
5189         rm -f $DIR/f68*
5190 }
5191
5192 meminfo() {
5193         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5194 }
5195
5196 swap_used() {
5197         swapon -s | awk '($1 == "'$1'") { print $4 }'
5198 }
5199
5200 # test case for lloop driver, basic function
5201 test_68a() {
5202         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5203         [ "$UID" != 0 ] && skip_env "must run as root" && return
5204         llite_lloop_enabled || \
5205                 { skip_env "llite_lloop module disabled" && return; }
5206
5207         trap cleanup_68 EXIT
5208
5209         if ! module_loaded llite_lloop; then
5210                 if load_module llite/llite_lloop; then
5211                         LLITELOOPLOAD=yes
5212                 else
5213                         skip_env "can't find module llite_lloop"
5214                         return
5215                 fi
5216         fi
5217
5218         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5219         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5220         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5221
5222         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5223         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5224
5225         cleanup_68
5226 }
5227 run_test 68a "lloop driver - basic test ========================"
5228
5229 # excercise swapping to lustre by adding a high priority swapfile entry
5230 # and then consuming memory until it is used.
5231 test_68b() {  # was test_68
5232         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5233         [ "$UID" != 0 ] && skip_env "must run as root" && return
5234         lctl get_param -n devices | grep -q obdfilter && \
5235                 skip "local OST" && return
5236
5237         grep -q llite_lloop /proc/modules
5238         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5239
5240         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5241                 skip "can't reliably test swap with TCP" && return
5242
5243         MEMTOTAL=`meminfo MemTotal`
5244         NR_BLOCKS=$((MEMTOTAL>>8))
5245         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5246
5247         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5248         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5249         mkswap $DIR/f68b
5250
5251         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5252
5253         trap cleanup_68 EXIT
5254
5255         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5256
5257         echo "before: `swapon -s | grep $LLOOP`"
5258         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5259         echo "after: `swapon -s | grep $LLOOP`"
5260         SWAPUSED=`swap_used $LLOOP`
5261
5262         cleanup_68
5263
5264         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5265 }
5266 run_test 68b "support swapping to Lustre ========================"
5267
5268 # bug5265, obdfilter oa2dentry return -ENOENT
5269 # #define OBD_FAIL_OST_ENOENT 0x217
5270 test_69() {
5271         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5272         remote_ost_nodsh && skip "remote OST with nodsh" && return
5273
5274         f="$DIR/$tfile"
5275         $SETSTRIPE -c 1 -i 0 $f
5276
5277         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5278
5279         do_facet ost1 lctl set_param fail_loc=0x217
5280         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5281         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5282
5283         do_facet ost1 lctl set_param fail_loc=0
5284         $DIRECTIO write $f 0 2 || error "write error"
5285
5286         cancel_lru_locks osc
5287         $DIRECTIO read $f 0 1 || error "read error"
5288
5289         do_facet ost1 lctl set_param fail_loc=0x217
5290         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5291
5292         do_facet ost1 lctl set_param fail_loc=0
5293         rm -f $f
5294 }
5295 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5296
5297 test_71() {
5298     test_mkdir -p $DIR/$tdir
5299     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5300 }
5301 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5302
5303 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5304         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5305         [ "$RUNAS_ID" = "$UID" ] &&
5306                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5307
5308         # Check that testing environment is properly set up. Skip if not
5309         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5310                 skip_env "User $RUNAS_ID does not exist - skipping"
5311                 return 0
5312         }
5313         # We had better clear the $DIR to get enough space for dd
5314         rm -rf $DIR/*
5315         touch $DIR/$tfile
5316         chmod 777 $DIR/$tfile
5317         chmod ug+s $DIR/$tfile
5318         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5319                 error "$RUNAS dd $DIR/$tfile failed"
5320         # See if we are still setuid/sgid
5321         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5322                 error "S/gid is not dropped on write"
5323         # Now test that MDS is updated too
5324         cancel_lru_locks mdc
5325         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5326                 error "S/gid is not dropped on MDS"
5327         rm -f $DIR/$tfile
5328 }
5329 run_test 72a "Test that remove suid works properly (bug5695) ===="
5330
5331 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5332         local perm
5333
5334         [ "$RUNAS_ID" = "$UID" ] && \
5335                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5336         [ "$RUNAS_ID" -eq 0 ] && \
5337                 skip_env "RUNAS_ID = 0 -- skipping" && return
5338
5339         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5340         # Check that testing environment is properly set up. Skip if not
5341         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5342                 skip_env "User $RUNAS_ID does not exist - skipping"
5343                 return 0
5344         }
5345         touch $DIR/${tfile}-f{g,u}
5346         test_mkdir $DIR/${tfile}-dg
5347         test_mkdir $DIR/${tfile}-du
5348         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5349         chmod g+s $DIR/${tfile}-{f,d}g
5350         chmod u+s $DIR/${tfile}-{f,d}u
5351         for perm in 777 2777 4777; do
5352                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5353                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5354                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5355                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5356         done
5357         true
5358 }
5359 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5360
5361 # bug 3462 - multiple simultaneous MDC requests
5362 test_73() {
5363         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5364         test_mkdir $DIR/d73-1
5365         test_mkdir $DIR/d73-2
5366         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5367         pid1=$!
5368
5369         lctl set_param fail_loc=0x80000129
5370         $MULTIOP $DIR/d73-1/f73-2 Oc &
5371         sleep 1
5372         lctl set_param fail_loc=0
5373
5374         $MULTIOP $DIR/d73-2/f73-3 Oc &
5375         pid3=$!
5376
5377         kill -USR1 $pid1
5378         wait $pid1 || return 1
5379
5380         sleep 25
5381
5382         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5383         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5384         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5385
5386         rm -rf $DIR/d73-*
5387 }
5388 run_test 73 "multiple MDC requests (should not deadlock)"
5389
5390 test_74a() { # bug 6149, 6184
5391         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5392         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5393         #
5394         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5395         # will spin in a tight reconnection loop
5396         touch $DIR/f74a
5397         $LCTL set_param fail_loc=0x8000030e
5398         # get any lock that won't be difficult - lookup works.
5399         ls $DIR/f74a
5400         $LCTL set_param fail_loc=0
5401         rm -f $DIR/f74a
5402         true
5403 }
5404 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5405
5406 test_74b() { # bug 13310
5407         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5408         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5409         #
5410         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5411         # will spin in a tight reconnection loop
5412         $LCTL set_param fail_loc=0x8000030e
5413         # get a "difficult" lock
5414         touch $DIR/f74b
5415         $LCTL set_param fail_loc=0
5416         rm -f $DIR/f74b
5417         true
5418 }
5419 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5420
5421 test_74c() {
5422         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5423         #define OBD_FAIL_LDLM_NEW_LOCK
5424         $LCTL set_param fail_loc=0x319
5425         touch $DIR/$tfile && error "touch successful"
5426         $LCTL set_param fail_loc=0
5427         true
5428 }
5429 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5430
5431 num_inodes() {
5432         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5433 }
5434
5435 get_inode_slab_tunables() {
5436         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5437 }
5438
5439 set_inode_slab_tunables() {
5440         echo "lustre_inode_cache $1" > /proc/slabinfo
5441 }
5442
5443 test_76() { # Now for bug 20433, added originally in bug 1443
5444         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5445         local SLAB_SETTINGS=`get_inode_slab_tunables`
5446         local CPUS=`getconf _NPROCESSORS_ONLN`
5447         # we cannot set limit below 1 which means 1 inode in each
5448         # per-cpu cache is still allowed
5449         set_inode_slab_tunables "1 1 0"
5450         cancel_lru_locks osc
5451         BEFORE_INODES=$(num_inodes)
5452         echo "before inodes: $BEFORE_INODES"
5453         local COUNT=1000
5454         [ "$SLOW" = "no" ] && COUNT=100
5455         for i in $(seq $COUNT); do
5456                 touch $DIR/$tfile
5457                 rm -f $DIR/$tfile
5458         done
5459         cancel_lru_locks osc
5460         AFTER_INODES=$(num_inodes)
5461         echo "after inodes: $AFTER_INODES"
5462         local wait=0
5463         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5464                 sleep 2
5465                 AFTER_INODES=$(num_inodes)
5466                 wait=$((wait+2))
5467                 echo "wait $wait seconds inodes: $AFTER_INODES"
5468                 if [ $wait -gt 30 ]; then
5469                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5470                 fi
5471         done
5472         set_inode_slab_tunables "$SLAB_SETTINGS"
5473 }
5474 run_test 76 "confirm clients recycle inodes properly ===="
5475
5476
5477 export ORIG_CSUM=""
5478 set_checksums()
5479 {
5480         # Note: in sptlrpc modes which enable its own bulk checksum, the
5481         # original crc32_le bulk checksum will be automatically disabled,
5482         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5483         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5484         # In this case set_checksums() will not be no-op, because sptlrpc
5485         # bulk checksum will be enabled all through the test.
5486
5487         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5488         lctl set_param -n osc.*.checksums $1
5489         return 0
5490 }
5491
5492 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5493                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5494 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5495 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5496 set_checksum_type()
5497 {
5498         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5499         log "set checksum type to $1"
5500         return 0
5501 }
5502 F77_TMP=$TMP/f77-temp
5503 F77SZ=8
5504 setup_f77() {
5505         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5506                 error "error writing to $F77_TMP"
5507 }
5508
5509 test_77a() { # bug 10889
5510         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5511         $GSS && skip "could not run with gss" && return
5512         [ ! -f $F77_TMP ] && setup_f77
5513         set_checksums 1
5514         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5515         set_checksums 0
5516         rm -f $DIR/$tfile
5517 }
5518 run_test 77a "normal checksum read/write operation"
5519
5520 test_77b() { # bug 10889
5521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5522         $GSS && skip "could not run with gss" && return
5523         [ ! -f $F77_TMP ] && setup_f77
5524         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5525         $LCTL set_param fail_loc=0x80000409
5526         set_checksums 1
5527
5528         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5529                 error "dd error: $?"
5530         $LCTL set_param fail_loc=0
5531
5532         for algo in $CKSUM_TYPES; do
5533                 cancel_lru_locks osc
5534                 set_checksum_type $algo
5535                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5536                 $LCTL set_param fail_loc=0x80000408
5537                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5538                 $LCTL set_param fail_loc=0
5539         done
5540         set_checksums 0
5541         set_checksum_type $ORIG_CSUM_TYPE
5542         rm -f $DIR/$tfile
5543 }
5544 run_test 77b "checksum error on client write, read"
5545
5546 test_77d() { # bug 10889
5547         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5548         $GSS && skip "could not run with gss" && return
5549         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5550         $LCTL set_param fail_loc=0x80000409
5551         set_checksums 1
5552         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5553                 error "direct write: rc=$?"
5554         $LCTL set_param fail_loc=0
5555         set_checksums 0
5556
5557         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5558         $LCTL set_param fail_loc=0x80000408
5559         set_checksums 1
5560         cancel_lru_locks osc
5561         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5562                 error "direct read: rc=$?"
5563         $LCTL set_param fail_loc=0
5564         set_checksums 0
5565 }
5566 run_test 77d "checksum error on OST direct write, read"
5567
5568 test_77f() { # bug 10889
5569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5570         $GSS && skip "could not run with gss" && return
5571         set_checksums 1
5572         for algo in $CKSUM_TYPES; do
5573                 cancel_lru_locks osc
5574                 set_checksum_type $algo
5575                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5576                 $LCTL set_param fail_loc=0x409
5577                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5578                         error "direct write succeeded"
5579                 $LCTL set_param fail_loc=0
5580         done
5581         set_checksum_type $ORIG_CSUM_TYPE
5582         set_checksums 0
5583 }
5584 run_test 77f "repeat checksum error on write (expect error)"
5585
5586 test_77g() { # bug 10889
5587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5588         $GSS && skip "could not run with gss" && return
5589         remote_ost_nodsh && skip "remote OST with nodsh" && return
5590
5591         [ ! -f $F77_TMP ] && setup_f77
5592
5593         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5594         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5595         do_facet ost1 lctl set_param fail_loc=0x8000021a
5596         set_checksums 1
5597         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5598                 error "write error: rc=$?"
5599         do_facet ost1 lctl set_param fail_loc=0
5600         set_checksums 0
5601
5602         cancel_lru_locks osc
5603         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5604         do_facet ost1 lctl set_param fail_loc=0x8000021b
5605         set_checksums 1
5606         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5607         do_facet ost1 lctl set_param fail_loc=0
5608         set_checksums 0
5609 }
5610 run_test 77g "checksum error on OST write, read"
5611
5612 test_77i() { # bug 13805
5613         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5614         $GSS && skip "could not run with gss" && return
5615         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5616         lctl set_param fail_loc=0x40b
5617         remount_client $MOUNT
5618         lctl set_param fail_loc=0
5619         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5620                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5621                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5622                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5623         done
5624         remount_client $MOUNT
5625 }
5626 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5627
5628 test_77j() { # bug 13805
5629         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5630         $GSS && skip "could not run with gss" && return
5631         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5632         lctl set_param fail_loc=0x40c
5633         remount_client $MOUNT
5634         lctl set_param fail_loc=0
5635         sleep 2 # wait async osc connect to finish
5636         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5637                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5638                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5639                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5640         done
5641         remount_client $MOUNT
5642 }
5643 run_test 77j "client only supporting ADLER32"
5644
5645 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5646 rm -f $F77_TMP
5647 unset F77_TMP
5648
5649 test_78() { # bug 10901
5650         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5651         remote_ost || { skip_env "local OST" && return; }
5652
5653         NSEQ=5
5654         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5655         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5656         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5657         echo "MemTotal: $MEMTOTAL"
5658
5659         # reserve 256MB of memory for the kernel and other running processes,
5660         # and then take 1/2 of the remaining memory for the read/write buffers.
5661         if [ $MEMTOTAL -gt 512 ] ;then
5662                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5663         else
5664                 # for those poor memory-starved high-end clusters...
5665                 MEMTOTAL=$((MEMTOTAL / 2))
5666         fi
5667         echo "Mem to use for directio: $MEMTOTAL"
5668
5669         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5670         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5671         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5672         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5673                 head -n1)
5674         echo "Smallest OST: $SMALLESTOST"
5675         [[ $SMALLESTOST -lt 10240 ]] &&
5676                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5677
5678         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5679                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5680
5681         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5682         echo "File size: $F78SIZE"
5683         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5684         for i in $(seq 1 $NSEQ); do
5685                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5686                 echo directIO rdwr round $i of $NSEQ
5687                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5688         done
5689
5690         rm -f $DIR/$tfile
5691 }
5692 run_test 78 "handle large O_DIRECT writes correctly ============"
5693
5694 test_79() { # bug 12743
5695         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5696         wait_delete_completed
5697
5698         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5699         BKFREE=$(calc_osc_kbytes kbytesfree)
5700         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5701
5702         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5703         DFTOTAL=`echo $STRING | cut -d, -f1`
5704         DFUSED=`echo $STRING  | cut -d, -f2`
5705         DFAVAIL=`echo $STRING | cut -d, -f3`
5706         DFFREE=$(($DFTOTAL - $DFUSED))
5707
5708         ALLOWANCE=$((64 * $OSTCOUNT))
5709
5710         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5711            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5712                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5713         fi
5714         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5715            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5716                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5717         fi
5718         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5719            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5720                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5721         fi
5722 }
5723 run_test 79 "df report consistency check ======================="
5724
5725 test_80() { # bug 10718
5726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5727         # relax strong synchronous semantics for slow backends like ZFS
5728         local soc="obdfilter.*.sync_on_lock_cancel"
5729         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5730         local hosts=
5731         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5732                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5733                           facet_active_host $host; done | sort -u)
5734                 do_nodes $hosts lctl set_param $soc=never
5735         fi
5736
5737         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5738         sync; sleep 1; sync
5739         local BEFORE=`date +%s`
5740         cancel_lru_locks osc
5741         local AFTER=`date +%s`
5742         local DIFF=$((AFTER-BEFORE))
5743         if [ $DIFF -gt 1 ] ; then
5744                 error "elapsed for 1M@1T = $DIFF"
5745         fi
5746
5747         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5748
5749         rm -f $DIR/$tfile
5750 }
5751 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5752
5753 test_81a() { # LU-456
5754         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5755         remote_ost_nodsh && skip "remote OST with nodsh" && return
5756         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5757         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5758         do_facet ost1 lctl set_param fail_loc=0x80000228
5759
5760         # write should trigger a retry and success
5761         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5762         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5763         RC=$?
5764         if [ $RC -ne 0 ] ; then
5765                 error "write should success, but failed for $RC"
5766         fi
5767 }
5768 run_test 81a "OST should retry write when get -ENOSPC ==============="
5769
5770 test_81b() { # LU-456
5771         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5772         remote_ost_nodsh && skip "remote OST with nodsh" && return
5773         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5774         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5775         do_facet ost1 lctl set_param fail_loc=0x228
5776
5777         # write should retry several times and return -ENOSPC finally
5778         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5779         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5780         RC=$?
5781         ENOSPC=28
5782         if [ $RC -ne $ENOSPC ] ; then
5783                 error "dd should fail for -ENOSPC, but succeed."
5784         fi
5785 }
5786 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5787
5788 test_82() { # LU-1031
5789         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5790         local gid1=14091995
5791         local gid2=16022000
5792
5793         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5794         local MULTIPID1=$!
5795         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5796         local MULTIPID2=$!
5797         kill -USR1 $MULTIPID2
5798         sleep 2
5799         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5800                 error "First grouplock does not block second one"
5801         else
5802                 echo "Second grouplock blocks first one"
5803         fi
5804         kill -USR1 $MULTIPID1
5805         wait $MULTIPID1
5806         wait $MULTIPID2
5807 }
5808 run_test 82 "Basic grouplock test ==============================="
5809
5810 test_99a() {
5811         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
5812                 return
5813         test_mkdir -p $DIR/d99cvsroot
5814         chown $RUNAS_ID $DIR/d99cvsroot
5815         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
5816         cd $TMP
5817
5818         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
5819         cd $oldPWD
5820 }
5821 run_test 99a "cvs init ========================================="
5822
5823 test_99b() {
5824         [ -z "$(which cvs 2>/dev/null)" ] &&
5825                 skip_env "could not find cvs" && return
5826         [ ! -d $DIR/d99cvsroot ] && test_99a
5827         cd /etc/init.d
5828         # some versions of cvs import exit(1) when asked to import links or
5829         # files they can't read.  ignore those files.
5830         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
5831                         ! -perm +4 -printf '-I %f\n')
5832         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
5833                 d99reposname vtag rtag
5834 }
5835 run_test 99b "cvs import ======================================="
5836
5837 test_99c() {
5838         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5839         [ ! -d $DIR/d99cvsroot ] && test_99b
5840         cd $DIR
5841         test_mkdir -p $DIR/d99reposname
5842         chown $RUNAS_ID $DIR/d99reposname
5843         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
5844 }
5845 run_test 99c "cvs checkout ====================================="
5846
5847 test_99d() {
5848         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5849         [ ! -d $DIR/d99cvsroot ] && test_99c
5850         cd $DIR/d99reposname
5851         $RUNAS touch foo99
5852         $RUNAS cvs add -m 'addmsg' foo99
5853 }
5854 run_test 99d "cvs add =========================================="
5855
5856 test_99e() {
5857         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5858         [ ! -d $DIR/d99cvsroot ] && test_99c
5859         cd $DIR/d99reposname
5860         $RUNAS cvs update
5861 }
5862 run_test 99e "cvs update ======================================="
5863
5864 test_99f() {
5865         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5866         [ ! -d $DIR/d99cvsroot ] && test_99d
5867         cd $DIR/d99reposname
5868         $RUNAS cvs commit -m 'nomsg' foo99
5869     rm -fr $DIR/d99cvsroot
5870 }
5871 run_test 99f "cvs commit ======================================="
5872
5873 test_100() {
5874         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5875         [ "$NETTYPE" = tcp ] || \
5876                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
5877                         return ; }
5878
5879         remote_ost_nodsh && skip "remote OST with nodsh" && return
5880         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5881         remote_servers || \
5882                 { skip "useless for local single node setup" && return; }
5883
5884         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
5885                 [ "$PROT" != "tcp" ] && continue
5886                 RPORT=$(echo $REMOTE | cut -d: -f2)
5887                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
5888
5889                 rc=0
5890                 LPORT=`echo $LOCAL | cut -d: -f2`
5891                 if [ $LPORT -ge 1024 ]; then
5892                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
5893                         netstat -tna
5894                         error_exit "local: $LPORT > 1024, remote: $RPORT"
5895                 fi
5896         done
5897         [ "$rc" = 0 ] || error_exit "privileged port not found" )
5898 }
5899 run_test 100 "check local port using privileged port ==========="
5900
5901 function get_named_value()
5902 {
5903     local tag
5904
5905     tag=$1
5906     while read ;do
5907         line=$REPLY
5908         case $line in
5909         $tag*)
5910             echo $line | sed "s/^$tag[ ]*//"
5911             break
5912             ;;
5913         esac
5914     done
5915 }
5916
5917 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
5918                    awk '/^max_cached_mb/ { print $2 }')
5919
5920 cleanup_101a() {
5921         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
5922         trap 0
5923 }
5924
5925 test_101a() {
5926         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5927         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
5928         local s
5929         local discard
5930         local nreads=10000
5931         local cache_limit=32
5932
5933         $LCTL set_param -n osc.*-osc*.rpc_stats 0
5934         trap cleanup_101a EXIT
5935         $LCTL set_param -n llite.*.read_ahead_stats 0
5936         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
5937
5938         #
5939         # randomly read 10000 of 64K chunks from file 3x 32MB in size
5940         #
5941         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
5942         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
5943
5944         discard=0
5945         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
5946                 get_named_value 'read but discarded' | cut -d" " -f1); do
5947                         discard=$(($discard + $s))
5948         done
5949         cleanup_101a
5950
5951         if [[ $(($discard * 10)) -gt $nreads ]]; then
5952                 $LCTL get_param osc.*-osc*.rpc_stats
5953                 $LCTL get_param llite.*.read_ahead_stats
5954                 error "too many ($discard) discarded pages"
5955         fi
5956         rm -f $DIR/$tfile || true
5957 }
5958 run_test 101a "check read-ahead for random reads ================"
5959
5960 setup_test101bc() {
5961         test_mkdir -p $DIR/$tdir
5962         local STRIPE_SIZE=$1
5963         local FILE_LENGTH=$2
5964         STRIPE_OFFSET=0
5965
5966         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
5967
5968         local list=$(comma_list $(osts_nodes))
5969         set_osd_param $list '' read_cache_enable 0
5970         set_osd_param $list '' writethrough_cache_enable 0
5971
5972         trap cleanup_test101bc EXIT
5973         # prepare the read-ahead file
5974         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
5975
5976         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
5977                                 count=$FILE_SIZE_MB 2> /dev/null
5978
5979 }
5980
5981 cleanup_test101bc() {
5982         trap 0
5983         rm -rf $DIR/$tdir
5984         rm -f $DIR/$tfile
5985
5986         local list=$(comma_list $(osts_nodes))
5987         set_osd_param $list '' read_cache_enable 1
5988         set_osd_param $list '' writethrough_cache_enable 1
5989 }
5990
5991 calc_total() {
5992         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
5993 }
5994
5995 ra_check_101() {
5996         local READ_SIZE=$1
5997         local STRIPE_SIZE=$2
5998         local FILE_LENGTH=$3
5999         local RA_INC=1048576
6000         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6001         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6002                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6003         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6004                         get_named_value 'read but discarded' |
6005                         cut -d" " -f1 | calc_total)
6006         if [[ $DISCARD -gt $discard_limit ]]; then
6007                 $LCTL get_param llite.*.read_ahead_stats
6008                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6009         else
6010                 echo "Read-ahead success for size ${READ_SIZE}"
6011         fi
6012 }
6013
6014 test_101b() {
6015         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6016         [[ $OSTCOUNT -lt 2 ]] &&
6017                 skip_env "skipping stride IO stride-ahead test" && return
6018         local STRIPE_SIZE=1048576
6019         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6020         if [ $SLOW == "yes" ]; then
6021                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6022         else
6023                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6024         fi
6025
6026         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6027
6028         # prepare the read-ahead file
6029         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6030         cancel_lru_locks osc
6031         for BIDX in 2 4 8 16 32 64 128 256
6032         do
6033                 local BSIZE=$((BIDX*4096))
6034                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6035                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6036                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6037                 $LCTL set_param -n llite.*.read_ahead_stats 0
6038                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6039                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6040                 cancel_lru_locks osc
6041                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6042         done
6043         cleanup_test101bc
6044         true
6045 }
6046 run_test 101b "check stride-io mode read-ahead ================="
6047
6048 test_101c() {
6049         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6050         local STRIPE_SIZE=1048576
6051         local FILE_LENGTH=$((STRIPE_SIZE*100))
6052         local nreads=10000
6053         local osc_rpc_stats
6054
6055         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6056
6057         cancel_lru_locks osc
6058         $LCTL set_param osc.*.rpc_stats 0
6059         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6060         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6061                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6062                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6063                 local size
6064
6065                 if [ $lines -le 20 ]; then
6066                         continue
6067                 fi
6068                 for size in 1 2 4 8; do
6069                         local rpc=$(echo "$stats" |
6070                                     awk '($1 == "'$size':") {print $2; exit; }')
6071                         [ $rpc != 0 ] &&
6072                                 error "Small $((size*4))k read IO $rpc !"
6073                 done
6074                 echo "$osc_rpc_stats check passed!"
6075         done
6076         cleanup_test101bc
6077         true
6078 }
6079 run_test 101c "check stripe_size aligned read-ahead ================="
6080
6081 set_read_ahead() {
6082         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6083         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6084 }
6085
6086 test_101d() {
6087         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6088         local file=$DIR/$tfile
6089         local sz_MB=${FILESIZE_101d:-500}
6090         local ra_MB=${READAHEAD_MB:-40}
6091
6092         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6093         [ $free_MB -lt $sz_MB ] &&
6094                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6095
6096         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6097         $SETSTRIPE -c -1 $file || error "setstripe failed"
6098
6099         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6100         echo Cancel LRU locks on lustre client to flush the client cache
6101         cancel_lru_locks osc
6102
6103         echo Disable read-ahead
6104         local old_READAHEAD=$(set_read_ahead 0)
6105
6106         echo Reading the test file $file with read-ahead disabled
6107         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6108
6109         echo Cancel LRU locks on lustre client to flush the client cache
6110         cancel_lru_locks osc
6111         echo Enable read-ahead with ${ra_MB}MB
6112         set_read_ahead $ra_MB
6113
6114         echo Reading the test file $file with read-ahead enabled
6115         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6116
6117         echo "read-ahead disabled time read $raOFF"
6118         echo "read-ahead enabled  time read $raON"
6119
6120         set_read_ahead $old_READAHEAD
6121         rm -f $file
6122         wait_delete_completed
6123
6124         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6125                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6126 }
6127 run_test 101d "file read with and without read-ahead enabled"
6128
6129 test_101e() {
6130         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6131         local file=$DIR/$tfile
6132         local size_KB=500  #KB
6133         local count=100
6134         local bsize=1024
6135
6136         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6137         local need_KB=$((count * size_KB))
6138         [[ $free_KB -le $need_KB ]] &&
6139                 skip_env "Need free space $need_KB, have $free_KB" && return
6140
6141         echo "Creating $count ${size_KB}K test files"
6142         for ((i = 0; i < $count; i++)); do
6143                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6144         done
6145
6146         echo "Cancel LRU locks on lustre client to flush the client cache"
6147         cancel_lru_locks osc
6148
6149         echo "Reset readahead stats"
6150         $LCTL set_param -n llite.*.read_ahead_stats 0
6151
6152         for ((i = 0; i < $count; i++)); do
6153                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6154         done
6155
6156         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6157                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6158
6159         for ((i = 0; i < $count; i++)); do
6160                 rm -rf $file.$i 2>/dev/null
6161         done
6162
6163         #10000 means 20% reads are missing in readahead
6164         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6165 }
6166 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6167
6168 cleanup_test101f() {
6169     trap 0
6170     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6171     rm -rf $DIR/$tfile 2>/dev/null
6172 }
6173
6174 test_101f() {
6175         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6176     local file=$DIR/$tfile
6177     local nreads=1000
6178
6179     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6180     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6181     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6182     trap cleanup_test101f EXIT
6183
6184     echo Cancel LRU locks on lustre client to flush the client cache
6185     cancel_lru_locks osc
6186
6187     echo Reset readahead stats
6188     $LCTL set_param -n llite.*.read_ahead_stats 0
6189     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6190     # readahead should read in 2M file on second read, so only miss
6191     # 2 pages.
6192     echo Random 4K reads on 2M file for 1000 times
6193     $READS -f $file -s 2097152 -b 4096 -n $nreads
6194
6195     echo checking missing pages
6196     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6197           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6198
6199     [ $miss -lt 3 ] || error "misses too much pages!"
6200     cleanup_test101f
6201 }
6202 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6203
6204 setup_test102() {
6205         test_mkdir -p $DIR/$tdir
6206         chown $RUNAS_ID $DIR/$tdir
6207         STRIPE_SIZE=65536
6208         STRIPE_OFFSET=1
6209         STRIPE_COUNT=$OSTCOUNT
6210         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6211
6212         trap cleanup_test102 EXIT
6213         cd $DIR
6214         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6215         cd $DIR/$tdir
6216         for num in 1 2 3 4; do
6217                 for count in $(seq 1 $STRIPE_COUNT); do
6218                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6219                                 local size=`expr $STRIPE_SIZE \* $num`
6220                                 local file=file"$num-$idx-$count"
6221                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6222                         done
6223                 done
6224         done
6225
6226         cd $DIR
6227         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6228 }
6229
6230 cleanup_test102() {
6231         trap 0
6232         rm -f $TMP/f102.tar
6233         rm -rf $DIR/d0.sanity/d102
6234 }
6235
6236 test_102a() {
6237         local testfile=$DIR/xattr_testfile
6238
6239         touch $testfile
6240
6241         [ "$UID" != 0 ] && skip_env "must run as root" && return
6242         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6243                 skip_env "must have user_xattr" && return
6244
6245         [ -z "$(which setfattr 2>/dev/null)" ] &&
6246                 skip_env "could not find setfattr" && return
6247
6248         echo "set/get xattr..."
6249         setfattr -n trusted.name1 -v value1 $testfile ||
6250                 error "setfattr -n trusted.name1=value1 $testfile failed"
6251         getfattr -n trusted.name1 $testfile 2> /dev/null |
6252           grep "trusted.name1=.value1" ||
6253                 error "$testfile missing trusted.name1=value1"
6254
6255         setfattr -n user.author1 -v author1 $testfile ||
6256                 error "setfattr -n user.author1=author1 $testfile failed"
6257         getfattr -n user.author1 $testfile 2> /dev/null |
6258           grep "user.author1=.author1" ||
6259                 error "$testfile missing trusted.author1=author1"
6260
6261         echo "listxattr..."
6262         setfattr -n trusted.name2 -v value2 $testfile ||
6263                 error "$testfile unable to set trusted.name2"
6264         setfattr -n trusted.name3 -v value3 $testfile ||
6265                 error "$testfile unable to set trusted.name3"
6266         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6267             grep "trusted.name" | wc -l) -eq 3 ] ||
6268                 error "$testfile missing 3 trusted.name xattrs"
6269
6270         setfattr -n user.author2 -v author2 $testfile ||
6271                 error "$testfile unable to set user.author2"
6272         setfattr -n user.author3 -v author3 $testfile ||
6273                 error "$testfile unable to set user.author3"
6274         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6275             grep "user.author" | wc -l) -eq 3 ] ||
6276                 error "$testfile missing 3 user.author xattrs"
6277
6278         echo "remove xattr..."
6279         setfattr -x trusted.name1 $testfile ||
6280                 error "$testfile error deleting trusted.name1"
6281         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6282                 error "$testfile did not delete trusted.name1 xattr"
6283
6284         setfattr -x user.author1 $testfile ||
6285                 error "$testfile error deleting user.author1"
6286         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6287                 error "$testfile did not delete trusted.name1 xattr"
6288
6289         # b10667: setting lustre special xattr be silently discarded
6290         echo "set lustre special xattr ..."
6291         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6292                 error "$testfile allowed setting trusted.lov"
6293 }
6294 run_test 102a "user xattr test =================================="
6295
6296 test_102b() {
6297         [ -z "$(which setfattr 2>/dev/null)" ] &&
6298                 skip_env "could not find setfattr" && return
6299
6300         # b10930: get/set/list trusted.lov xattr
6301         echo "get/set/list trusted.lov xattr ..."
6302         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6303         local testfile=$DIR/$tfile
6304         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6305                 error "setstripe failed"
6306         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6307                 error "getstripe failed"
6308         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6309                 error "can't get trusted.lov from $testfile"
6310
6311         local testfile2=${testfile}2
6312         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6313                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6314
6315         $MCREATE $testfile2
6316         setfattr -n trusted.lov -v $value $testfile2
6317         local stripe_size=$($GETSTRIPE -S $testfile2)
6318         local stripe_count=$($GETSTRIPE -c $testfile2)
6319         [[ $stripe_size -eq 65536 ]] ||
6320                 error "stripe size $stripe_size != 65536"
6321         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6322                 error "stripe count $stripe_count != $STRIPECOUNT"
6323         rm -f $DIR/$tfile
6324 }
6325 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6326
6327 test_102c() {
6328         [ -z "$(which setfattr 2>/dev/null)" ] &&
6329                 skip_env "could not find setfattr" && return
6330
6331         # b10930: get/set/list lustre.lov xattr
6332         echo "get/set/list lustre.lov xattr ..."
6333         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6334         test_mkdir -p $DIR/$tdir
6335         chown $RUNAS_ID $DIR/$tdir
6336         local testfile=$DIR/$tdir/$tfile
6337         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6338                 error "setstripe failed"
6339         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6340                 error "getstripe failed"
6341         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6342         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6343
6344         local testfile2=${testfile}2
6345         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6346                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6347
6348         $RUNAS $MCREATE $testfile2
6349         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6350         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6351         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6352         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6353         [ $stripe_count -eq $STRIPECOUNT ] ||
6354                 error "stripe count $stripe_count != $STRIPECOUNT"
6355 }
6356 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6357
6358 compare_stripe_info1() {
6359         local stripe_index_all_zero=true
6360
6361         for num in 1 2 3 4; do
6362                 for count in $(seq 1 $STRIPE_COUNT); do
6363                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6364                                 local size=$((STRIPE_SIZE * num))
6365                                 local file=file"$num-$offset-$count"
6366                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6367                                 [[ $stripe_size -ne $size ]] &&
6368                                     error "$file: size $stripe_size != $size"
6369                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6370                                 # allow fewer stripes to be created, ORI-601
6371                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6372                                     error "$file: count $stripe_count != $count"
6373                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6374                                 [[ $stripe_index -ne 0 ]] &&
6375                                         stripe_index_all_zero=false
6376                         done
6377                 done
6378         done
6379         $stripe_index_all_zero &&
6380                 error "all files are being extracted starting from OST index 0"
6381         return 0
6382 }
6383
6384 find_lustre_tar() {
6385         [ -n "$(which tar 2>/dev/null)" ] &&
6386                 strings $(which tar) | grep -q "lustre" && echo tar
6387 }
6388
6389 test_102d() {
6390         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6391         # b10930: tar test for trusted.lov xattr
6392         TAR=$(find_lustre_tar)
6393         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6394         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6395         setup_test102
6396         test_mkdir -p $DIR/d102d
6397         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6398         cd $DIR/d102d/$tdir
6399         compare_stripe_info1
6400 }
6401 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6402
6403 test_102f() {
6404         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6405         # b10930: tar test for trusted.lov xattr
6406         TAR=$(find_lustre_tar)
6407         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6408         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6409         setup_test102
6410         test_mkdir -p $DIR/d102f
6411         cd $DIR
6412         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6413         cd $DIR/d102f/$tdir
6414         compare_stripe_info1
6415 }
6416 run_test 102f "tar copy files, not keep osts ==========="
6417
6418 grow_xattr() {
6419         local xsize=${1:-1024}  # in bytes
6420         local file=$DIR/$tfile
6421
6422         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6423                 skip "must have user_xattr" && return 0
6424         [ -z "$(which setfattr 2>/dev/null)" ] &&
6425                 skip_env "could not find setfattr" && return 0
6426         [ -z "$(which getfattr 2>/dev/null)" ] &&
6427                 skip_env "could not find getfattr" && return 0
6428
6429         touch $file
6430
6431         local value="$(generate_string $xsize)"
6432
6433         local xbig=trusted.big
6434         log "save $xbig on $file"
6435         setfattr -n $xbig -v $value $file ||
6436                 error "saving $xbig on $file failed"
6437
6438         local orig=$(get_xattr_value $xbig $file)
6439         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6440
6441         local xsml=trusted.sml
6442         log "save $xsml on $file"
6443         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6444
6445         local new=$(get_xattr_value $xbig $file)
6446         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6447
6448         log "grow $xsml on $file"
6449         setfattr -n $xsml -v "$value" $file ||
6450                 error "growing $xsml on $file failed"
6451
6452         new=$(get_xattr_value $xbig $file)
6453         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6454         log "$xbig still valid after growing $xsml"
6455
6456         rm -f $file
6457 }
6458
6459 test_102h() { # bug 15777
6460         grow_xattr 1024
6461 }
6462 run_test 102h "grow xattr from inside inode to external block"
6463
6464 test_102ha() {
6465         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6466         grow_xattr $(max_xattr_size)
6467 }
6468 run_test 102ha "grow xattr from inside inode to external inode"
6469
6470 test_102i() { # bug 17038
6471         [ -z "$(which getfattr 2>/dev/null)" ] &&
6472                 skip "could not find getfattr" && return
6473         touch $DIR/$tfile
6474         ln -s $DIR/$tfile $DIR/${tfile}link
6475         getfattr -n trusted.lov $DIR/$tfile ||
6476                 error "lgetxattr on $DIR/$tfile failed"
6477         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6478                 grep -i "no such attr" ||
6479                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6480         rm -f $DIR/$tfile $DIR/${tfile}link
6481 }
6482 run_test 102i "lgetxattr test on symbolic link ============"
6483
6484 test_102j() {
6485         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6486         TAR=$(find_lustre_tar)
6487         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6488         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6489         setup_test102 "$RUNAS"
6490         test_mkdir -p $DIR/d102j
6491         chown $RUNAS_ID $DIR/d102j
6492         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6493         cd $DIR/d102j/$tdir
6494         compare_stripe_info1 "$RUNAS"
6495 }
6496 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6497
6498 test_102k() {
6499         [ -z "$(which setfattr 2>/dev/null)" ] &&
6500                 skip "could not find setfattr" && return
6501         touch $DIR/$tfile
6502         # b22187 just check that does not crash for regular file.
6503         setfattr -n trusted.lov $DIR/$tfile
6504         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6505         local test_kdir=$DIR/d102k
6506         test_mkdir $test_kdir
6507         local default_size=`$GETSTRIPE -S $test_kdir`
6508         local default_count=`$GETSTRIPE -c $test_kdir`
6509         local default_offset=`$GETSTRIPE -i $test_kdir`
6510         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6511                 error 'dir setstripe failed'
6512         setfattr -n trusted.lov $test_kdir
6513         local stripe_size=`$GETSTRIPE -S $test_kdir`
6514         local stripe_count=`$GETSTRIPE -c $test_kdir`
6515         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6516         [ $stripe_size -eq $default_size ] ||
6517                 error "stripe size $stripe_size != $default_size"
6518         [ $stripe_count -eq $default_count ] ||
6519                 error "stripe count $stripe_count != $default_count"
6520         [ $stripe_offset -eq $default_offset ] ||
6521                 error "stripe offset $stripe_offset != $default_offset"
6522         rm -rf $DIR/$tfile $test_kdir
6523 }
6524 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6525
6526 test_102l() {
6527         [ -z "$(which getfattr 2>/dev/null)" ] &&
6528                 skip "could not find getfattr" && return
6529
6530         # LU-532 trusted. xattr is invisible to non-root
6531         local testfile=$DIR/$tfile
6532
6533         touch $testfile
6534
6535         echo "listxattr as user..."
6536         chown $RUNAS_ID $testfile
6537         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6538             grep -q "trusted" &&
6539                 error "$testfile trusted xattrs are user visible"
6540
6541         return 0;
6542 }
6543 run_test 102l "listxattr size test =================================="
6544
6545 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6546         local path=$DIR/$tfile
6547         touch $path
6548
6549         listxattr_size_check $path || error "listattr_size_check $path failed"
6550 }
6551 run_test 102m "Ensure listxattr fails on small bufffer ========"
6552
6553 cleanup_test102
6554
6555 getxattr() { # getxattr path name
6556         # Return the base64 encoding of the value of xattr name on path.
6557         local path=$1
6558         local name=$2
6559
6560         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6561         # file: $path
6562         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6563         #
6564         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6565
6566         getfattr --absolute-names --encoding=base64 --name=$name $path |
6567                 awk -F= -v name=$name '$1 == name {
6568                         print substr($0, index($0, "=") + 1);
6569         }'
6570 }
6571
6572 test_102n() { # LU-4101 mdt: protect internal xattrs
6573         local file0=$DIR/$tfile.0
6574         local file1=$DIR/$tfile.1
6575         local xattr0=$TMP/$tfile.0
6576         local xattr1=$TMP/$tfile.1
6577         local name
6578         local value
6579
6580         [ -z "$(which setfattr 2>/dev/null)" ] &&
6581                 skip "could not find setfattr" && return
6582
6583         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6584         then
6585                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6586                 return
6587         fi
6588
6589         rm -rf $file0 $file1 $xattr0 $xattr1
6590         touch $file0 $file1
6591
6592         # Get 'before' xattrs of $file1.
6593         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6594
6595         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6596                 # Try to copy xattr from $file0 to $file1.
6597                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6598
6599                 setfattr --name=trusted.$name --value="$value" $file1 ||
6600                         error "setxattr 'trusted.$name' failed"
6601
6602                 # Try to set a garbage xattr.
6603                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6604
6605                 setfattr --name=trusted.$name --value="$value" $file1 ||
6606                         error "setxattr 'trusted.$name' failed"
6607
6608                 # Try to remove the xattr from $file1. We don't care if this
6609                 # appears to succeed or fail, we just don't want there to be
6610                 # any changes or crashes.
6611                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6612         done
6613
6614         # Get 'after' xattrs of file1.
6615         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6616
6617         if ! diff $xattr0 $xattr1; then
6618                 error "before and after xattrs of '$file1' differ"
6619         fi
6620
6621         rm -rf $file0 $file1 $xattr0 $xattr1
6622
6623         return 0
6624 }
6625 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6626
6627 test_102p() { # LU-4703 setxattr did not check ownership
6628         local testfile=$DIR/$tfile
6629
6630         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6631                 skip "MDS needs to be at least 2.5.56" && return
6632
6633         touch $testfile
6634
6635         echo "setfacl as user..."
6636         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6637         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6638
6639         echo "setfattr as user..."
6640         setfacl -m "u:$RUNAS_ID:---" $testfile
6641         $RUNAS setfattr -x system.posix_acl_access $testfile
6642         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6643 }
6644 run_test 102p "check setxattr(2) correctly fails without permission"
6645
6646 run_acl_subtest()
6647 {
6648     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6649     return $?
6650 }
6651
6652 test_103 () {
6653         [ "$UID" != 0 ] && skip_env "must run as root" && return
6654         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6655                 skip "must have acl enabled" && return
6656         [ -z "$(which setfacl 2>/dev/null)" ] &&
6657                 skip_env "could not find setfacl" && return
6658         $GSS && skip "could not run under gss" && return
6659
6660         declare -a identity_old
6661
6662         for num in $(seq $MDSCOUNT); do
6663                 switch_identity $num true || identity_old[$num]=$?
6664         done
6665
6666         SAVE_UMASK=$(umask)
6667         umask 0022
6668         cd $DIR
6669
6670         echo "performing cp ..."
6671         run_acl_subtest cp || error "run_acl_subtest cp failed"
6672         echo "performing getfacl-noacl..."
6673         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6674         echo "performing misc..."
6675         run_acl_subtest misc || error  "misc test failed"
6676         echo "performing permissions..."
6677         run_acl_subtest permissions || error "permissions failed"
6678         echo "performing setfacl..."
6679         run_acl_subtest setfacl || error  "setfacl test failed"
6680
6681         # inheritance test got from HP
6682         echo "performing inheritance..."
6683         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6684         chmod +x make-tree || error "chmod +x failed"
6685         run_acl_subtest inheritance || error "inheritance test failed"
6686         rm -f make-tree
6687
6688         echo "LU-974 ignore umask when acl is enabled..."
6689         run_acl_subtest 974 || error "LU-974 umask test failed"
6690         if [ $MDSCOUNT -ge 2 ]; then
6691                 run_acl_subtest 974_remote ||
6692                         error "LU-974 umask test failed under remote dir"
6693         fi
6694
6695         echo "LU-2561 newly created file is same size as directory..."
6696         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6697                 run_acl_subtest 2561 || error "LU-2561 test failed"
6698         else
6699                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6700         fi
6701
6702         cd $SAVE_PWD
6703         umask $SAVE_UMASK
6704
6705         for num in $(seq $MDSCOUNT); do
6706                 if [ "${identity_old[$num]}" = 1 ]; then
6707                         switch_identity $num false || identity_old[$num]=$?
6708                 fi
6709         done
6710 }
6711 run_test 103 "acl test ========================================="
6712
6713 test_104a() {
6714         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6715         touch $DIR/$tfile
6716         lfs df || error "lfs df failed"
6717         lfs df -ih || error "lfs df -ih failed"
6718         lfs df -h $DIR || error "lfs df -h $DIR failed"
6719         lfs df -i $DIR || error "lfs df -i $DIR failed"
6720         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6721         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6722
6723         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6724         lctl --device %$OSC deactivate
6725         lfs df || error "lfs df with deactivated OSC failed"
6726         lctl --device %$OSC activate
6727         # wait the osc back to normal
6728         wait_osc_import_state client ost FULL
6729
6730         lfs df || error "lfs df with reactivated OSC failed"
6731         rm -f $DIR/$tfile
6732 }
6733 run_test 104a "lfs df [-ih] [path] test ========================="
6734
6735 test_104b() {
6736         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6737         [ $RUNAS_ID -eq $UID ] &&
6738                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6739         chmod 666 /dev/obd
6740         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6741                         grep "Permission denied" | wc -l)))
6742         if [ $denied_cnt -ne 0 ]; then
6743                 error "lfs check servers test failed"
6744         fi
6745 }
6746 run_test 104b "$RUNAS lfs check servers test ===================="
6747
6748 test_105a() {
6749         # doesn't work on 2.4 kernels
6750         touch $DIR/$tfile
6751         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6752                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
6753         else
6754                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
6755         fi
6756         rm -f $DIR/$tfile
6757 }
6758 run_test 105a "flock when mounted without -o flock test ========"
6759
6760 test_105b() {
6761         touch $DIR/$tfile
6762         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6763                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
6764         else
6765                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
6766         fi
6767         rm -f $DIR/$tfile
6768 }
6769 run_test 105b "fcntl when mounted without -o flock test ========"
6770
6771 test_105c() {
6772         touch $DIR/$tfile
6773         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6774                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
6775         else
6776                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
6777         fi
6778         rm -f $DIR/$tfile
6779 }
6780 run_test 105c "lockf when mounted without -o flock test ========"
6781
6782 test_105d() { # bug 15924
6783         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6784         test_mkdir -p $DIR/$tdir
6785         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6786                 skip "mount w/o flock enabled" && return
6787         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
6788         $LCTL set_param fail_loc=0x80000315
6789         flocks_test 2 $DIR/$tdir
6790 }
6791 run_test 105d "flock race (should not freeze) ========"
6792
6793 test_105e() { # bug 22660 && 22040
6794         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6795                 skip "mount w/o flock enabled" && return
6796         touch $DIR/$tfile
6797         flocks_test 3 $DIR/$tfile
6798 }
6799 run_test 105e "Two conflicting flocks from same process ======="
6800
6801 test_106() { #bug 10921
6802         test_mkdir -p $DIR/$tdir
6803         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
6804         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
6805 }
6806 run_test 106 "attempt exec of dir followed by chown of that dir"
6807
6808 test_107() {
6809         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6810         CDIR=`pwd`
6811         cd $DIR
6812
6813         local file=core
6814         rm -f $file
6815
6816         local save_pattern=$(sysctl -n kernel.core_pattern)
6817         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
6818         sysctl -w kernel.core_pattern=$file
6819         sysctl -w kernel.core_uses_pid=0
6820
6821         ulimit -c unlimited
6822         sleep 60 &
6823         SLEEPPID=$!
6824
6825         sleep 1
6826
6827         kill -s 11 $SLEEPPID
6828         wait $SLEEPPID
6829         if [ -e $file ]; then
6830                 size=`stat -c%s $file`
6831                 [ $size -eq 0 ] && error "Fail to create core file $file"
6832         else
6833                 error "Fail to create core file $file"
6834         fi
6835         rm -f $file
6836         sysctl -w kernel.core_pattern=$save_pattern
6837         sysctl -w kernel.core_uses_pid=$save_uses_pid
6838         cd $CDIR
6839 }
6840 run_test 107 "Coredump on SIG"
6841
6842 test_110() {
6843         test_mkdir -p $DIR/$tdir
6844         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
6845                 error "mkdir with 255 char failed"
6846         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
6847                 error "mkdir with 256 char should fail, but did not"
6848         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
6849                 error "create with 255 char failed"
6850         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
6851                 error "create with 256 char should fail, but did not"
6852
6853         ls -l $DIR/$tdir
6854         rm -rf $DIR/$tdir
6855 }
6856 run_test 110 "filename length checking"
6857
6858 test_115() {
6859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6860         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
6861                 tail -1 | cut -c11-20)
6862         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
6863         echo "Starting with $OSTIO_pre threads"
6864
6865         NUMTEST=20000
6866         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
6867         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
6868         echo "$NUMTEST creates/unlinks"
6869         test_mkdir -p $DIR/$tdir
6870         createmany -o $DIR/$tdir/$tfile $NUMTEST
6871         unlinkmany $DIR/$tdir/$tfile $NUMTEST
6872
6873         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
6874                 tail -1 | cut -c11-20)
6875
6876         # don't return an error
6877         [ $OSTIO_post == $OSTIO_pre ] && echo \
6878             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
6879             echo "This may be fine, depending on what ran before this test" &&
6880             echo "and how fast this system is." && return
6881
6882         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
6883 }
6884 run_test 115 "verify dynamic thread creation===================="
6885
6886 free_min_max () {
6887         wait_delete_completed
6888         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
6889         echo OST kbytes available: ${AVAIL[@]}
6890         MAXI=0; MAXV=${AVAIL[0]}
6891         MINI=0; MINV=${AVAIL[0]}
6892         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
6893                 #echo OST $i: ${AVAIL[i]}kb
6894                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
6895                         MAXV=${AVAIL[i]}; MAXI=$i
6896                 fi
6897                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
6898                         MINV=${AVAIL[i]}; MINI=$i
6899                 fi
6900         done
6901         echo Min free space: OST $MINI: $MINV
6902         echo Max free space: OST $MAXI: $MAXV
6903 }
6904
6905 test_116a() { # was previously test_116()
6906         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6907         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
6908
6909         echo -n "Free space priority "
6910         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
6911                 head -n1
6912         declare -a AVAIL
6913         free_min_max
6914
6915         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
6916         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
6917                 && return
6918         trap simple_cleanup_common EXIT
6919
6920
6921         # Check if we need to generate uneven OSTs
6922         test_mkdir -p $DIR/$tdir/OST${MINI}
6923         local FILL=$(($MINV / 4))
6924         local DIFF=$(($MAXV - $MINV))
6925         local DIFF2=$(($DIFF * 100 / $MINV))
6926
6927         local threshold=$(do_facet $SINGLEMDS \
6928                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
6929         threshold=${threshold%%%}
6930         echo -n "Check for uneven OSTs: "
6931         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
6932
6933         if [[ $DIFF2 -gt $threshold ]]; then
6934                 echo "ok"
6935                 echo "Don't need to fill OST$MINI"
6936         else
6937                 # generate uneven OSTs. Write 2% over the QOS threshold value
6938                 echo "no"
6939                 DIFF=$(($threshold - $DIFF2 + 2))
6940                 DIFF2=$(( ($MINV * $DIFF)/100 ))
6941                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
6942                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
6943                         error "setstripe failed"
6944                 DIFF=$(($DIFF2 / 2048))
6945                 i=0
6946                 while [ $i -lt $DIFF ]; do
6947                         i=$(($i + 1))
6948                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
6949                                 bs=2M count=1 2>/dev/null
6950                         echo -n .
6951                 done
6952                 echo .
6953                 sync
6954                 sleep_maxage
6955                 free_min_max
6956         fi
6957
6958         DIFF=$(($MAXV - $MINV))
6959         DIFF2=$(($DIFF * 100 / $MINV))
6960         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
6961         if [[ $DIFF2 -gt $threshold ]]; then
6962                 echo "ok"
6963         else
6964                 echo "failed - QOS mode won't be used"
6965                 skip "QOS imbalance criteria not met"
6966                 simple_cleanup_common
6967                 return
6968         fi
6969
6970         MINI1=$MINI; MINV1=$MINV
6971         MAXI1=$MAXI; MAXV1=$MAXV
6972
6973         # now fill using QOS
6974         $SETSTRIPE -c 1 $DIR/$tdir
6975         FILL=$(($FILL / 200))
6976         if [ $FILL -gt 600 ]; then
6977                 FILL=600
6978         fi
6979         echo "writing $FILL files to QOS-assigned OSTs"
6980         i=0
6981         while [ $i -lt $FILL ]; do
6982                 i=$((i + 1))
6983                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
6984                         count=1 2>/dev/null
6985                 echo -n .
6986         done
6987         echo "wrote $i 200k files"
6988         sync
6989         sleep_maxage
6990
6991         echo "Note: free space may not be updated, so measurements might be off"
6992         free_min_max
6993         DIFF2=$(($MAXV - $MINV))
6994         echo "free space delta: orig $DIFF final $DIFF2"
6995         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
6996         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
6997         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
6998         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
6999         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7000         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7001         [ $DIFF -gt 0 ] &&
7002                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7003
7004         # Figure out which files were written where
7005         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7006                   awk '/'$MINI1': / {print $2; exit}')
7007         echo $UUID
7008         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7009         echo "$MINC files created on smaller OST $MINI1"
7010         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7011                   awk '/'$MAXI1': / {print $2; exit}')
7012         echo $UUID
7013         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7014         echo "$MAXC files created on larger OST $MAXI1"
7015         FILL=$(($MAXC * 100 / $MINC - 100))
7016         [[ $MINC -gt 0 ]] &&
7017                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7018         [[ $MAXC -gt $MINC ]] ||
7019                 error_ignore LU-9 "stripe QOS didn't balance free space"
7020         simple_cleanup_common
7021 }
7022 run_test 116a "stripe QOS: free space balance ==================="
7023
7024 test_116b() { # LU-2093
7025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7026         [ -z "$($LCTL get_param -n lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr |
7027                 head -1 2>/dev/null)" ] && skip "no QOS" && return
7028 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7029         local old_rr
7030         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7031                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7032         do_facet $SINGLEMDS lctl set_param \
7033                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7034         mkdir -p $DIR/$tdir
7035         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7036         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7037         do_facet $SINGLEMDS lctl set_param fail_loc=0
7038         rm -rf $DIR/$tdir
7039         do_facet $SINGLEMDS lctl set_param \
7040                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7041 }
7042 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7043
7044 test_117() # bug 10891
7045 {
7046         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7047         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7048         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7049         lctl set_param fail_loc=0x21e
7050         > $DIR/$tfile || error "truncate failed"
7051         lctl set_param fail_loc=0
7052         echo "Truncate succeeded."
7053         rm -f $DIR/$tfile
7054 }
7055 run_test 117 "verify osd extend =========="
7056
7057 NO_SLOW_RESENDCOUNT=4
7058 export OLD_RESENDCOUNT=""
7059 set_resend_count () {
7060         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7061         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7062         lctl set_param -n $PROC_RESENDCOUNT $1
7063         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7064 }
7065
7066 # for reduce test_118* time (b=14842)
7067 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7068
7069 # Reset async IO behavior after error case
7070 reset_async() {
7071         FILE=$DIR/reset_async
7072
7073         # Ensure all OSCs are cleared
7074         $SETSTRIPE -c -1 $FILE
7075         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7076         sync
7077         rm $FILE
7078 }
7079
7080 test_118a() #bug 11710
7081 {
7082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7083         reset_async
7084
7085         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7086         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7087         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7088
7089         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7090                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7091                 return 1;
7092         fi
7093         rm -f $DIR/$tfile
7094 }
7095 run_test 118a "verify O_SYNC works =========="
7096
7097 test_118b()
7098 {
7099         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7100         remote_ost_nodsh && skip "remote OST with nodsh" && return
7101
7102         reset_async
7103
7104         #define OBD_FAIL_OST_ENOENT 0x217
7105         set_nodes_failloc "$(osts_nodes)" 0x217
7106         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7107         RC=$?
7108         set_nodes_failloc "$(osts_nodes)" 0
7109         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7110         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7111                     grep -c writeback)
7112
7113         if [[ $RC -eq 0 ]]; then
7114                 error "Must return error due to dropped pages, rc=$RC"
7115                 return 1;
7116         fi
7117
7118         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7119                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7120                 return 1;
7121         fi
7122
7123         echo "Dirty pages not leaked on ENOENT"
7124
7125         # Due to the above error the OSC will issue all RPCs syncronously
7126         # until a subsequent RPC completes successfully without error.
7127         $MULTIOP $DIR/$tfile Ow4096yc
7128         rm -f $DIR/$tfile
7129
7130         return 0
7131 }
7132 run_test 118b "Reclaim dirty pages on fatal error =========="
7133
7134 test_118c()
7135 {
7136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7137
7138         # for 118c, restore the original resend count, LU-1940
7139         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7140                                 set_resend_count $OLD_RESENDCOUNT
7141         remote_ost_nodsh && skip "remote OST with nodsh" && return
7142
7143         reset_async
7144
7145         #define OBD_FAIL_OST_EROFS               0x216
7146         set_nodes_failloc "$(osts_nodes)" 0x216
7147
7148         # multiop should block due to fsync until pages are written
7149         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7150         MULTIPID=$!
7151         sleep 1
7152
7153         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7154                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7155         fi
7156
7157         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7158                     grep -c writeback)
7159         if [[ $WRITEBACK -eq 0 ]]; then
7160                 error "No page in writeback, writeback=$WRITEBACK"
7161         fi
7162
7163         set_nodes_failloc "$(osts_nodes)" 0
7164         wait $MULTIPID
7165         RC=$?
7166         if [[ $RC -ne 0 ]]; then
7167                 error "Multiop fsync failed, rc=$RC"
7168         fi
7169
7170         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7171         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7172                     grep -c writeback)
7173         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7174                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7175         fi
7176
7177         rm -f $DIR/$tfile
7178         echo "Dirty pages flushed via fsync on EROFS"
7179         return 0
7180 }
7181 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7182
7183 # continue to use small resend count to reduce test_118* time (b=14842)
7184 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7185
7186 test_118d()
7187 {
7188         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7189         remote_ost_nodsh && skip "remote OST with nodsh" && return
7190
7191         reset_async
7192
7193         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7194         set_nodes_failloc "$(osts_nodes)" 0x214
7195         # multiop should block due to fsync until pages are written
7196         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7197         MULTIPID=$!
7198         sleep 1
7199
7200         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7201                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7202         fi
7203
7204         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7205                     grep -c writeback)
7206         if [[ $WRITEBACK -eq 0 ]]; then
7207                 error "No page in writeback, writeback=$WRITEBACK"
7208         fi
7209
7210         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7211         set_nodes_failloc "$(osts_nodes)" 0
7212
7213         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7214         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7215                     grep -c writeback)
7216         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7217                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7218         fi
7219
7220         rm -f $DIR/$tfile
7221         echo "Dirty pages gaurenteed flushed via fsync"
7222         return 0
7223 }
7224 run_test 118d "Fsync validation inject a delay of the bulk =========="
7225
7226 test_118f() {
7227         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7228         reset_async
7229
7230         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7231         lctl set_param fail_loc=0x8000040a
7232
7233         # Should simulate EINVAL error which is fatal
7234         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7235         RC=$?
7236         if [[ $RC -eq 0 ]]; then
7237                 error "Must return error due to dropped pages, rc=$RC"
7238         fi
7239
7240         lctl set_param fail_loc=0x0
7241
7242         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7243         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7244         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7245                     grep -c writeback)
7246         if [[ $LOCKED -ne 0 ]]; then
7247                 error "Locked pages remain in cache, locked=$LOCKED"
7248         fi
7249
7250         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7251                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7252         fi
7253
7254         rm -f $DIR/$tfile
7255         echo "No pages locked after fsync"
7256
7257         reset_async
7258         return 0
7259 }
7260 run_test 118f "Simulate unrecoverable OSC side error =========="
7261
7262 test_118g() {
7263         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7264         reset_async
7265
7266         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7267         lctl set_param fail_loc=0x406
7268
7269         # simulate local -ENOMEM
7270         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7271         RC=$?
7272
7273         lctl set_param fail_loc=0
7274         if [[ $RC -eq 0 ]]; then
7275                 error "Must return error due to dropped pages, rc=$RC"
7276         fi
7277
7278         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7279         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7280         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7281                         grep -c writeback)
7282         if [[ $LOCKED -ne 0 ]]; then
7283                 error "Locked pages remain in cache, locked=$LOCKED"
7284         fi
7285
7286         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7287                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7288         fi
7289
7290         rm -f $DIR/$tfile
7291         echo "No pages locked after fsync"
7292
7293         reset_async
7294         return 0
7295 }
7296 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7297
7298 test_118h() {
7299         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7300         remote_ost_nodsh && skip "remote OST with nodsh" && return
7301
7302         reset_async
7303
7304         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7305         set_nodes_failloc "$(osts_nodes)" 0x20e
7306         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7307         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7308         RC=$?
7309
7310         set_nodes_failloc "$(osts_nodes)" 0
7311         if [[ $RC -eq 0 ]]; then
7312                 error "Must return error due to dropped pages, rc=$RC"
7313         fi
7314
7315         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7316         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7317         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7318                     grep -c writeback)
7319         if [[ $LOCKED -ne 0 ]]; then
7320                 error "Locked pages remain in cache, locked=$LOCKED"
7321         fi
7322
7323         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7324                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7325         fi
7326
7327         rm -f $DIR/$tfile
7328         echo "No pages locked after fsync"
7329
7330         return 0
7331 }
7332 run_test 118h "Verify timeout in handling recoverables errors  =========="
7333
7334 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7335
7336 test_118i() {
7337         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7338         remote_ost_nodsh && skip "remote OST with nodsh" && return
7339
7340         reset_async
7341
7342         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7343         set_nodes_failloc "$(osts_nodes)" 0x20e
7344
7345         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7346         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7347         PID=$!
7348         sleep 5
7349         set_nodes_failloc "$(osts_nodes)" 0
7350
7351         wait $PID
7352         RC=$?
7353         if [[ $RC -ne 0 ]]; then
7354                 error "got error, but should be not, rc=$RC"
7355         fi
7356
7357         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7358         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7359         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7360         if [[ $LOCKED -ne 0 ]]; then
7361                 error "Locked pages remain in cache, locked=$LOCKED"
7362         fi
7363
7364         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7365                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7366         fi
7367
7368         rm -f $DIR/$tfile
7369         echo "No pages locked after fsync"
7370
7371         return 0
7372 }
7373 run_test 118i "Fix error before timeout in recoverable error  =========="
7374
7375 [ "$SLOW" = "no" ] && set_resend_count 4
7376
7377 test_118j() {
7378         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7379         remote_ost_nodsh && skip "remote OST with nodsh" && return
7380
7381         reset_async
7382
7383         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7384         set_nodes_failloc "$(osts_nodes)" 0x220
7385
7386         # return -EIO from OST
7387         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7388         RC=$?
7389         set_nodes_failloc "$(osts_nodes)" 0x0
7390         if [[ $RC -eq 0 ]]; then
7391                 error "Must return error due to dropped pages, rc=$RC"
7392         fi
7393
7394         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7395         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7396         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7397         if [[ $LOCKED -ne 0 ]]; then
7398                 error "Locked pages remain in cache, locked=$LOCKED"
7399         fi
7400
7401         # in recoverable error on OST we want resend and stay until it finished
7402         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7403                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7404         fi
7405
7406         rm -f $DIR/$tfile
7407         echo "No pages locked after fsync"
7408
7409         return 0
7410 }
7411 run_test 118j "Simulate unrecoverable OST side error =========="
7412
7413 test_118k()
7414 {
7415         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7416         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7417
7418         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7419         set_nodes_failloc "$(osts_nodes)" 0x20e
7420         test_mkdir -p $DIR/$tdir
7421
7422         for ((i=0;i<10;i++)); do
7423                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7424                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7425                 SLEEPPID=$!
7426                 sleep 0.500s
7427                 kill $SLEEPPID
7428                 wait $SLEEPPID
7429         done
7430
7431         set_nodes_failloc "$(osts_nodes)" 0
7432         rm -rf $DIR/$tdir
7433 }
7434 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7435
7436 test_118l()
7437 {
7438         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7439         # LU-646
7440         test_mkdir -p $DIR/$tdir
7441         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7442         rm -rf $DIR/$tdir
7443 }
7444 run_test 118l "fsync dir ========="
7445
7446 test_118m() # LU-3066
7447 {
7448         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7449         test_mkdir -p $DIR/$tdir
7450         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7451         rm -rf $DIR/$tdir
7452 }
7453 run_test 118m "fdatasync dir ========="
7454
7455 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7456
7457 test_119a() # bug 11737
7458 {
7459         BSIZE=$((512 * 1024))
7460         directio write $DIR/$tfile 0 1 $BSIZE
7461         # We ask to read two blocks, which is more than a file size.
7462         # directio will indicate an error when requested and actual
7463         # sizes aren't equeal (a normal situation in this case) and
7464         # print actual read amount.
7465         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7466         if [ "$NOB" != "$BSIZE" ]; then
7467                 error "read $NOB bytes instead of $BSIZE"
7468         fi
7469         rm -f $DIR/$tfile
7470 }
7471 run_test 119a "Short directIO read must return actual read amount"
7472
7473 test_119b() # bug 11737
7474 {
7475         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7476
7477         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7478         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7479         sync
7480         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7481                 error "direct read failed"
7482         rm -f $DIR/$tfile
7483 }
7484 run_test 119b "Sparse directIO read must return actual read amount"
7485
7486 test_119c() # bug 13099
7487 {
7488         BSIZE=1048576
7489         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7490         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7491         rm -f $DIR/$tfile
7492 }
7493 run_test 119c "Testing for direct read hitting hole"
7494
7495 test_119d() # bug 15950
7496 {
7497         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7498         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7499         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7500         BSIZE=1048576
7501         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7502         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7503         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7504         lctl set_param fail_loc=0x40d
7505         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7506         pid_dio=$!
7507         sleep 1
7508         cat $DIR/$tfile > /dev/null &
7509         lctl set_param fail_loc=0
7510         pid_reads=$!
7511         wait $pid_dio
7512         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7513         sleep 2
7514         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7515         error "the read rpcs have not completed in 2s"
7516         rm -f $DIR/$tfile
7517         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7518 }
7519 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7520
7521 test_120a() {
7522         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7523         test_mkdir -p $DIR/$tdir
7524         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7525                skip "no early lock cancel on server" && return 0
7526
7527         lru_resize_disable mdc
7528         lru_resize_disable osc
7529         cancel_lru_locks mdc
7530         # asynchronous object destroy at MDT could cause bl ast to client
7531         cancel_lru_locks osc
7532
7533         stat $DIR/$tdir > /dev/null
7534         can1=$(do_facet $SINGLEMDS \
7535                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7536                awk '/ldlm_cancel/ {print $2}')
7537         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7538                awk '/ldlm_bl_callback/ {print $2}')
7539         test_mkdir -c1 $DIR/$tdir/d1
7540         can2=$(do_facet $SINGLEMDS \
7541                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7542                awk '/ldlm_cancel/ {print $2}')
7543         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7544                awk '/ldlm_bl_callback/ {print $2}')
7545         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7546         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7547         lru_resize_enable mdc
7548         lru_resize_enable osc
7549 }
7550 run_test 120a "Early Lock Cancel: mkdir test"
7551
7552 test_120b() {
7553         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7554         test_mkdir $DIR/$tdir
7555         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7556                skip "no early lock cancel on server" && return 0
7557         lru_resize_disable mdc
7558         lru_resize_disable osc
7559         cancel_lru_locks mdc
7560         stat $DIR/$tdir > /dev/null
7561         can1=$(do_facet $SINGLEMDS \
7562                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7563                awk '/ldlm_cancel/ {print $2}')
7564         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7565                awk '/ldlm_bl_callback/ {print $2}')
7566         touch $DIR/$tdir/f1
7567         can2=$(do_facet $SINGLEMDS \
7568                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7569                awk '/ldlm_cancel/ {print $2}')
7570         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7571                awk '/ldlm_bl_callback/ {print $2}')
7572         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7573         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7574         lru_resize_enable mdc
7575         lru_resize_enable osc
7576 }
7577 run_test 120b "Early Lock Cancel: create test"
7578
7579 test_120c() {
7580         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7581         test_mkdir -c1 $DIR/$tdir
7582         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7583                skip "no early lock cancel on server" && return 0
7584         lru_resize_disable mdc
7585         lru_resize_disable osc
7586         test_mkdir -p -c1 $DIR/$tdir/d1
7587         test_mkdir -p -c1 $DIR/$tdir/d2
7588         touch $DIR/$tdir/d1/f1
7589         cancel_lru_locks mdc
7590         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7591         can1=$(do_facet $SINGLEMDS \
7592                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7593                awk '/ldlm_cancel/ {print $2}')
7594         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7595                awk '/ldlm_bl_callback/ {print $2}')
7596         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7597         can2=$(do_facet $SINGLEMDS \
7598                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7599                awk '/ldlm_cancel/ {print $2}')
7600         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7601                awk '/ldlm_bl_callback/ {print $2}')
7602         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7603         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7604         lru_resize_enable mdc
7605         lru_resize_enable osc
7606 }
7607 run_test 120c "Early Lock Cancel: link test"
7608
7609 test_120d() {
7610         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7611         test_mkdir -p -c1 $DIR/$tdir
7612         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7613                skip "no early lock cancel on server" && return 0
7614         lru_resize_disable mdc
7615         lru_resize_disable osc
7616         touch $DIR/$tdir
7617         cancel_lru_locks mdc
7618         stat $DIR/$tdir > /dev/null
7619         can1=$(do_facet $SINGLEMDS \
7620                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7621                awk '/ldlm_cancel/ {print $2}')
7622         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7623                awk '/ldlm_bl_callback/ {print $2}')
7624         chmod a+x $DIR/$tdir
7625         can2=$(do_facet $SINGLEMDS \
7626                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7627                awk '/ldlm_cancel/ {print $2}')
7628         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7629                awk '/ldlm_bl_callback/ {print $2}')
7630         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7631         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7632         lru_resize_enable mdc
7633         lru_resize_enable osc
7634 }
7635 run_test 120d "Early Lock Cancel: setattr test"
7636
7637 test_120e() {
7638         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7639         test_mkdir -p -c1 $DIR/$tdir
7640         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7641                skip "no early lock cancel on server" && return 0
7642         lru_resize_disable mdc
7643         lru_resize_disable osc
7644         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7645         cancel_lru_locks mdc
7646         cancel_lru_locks osc
7647         dd if=$DIR/$tdir/f1 of=/dev/null
7648         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7649         can1=$(do_facet $SINGLEMDS \
7650                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7651                awk '/ldlm_cancel/ {print $2}')
7652         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7653                awk '/ldlm_bl_callback/ {print $2}')
7654         unlink $DIR/$tdir/f1
7655         can2=$(do_facet $SINGLEMDS \
7656                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7657                awk '/ldlm_cancel/ {print $2}')
7658         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7659                awk '/ldlm_bl_callback/ {print $2}')
7660         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7661         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7662         lru_resize_enable mdc
7663         lru_resize_enable osc
7664 }
7665 run_test 120e "Early Lock Cancel: unlink test"
7666
7667 test_120f() {
7668         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7669         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7670                skip "no early lock cancel on server" && return 0
7671         test_mkdir -p -c1 $DIR/$tdir
7672         lru_resize_disable mdc
7673         lru_resize_disable osc
7674         test_mkdir -p -c1 $DIR/$tdir/d1
7675         test_mkdir -p -c1 $DIR/$tdir/d2
7676         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7677         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7678         cancel_lru_locks mdc
7679         cancel_lru_locks osc
7680         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7681         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7682         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7683         can1=$(do_facet $SINGLEMDS \
7684                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7685                awk '/ldlm_cancel/ {print $2}')
7686         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7687                awk '/ldlm_bl_callback/ {print $2}')
7688         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7689         can2=$(do_facet $SINGLEMDS \
7690                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7691                awk '/ldlm_cancel/ {print $2}')
7692         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7693                awk '/ldlm_bl_callback/ {print $2}')
7694         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7695         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7696         lru_resize_enable mdc
7697         lru_resize_enable osc
7698 }
7699 run_test 120f "Early Lock Cancel: rename test"
7700
7701 test_120g() {
7702         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7703         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7704                skip "no early lock cancel on server" && return 0
7705         lru_resize_disable mdc
7706         lru_resize_disable osc
7707         count=10000
7708         echo create $count files
7709         test_mkdir -p $DIR/$tdir
7710         cancel_lru_locks mdc
7711         cancel_lru_locks osc
7712         t0=`date +%s`
7713
7714         can0=$(do_facet $SINGLEMDS \
7715                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7716                awk '/ldlm_cancel/ {print $2}')
7717         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7718                awk '/ldlm_bl_callback/ {print $2}')
7719         createmany -o $DIR/$tdir/f $count
7720         sync
7721         can1=$(do_facet $SINGLEMDS \
7722                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7723                awk '/ldlm_cancel/ {print $2}')
7724         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7725                awk '/ldlm_bl_callback/ {print $2}')
7726         t1=$(date +%s)
7727         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7728         echo rm $count files
7729         rm -r $DIR/$tdir
7730         sync
7731         can2=$(do_facet $SINGLEMDS \
7732                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7733                awk '/ldlm_cancel/ {print $2}')
7734         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7735                awk '/ldlm_bl_callback/ {print $2}')
7736         t2=$(date +%s)
7737         echo total: $count removes in $((t2-t1))
7738         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7739         sleep 2
7740         # wait for commitment of removal
7741         lru_resize_enable mdc
7742         lru_resize_enable osc
7743 }
7744 run_test 120g "Early Lock Cancel: performance test"
7745
7746 test_121() { #bug #10589
7747         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7748         rm -rf $DIR/$tfile
7749         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
7750 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
7751         lctl set_param fail_loc=0x310
7752         cancel_lru_locks osc > /dev/null
7753         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
7754         lctl set_param fail_loc=0
7755         [[ $reads -eq $writes ]] ||
7756                 error "read $reads blocks, must be $writes blocks"
7757 }
7758 run_test 121 "read cancel race ========="
7759
7760 test_123a() { # was test 123, statahead(bug 11401)
7761         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7762         SLOWOK=0
7763         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
7764             log "testing on UP system. Performance may be not as good as expected."
7765                         SLOWOK=1
7766         fi
7767
7768         rm -rf $DIR/$tdir
7769         test_mkdir -p $DIR/$tdir
7770         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7771         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
7772         MULT=10
7773         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
7774                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
7775
7776                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7777                 lctl set_param -n llite.*.statahead_max 0
7778                 lctl get_param llite.*.statahead_max
7779                 cancel_lru_locks mdc
7780                 cancel_lru_locks osc
7781                 stime=`date +%s`
7782                 time ls -l $DIR/$tdir | wc -l
7783                 etime=`date +%s`
7784                 delta=$((etime - stime))
7785                 log "ls $i files without statahead: $delta sec"
7786                 lctl set_param llite.*.statahead_max=$max
7787
7788                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7789                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
7790                 cancel_lru_locks mdc
7791                 cancel_lru_locks osc
7792                 stime=`date +%s`
7793                 time ls -l $DIR/$tdir | wc -l
7794                 etime=`date +%s`
7795                 delta_sa=$((etime - stime))
7796                 log "ls $i files with statahead: $delta_sa sec"
7797                 lctl get_param -n llite.*.statahead_stats
7798                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7799
7800                 [[ $swrong -lt $ewrong ]] &&
7801                         log "statahead was stopped, maybe too many locks held!"
7802                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
7803
7804                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7805                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7806                     lctl set_param -n llite.*.statahead_max 0
7807                     lctl get_param llite.*.statahead_max
7808                     cancel_lru_locks mdc
7809                     cancel_lru_locks osc
7810                     stime=`date +%s`
7811                     time ls -l $DIR/$tdir | wc -l
7812                     etime=`date +%s`
7813                     delta=$((etime - stime))
7814                     log "ls $i files again without statahead: $delta sec"
7815                     lctl set_param llite.*.statahead_max=$max
7816                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7817                         if [  $SLOWOK -eq 0 ]; then
7818                                 error "ls $i files is slower with statahead!"
7819                         else
7820                                 log "ls $i files is slower with statahead!"
7821                         fi
7822                         break
7823                     fi
7824                 fi
7825
7826                 [ $delta -gt 20 ] && break
7827                 [ $delta -gt 8 ] && MULT=$((50 / delta))
7828                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
7829         done
7830         log "ls done"
7831
7832         stime=`date +%s`
7833         rm -r $DIR/$tdir
7834         sync
7835         etime=`date +%s`
7836         delta=$((etime - stime))
7837         log "rm -r $DIR/$tdir/: $delta seconds"
7838         log "rm done"
7839         lctl get_param -n llite.*.statahead_stats
7840 }
7841 run_test 123a "verify statahead work"
7842
7843 test_123b () { # statahead(bug 15027)
7844         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7845         test_mkdir -p $DIR/$tdir
7846         createmany -o $DIR/$tdir/$tfile-%d 1000
7847
7848         cancel_lru_locks mdc
7849         cancel_lru_locks osc
7850
7851 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
7852         lctl set_param fail_loc=0x80000803
7853         ls -lR $DIR/$tdir > /dev/null
7854         log "ls done"
7855         lctl set_param fail_loc=0x0
7856         lctl get_param -n llite.*.statahead_stats
7857         rm -r $DIR/$tdir
7858         sync
7859
7860 }
7861 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
7862
7863 test_124a() {
7864         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7865         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
7866                 skip "no lru resize on server" && return 0
7867         local NR=2000
7868         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
7869
7870         log "create $NR files at $DIR/$tdir"
7871         createmany -o $DIR/$tdir/f $NR ||
7872                 error "failed to create $NR files in $DIR/$tdir"
7873
7874         cancel_lru_locks mdc
7875         ls -l $DIR/$tdir > /dev/null
7876
7877         local NSDIR=""
7878         local LRU_SIZE=0
7879         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
7880                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
7881                 LRU_SIZE=$($LCTL get_param -n $PARAM)
7882                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
7883                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
7884                         log "NSDIR=$NSDIR"
7885                         log "NS=$(basename $NSDIR)"
7886                         break
7887                 fi
7888         done
7889
7890         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
7891                 skip "Not enough cached locks created!"
7892                 return 0
7893         fi
7894         log "LRU=$LRU_SIZE"
7895
7896         local SLEEP=30
7897
7898         # We know that lru resize allows one client to hold $LIMIT locks
7899         # for 10h. After that locks begin to be killed by client.
7900         local MAX_HRS=10
7901         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
7902         log "LIMIT=$LIMIT"
7903
7904         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
7905         # killing locks. Some time was spent for creating locks. This means
7906         # that up to the moment of sleep finish we must have killed some of
7907         # them (10-100 locks). This depends on how fast ther were created.
7908         # Many of them were touched in almost the same moment and thus will
7909         # be killed in groups.
7910         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
7911
7912         # Use $LRU_SIZE_B here to take into account real number of locks
7913         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
7914         local LRU_SIZE_B=$LRU_SIZE
7915         log "LVF=$LVF"
7916         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
7917         log "OLD_LVF=$OLD_LVF"
7918         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
7919
7920         # Let's make sure that we really have some margin. Client checks
7921         # cached locks every 10 sec.
7922         SLEEP=$((SLEEP+20))
7923         log "Sleep ${SLEEP} sec"
7924         local SEC=0
7925         while ((SEC<$SLEEP)); do
7926                 echo -n "..."
7927                 sleep 5
7928                 SEC=$((SEC+5))
7929                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
7930                 echo -n "$LRU_SIZE"
7931         done
7932         echo ""
7933         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
7934         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
7935
7936         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
7937                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
7938                 unlinkmany $DIR/$tdir/f $NR
7939                 return
7940         }
7941
7942         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
7943         log "unlink $NR files at $DIR/$tdir"
7944         unlinkmany $DIR/$tdir/f $NR
7945 }
7946 run_test 124a "lru resize ======================================="
7947
7948 get_max_pool_limit()
7949 {
7950         local limit=$($LCTL get_param \
7951                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
7952         local max=0
7953         for l in $limit; do
7954                 if [[ $l -gt $max ]]; then
7955                         max=$l
7956                 fi
7957         done
7958         echo $max
7959 }
7960
7961 test_124b() {
7962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7963         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
7964                 skip "no lru resize on server" && return 0
7965
7966         LIMIT=$(get_max_pool_limit)
7967
7968         NR=$(($(default_lru_size)*20))
7969         if [[ $NR -gt $LIMIT ]]; then
7970                 log "Limit lock number by $LIMIT locks"
7971                 NR=$LIMIT
7972         fi
7973         lru_resize_disable mdc
7974         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
7975                 error "failed to create $DIR/$tdir/disable_lru_resize"
7976
7977         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
7978         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
7979         cancel_lru_locks mdc
7980         stime=`date +%s`
7981         PID=""
7982         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7983         PID="$PID $!"
7984         sleep 2
7985         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7986         PID="$PID $!"
7987         sleep 2
7988         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7989         PID="$PID $!"
7990         wait $PID
7991         etime=`date +%s`
7992         nolruresize_delta=$((etime-stime))
7993         log "ls -la time: $nolruresize_delta seconds"
7994         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7995         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
7996
7997         lru_resize_enable mdc
7998         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
7999                 error "failed to create $DIR/$tdir/enable_lru_resize"
8000
8001         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8002         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8003         cancel_lru_locks mdc
8004         stime=`date +%s`
8005         PID=""
8006         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8007         PID="$PID $!"
8008         sleep 2
8009         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8010         PID="$PID $!"
8011         sleep 2
8012         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8013         PID="$PID $!"
8014         wait $PID
8015         etime=`date +%s`
8016         lruresize_delta=$((etime-stime))
8017         log "ls -la time: $lruresize_delta seconds"
8018         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8019
8020         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8021                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8022         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8023                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8024         else
8025                 log "lru resize performs the same with no lru resize"
8026         fi
8027         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8028 }
8029 run_test 124b "lru resize (performance test) ======================="
8030
8031 test_125() { # 13358
8032         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8033         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8034         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8035         test_mkdir -p $DIR/d125 || error "mkdir failed"
8036         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8037         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8038         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8039 }
8040 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8041
8042 test_126() { # bug 12829/13455
8043         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8044         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8045         $GSS && skip "must run as gss disabled" && return
8046
8047         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8048         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8049         rm -f $DIR/$tfile
8050         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8051 }
8052 run_test 126 "check that the fsgid provided by the client is taken into account"
8053
8054 test_127a() { # bug 15521
8055         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8056         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8057         $LCTL set_param osc.*.stats=0
8058         FSIZE=$((2048 * 1024))
8059         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8060         cancel_lru_locks osc
8061         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8062
8063         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8064         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8065                 echo "got $COUNT $NAME"
8066                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8067                 eval $NAME=$COUNT || error "Wrong proc format"
8068
8069                 case $NAME in
8070                         read_bytes|write_bytes)
8071                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8072                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8073                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8074                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8075                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8076                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8077                                 error "sumsquare is too small: $SUMSQ"
8078                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8079                                 error "sumsquare is too big: $SUMSQ"
8080                         ;;
8081                         *) ;;
8082                 esac
8083         done < $DIR/${tfile}.tmp
8084
8085         #check that we actually got some stats
8086         [ "$read_bytes" ] || error "Missing read_bytes stats"
8087         [ "$write_bytes" ] || error "Missing write_bytes stats"
8088         [ "$read_bytes" != 0 ] || error "no read done"
8089         [ "$write_bytes" != 0 ] || error "no write done"
8090 }
8091 run_test 127a "verify the client stats are sane"
8092
8093 test_127b() { # bug LU-333
8094         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8095         $LCTL set_param llite.*.stats=0
8096         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8097         # perform 2 reads and writes so MAX is different from SUM.
8098         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8099         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8100         cancel_lru_locks osc
8101         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8102         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8103
8104         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8105         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8106                 echo "got $COUNT $NAME"
8107                 eval $NAME=$COUNT || error "Wrong proc format"
8108
8109         case $NAME in
8110                 read_bytes)
8111                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8112                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8113                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8114                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8115                         ;;
8116                 write_bytes)
8117                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8118                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8119                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8120                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8121                         ;;
8122                         *) ;;
8123                 esac
8124         done < $TMP/${tfile}.tmp
8125
8126         #check that we actually got some stats
8127         [ "$read_bytes" ] || error "Missing read_bytes stats"
8128         [ "$write_bytes" ] || error "Missing write_bytes stats"
8129         [ "$read_bytes" != 0 ] || error "no read done"
8130         [ "$write_bytes" != 0 ] || error "no write done"
8131 }
8132 run_test 127b "verify the llite client stats are sane"
8133
8134 test_128() { # bug 15212
8135         touch $DIR/$tfile
8136         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8137                 find $DIR/$tfile
8138                 find $DIR/$tfile
8139         EOF
8140
8141         result=$(grep error $TMP/$tfile.log)
8142         rm -f $DIR/$tfile
8143         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8144 }
8145 run_test 128 "interactive lfs for 2 consecutive find's"
8146
8147 set_dir_limits () {
8148         local mntdev
8149         local canondev
8150         local node
8151
8152         local LDPROC=/proc/fs/ldiskfs
8153         local facets=$(get_facets MDS)
8154
8155         for facet in ${facets//,/ }; do
8156                 canondev=$(ldiskfs_canon \
8157                            *.$(convert_facet2label $facet).mntdev $facet)
8158                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8159                                                 LDPROC=/sys/fs/ldiskfs
8160                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8161         done
8162 }
8163
8164 test_129() {
8165         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8166         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8167                 skip "Only applicable to ldiskfs-based MDTs"
8168                 return
8169         fi
8170         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8171         ENOSPC=28
8172         EFBIG=27
8173
8174         rm -rf $DIR/$tdir
8175         test_mkdir -p $DIR/$tdir
8176
8177         # block size of mds1
8178         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8179         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8180         local MAX=$((MDSBLOCKSIZE * 3))
8181         set_dir_limits $MAX
8182         local I=$(stat -c%s "$DIR/$tdir")
8183         local J=0
8184         local STRIPE_COUNT=1
8185         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8186         MAX=$((MAX*STRIPE_COUNT))
8187         while [[ $I -le $MAX ]]; do
8188                 $MULTIOP $DIR/$tdir/$J Oc
8189                 rc=$?
8190                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8191                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8192                 #and EFBIG for previous versions
8193                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8194                         set_dir_limits 0
8195                         echo "return code $rc received as expected"
8196                         multiop $DIR/$tdir/$J Oc ||
8197                                 error_exit "multiop failed w/o dir size limit"
8198
8199                         I=$(stat -c%s "$DIR/$tdir")
8200
8201                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8202                                         $(version_code 2.4.51) ]
8203                         then
8204                                 [[ $I -eq $MAX ]] && return 0
8205                         else
8206                                 [[ $I -gt $MAX ]] && return 0
8207                         fi
8208                         error_exit "current dir size $I, previous limit $MAX"
8209                 elif [ $rc -ne 0 ]; then
8210                         set_dir_limits 0
8211                         error_exit "return code $rc received instead of expected " \
8212                                    "$EFBIG or $ENOSPC, files in dir $I"
8213                 fi
8214                 J=$((J+1))
8215                 I=$(stat -c%s "$DIR/$tdir")
8216         done
8217
8218         set_dir_limits 0
8219         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8220 }
8221 run_test 129 "test directory size limit ========================"
8222
8223 OLDIFS="$IFS"
8224 cleanup_130() {
8225         trap 0
8226         IFS="$OLDIFS"
8227 }
8228
8229 test_130a() {
8230         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8231         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8232                 return
8233
8234         trap cleanup_130 EXIT RETURN
8235
8236         local fm_file=$DIR/$tfile
8237         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8238         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8239                 error "dd failed for $fm_file"
8240
8241         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8242         filefrag -ves $fm_file
8243         RC=$?
8244         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8245                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8246         [ $RC != 0 ] && error "filefrag $fm_file failed"
8247
8248         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8249                       grep -v "ext:" | grep -v "found")
8250         lun=$($GETSTRIPE -i $fm_file)
8251
8252         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8253         IFS=$'\n'
8254         tot_len=0
8255         for line in $filefrag_op
8256         do
8257                 frag_lun=`echo $line | cut -d: -f5`
8258                 ext_len=`echo $line | cut -d: -f4`
8259                 if (( $frag_lun != $lun )); then
8260                         cleanup_130
8261                         error "FIEMAP on 1-stripe file($fm_file) failed"
8262                         return
8263                 fi
8264                 (( tot_len += ext_len ))
8265         done
8266
8267         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8268                 cleanup_130
8269                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8270                 return
8271         fi
8272
8273         cleanup_130
8274
8275         echo "FIEMAP on single striped file succeeded"
8276 }
8277 run_test 130a "FIEMAP (1-stripe file)"
8278
8279 test_130b() {
8280         [ "$OSTCOUNT" -lt "2" ] &&
8281                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8282
8283         [ "$OSTCOUNT" -ge "10" ] &&
8284                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8285
8286         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8287         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8288                 return
8289
8290         trap cleanup_130 EXIT RETURN
8291
8292         local fm_file=$DIR/$tfile
8293         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8294         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8295                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8296
8297         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8298                 error "dd failed on $fm_file"
8299
8300         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8301         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8302                       grep -v "ext:" | grep -v "found")
8303
8304         last_lun=$(echo $filefrag_op | cut -d: -f5)
8305
8306         IFS=$'\n'
8307         tot_len=0
8308         num_luns=1
8309         for line in $filefrag_op
8310         do
8311                 frag_lun=`echo $line | cut -d: -f5`
8312                 ext_len=`echo $line | cut -d: -f4`
8313                 if (( $frag_lun != $last_lun )); then
8314                         if (( tot_len != 1024 )); then
8315                                 cleanup_130
8316                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8317                                 return
8318                         else
8319                                 (( num_luns += 1 ))
8320                                 tot_len=0
8321                         fi
8322                 fi
8323                 (( tot_len += ext_len ))
8324                 last_lun=$frag_lun
8325         done
8326         if (( num_luns != 2 || tot_len != 1024 )); then
8327                 cleanup_130
8328                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8329                 return
8330         fi
8331
8332         cleanup_130
8333
8334         echo "FIEMAP on 2-stripe file succeeded"
8335 }
8336 run_test 130b "FIEMAP (2-stripe file)"
8337
8338 test_130c() {
8339         [ "$OSTCOUNT" -lt "2" ] &&
8340                 skip_env "skipping FIEMAP on 2-stripe file" && return
8341
8342         [ "$OSTCOUNT" -ge "10" ] &&
8343                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8344
8345         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8346         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8347                 return
8348
8349         trap cleanup_130 EXIT RETURN
8350
8351         local fm_file=$DIR/$tfile
8352         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8353         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8354                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8355
8356         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8357
8358         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8359         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8360
8361         last_lun=`echo $filefrag_op | cut -d: -f5`
8362
8363         IFS=$'\n'
8364         tot_len=0
8365         num_luns=1
8366         for line in $filefrag_op
8367         do
8368                 frag_lun=`echo $line | cut -d: -f5`
8369                 ext_len=`echo $line | cut -d: -f4`
8370                 if (( $frag_lun != $last_lun )); then
8371                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8372                         if (( logical != 512 )); then
8373                                 cleanup_130
8374                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8375                                 return
8376                         fi
8377                         if (( tot_len != 512 )); then
8378                                 cleanup_130
8379                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8380                                 return
8381                         else
8382                                 (( num_luns += 1 ))
8383                                 tot_len=0
8384                         fi
8385                 fi
8386                 (( tot_len += ext_len ))
8387                 last_lun=$frag_lun
8388         done
8389         if (( num_luns != 2 || tot_len != 512 )); then
8390                 cleanup_130
8391                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8392                 return
8393         fi
8394
8395         cleanup_130
8396
8397         echo "FIEMAP on 2-stripe file with hole succeeded"
8398 }
8399 run_test 130c "FIEMAP (2-stripe file with hole)"
8400
8401 test_130d() {
8402         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8403
8404         [ "$OSTCOUNT" -ge "10" ] &&
8405                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8406
8407         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8408         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8409
8410         trap cleanup_130 EXIT RETURN
8411
8412         local fm_file=$DIR/$tfile
8413         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8414         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8415                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8416
8417         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8418         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8419                 error "dd failed on $fm_file"
8420
8421         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8422         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8423                 grep -v "ext:" | grep -v "found"`
8424
8425         last_lun=`echo $filefrag_op | cut -d: -f5`
8426
8427         IFS=$'\n'
8428         tot_len=0
8429         num_luns=1
8430         for line in $filefrag_op
8431         do
8432                 frag_lun=`echo $line | cut -d: -f5`
8433                 ext_len=`echo $line | cut -d: -f4`
8434                 if (( $frag_lun != $last_lun )); then
8435                         if (( tot_len != 1024 )); then
8436                                 cleanup_130
8437                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8438                                 return
8439                         else
8440                                 (( num_luns += 1 ))
8441                                 tot_len=0
8442                         fi
8443                 fi
8444                 (( tot_len += ext_len ))
8445                 last_lun=$frag_lun
8446         done
8447         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8448                 cleanup_130
8449                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8450                 return
8451         fi
8452
8453         cleanup_130
8454
8455         echo "FIEMAP on N-stripe file succeeded"
8456 }
8457 run_test 130d "FIEMAP (N-stripe file)"
8458
8459 test_130e() {
8460         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8461
8462         [ "$OSTCOUNT" -ge "10" ] &&
8463                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8464
8465         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8466         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8467
8468         trap cleanup_130 EXIT RETURN
8469
8470         local fm_file=$DIR/$tfile
8471         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8472         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8473                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8474
8475         NUM_BLKS=512
8476         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8477         for ((i = 0; i < $NUM_BLKS; i++))
8478         do
8479                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8480         done
8481
8482         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8483         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8484
8485         last_lun=`echo $filefrag_op | cut -d: -f5`
8486
8487         IFS=$'\n'
8488         tot_len=0
8489         num_luns=1
8490         for line in $filefrag_op
8491         do
8492                 frag_lun=`echo $line | cut -d: -f5`
8493                 ext_len=`echo $line | cut -d: -f4`
8494                 if (( $frag_lun != $last_lun )); then
8495                         if (( tot_len != $EXPECTED_LEN )); then
8496                                 cleanup_130
8497                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8498                                 return
8499                         else
8500                                 (( num_luns += 1 ))
8501                                 tot_len=0
8502                         fi
8503                 fi
8504                 (( tot_len += ext_len ))
8505                 last_lun=$frag_lun
8506         done
8507         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8508                 cleanup_130
8509                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8510                 return
8511         fi
8512
8513         cleanup_130
8514
8515         echo "FIEMAP with continuation calls succeeded"
8516 }
8517 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8518
8519 # Test for writev/readv
8520 test_131a() {
8521         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8522         error "writev test failed"
8523         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8524         error "readv failed"
8525         rm -f $DIR/$tfile
8526 }
8527 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8528
8529 test_131b() {
8530         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8531         error "append writev test failed"
8532         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8533         error "append writev test failed"
8534         rm -f $DIR/$tfile
8535 }
8536 run_test 131b "test append writev"
8537
8538 test_131c() {
8539         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8540         error "NOT PASS"
8541 }
8542 run_test 131c "test read/write on file w/o objects"
8543
8544 test_131d() {
8545         rwv -f $DIR/$tfile -w -n 1 1572864
8546         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8547         if [ "$NOB" != 1572864 ]; then
8548                 error "Short read filed: read $NOB bytes instead of 1572864"
8549         fi
8550         rm -f $DIR/$tfile
8551 }
8552 run_test 131d "test short read"
8553
8554 test_131e() {
8555         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8556         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8557         error "read hitting hole failed"
8558         rm -f $DIR/$tfile
8559 }
8560 run_test 131e "test read hitting hole"
8561
8562 get_ost_param() {
8563         local token=$1
8564         local gl_sum=0
8565         for node in $(osts_nodes); do
8566                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8567                 [ x$gl = x"" ] && gl=0
8568                 gl_sum=$((gl_sum + gl))
8569         done
8570         echo $gl_sum
8571 }
8572
8573 som_mode_switch() {
8574         local som=$1
8575         local gl1=$2
8576         local gl2=$3
8577
8578         if [ x$som = x"enabled" ]; then
8579                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8580                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
8581                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8582         else
8583                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8584                 MOUNTOPT="$MOUNTOPT,som_preview"
8585                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8586         fi
8587
8588         # do remount to make new mount-conf parameters actual
8589         echo remounting...
8590         sync
8591         stopall
8592         setupall
8593 }
8594
8595 test_132() { #1028, SOM
8596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8597         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8598         local num=$(get_mds_dir $DIR)
8599         local mymds=mds${num}
8600         local MOUNTOPT_SAVE=$MOUNTOPT
8601
8602         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8603         cancel_lru_locks osc
8604
8605         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8606
8607         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8608         stat $DIR/$tfile >/dev/null
8609         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8610         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8611         rm $DIR/$tfile
8612         som_mode_switch $som1 $gl1 $gl2
8613
8614         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8615         cancel_lru_locks osc
8616
8617         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8618         if [ $som1 == $som2 ]; then
8619             error "som is still "$som2
8620             if [ x$som2 = x"enabled" ]; then
8621                 som2="disabled"
8622             else
8623                 som2="enabled"
8624             fi
8625         fi
8626
8627         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8628         stat $DIR/$tfile >/dev/null
8629         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8630         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8631         som_mode_switch $som2 $gl1 $gl2
8632         MOUNTOPT=$MOUNTOPT_SAVE
8633 }
8634 run_test 132 "som avoids glimpse rpc"
8635
8636 check_stats() {
8637         local res
8638         local count
8639         case $1 in
8640         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8641                  ;;
8642         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8643                  ;;
8644         *) error "Wrong argument $1" ;;
8645         esac
8646         echo $res
8647         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8648         # if the argument $3 is zero, it means any stat increment is ok.
8649         if [[ $3 -gt 0 ]]; then
8650                 count=$(echo $res | awk '{ print $2 }')
8651                 [[ $count -ne $3 ]] &&
8652                         error "The $2 counter on $1 is wrong - expected $3"
8653         fi
8654 }
8655
8656 test_133a() {
8657         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8658         remote_ost_nodsh && skip "remote OST with nodsh" && return
8659         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8660
8661         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8662                 { skip "MDS doesn't support rename stats"; return; }
8663         local testdir=$DIR/${tdir}/stats_testdir
8664         mkdir -p $DIR/${tdir}
8665
8666         # clear stats.
8667         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8668         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8669
8670         # verify mdt stats first.
8671         mkdir ${testdir} || error "mkdir failed"
8672         check_stats $SINGLEMDS "mkdir" 1
8673         touch ${testdir}/${tfile} || "touch failed"
8674         check_stats $SINGLEMDS "open" 1
8675         check_stats $SINGLEMDS "close" 1
8676         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8677         check_stats $SINGLEMDS "mknod" 1
8678         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8679         check_stats $SINGLEMDS "unlink" 1
8680         rm -f ${testdir}/${tfile} || error "file remove failed"
8681         check_stats $SINGLEMDS "unlink" 2
8682
8683         # remove working dir and check mdt stats again.
8684         rmdir ${testdir} || error "rmdir failed"
8685         check_stats $SINGLEMDS "rmdir" 1
8686
8687         local testdir1=$DIR/${tdir}/stats_testdir1
8688         mkdir -p ${testdir}
8689         mkdir -p ${testdir1}
8690         touch ${testdir1}/test1
8691         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8692         check_stats $SINGLEMDS "crossdir_rename" 1
8693
8694         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8695         check_stats $SINGLEMDS "samedir_rename" 1
8696
8697         rm -rf $DIR/${tdir}
8698 }
8699 run_test 133a "Verifying MDT stats ========================================"
8700
8701 test_133b() {
8702         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8703         remote_ost_nodsh && skip "remote OST with nodsh" && return
8704         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8705         local testdir=$DIR/${tdir}/stats_testdir
8706         mkdir -p ${testdir} || error "mkdir failed"
8707         touch ${testdir}/${tfile} || "touch failed"
8708         cancel_lru_locks mdc
8709
8710         # clear stats.
8711         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8712         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8713
8714         # extra mdt stats verification.
8715         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8716         check_stats $SINGLEMDS "setattr" 1
8717         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8718         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8719         then            # LU-1740
8720                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8721                 check_stats $SINGLEMDS "getattr" 1
8722         fi
8723         $LFS df || error "lfs failed"
8724         check_stats $SINGLEMDS "statfs" 1
8725
8726         rm -rf $DIR/${tdir}
8727 }
8728 run_test 133b "Verifying extra MDT stats =================================="
8729
8730 test_133c() {
8731         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8732         remote_ost_nodsh && skip "remote OST with nodsh" && return
8733         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8734         local testdir=$DIR/${tdir}/stats_testdir
8735         test_mkdir -p ${testdir} || error "mkdir failed"
8736
8737         # verify obdfilter stats.
8738         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8739         sync
8740         cancel_lru_locks osc
8741         wait_delete_completed
8742
8743         # clear stats.
8744         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8745         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8746
8747         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
8748         sync
8749         cancel_lru_locks osc
8750         check_stats ost "write" 1
8751
8752         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
8753         check_stats ost "read" 1
8754
8755         > ${testdir}/${tfile} || error "truncate failed"
8756         check_stats ost "punch" 1
8757
8758         rm -f ${testdir}/${tfile} || error "file remove failed"
8759         wait_delete_completed
8760         check_stats ost "destroy" 1
8761
8762         rm -rf $DIR/${tdir}
8763 }
8764 run_test 133c "Verifying OST stats ========================================"
8765
8766 order_2() {
8767         local value=$1
8768         local orig=$value
8769         local order=1
8770
8771         while [ $value -ge 2 ]; do
8772                 order=$((order*2))
8773                 value=$((value/2))
8774         done
8775
8776         if [ $orig -gt $order ]; then
8777                 order=$((order*2))
8778         fi
8779         echo $order
8780 }
8781
8782 size_in_KMGT() {
8783     local value=$1
8784     local size=('K' 'M' 'G' 'T');
8785     local i=0
8786     local size_string=$value
8787
8788     while [ $value -ge 1024 ]; do
8789         if [ $i -gt 3 ]; then
8790             #T is the biggest unit we get here, if that is bigger,
8791             #just return XXXT
8792             size_string=${value}T
8793             break
8794         fi
8795         value=$((value >> 10))
8796         if [ $value -lt 1024 ]; then
8797             size_string=${value}${size[$i]}
8798             break
8799         fi
8800         i=$((i + 1))
8801     done
8802
8803     echo $size_string
8804 }
8805
8806 get_rename_size() {
8807     local size=$1
8808     local context=${2:-.}
8809     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
8810                 grep -A1 $context |
8811                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
8812     echo $sample
8813 }
8814
8815 test_133d() {
8816         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8817         remote_ost_nodsh && skip "remote OST with nodsh" && return
8818         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8819         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8820         { skip "MDS doesn't support rename stats"; return; }
8821
8822         local testdir1=$DIR/${tdir}/stats_testdir1
8823         local testdir2=$DIR/${tdir}/stats_testdir2
8824
8825         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8826
8827         mkdir -p ${testdir1} || error "mkdir failed"
8828         mkdir -p ${testdir2} || error "mkdir failed"
8829
8830         createmany -o $testdir1/test 512 || error "createmany failed"
8831
8832         # check samedir rename size
8833         mv ${testdir1}/test0 ${testdir1}/test_0
8834
8835         local testdir1_size=$(ls -l $DIR/${tdir} |
8836                 awk '/stats_testdir1/ {print $5}')
8837         local testdir2_size=$(ls -l $DIR/${tdir} |
8838                 awk '/stats_testdir2/ {print $5}')
8839
8840         testdir1_size=$(order_2 $testdir1_size)
8841         testdir2_size=$(order_2 $testdir2_size)
8842
8843         testdir1_size=$(size_in_KMGT $testdir1_size)
8844         testdir2_size=$(size_in_KMGT $testdir2_size)
8845
8846         echo "source rename dir size: ${testdir1_size}"
8847         echo "target rename dir size: ${testdir2_size}"
8848
8849         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
8850         eval $cmd || error "$cmd failed"
8851         local samedir=$($cmd | grep 'same_dir')
8852         local same_sample=$(get_rename_size $testdir1_size)
8853         [ -z "$samedir" ] && error "samedir_rename_size count error"
8854         [[ $same_sample -eq 1 ]] ||
8855                 error "samedir_rename_size error $same_sample"
8856         echo "Check same dir rename stats success"
8857
8858         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8859
8860         # check crossdir rename size
8861         mv ${testdir1}/test_0 ${testdir2}/test_0
8862
8863         testdir1_size=$(ls -l $DIR/${tdir} |
8864                 awk '/stats_testdir1/ {print $5}')
8865         testdir2_size=$(ls -l $DIR/${tdir} |
8866                 awk '/stats_testdir2/ {print $5}')
8867
8868         testdir1_size=$(order_2 $testdir1_size)
8869         testdir2_size=$(order_2 $testdir2_size)
8870
8871         testdir1_size=$(size_in_KMGT $testdir1_size)
8872         testdir2_size=$(size_in_KMGT $testdir2_size)
8873
8874         echo "source rename dir size: ${testdir1_size}"
8875         echo "target rename dir size: ${testdir2_size}"
8876
8877         eval $cmd || error "$cmd failed"
8878         local crossdir=$($cmd | grep 'crossdir')
8879         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
8880         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
8881         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
8882         [[ $src_sample -eq 1 ]] ||
8883                 error "crossdir_rename_size error $src_sample"
8884         [[ $tgt_sample -eq 1 ]] ||
8885                 error "crossdir_rename_size error $tgt_sample"
8886         echo "Check cross dir rename stats success"
8887         rm -rf $DIR/${tdir}
8888 }
8889 run_test 133d "Verifying rename_stats ========================================"
8890
8891 test_133e() {
8892         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8893         local testdir=$DIR/${tdir}/stats_testdir
8894         local ctr f0 f1 bs=32768 count=42 sum
8895
8896         remote_ost_nodsh && skip "remote OST with nodsh" && return
8897         mkdir -p ${testdir} || error "mkdir failed"
8898
8899         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8900
8901         for ctr in {write,read}_bytes; do
8902                 sync
8903                 cancel_lru_locks osc
8904
8905                 do_facet ost1 $LCTL set_param -n \
8906                         "obdfilter.*.exports.clear=clear"
8907
8908                 if [ $ctr = write_bytes ]; then
8909                         f0=/dev/zero
8910                         f1=${testdir}/${tfile}
8911                 else
8912                         f0=${testdir}/${tfile}
8913                         f1=/dev/null
8914                 fi
8915
8916                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
8917                         error "dd failed"
8918                 sync
8919                 cancel_lru_locks osc
8920
8921                 sum=$(do_facet ost1 $LCTL get_param \
8922                         "obdfilter.*.exports.*.stats" |
8923                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
8924                                 $1 == ctr { sum += $7 }
8925                                 END { printf("%0.0f", sum) }')
8926
8927                 if ((sum != bs * count)); then
8928                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
8929                 fi
8930         done
8931
8932         rm -rf $DIR/${tdir}
8933 }
8934 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
8935
8936 test_133f() {
8937         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
8938         local facet
8939
8940         # First without trusting modes.
8941         find $proc_dirs -exec cat '{}' \; &> /dev/null
8942
8943         # Second verifying readability.
8944         find $proc_dirs \
8945                 -type f \
8946                 -exec cat '{}' \; &> /dev/null ||
8947                         error "proc file read failed"
8948
8949         for facet in $SINGLEMDS ost1; do
8950                 do_facet $facet find $proc_dirs \
8951                         ! -name req_history \
8952                         -exec cat '{}' \\\; &> /dev/null
8953
8954                 do_facet $facet find $proc_dirs \
8955                         ! -name req_history \
8956                         -type f \
8957                         -exec cat '{}' \\\; &> /dev/null ||
8958                                 error "proc file read failed"
8959         done
8960 }
8961 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
8962
8963 test_133g() {
8964         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
8965         local facet
8966
8967         # Second verifying readability.
8968         find $proc_dirs \
8969                 -type f \
8970                 -not -name force_lbug \
8971                 -not -name changelog_mask \
8972                 -exec badarea_io '{}' \; > /dev/null
8973
8974         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
8975                 skip "Too old lustre on MDS"
8976
8977         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
8978                 skip "Too old lustre on ost1"
8979
8980         for facet in $SINGLEMDS ost1; do
8981                 do_facet $facet find $proc_dirs \
8982                         -type f \
8983                         -not -name force_lbug \
8984                         -not -name changelog_mask \
8985                         -exec badarea_io '{}' \\\; &> /dev/null
8986
8987         done
8988
8989         true
8990 }
8991 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
8992
8993 test_140() { #bug-17379
8994         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8995         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
8996         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
8997         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
8998
8999         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9000         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9001         local i=0
9002         while i=`expr $i + 1`; do
9003                 test_mkdir -p $i || error "Creating dir $i"
9004                 cd $i || error "Changing to $i"
9005                 ln -s ../stat stat || error "Creating stat symlink"
9006                 # Read the symlink until ELOOP present,
9007                 # not LBUGing the system is considered success,
9008                 # we didn't overrun the stack.
9009                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9010                 [ $ret -ne 0 ] && {
9011                         if [ $ret -eq 40 ]; then
9012                                 break  # -ELOOP
9013                         else
9014                                 error "Open stat symlink"
9015                                 return
9016                         fi
9017                 }
9018         done
9019         i=`expr $i - 1`
9020         echo "The symlink depth = $i"
9021         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9022                                         error "Invalid symlink depth"
9023
9024         # Test recursive symlink
9025         ln -s symlink_self symlink_self
9026         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9027         echo "open symlink_self returns $ret"
9028         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9029 }
9030 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9031
9032 test_150() {
9033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9034         local TF="$TMP/$tfile"
9035
9036         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9037         cp $TF $DIR/$tfile
9038         cancel_lru_locks osc
9039         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9040         remount_client $MOUNT
9041         df -P $MOUNT
9042         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9043
9044         $TRUNCATE $TF 6000
9045         $TRUNCATE $DIR/$tfile 6000
9046         cancel_lru_locks osc
9047         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9048
9049         echo "12345" >>$TF
9050         echo "12345" >>$DIR/$tfile
9051         cancel_lru_locks osc
9052         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9053
9054         echo "12345" >>$TF
9055         echo "12345" >>$DIR/$tfile
9056         cancel_lru_locks osc
9057         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9058
9059         rm -f $TF
9060         true
9061 }
9062 run_test 150 "truncate/append tests"
9063
9064 #LU-2902 roc_hit was not able to read all values from lproc
9065 function roc_hit_init() {
9066         local list=$(comma_list $(osts_nodes))
9067         local dir=$DIR/$tdir-check
9068         local file=$dir/file
9069         local BEFORE
9070         local AFTER
9071         local idx
9072
9073         test_mkdir -p $dir
9074         #use setstripe to do a write to every ost
9075         for i in $(seq 0 $((OSTCOUNT-1))); do
9076                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9077                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9078                 idx=$(printf %04x $i)
9079                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9080                         awk '$1 == "cache_access" {sum += $2}
9081                                 END { printf("%0.0f", sum) }')
9082
9083                 cancel_lru_locks osc
9084                 cat $file >/dev/null
9085
9086                 AFTER=$(get_osd_param $list *OST*$idx stats |
9087                         awk '$1 == "cache_access" {sum += $2}
9088                                 END { printf("%0.0f", sum) }')
9089
9090                 echo BEFORE:$BEFORE AFTER:$AFTER
9091                 if ! let "AFTER - BEFORE == 4"; then
9092                         rm -rf $dir
9093                         error "roc_hit is not safe to use"
9094                 fi
9095                 rm $file
9096         done
9097
9098         rm -rf $dir
9099 }
9100
9101 function roc_hit() {
9102         local list=$(comma_list $(osts_nodes))
9103         echo $(get_osd_param $list '' stats |
9104                 awk '$1 == "cache_hit" {sum += $2}
9105                         END { printf("%0.0f", sum) }')
9106 }
9107
9108 function set_cache() {
9109         local on=1
9110
9111         if [ "$2" == "off" ]; then
9112                 on=0;
9113         fi
9114         local list=$(comma_list $(osts_nodes))
9115         set_osd_param $list '' $1_cache_enable $on
9116
9117         cancel_lru_locks osc
9118 }
9119
9120 test_151() {
9121         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9122         remote_ost_nodsh && skip "remote OST with nodsh" && return
9123
9124         local CPAGES=3
9125         local list=$(comma_list $(osts_nodes))
9126
9127         # check whether obdfilter is cache capable at all
9128         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9129                 echo "not cache-capable obdfilter"
9130                 return 0
9131         fi
9132
9133         # check cache is enabled on all obdfilters
9134         if get_osd_param $list '' read_cache_enable | grep 0; then
9135                 echo "oss cache is disabled"
9136                 return 0
9137         fi
9138
9139         set_osd_param $list '' writethrough_cache_enable 1
9140
9141         # check write cache is enabled on all obdfilters
9142         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9143                 echo "oss write cache is NOT enabled"
9144                 return 0
9145         fi
9146
9147         roc_hit_init
9148
9149         #define OBD_FAIL_OBD_NO_LRU  0x609
9150         do_nodes $list $LCTL set_param fail_loc=0x609
9151
9152         # pages should be in the case right after write
9153         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9154                 error "dd failed"
9155
9156         local BEFORE=$(roc_hit)
9157         cancel_lru_locks osc
9158         cat $DIR/$tfile >/dev/null
9159         local AFTER=$(roc_hit)
9160
9161         do_nodes $list $LCTL set_param fail_loc=0
9162
9163         if ! let "AFTER - BEFORE == CPAGES"; then
9164                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9165         fi
9166
9167         # the following read invalidates the cache
9168         cancel_lru_locks osc
9169         set_osd_param $list '' read_cache_enable 0
9170         cat $DIR/$tfile >/dev/null
9171
9172         # now data shouldn't be found in the cache
9173         BEFORE=$(roc_hit)
9174         cancel_lru_locks osc
9175         cat $DIR/$tfile >/dev/null
9176         AFTER=$(roc_hit)
9177         if let "AFTER - BEFORE != 0"; then
9178                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9179         fi
9180
9181         set_osd_param $list '' read_cache_enable 1
9182         rm -f $DIR/$tfile
9183 }
9184 run_test 151 "test cache on oss and controls ==============================="
9185
9186 test_152() {
9187         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9188         local TF="$TMP/$tfile"
9189
9190         # simulate ENOMEM during write
9191 #define OBD_FAIL_OST_NOMEM      0x226
9192         lctl set_param fail_loc=0x80000226
9193         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9194         cp $TF $DIR/$tfile
9195         sync || error "sync failed"
9196         lctl set_param fail_loc=0
9197
9198         # discard client's cache
9199         cancel_lru_locks osc
9200
9201         # simulate ENOMEM during read
9202         lctl set_param fail_loc=0x80000226
9203         cmp $TF $DIR/$tfile || error "cmp failed"
9204         lctl set_param fail_loc=0
9205
9206         rm -f $TF
9207 }
9208 run_test 152 "test read/write with enomem ============================"
9209
9210 test_153() {
9211         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9212 }
9213 run_test 153 "test if fdatasync does not crash ======================="
9214
9215 dot_lustre_fid_permission_check() {
9216         local fid=$1
9217         local ffid=$MOUNT/.lustre/fid/$fid
9218         local test_dir=$2
9219
9220         echo "stat fid $fid"
9221         stat $ffid > /dev/null || error "stat $ffid failed."
9222         echo "touch fid $fid"
9223         touch $ffid || error "touch $ffid failed."
9224         echo "write to fid $fid"
9225         cat /etc/hosts > $ffid || error "write $ffid failed."
9226         echo "read fid $fid"
9227         diff /etc/hosts $ffid || error "read $ffid failed."
9228         echo "append write to fid $fid"
9229         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9230         echo "rename fid $fid"
9231         mv $ffid $test_dir/$tfile.1 &&
9232                 error "rename $ffid to $tfile.1 should fail."
9233         touch $test_dir/$tfile.1
9234         mv $test_dir/$tfile.1 $ffid &&
9235                 error "rename $tfile.1 to $ffid should fail."
9236         rm -f $test_dir/$tfile.1
9237         echo "truncate fid $fid"
9238         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9239         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9240                 echo "link fid $fid"
9241                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9242         fi
9243         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9244                 echo "setfacl fid $fid"
9245                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9246                 echo "getfacl fid $fid"
9247                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9248         fi
9249         echo "unlink fid $fid"
9250         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9251         echo "mknod fid $fid"
9252         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9253
9254         fid=[0xf00000400:0x1:0x0]
9255         ffid=$MOUNT/.lustre/fid/$fid
9256
9257         echo "stat non-exist fid $fid"
9258         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9259         echo "write to non-exist fid $fid"
9260         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9261         echo "link new fid $fid"
9262         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9263
9264         mkdir -p $test_dir/$tdir
9265         touch $test_dir/$tdir/$tfile
9266         fid=$($LFS path2fid $test_dir/$tdir)
9267         rc=$?
9268         [ $rc -ne 0 ] &&
9269                 error "error: could not get fid for $test_dir/$dir/$tfile."
9270
9271         ffid=$MOUNT/.lustre/fid/$fid
9272
9273         echo "ls $fid"
9274         ls $ffid > /dev/null || error "ls $ffid failed."
9275         echo "touch $fid/$tfile.1"
9276         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9277
9278         echo "touch $MOUNT/.lustre/fid/$tfile"
9279         touch $MOUNT/.lustre/fid/$tfile && \
9280                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9281
9282         echo "setxattr to $MOUNT/.lustre/fid"
9283         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9284
9285         echo "listxattr for $MOUNT/.lustre/fid"
9286         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9287
9288         echo "delxattr from $MOUNT/.lustre/fid"
9289         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9290
9291         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9292         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9293                 error "touch invalid fid should fail."
9294
9295         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9296         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9297                 error "touch non-normal fid should fail."
9298
9299         echo "rename $tdir to $MOUNT/.lustre/fid"
9300         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9301                 error "rename to $MOUNT/.lustre/fid should fail."
9302
9303         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9304         then            # LU-3547
9305                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9306                 local new_obf_mode=777
9307
9308                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9309                 chmod $new_obf_mode $DIR/.lustre/fid ||
9310                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9311
9312                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9313                 [ $obf_mode -eq $new_obf_mode ] ||
9314                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9315
9316                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9317                 chmod $old_obf_mode $DIR/.lustre/fid ||
9318                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9319         fi
9320
9321         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9322         fid=$($LFS path2fid $test_dir/$tfile-2)
9323         echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9324         cp /etc/passwd $MOUNT/.lustre/fid/$fid &&
9325                 error "create lov data thru .lustre should fail."
9326         echo "cp /etc/passwd $test_dir/$tfile-2"
9327         cp /etc/passwd $test_dir/$tfile-2 ||
9328                 error "copy to $test_dir/$tfile-2 failed."
9329         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9330         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9331                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9332
9333         rm -rf $test_dir/tfile.lnk
9334         rm -rf $test_dir/$tfile-2
9335 }
9336
9337 test_154A() {
9338         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9339                 skip "Need MDS version at least 2.4.1" && return
9340
9341         touch $DIR/$tfile
9342         local FID=$($LFS path2fid $DIR/$tfile)
9343         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9344
9345         # check that we get the same pathname back
9346         local FOUND=$($LFS fid2path $MOUNT $FID)
9347         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9348         [ "$FOUND" != "$DIR/$tfile" ] &&
9349                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9350
9351         rm -rf $DIR/$tfile
9352 }
9353 run_test 154A "lfs path2fid and fid2path basic checks"
9354
9355 test_154a() {
9356         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9357         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9358                 { skip "Need MDS version at least 2.2.51"; return 0; }
9359         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9360
9361         cp /etc/hosts $DIR/$tfile
9362
9363         fid=$($LFS path2fid $DIR/$tfile)
9364         rc=$?
9365         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9366
9367         dot_lustre_fid_permission_check "$fid" $DIR ||
9368                 error "dot lustre permission check $fid failed"
9369
9370         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9371
9372         touch $MOUNT/.lustre/file &&
9373                 error "creation is not allowed under .lustre"
9374
9375         mkdir $MOUNT/.lustre/dir &&
9376                 error "mkdir is not allowed under .lustre"
9377
9378         rm -rf $DIR/$tfile
9379 }
9380 run_test 154a "Open-by-FID"
9381
9382 test_154b() {
9383         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9384         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9385                 { skip "Need MDS version at least 2.2.51"; return 0; }
9386
9387         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9388
9389         local remote_dir=$DIR/$tdir/remote_dir
9390         local MDTIDX=1
9391         local rc=0
9392
9393         mkdir -p $DIR/$tdir
9394         $LFS mkdir -i $MDTIDX -c $MDSCOUNT $remote_dir ||
9395                 error "create remote directory failed"
9396
9397         cp /etc/hosts $remote_dir/$tfile
9398
9399         fid=$($LFS path2fid $remote_dir/$tfile)
9400         rc=$?
9401         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9402
9403         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9404                 error "dot lustre permission check $fid failed"
9405         rm -rf $DIR/$tdir
9406 }
9407 run_test 154b "Open-by-FID for remote directory"
9408
9409 test_154c() {
9410         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9411                 skip "Need MDS version at least 2.4.1" && return
9412
9413         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9414         local FID1=$($LFS path2fid $DIR/$tfile.1)
9415         local FID2=$($LFS path2fid $DIR/$tfile.2)
9416         local FID3=$($LFS path2fid $DIR/$tfile.3)
9417
9418         local N=1
9419         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9420                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9421                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9422                 local want=FID$N
9423                 [ "$FID" = "${!want}" ] ||
9424                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9425                 N=$((N + 1))
9426         done
9427
9428         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9429                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9430                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9431                 N=$((N + 1))
9432         done
9433 }
9434 run_test 154c "lfs path2fid and fid2path multiple arguments"
9435
9436 test_154d() {
9437         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9438                 skip "Need MDS version at least 2.5.53" && return
9439
9440         if remote_mds; then
9441                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9442         else
9443                 nid="0@lo"
9444         fi
9445         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9446         local fd
9447         local cmd
9448
9449         rm -f $DIR/$tfile
9450         touch $DIR/$tfile
9451
9452         fid=$($LFS path2fid $DIR/$tfile)
9453         # Open the file
9454         fd=$(free_fd)
9455         cmd="exec $fd<$DIR/$tfile"
9456         eval $cmd
9457         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9458         echo $fid_list | grep $fid
9459         rc=$?
9460
9461         cmd="exec $fd>/dev/null"
9462         eval $cmd
9463         if [ $rc -ne 0 ]; then
9464                 error "FID $fid not found in open files list $fid_list"
9465         fi
9466 }
9467 run_test 154d "Verify open file fid"
9468
9469 test_155_small_load() {
9470     local temp=$TMP/$tfile
9471     local file=$DIR/$tfile
9472
9473     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9474         error "dd of=$temp bs=6096 count=1 failed"
9475     cp $temp $file
9476     cancel_lru_locks osc
9477     cmp $temp $file || error "$temp $file differ"
9478
9479     $TRUNCATE $temp 6000
9480     $TRUNCATE $file 6000
9481     cmp $temp $file || error "$temp $file differ (truncate1)"
9482
9483     echo "12345" >>$temp
9484     echo "12345" >>$file
9485     cmp $temp $file || error "$temp $file differ (append1)"
9486
9487     echo "12345" >>$temp
9488     echo "12345" >>$file
9489     cmp $temp $file || error "$temp $file differ (append2)"
9490
9491     rm -f $temp $file
9492     true
9493 }
9494
9495 test_155_big_load() {
9496     remote_ost_nodsh && skip "remote OST with nodsh" && return
9497     local temp=$TMP/$tfile
9498     local file=$DIR/$tfile
9499
9500     free_min_max
9501     local cache_size=$(do_facet ost$((MAXI+1)) \
9502         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9503     local large_file_size=$((cache_size * 2))
9504
9505     echo "OSS cache size: $cache_size KB"
9506     echo "Large file size: $large_file_size KB"
9507
9508     [ $MAXV -le $large_file_size ] && \
9509         skip_env "max available OST size needs > $large_file_size KB" && \
9510         return 0
9511
9512     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9513
9514     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9515         error "dd of=$temp bs=$large_file_size count=1k failed"
9516     cp $temp $file
9517     ls -lh $temp $file
9518     cancel_lru_locks osc
9519     cmp $temp $file || error "$temp $file differ"
9520
9521     rm -f $temp $file
9522     true
9523 }
9524
9525 test_155a() {
9526         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9527         set_cache read on
9528         set_cache writethrough on
9529         test_155_small_load
9530 }
9531 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9532
9533 test_155b() {
9534         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9535         set_cache read on
9536         set_cache writethrough off
9537         test_155_small_load
9538 }
9539 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9540
9541 test_155c() {
9542         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9543         set_cache read off
9544         set_cache writethrough on
9545         test_155_small_load
9546 }
9547 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9548
9549 test_155d() {
9550         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9551         set_cache read off
9552         set_cache writethrough off
9553         test_155_small_load
9554 }
9555 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9556
9557 test_155e() {
9558         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9559         set_cache read on
9560         set_cache writethrough on
9561         test_155_big_load
9562 }
9563 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9564
9565 test_155f() {
9566         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9567         set_cache read on
9568         set_cache writethrough off
9569         test_155_big_load
9570 }
9571 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9572
9573 test_155g() {
9574         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9575         set_cache read off
9576         set_cache writethrough on
9577         test_155_big_load
9578 }
9579 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9580
9581 test_155h() {
9582         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9583         set_cache read off
9584         set_cache writethrough off
9585         test_155_big_load
9586 }
9587 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9588
9589 test_156() {
9590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9591         local CPAGES=3
9592         local BEFORE
9593         local AFTER
9594         local file="$DIR/$tfile"
9595
9596         [ "$(facet_fstype ost1)" = "zfs" ] &&
9597                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9598                 return
9599
9600         roc_hit_init
9601
9602     log "Turn on read and write cache"
9603     set_cache read on
9604     set_cache writethrough on
9605
9606     log "Write data and read it back."
9607     log "Read should be satisfied from the cache."
9608     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9609     BEFORE=`roc_hit`
9610     cancel_lru_locks osc
9611     cat $file >/dev/null
9612     AFTER=`roc_hit`
9613     if ! let "AFTER - BEFORE == CPAGES"; then
9614         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9615     else
9616         log "cache hits:: before: $BEFORE, after: $AFTER"
9617     fi
9618
9619     log "Read again; it should be satisfied from the cache."
9620     BEFORE=$AFTER
9621     cancel_lru_locks osc
9622     cat $file >/dev/null
9623     AFTER=`roc_hit`
9624     if ! let "AFTER - BEFORE == CPAGES"; then
9625         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9626     else
9627         log "cache hits:: before: $BEFORE, after: $AFTER"
9628     fi
9629
9630
9631     log "Turn off the read cache and turn on the write cache"
9632     set_cache read off
9633     set_cache writethrough on
9634
9635     log "Read again; it should be satisfied from the cache."
9636     BEFORE=`roc_hit`
9637     cancel_lru_locks osc
9638     cat $file >/dev/null
9639     AFTER=`roc_hit`
9640     if ! let "AFTER - BEFORE == CPAGES"; then
9641         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9642     else
9643         log "cache hits:: before: $BEFORE, after: $AFTER"
9644     fi
9645
9646     log "Read again; it should not be satisfied from the cache."
9647     BEFORE=$AFTER
9648     cancel_lru_locks osc
9649     cat $file >/dev/null
9650     AFTER=`roc_hit`
9651     if ! let "AFTER - BEFORE == 0"; then
9652         error "IN CACHE: before: $BEFORE, after: $AFTER"
9653     else
9654         log "cache hits:: before: $BEFORE, after: $AFTER"
9655     fi
9656
9657     log "Write data and read it back."
9658     log "Read should be satisfied from the cache."
9659     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9660     BEFORE=`roc_hit`
9661     cancel_lru_locks osc
9662     cat $file >/dev/null
9663     AFTER=`roc_hit`
9664     if ! let "AFTER - BEFORE == CPAGES"; then
9665         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9666     else
9667         log "cache hits:: before: $BEFORE, after: $AFTER"
9668     fi
9669
9670     log "Read again; it should not be satisfied from the cache."
9671     BEFORE=$AFTER
9672     cancel_lru_locks osc
9673     cat $file >/dev/null
9674     AFTER=`roc_hit`
9675     if ! let "AFTER - BEFORE == 0"; then
9676         error "IN CACHE: before: $BEFORE, after: $AFTER"
9677     else
9678         log "cache hits:: before: $BEFORE, after: $AFTER"
9679     fi
9680
9681
9682     log "Turn off read and write cache"
9683     set_cache read off
9684     set_cache writethrough off
9685
9686     log "Write data and read it back"
9687     log "It should not be satisfied from the cache."
9688     rm -f $file
9689     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9690     cancel_lru_locks osc
9691     BEFORE=`roc_hit`
9692     cat $file >/dev/null
9693     AFTER=`roc_hit`
9694         if ! let "AFTER - BEFORE == 0"; then
9695                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9696         else
9697                 log "cache hits:: before: $BEFORE, after: $AFTER"
9698         fi
9699
9700     log "Turn on the read cache and turn off the write cache"
9701     set_cache read on
9702     set_cache writethrough off
9703
9704     log "Write data and read it back"
9705     log "It should not be satisfied from the cache."
9706     rm -f $file
9707     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9708     BEFORE=`roc_hit`
9709     cancel_lru_locks osc
9710     cat $file >/dev/null
9711     AFTER=`roc_hit`
9712         if ! let "AFTER - BEFORE == 0"; then
9713                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9714         else
9715                 log "cache hits:: before: $BEFORE, after: $AFTER"
9716         fi
9717
9718     log "Read again; it should be satisfied from the cache."
9719     BEFORE=`roc_hit`
9720     cancel_lru_locks osc
9721     cat $file >/dev/null
9722     AFTER=`roc_hit`
9723     if ! let "AFTER - BEFORE == CPAGES"; then
9724         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9725     else
9726         log "cache hits:: before: $BEFORE, after: $AFTER"
9727     fi
9728
9729     rm -f $file
9730 }
9731 run_test 156 "Verification of tunables ============================"
9732
9733 #Changelogs
9734 err17935 () {
9735         if [[ $MDSCOUNT -gt 1 ]]; then
9736                 error_ignore bz17935 $*
9737         else
9738                 error $*
9739         fi
9740 }
9741
9742 changelog_chmask()
9743 {
9744         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
9745
9746         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
9747
9748         if [ $MASK -eq 1 ]; then
9749                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
9750         else
9751                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
9752         fi
9753 }
9754
9755 changelog_extract_field() {
9756         local mdt=$1
9757         local cltype=$2
9758         local file=$3
9759         local identifier=$4
9760
9761         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
9762                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
9763                 tail -1
9764 }
9765
9766 test_160a() {
9767         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9768         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9769         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9770                 { skip "Need MDS version at least 2.2.0"; return; }
9771
9772         local CL_USERS="mdd.$MDT0.changelog_users"
9773         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9774         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9775         echo "Registered as changelog user $USER"
9776         $GET_CL_USERS | grep -q $USER ||
9777                 error "User $USER not found in changelog_users"
9778
9779         # change something
9780         test_mkdir -p $DIR/$tdir/pics/2008/zachy
9781         touch $DIR/$tdir/pics/2008/zachy/timestamp
9782         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
9783         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
9784         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
9785         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
9786         rm $DIR/$tdir/pics/desktop.jpg
9787
9788         $LFS changelog $MDT0 | tail -5
9789
9790         echo "verifying changelog mask"
9791         changelog_chmask "MKDIR"
9792         changelog_chmask "CLOSE"
9793
9794         test_mkdir -p $DIR/$tdir/pics/zach/sofia
9795         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9796
9797         changelog_chmask "MKDIR"
9798         changelog_chmask "CLOSE"
9799
9800         test_mkdir -p $DIR/$tdir/pics/2008/sofia
9801         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9802
9803         $LFS changelog $MDT0
9804         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
9805         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
9806         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
9807         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
9808
9809         # verify contents
9810         echo "verifying target fid"
9811         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
9812         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
9813         [ "$fidc" == "$fidf" ] ||
9814                 err17935 "fid in changelog $fidc != file fid $fidf"
9815         echo "verifying parent fid"
9816         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
9817         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
9818         [ "$fidc" == "$fidf" ] ||
9819                 err17935 "pfid in changelog $fidc != dir fid $fidf"
9820
9821         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9822         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
9823         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9824         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
9825         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
9826                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
9827
9828         MIN_REC=$($GET_CL_USERS |
9829                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
9830         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
9831         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
9832         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
9833                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
9834
9835         # LU-3446 changelog index reset on MDT restart
9836         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
9837         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9838         $LFS changelog_clear $MDT0 $USER 0
9839         stop $SINGLEMDS || error "Fail to stop MDT."
9840         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
9841         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9842         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
9843         [ $CUR_REC1 == $CUR_REC2 ] ||
9844                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
9845
9846         echo "verifying user deregister"
9847         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9848         $GET_CL_USERS | grep -q $USER &&
9849                 error "User $USER still in changelog_users"
9850
9851         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
9852         if [ $USERS -eq 0 ]; then
9853                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9854                 touch $DIR/$tdir/chloe
9855                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9856                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
9857                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
9858         else
9859                 echo "$USERS other changelog users; can't verify off"
9860         fi
9861 }
9862 run_test 160a "changelog sanity"
9863
9864 test_160b() { # LU-3587
9865         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9866         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9867         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9868                 { skip "Need MDS version at least 2.2.0"; return; }
9869
9870         local CL_USERS="mdd.$MDT0.changelog_users"
9871         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9872         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9873         echo "Registered as changelog user $USER"
9874         $GET_CL_USERS | grep -q $USER ||
9875                 error "User $USER not found in changelog_users"
9876
9877         local LONGNAME1=$(str_repeat a 255)
9878         local LONGNAME2=$(str_repeat b 255)
9879
9880         cd $DIR
9881         echo "creating very long named file"
9882         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
9883         echo "moving very long named file"
9884         mv $LONGNAME1 $LONGNAME2
9885
9886         $LFS changelog $MDT0 | grep RENME
9887
9888         echo "deregistering $USER"
9889         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9890
9891         rm -f $LONGNAME2
9892 }
9893 run_test 160b "Verify that very long rename doesn't crash in changelog"
9894
9895 test_160c() {
9896         local rc=0
9897         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9898
9899         # Registration step
9900         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
9901                 changelog_register -n)
9902
9903         rm -rf $DIR/$tdir
9904         mkdir -p $DIR/$tdir
9905         $MCREATE $DIR/$tdir/foo_160c
9906         changelog_chmask "TRUNC"
9907         $TRUNCATE $DIR/$tdir/foo_160c 200
9908         changelog_chmask "TRUNC"
9909         $TRUNCATE $DIR/$tdir/foo_160c 199
9910         $LFS changelog $MDT0
9911         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
9912         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
9913         $LFS changelog_clear $MDT0 $USER 0
9914
9915         # Deregistration step
9916         echo "deregistering $USER"
9917         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9918 }
9919 run_test 160c "verify that changelog log catch the truncate event"
9920
9921 test_161a() {
9922         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9923         test_mkdir -p -c1 $DIR/$tdir
9924         cp /etc/hosts $DIR/$tdir/$tfile
9925         test_mkdir -c1 $DIR/$tdir/foo1
9926         test_mkdir -c1 $DIR/$tdir/foo2
9927         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
9928         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
9929         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
9930         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
9931         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
9932         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9933                 $LFS fid2path $DIR $FID
9934                 err17935 "bad link ea"
9935         fi
9936     # middle
9937     rm $DIR/$tdir/foo2/zachary
9938     # last
9939     rm $DIR/$tdir/foo2/thor
9940     # first
9941     rm $DIR/$tdir/$tfile
9942     # rename
9943     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
9944     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
9945         then
9946         $LFS fid2path $DIR $FID
9947         err17935 "bad link rename"
9948     fi
9949     rm $DIR/$tdir/foo2/maggie
9950
9951         # overflow the EA
9952         local longname=filename_avg_len_is_thirty_two_
9953         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
9954                 error "failed to hardlink many files"
9955         links=$($LFS fid2path $DIR $FID | wc -l)
9956         echo -n "${links}/1000 links in link EA"
9957         [[ $links -gt 60 ]] ||
9958                 err17935 "expected at least 60 links in link EA"
9959         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
9960                 error "failed to unlink many hardlinks"
9961 }
9962 run_test 161a "link ea sanity"
9963
9964 test_161b() {
9965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9966         [ $MDSCOUNT -lt 2 ] &&
9967                 skip "skipping remote directory test" && return
9968         local MDTIDX=1
9969         local remote_dir=$DIR/$tdir/remote_dir
9970
9971         mkdir -p $DIR/$tdir
9972         $LFS mkdir -i $MDTIDX $remote_dir ||
9973                 error "create remote directory failed"
9974
9975         cp /etc/hosts $remote_dir/$tfile
9976         mkdir -p $remote_dir/foo1
9977         mkdir -p $remote_dir/foo2
9978         ln $remote_dir/$tfile $remote_dir/foo1/sofia
9979         ln $remote_dir/$tfile $remote_dir/foo2/zachary
9980         ln $remote_dir/$tfile $remote_dir/foo1/luna
9981         ln $remote_dir/$tfile $remote_dir/foo2/thor
9982
9983         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
9984                      tr -d ']')
9985         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9986                 $LFS fid2path $DIR $FID
9987                 err17935 "bad link ea"
9988         fi
9989         # middle
9990         rm $remote_dir/foo2/zachary
9991         # last
9992         rm $remote_dir/foo2/thor
9993         # first
9994         rm $remote_dir/$tfile
9995         # rename
9996         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
9997         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
9998         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
9999                 $LFS fid2path $DIR $FID
10000                 err17935 "bad link rename"
10001         fi
10002         rm $remote_dir/foo2/maggie
10003
10004         # overflow the EA
10005         local longname=filename_avg_len_is_thirty_two_
10006         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10007                 error "failed to hardlink many files"
10008         links=$($LFS fid2path $DIR $FID | wc -l)
10009         echo -n "${links}/1000 links in link EA"
10010         [[ ${links} -gt 60 ]] ||
10011                 err17935 "expected at least 60 links in link EA"
10012         unlinkmany $remote_dir/foo2/$longname 1000 ||
10013         error "failed to unlink many hardlinks"
10014 }
10015 run_test 161b "link ea sanity under remote directory"
10016
10017 test_161c() {
10018         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10019         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10020                 skip "Need MDS version at least 2.1.5" && return
10021
10022         # define CLF_RENAME_LAST 0x0001
10023         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10024         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10025                 changelog_register -n)
10026         rm -rf $DIR/$tdir
10027         mkdir -p $DIR/$tdir
10028         touch $DIR/$tdir/foo_161c
10029         touch $DIR/$tdir/bar_161c
10030         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10031         $LFS changelog $MDT0 | grep RENME
10032         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10033                 cut -f5 -d' ')
10034         $LFS changelog_clear $MDT0 $USER 0
10035         if [ x$flags != "x0x1" ]; then
10036                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10037                         $USER
10038                 error "flag $flags is not 0x1"
10039         fi
10040         echo "rename overwrite a target having nlink = 1," \
10041                 "changelog record has flags of $flags"
10042
10043         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10044         touch $DIR/$tdir/foo_161c
10045         touch $DIR/$tdir/bar_161c
10046         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10047         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10048         $LFS changelog $MDT0 | grep RENME
10049         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10050         $LFS changelog_clear $MDT0 $USER 0
10051         if [ x$flags != "x0x0" ]; then
10052                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10053                         $USER
10054                 error "flag $flags is not 0x0"
10055         fi
10056         echo "rename overwrite a target having nlink > 1," \
10057                 "changelog record has flags of $flags"
10058
10059         # rename doesn't overwrite a target (changelog flag 0x0)
10060         touch $DIR/$tdir/foo_161c
10061         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10062         $LFS changelog $MDT0 | grep RENME
10063         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10064         $LFS changelog_clear $MDT0 $USER 0
10065         if [ x$flags != "x0x0" ]; then
10066                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10067                         $USER
10068                 error "flag $flags is not 0x0"
10069         fi
10070         echo "rename doesn't overwrite a target," \
10071                 "changelog record has flags of $flags"
10072
10073         # define CLF_UNLINK_LAST 0x0001
10074         # unlink a file having nlink = 1 (changelog flag 0x1)
10075         rm -f $DIR/$tdir/foo2_161c
10076         $LFS changelog $MDT0 | grep UNLNK
10077         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10078         $LFS changelog_clear $MDT0 $USER 0
10079         if [ x$flags != "x0x1" ]; then
10080                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10081                         $USER
10082                 error "flag $flags is not 0x1"
10083         fi
10084         echo "unlink a file having nlink = 1," \
10085                 "changelog record has flags of $flags"
10086
10087         # unlink a file having nlink > 1 (changelog flag 0x0)
10088         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10089         rm -f $DIR/$tdir/foobar_161c
10090         $LFS changelog $MDT0 | grep UNLNK
10091         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10092         $LFS changelog_clear $MDT0 $USER 0
10093         if [ x$flags != "x0x0" ]; then
10094                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10095                         $USER
10096                 error "flag $flags is not 0x0"
10097         fi
10098         echo "unlink a file having nlink > 1," \
10099                 "changelog record has flags of $flags"
10100         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10101 }
10102 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10103
10104 check_path() {
10105     local expected=$1
10106     shift
10107     local fid=$2
10108
10109     local path=$(${LFS} fid2path $*)
10110     RC=$?
10111
10112     if [ $RC -ne 0 ]; then
10113         err17935 "path looked up of $expected failed. Error $RC"
10114         return $RC
10115     elif [ "${path}" != "${expected}" ]; then
10116         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10117         return 2
10118     fi
10119     echo "fid $fid resolves to path $path (expected $expected)"
10120 }
10121
10122 test_162() {
10123         # Make changes to filesystem
10124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10125         test_mkdir -p $DIR/$tdir/d2
10126         touch $DIR/$tdir/d2/$tfile
10127         touch $DIR/$tdir/d2/x1
10128         touch $DIR/$tdir/d2/x2
10129         test_mkdir -p $DIR/$tdir/d2/a/b/c
10130         test_mkdir -p $DIR/$tdir/d2/p/q/r
10131         # regular file
10132         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10133         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
10134
10135         # softlink
10136         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10137         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10138         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
10139
10140         # softlink to wrong file
10141         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10142         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10143         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
10144
10145         # hardlink
10146         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10147         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10148         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10149         # fid2path dir/fsname should both work
10150         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
10151         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
10152
10153         # hardlink count: check that there are 2 links
10154         # Doesnt work with CMD yet: 17935
10155         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10156                 err17935 "expected 2 links"
10157
10158         # hardlink indexing: remove the first link
10159         rm $DIR/$tdir/d2/p/q/r/hlink
10160         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
10161
10162         return 0
10163 }
10164 run_test 162 "path lookup sanity"
10165
10166 test_169() {
10167         # do directio so as not to populate the page cache
10168         log "creating a 10 Mb file"
10169         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10170         log "starting reads"
10171         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10172         log "truncating the file"
10173         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10174         log "killing dd"
10175         kill %+ || true # reads might have finished
10176         echo "wait until dd is finished"
10177         wait
10178         log "removing the temporary file"
10179         rm -rf $DIR/$tfile || error "tmp file removal failed"
10180 }
10181 run_test 169 "parallel read and truncate should not deadlock"
10182
10183 test_170() {
10184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10185         $LCTL clear     # bug 18514
10186         $LCTL debug_daemon start $TMP/${tfile}_log_good
10187         touch $DIR/$tfile
10188         $LCTL debug_daemon stop
10189         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10190                error "sed failed to read log_good"
10191
10192         $LCTL debug_daemon start $TMP/${tfile}_log_good
10193         rm -rf $DIR/$tfile
10194         $LCTL debug_daemon stop
10195
10196         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10197                error "lctl df log_bad failed"
10198
10199         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10200         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10201
10202         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10203         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10204
10205         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10206                 error "bad_line good_line1 good_line2 are empty"
10207
10208         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10209         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10210         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10211
10212         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10213         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10214         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10215
10216         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10217                 error "bad_line_new good_line_new are empty"
10218
10219         local expected_good=$((good_line1 + good_line2*2))
10220
10221         rm -f $TMP/${tfile}*
10222         # LU-231, short malformed line may not be counted into bad lines
10223         if [ $bad_line -ne $bad_line_new ] &&
10224                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10225                 error "expected $bad_line bad lines, but got $bad_line_new"
10226                 return 1
10227         fi
10228
10229         if [ $expected_good -ne $good_line_new ]; then
10230                 error "expected $expected_good good lines, but got $good_line_new"
10231                 return 2
10232         fi
10233         true
10234 }
10235 run_test 170 "test lctl df to handle corrupted log ====================="
10236
10237 test_171() { # bug20592
10238         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10239 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10240         $LCTL set_param fail_loc=0x50e
10241         $LCTL set_param fail_val=3000
10242         multiop_bg_pause $DIR/$tfile O_s || true
10243         local MULTIPID=$!
10244         kill -USR1 $MULTIPID
10245         # cause log dump
10246         sleep 3
10247         wait $MULTIPID
10248         if dmesg | grep "recursive fault"; then
10249                 error "caught a recursive fault"
10250         fi
10251         $LCTL set_param fail_loc=0
10252         true
10253 }
10254 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10255
10256 # it would be good to share it with obdfilter-survey/libecho code
10257 setup_obdecho_osc () {
10258         local rc=0
10259         local ost_nid=$1
10260         local obdfilter_name=$2
10261         echo "Creating new osc for $obdfilter_name on $ost_nid"
10262         # make sure we can find loopback nid
10263         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10264
10265         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10266                            ${obdfilter_name}_osc_UUID || rc=2; }
10267         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10268                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10269         return $rc
10270 }
10271
10272 cleanup_obdecho_osc () {
10273         local obdfilter_name=$1
10274         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10275         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10276         return 0
10277 }
10278
10279 obdecho_test() {
10280         local OBD=$1
10281         local node=$2
10282         local pages=${3:-64}
10283         local rc=0
10284         local id
10285
10286         local count=10
10287         local obd_size=$(get_obd_size $node $OBD)
10288         local page_size=$(get_page_size $node)
10289         if [[ -n "$obd_size" ]]; then
10290                 local new_count=$((obd_size / (pages * page_size / 1024)))
10291                 [[ $new_count -ge $count ]] || count=$new_count
10292         fi
10293
10294         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10295         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10296                            rc=2; }
10297         if [ $rc -eq 0 ]; then
10298             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10299             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10300         fi
10301         echo "New object id is $id"
10302         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10303                            rc=4; }
10304         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10305                            "test_brw $count w v $pages $id" || rc=4; }
10306         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10307                            rc=4; }
10308         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10309                                         "cleanup" || rc=5; }
10310         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10311                                         "detach" || rc=6; }
10312         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10313         return $rc
10314 }
10315
10316 test_180a() {
10317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10318         remote_ost_nodsh && skip "remote OST with nodsh" && return
10319         local rc=0
10320         local rmmod_local=0
10321
10322         if ! module_loaded obdecho; then
10323             load_module obdecho/obdecho
10324             rmmod_local=1
10325         fi
10326
10327         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10328         local host=$(lctl get_param -n osc.$osc.import |
10329                              awk '/current_connection:/ {print $2}' )
10330         local target=$(lctl get_param -n osc.$osc.import |
10331                              awk '/target:/ {print $2}' )
10332         target=${target%_UUID}
10333
10334         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10335         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10336         [[ -n $target ]] && cleanup_obdecho_osc $target
10337         [ $rmmod_local -eq 1 ] && rmmod obdecho
10338         return $rc
10339 }
10340 run_test 180a "test obdecho on osc"
10341
10342 test_180b() {
10343         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10344         remote_ost_nodsh && skip "remote OST with nodsh" && return
10345         local rc=0
10346         local rmmod_remote=0
10347
10348         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10349                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10350                       "modprobe obdecho; }" && rmmod_remote=1
10351         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10352         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10353         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10354         return $rc
10355 }
10356 run_test 180b "test obdecho directly on obdfilter"
10357
10358 test_180c() { # LU-2598
10359         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10360         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10361                 skip "Need MDS version at least 2.4.0" && return
10362
10363         local rc=0
10364         local rmmod_remote=false
10365         local pages=16384 # 64MB bulk I/O RPC size
10366         local target
10367
10368         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10369                 rmmod_remote=true || error "failed to load module obdecho"
10370
10371         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10372                 head -n1)
10373         if [ -n "$target" ]; then
10374                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10375         else
10376                 echo "there is no obdfilter target on ost1"
10377                 rc=2
10378         fi
10379         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10380         return $rc
10381 }
10382 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10383
10384 test_181() { # bug 22177
10385         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10386         # create enough files to index the directory
10387         createmany -o $DIR/$tdir/foobar 4000
10388         # print attributes for debug purpose
10389         lsattr -d .
10390         # open dir
10391         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10392         MULTIPID=$!
10393         # remove the files & current working dir
10394         unlinkmany $DIR/$tdir/foobar 4000
10395         rmdir $DIR/$tdir
10396         kill -USR1 $MULTIPID
10397         wait $MULTIPID
10398         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10399         return 0
10400 }
10401 run_test 181 "Test open-unlinked dir ========================"
10402
10403 test_182() {
10404         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10405         # disable MDC RPC lock wouldn't crash client
10406         local fcount=1000
10407         local tcount=4
10408
10409         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10410 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10411         $LCTL set_param fail_loc=0x804
10412
10413         for (( i=0; i < $tcount; i++ )) ; do
10414                 mkdir $DIR/$tdir/$i
10415                 createmany -o $DIR/$tdir/$i/f- $fcount &
10416         done
10417         wait
10418
10419         for (( i=0; i < $tcount; i++ )) ; do
10420                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10421         done
10422         wait
10423
10424         rm -rf $DIR/$tdir
10425
10426         $LCTL set_param fail_loc=0
10427 }
10428 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10429
10430 test_183() { # LU-2275
10431         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10432                 skip "Need MDS version at least 2.3.56" && return
10433
10434         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10435         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10436         echo aaa > $DIR/$tdir/$tfile
10437
10438 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10439         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10440
10441         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10442         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10443
10444         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10445
10446         # Flush negative dentry cache
10447         touch $DIR/$tdir/$tfile
10448
10449         # We are not checking for any leaked references here, they'll
10450         # become evident next time we do cleanup with module unload.
10451         rm -rf $DIR/$tdir
10452 }
10453 run_test 183 "No crash or request leak in case of strange dispositions ========"
10454
10455 # test suite 184 is for LU-2016, LU-2017
10456 test_184a() {
10457         check_swap_layouts_support && return 0
10458
10459         dir0=$DIR/$tdir/$testnum
10460         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
10461         ref1=/etc/passwd
10462         ref2=/etc/group
10463         file1=$dir0/f1
10464         file2=$dir0/f2
10465         $SETSTRIPE -c1 $file1
10466         cp $ref1 $file1
10467         $SETSTRIPE -c2 $file2
10468         cp $ref2 $file2
10469         gen1=$($GETSTRIPE -g $file1)
10470         gen2=$($GETSTRIPE -g $file2)
10471
10472         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10473         gen=$($GETSTRIPE -g $file1)
10474         [[ $gen1 != $gen ]] ||
10475                 "Layout generation on $file1 does not change"
10476         gen=$($GETSTRIPE -g $file2)
10477         [[ $gen2 != $gen ]] ||
10478                 "Layout generation on $file2 does not change"
10479
10480         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10481         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10482 }
10483 run_test 184a "Basic layout swap"
10484
10485 test_184b() {
10486         check_swap_layouts_support && return 0
10487
10488         dir0=$DIR/$tdir/$testnum
10489         mkdir -p $dir0 || error "creating dir $dir0"
10490         file1=$dir0/f1
10491         file2=$dir0/f2
10492         file3=$dir0/f3
10493         dir1=$dir0/d1
10494         dir2=$dir0/d2
10495         mkdir $dir1 $dir2
10496         $SETSTRIPE -c1 $file1
10497         $SETSTRIPE -c2 $file2
10498         $SETSTRIPE -c1 $file3
10499         chown $RUNAS_ID $file3
10500         gen1=$($GETSTRIPE -g $file1)
10501         gen2=$($GETSTRIPE -g $file2)
10502
10503         $LFS swap_layouts $dir1 $dir2 &&
10504                 error "swap of directories layouts should fail"
10505         $LFS swap_layouts $dir1 $file1 &&
10506                 error "swap of directory and file layouts should fail"
10507         $RUNAS $LFS swap_layouts $file1 $file2 &&
10508                 error "swap of file we cannot write should fail"
10509         $LFS swap_layouts $file1 $file3 &&
10510                 error "swap of file with different owner should fail"
10511         /bin/true # to clear error code
10512 }
10513 run_test 184b "Forbidden layout swap (will generate errors)"
10514
10515 test_184c() {
10516         check_swap_layouts_support && return 0
10517
10518         local dir0=$DIR/$tdir/$testnum
10519         mkdir -p $dir0 || error "creating dir $dir0"
10520
10521         local ref1=$dir0/ref1
10522         local ref2=$dir0/ref2
10523         local file1=$dir0/file1
10524         local file2=$dir0/file2
10525         # create a file large enough for the concurent test
10526         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10527         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10528         echo "ref file size: ref1($(stat -c %s $ref1))," \
10529              "ref2($(stat -c %s $ref2))"
10530
10531         cp $ref2 $file2
10532         dd if=$ref1 of=$file1 bs=16k &
10533         local DD_PID=$!
10534
10535         # Make sure dd starts to copy file
10536         while [ ! -f $file1 ]; do sleep 0.1; done
10537
10538         $LFS swap_layouts $file1 $file2
10539         local rc=$?
10540         wait $DD_PID
10541         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10542         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10543
10544         # how many bytes copied before swapping layout
10545         local copied=$(stat -c %s $file2)
10546         local remaining=$(stat -c %s $ref1)
10547         remaining=$((remaining - copied))
10548         echo "Copied $copied bytes before swapping layout..."
10549
10550         cmp -n $copied $file1 $ref2 | grep differ &&
10551                 error "Content mismatch [0, $copied) of ref2 and file1"
10552         cmp -n $copied $file2 $ref1 ||
10553                 error "Content mismatch [0, $copied) of ref1 and file2"
10554         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10555                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10556
10557         # clean up
10558         rm -f $ref1 $ref2 $file1 $file2
10559 }
10560 run_test 184c "Concurrent write and layout swap"
10561
10562 test_184d() {
10563         check_swap_layouts_support && return 0
10564         [ -z "$(which getfattr 2>/dev/null)" ] &&
10565                 skip "no getfattr command" && return 0
10566
10567         local file1=$DIR/$tdir/$tfile-1
10568         local file2=$DIR/$tdir/$tfile-2
10569         local file3=$DIR/$tdir/$tfile-3
10570         local lovea1
10571         local lovea2
10572
10573         mkdir -p $DIR/$tdir
10574         touch $file1 || error "create $file1 failed"
10575         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10576                 error "create $file2 failed"
10577         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10578                 error "create $file3 failed"
10579         lovea1=$($LFS getstripe $file1 | sed 1d)
10580
10581         $LFS swap_layouts $file2 $file3 ||
10582                 error "swap $file2 $file3 layouts failed"
10583         $LFS swap_layouts $file1 $file2 ||
10584                 error "swap $file1 $file2 layouts failed"
10585
10586         lovea2=$($LFS getstripe $file2 | sed 1d)
10587         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10588
10589         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10590         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
10591 }
10592 run_test 184d "allow stripeless layouts swap"
10593
10594
10595 test_185() { # LU-2441
10596         # LU-3553 - no volatile file support in old servers
10597         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10598                 { skip "Need MDS version at least 2.3.60"; return 0; }
10599
10600         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10601         touch $DIR/$tdir/spoo
10602         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10603         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10604                 error "cannot create/write a volatile file"
10605         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10606                 error "FID is still valid after close"
10607
10608         multiop_bg_pause $DIR/$tdir vVw4096_c
10609         local multi_pid=$!
10610
10611         local OLD_IFS=$IFS
10612         IFS=":"
10613         local fidv=($fid)
10614         IFS=$OLD_IFS
10615         # assume that the next FID for this client is sequential, since stdout
10616         # is unfortunately eaten by multiop_bg_pause
10617         local n=$((${fidv[1]} + 1))
10618         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10619         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10620                 error "FID is missing before close"
10621         kill -USR1 $multi_pid
10622         # 1 second delay, so if mtime change we will see it
10623         sleep 1
10624         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10625         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10626 }
10627 run_test 185 "Volatile file support"
10628
10629 test_187a() {
10630         local dir0=$DIR/$tdir/$testnum
10631         mkdir -p $dir0 || error "creating dir $dir0"
10632
10633         local file=$dir0/file1
10634         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10635         local dv1=$($LFS data_version $file)
10636         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10637         local dv2=$($LFS data_version $file)
10638         [[ $dv1 != $dv2 ]] ||
10639                 error "data version did not change on write $dv1 == $dv2"
10640
10641         # clean up
10642         rm -f $file1
10643 }
10644 run_test 187a "Test data version change"
10645
10646 test_187b() {
10647         local dir0=$DIR/$tdir/$testnum
10648         mkdir -p $dir0 || error "creating dir $dir0"
10649
10650         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
10651         [[ ${DV[0]} != ${DV[1]} ]] ||
10652                 error "data version did not change on write"\
10653                       " ${DV[0]} == ${DV[1]}"
10654
10655         # clean up
10656         rm -f $file1
10657 }
10658 run_test 187b "Test data version change on volatile file"
10659
10660 # OST pools tests
10661 check_file_in_pool()
10662 {
10663         local file=$1
10664         local pool=$2
10665         local tlist="$3"
10666         local res=$($GETSTRIPE $file | grep 0x | cut -f2)
10667         for i in $res
10668         do
10669                 for t in $tlist ; do
10670                         [ "$i" -eq "$t" ] && continue 2
10671                 done
10672
10673                 echo "pool list: $tlist"
10674                 echo "striping: $res"
10675                 error_noexit "$file not allocated in $pool"
10676                 return 1
10677         done
10678         return 0
10679 }
10680
10681 pool_add() {
10682         echo "Creating new pool"
10683         local pool=$1
10684
10685         create_pool $FSNAME.$pool ||
10686                 { error_noexit "No pool created, result code $?"; return 1; }
10687         [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
10688                 { error_noexit "$pool not in lfs pool_list"; return 2; }
10689 }
10690
10691 pool_add_targets() {
10692         echo "Adding targets to pool"
10693         local pool=$1
10694         local first=$2
10695         local last=$3
10696         local step=${4:-1}
10697
10698         local list=$(seq $first $step $last)
10699
10700         local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
10701         do_facet mgs $LCTL pool_add \
10702                         $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
10703         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
10704                         | sort -u | tr '\n' ' ' " "$t" || { 
10705                 error_noexit "Add to pool failed"
10706                 return 1
10707         }
10708         local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
10709         local addcount=$(((last - first) / step + 1))
10710         [ $lfscount -eq $addcount ] || {
10711                 error_noexit "lfs pool_list bad ost count" \
10712                                                 "$lfscount != $addcount"
10713                 return 2
10714         }
10715 }
10716
10717 pool_set_dir() {
10718         local pool=$1
10719         local tdir=$2
10720         echo "Setting pool on directory $tdir"
10721
10722         $SETSTRIPE -c 2 -p $pool $tdir && return 0
10723
10724         error_noexit "Cannot set pool $pool to $tdir"
10725         return 1
10726 }
10727
10728 pool_check_dir() {
10729         local pool=$1
10730         local tdir=$2
10731         echo "Checking pool on directory $tdir"
10732
10733         local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
10734         [ "$res" = "$pool" ] && return 0
10735
10736         error_noexit "Pool on '$tdir' is '$res', not '$pool'"
10737         return 1
10738 }
10739
10740 pool_dir_rel_path() {
10741         echo "Testing relative path works well"
10742         local pool=$1
10743         local tdir=$2
10744         local root=$3
10745
10746         mkdir -p $root/$tdir/$tdir
10747         cd $root/$tdir
10748         pool_set_dir $pool $tdir          || return 1
10749         pool_set_dir $pool ./$tdir        || return 2
10750         pool_set_dir $pool ../$tdir       || return 3
10751         pool_set_dir $pool ../$tdir/$tdir || return 4
10752         rm -rf $tdir; cd - > /dev/null
10753 }
10754
10755 pool_alloc_files() {
10756         echo "Checking files allocation from directory pool"
10757         local pool=$1
10758         local tdir=$2
10759         local count=$3
10760         local tlist="$4"
10761
10762         local failed=0
10763         for i in $(seq -w 1 $count)
10764         do
10765                 local file=$tdir/file-$i
10766                 touch $file
10767                 check_file_in_pool $file $pool "$tlist" || \
10768                         failed=$((failed + 1))
10769         done
10770         [ "$failed" = 0 ] && return 0
10771
10772         error_noexit "$failed files not allocated in $pool"
10773         return 1
10774 }
10775
10776 pool_create_files() {
10777         echo "Creating files in pool"
10778         local pool=$1
10779         local tdir=$2
10780         local count=$3
10781         local tlist="$4"
10782
10783         mkdir -p $tdir
10784         local failed=0
10785         for i in $(seq -w 1 $count)
10786         do
10787                 local file=$tdir/spoo-$i
10788                 $SETSTRIPE -p $pool $file
10789                 check_file_in_pool $file $pool "$tlist" || \
10790                         failed=$((failed + 1))
10791         done
10792         [ "$failed" = 0 ] && return 0
10793
10794         error_noexit "$failed files not allocated in $pool"
10795         return 1
10796 }
10797
10798 pool_lfs_df() {
10799         echo "Checking 'lfs df' output"
10800         local pool=$1
10801
10802         local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
10803                         tr '\n' ' ')
10804         local res=$($LFS df --pool $FSNAME.$pool |
10805                         awk '{print $1}' |
10806                         grep "$FSNAME-OST" |
10807                         tr '\n' ' ')
10808         [ "$res" = "$t" ] && return 0
10809
10810         error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
10811         return 1
10812 }
10813
10814 pool_file_rel_path() {
10815         echo "Creating files in a pool with relative pathname"
10816         local pool=$1
10817         local tdir=$2
10818
10819         mkdir -p $tdir ||
10820                 { error_noexit "unable to create $tdir"; return 1 ; }
10821         local file="/..$tdir/$tfile-1"
10822         $SETSTRIPE -p $pool $file ||
10823                 { error_noexit "unable to create $file" ; return 2 ; }
10824
10825         cd $tdir
10826         $SETSTRIPE -p $pool $tfile-2 || {
10827                 error_noexit "unable to create $tfile-2 in $tdir"
10828                 return 3
10829         }
10830 }
10831
10832 pool_remove_first_target() {
10833         echo "Removing first target from a pool"
10834         local pool=$1
10835
10836         local pname="lov.$FSNAME-*.pools.$pool"
10837         local t=$($LCTL get_param -n $pname | head -n1)
10838         do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10839         wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
10840                 error_noexit "$t not removed from $FSNAME.$pool"
10841                 return 1
10842         }
10843 }
10844
10845 pool_remove_all_targets() {
10846         echo "Removing all targets from pool"
10847         local pool=$1
10848         local file=$2
10849         local pname="lov.$FSNAME-*.pools.$pool"
10850         for t in $($LCTL get_param -n $pname | sort -u)
10851         do
10852                 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10853         done
10854         wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
10855                 error_noexit "Pool $FSNAME.$pool cannot be drained"
10856                 return 1
10857         }
10858         # striping on an empty/nonexistant pool should fall back
10859         # to "pool of everything"
10860         touch $file || {
10861                 error_noexit "failed to use fallback striping for empty pool"
10862                 return 2
10863         }
10864         # setstripe on an empty pool should fail
10865         $SETSTRIPE -p $pool $file 2>/dev/null && {
10866                 error_noexit "expected failure when creating file" \
10867                                                         "with empty pool"
10868                 return 3
10869         }
10870         return 0
10871 }
10872
10873 pool_remove() {
10874         echo "Destroying pool"
10875         local pool=$1
10876         local file=$2
10877
10878         do_facet mgs $LCTL pool_destroy $FSNAME.$pool
10879
10880         sleep 2
10881         # striping on an empty/nonexistant pool should fall back 
10882         # to "pool of everything"
10883         touch $file || {
10884                 error_noexit "failed to use fallback striping for missing pool"
10885                 return 1
10886         }
10887         # setstripe on an empty pool should fail
10888         $SETSTRIPE -p $pool $file 2>/dev/null && {
10889                 error_noexit "expected failure when creating file" \
10890                                                         "with missing pool"
10891                 return 2
10892         }
10893
10894         # get param should return err once pool is gone
10895         if wait_update $HOSTNAME "lctl get_param -n \
10896                 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
10897         then
10898                 remove_pool_from_list $FSNAME.$pool
10899                 return 0
10900         fi
10901         error_noexit "Pool $FSNAME.$pool is not destroyed"
10902         return 3
10903 }
10904
10905 test_200() {
10906         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10907         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
10908
10909         local POOL=${POOL:-cea1}
10910         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
10911         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
10912         # Pool OST targets
10913         local first_ost=0
10914         local last_ost=$(($OSTCOUNT - 1))
10915         local ost_step=2
10916         local ost_list=$(seq $first_ost $ost_step $last_ost)
10917         local ost_range="$first_ost $last_ost $ost_step"
10918         local test_path=$POOL_ROOT/$POOL_DIR_NAME
10919         local file_dir=$POOL_ROOT/file_tst
10920
10921         local rc=0
10922         while : ; do
10923                 # former test_200a test_200b
10924                 pool_add $POOL                          || { rc=$? ; break; }
10925                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
10926                 # former test_200c test_200d
10927                 mkdir -p $test_path
10928                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
10929                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
10930                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
10931                                                         || { rc=$? ; break; }
10932                 # former test_200e test_200f
10933                 local files=$((OSTCOUNT*3))
10934                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
10935                                                         || { rc=$? ; break; }
10936                 pool_create_files $POOL $file_dir $files "$ost_list" \
10937                                                         || { rc=$? ; break; }
10938                 # former test_200g test_200h
10939                 pool_lfs_df $POOL                       || { rc=$? ; break; }
10940                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
10941
10942                 # former test_201a test_201b test_201c
10943                 pool_remove_first_target $POOL          || { rc=$? ; break; }
10944
10945                 local f=$test_path/$tfile
10946                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
10947                 pool_remove $POOL $f                    || { rc=$? ; break; }
10948                 break
10949         done
10950
10951         cleanup_pools
10952         return $rc
10953 }
10954 run_test 200 "OST pools"
10955
10956 # usage: default_attr <count | size | offset>
10957 default_attr() {
10958         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
10959 }
10960
10961 # usage: check_default_stripe_attr
10962 check_default_stripe_attr() {
10963         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
10964         case $1 in
10965         --stripe-count|--count)
10966                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
10967         --stripe-size|--size)
10968                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
10969         --stripe-index|--index)
10970                 EXPECTED=-1;;
10971         *)
10972                 error "unknown getstripe attr '$1'"
10973         esac
10974
10975         [ $ACTUAL != $EXPECTED ] &&
10976                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
10977 }
10978
10979 test_204a() {
10980         test_mkdir -p $DIR/$tdir
10981         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
10982
10983         check_default_stripe_attr --stripe-count
10984         check_default_stripe_attr --stripe-size
10985         check_default_stripe_attr --stripe-index
10986
10987         return 0
10988 }
10989 run_test 204a "Print default stripe attributes ================="
10990
10991 test_204b() {
10992         test_mkdir -p $DIR/$tdir
10993         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10994
10995         check_default_stripe_attr --stripe-size
10996         check_default_stripe_attr --stripe-index
10997
10998         return 0
10999 }
11000 run_test 204b "Print default stripe size and offset  ==========="
11001
11002 test_204c() {
11003         test_mkdir -p $DIR/$tdir
11004         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11005
11006         check_default_stripe_attr --stripe-count
11007         check_default_stripe_attr --stripe-index
11008
11009         return 0
11010 }
11011 run_test 204c "Print default stripe count and offset ==========="
11012
11013 test_204d() {
11014         test_mkdir -p $DIR/$tdir
11015         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11016
11017         check_default_stripe_attr --stripe-count
11018         check_default_stripe_attr --stripe-size
11019
11020         return 0
11021 }
11022 run_test 204d "Print default stripe count and size ============="
11023
11024 test_204e() {
11025         test_mkdir -p $DIR/$tdir
11026         $SETSTRIPE -d $DIR/$tdir
11027
11028         check_default_stripe_attr --stripe-count --raw
11029         check_default_stripe_attr --stripe-size --raw
11030         check_default_stripe_attr --stripe-index --raw
11031
11032         return 0
11033 }
11034 run_test 204e "Print raw stripe attributes ================="
11035
11036 test_204f() {
11037         test_mkdir -p $DIR/$tdir
11038         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11039
11040         check_default_stripe_attr --stripe-size --raw
11041         check_default_stripe_attr --stripe-index --raw
11042
11043         return 0
11044 }
11045 run_test 204f "Print raw stripe size and offset  ==========="
11046
11047 test_204g() {
11048         test_mkdir -p $DIR/$tdir
11049         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11050
11051         check_default_stripe_attr --stripe-count --raw
11052         check_default_stripe_attr --stripe-index --raw
11053
11054         return 0
11055 }
11056 run_test 204g "Print raw stripe count and offset ==========="
11057
11058 test_204h() {
11059         test_mkdir -p $DIR/$tdir
11060         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11061
11062         check_default_stripe_attr --stripe-count --raw
11063         check_default_stripe_attr --stripe-size --raw
11064
11065         return 0
11066 }
11067 run_test 204h "Print raw stripe count and size ============="
11068
11069 # Figure out which job scheduler is being used, if any,
11070 # or use a fake one
11071 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11072         JOBENV=SLURM_JOB_ID
11073 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11074         JOBENV=LSB_JOBID
11075 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11076         JOBENV=PBS_JOBID
11077 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11078         JOBENV=LOADL_STEP_ID
11079 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11080         JOBENV=JOB_ID
11081 else
11082         JOBENV=FAKE_JOBID
11083 fi
11084
11085 verify_jobstats() {
11086         local cmd=$1
11087         local target=$2
11088
11089         # clear old jobstats
11090         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11091         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11092
11093         # use a new JobID for this test, or we might see an old one
11094         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11095
11096         JOBVAL=${!JOBENV}
11097         log "Test: $cmd"
11098         log "Using JobID environment variable $JOBENV=$JOBVAL"
11099
11100         if [ $JOBENV = "FAKE_JOBID" ]; then
11101                 FAKE_JOBID=$JOBVAL $cmd
11102         else
11103                 $cmd
11104         fi
11105
11106         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11107                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11108                 do_facet $FACET lctl get_param mdt.*.job_stats |
11109                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11110         fi
11111         if [ "$target" = "ost" -o "$target" = "both" ]; then
11112                 FACET=ost1
11113                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11114                         grep $JOBVAL || error "No job stats found on OST $FACET"
11115         fi
11116 }
11117
11118 jobstats_set() {
11119         trap 0
11120         NEW_JOBENV=${1:-$OLD_JOBENV}
11121         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11122         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11123 }
11124
11125 test_205() { # Job stats
11126         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11127         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11128                 skip "Server doesn't support jobstats" && return 0
11129         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11130
11131         local cmd
11132         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11133         if [ $OLD_JOBENV != $JOBENV ]; then
11134                 jobstats_set $JOBENV
11135                 trap jobstats_set EXIT
11136         fi
11137
11138         # mkdir
11139         cmd="mkdir $DIR/$tfile"
11140         verify_jobstats "$cmd" "mdt"
11141         # rmdir
11142         cmd="rm -fr $DIR/$tfile"
11143         verify_jobstats "$cmd" "mdt"
11144         # mknod
11145         cmd="mknod $DIR/$tfile c 1 3"
11146         verify_jobstats "$cmd" "mdt"
11147         # unlink
11148         cmd="rm -f $DIR/$tfile"
11149         verify_jobstats "$cmd" "mdt"
11150         # open & close
11151         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11152         verify_jobstats "$cmd" "mdt"
11153         # setattr
11154         cmd="touch $DIR/$tfile"
11155         verify_jobstats "$cmd" "both"
11156         # write
11157         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11158         verify_jobstats "$cmd" "ost"
11159         # read
11160         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11161         verify_jobstats "$cmd" "ost"
11162         # truncate
11163         cmd="$TRUNCATE $DIR/$tfile 0"
11164         verify_jobstats "$cmd" "both"
11165         # rename
11166         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11167         verify_jobstats "$cmd" "mdt"
11168
11169         # cleanup
11170         rm -f $DIR/jobstats_test_rename
11171
11172         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11173 }
11174 run_test 205 "Verify job stats"
11175
11176 # LU-1480, LU-1773 and LU-1657
11177 test_206() {
11178         mkdir -p $DIR/$tdir
11179         $SETSTRIPE -c -1 $DIR/$tdir
11180 #define OBD_FAIL_LOV_INIT 0x1403
11181         $LCTL set_param fail_loc=0xa0001403
11182         $LCTL set_param fail_val=1
11183         touch $DIR/$tdir/$tfile || true
11184 }
11185 run_test 206 "fail lov_init_raid0() doesn't lbug"
11186
11187 test_207a() {
11188         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11189         local fsz=`stat -c %s $DIR/$tfile`
11190         cancel_lru_locks mdc
11191
11192         # do not return layout in getattr intent
11193 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11194         $LCTL set_param fail_loc=0x170
11195         local sz=`stat -c %s $DIR/$tfile`
11196
11197         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11198
11199         rm -rf $DIR/$tfile
11200 }
11201 run_test 207a "can refresh layout at glimpse"
11202
11203 test_207b() {
11204         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11205         local cksum=`md5sum $DIR/$tfile`
11206         local fsz=`stat -c %s $DIR/$tfile`
11207         cancel_lru_locks mdc
11208         cancel_lru_locks osc
11209
11210         # do not return layout in getattr intent
11211 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11212         $LCTL set_param fail_loc=0x171
11213
11214         # it will refresh layout after the file is opened but before read issues
11215         echo checksum is "$cksum"
11216         echo "$cksum" |md5sum -c --quiet || error "file differs"
11217
11218         rm -rf $DIR/$tfile
11219 }
11220 run_test 207b "can refresh layout at open"
11221
11222 test_208() {
11223         # FIXME: in this test suite, only RD lease is used. This is okay
11224         # for now as only exclusive open is supported. After generic lease
11225         # is done, this test suite should be revised. - Jinshan
11226
11227         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11228                 { skip "Need MDS version at least 2.4.52"; return 0; }
11229
11230         echo "==== test 1: verify get lease work"
11231         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11232
11233         echo "==== test 2: verify lease can be broken by upcoming open"
11234         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11235         local PID=$!
11236         sleep 1
11237
11238         $MULTIOP $DIR/$tfile oO_RDONLY:c
11239         kill -USR1 $PID && wait $PID || error "break lease error"
11240
11241         echo "==== test 3: verify lease can't be granted if an open already exists"
11242         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11243         local PID=$!
11244         sleep 1
11245
11246         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11247         kill -USR1 $PID && wait $PID || error "open file error"
11248
11249         echo "==== test 4: lease can sustain over recovery"
11250         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11251         PID=$!
11252         sleep 1
11253
11254         fail mds1
11255
11256         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11257
11258         echo "==== test 5: lease broken can't be regained by replay"
11259         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11260         PID=$!
11261         sleep 1
11262
11263         # open file to break lease and then recovery
11264         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11265         fail mds1
11266
11267         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11268
11269         rm -f $DIR/$tfile
11270 }
11271 run_test 208 "Exclusive open"
11272
11273 test_209() {
11274         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11275                 skip_env "must have disp_stripe" && return
11276
11277         touch $DIR/$tfile
11278         sync; sleep 5; sync;
11279
11280         echo 3 > /proc/sys/vm/drop_caches
11281         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11282
11283         # open/close 500 times
11284         for i in $(seq 500); do
11285                 cat $DIR/$tfile
11286         done
11287
11288         echo 3 > /proc/sys/vm/drop_caches
11289         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11290
11291         echo "before: $req_before, after: $req_after"
11292         [ $((req_after - req_before)) -ge 300 ] &&
11293                 error "open/close requests are not freed"
11294         return 0
11295 }
11296 run_test 209 "read-only open/close requests should be freed promptly"
11297
11298 test_212() {
11299         size=`date +%s`
11300         size=$((size % 8192 + 1))
11301         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11302         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11303         rm -f $DIR/f212 $DIR/f212.xyz
11304 }
11305 run_test 212 "Sendfile test ============================================"
11306
11307 test_213() {
11308         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11309         cancel_lru_locks osc
11310         lctl set_param fail_loc=0x8000040f
11311         # generate a read lock
11312         cat $DIR/$tfile > /dev/null
11313         # write to the file, it will try to cancel the above read lock.
11314         cat /etc/hosts >> $DIR/$tfile
11315 }
11316 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11317
11318 test_214() { # for bug 20133
11319         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11320         for (( i=0; i < 340; i++ )) ; do
11321                 touch $DIR/$tdir/d214c/a$i
11322         done
11323
11324         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11325         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11326         ls $DIR/d214c || error "ls $DIR/d214c failed"
11327         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11328         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11329 }
11330 run_test 214 "hash-indexed directory test - bug 20133"
11331
11332 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11333 create_lnet_proc_files() {
11334         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
11335         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11336
11337         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11338         rm -f "$TMP/lnet_$1.sys_tmp"
11339 }
11340
11341 # counterpart of create_lnet_proc_files
11342 remove_lnet_proc_files() {
11343         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11344 }
11345
11346 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11347 # 3rd arg as regexp for body
11348 check_lnet_proc_stats() {
11349         local l=$(cat "$TMP/lnet_$1" |wc -l)
11350         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11351
11352         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11353 }
11354
11355 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11356 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11357 # optional and can be regexp for 2nd line (lnet.routes case)
11358 check_lnet_proc_entry() {
11359         local blp=2          # blp stands for 'position of 1st line of body'
11360         [ -z "$5" ] || blp=3 # lnet.routes case
11361
11362         local l=$(cat "$TMP/lnet_$1" |wc -l)
11363         # subtracting one from $blp because the body can be empty
11364         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11365
11366         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11367                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11368
11369         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11370                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11371
11372         # bail out if any unexpected line happened
11373         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11374         [ "$?" != 0 ] || error "$2 misformatted"
11375 }
11376
11377 test_215() { # for bugs 18102, 21079, 21517
11378         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11379         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11380         local P='[1-9][0-9]*'           # positive numeric
11381         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11382         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11383         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11384         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11385
11386         local L1 # regexp for 1st line
11387         local L2 # regexp for 2nd line (optional)
11388         local BR # regexp for the rest (body)
11389
11390         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
11391         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11392         create_lnet_proc_files "stats"
11393         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
11394         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11395         remove_lnet_proc_files "stats"
11396
11397         # /proc/sys/lnet/routes should look like this:
11398         # Routing disabled/enabled
11399         # net hops priority state router
11400         # where net is a string like tcp0, hops > 0, priority >= 0,
11401         # state is up/down,
11402         # router is a string like 192.168.1.1@tcp2
11403         L1="^Routing (disabled|enabled)$"
11404         L2="^net +hops +priority +state +router$"
11405         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11406         create_lnet_proc_files "routes"
11407         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
11408         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11409         remove_lnet_proc_files "routes"
11410
11411         # /proc/sys/lnet/routers should look like this:
11412         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11413         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11414         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11415         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11416         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11417         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11418         create_lnet_proc_files "routers"
11419         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
11420         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11421         remove_lnet_proc_files "routers"
11422
11423         # /proc/sys/lnet/peers should look like this:
11424         # nid refs state last max rtr min tx min queue
11425         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11426         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11427         # numeric (0 or >0 or <0), queue >= 0.
11428         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11429         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11430         create_lnet_proc_files "peers"
11431         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
11432         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11433         remove_lnet_proc_files "peers"
11434
11435         # /proc/sys/lnet/buffers  should look like this:
11436         # pages count credits min
11437         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11438         L1="^pages +count +credits +min$"
11439         BR="^ +$N +$N +$I +$I$"
11440         create_lnet_proc_files "buffers"
11441         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
11442         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11443         remove_lnet_proc_files "buffers"
11444
11445         # /proc/sys/lnet/nis should look like this:
11446         # nid status alive refs peer rtr max tx min
11447         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11448         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11449         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11450         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11451         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11452         create_lnet_proc_files "nis"
11453         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
11454         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11455         remove_lnet_proc_files "nis"
11456
11457         # can we successfully write to /proc/sys/lnet/stats?
11458         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
11459         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11460 }
11461 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
11462
11463 test_216() { # bug 20317
11464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11465         remote_ost_nodsh && skip "remote OST with nodsh" && return
11466
11467         local node
11468         local facets=$(get_facets OST)
11469         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11470
11471         save_lustre_params client "osc.*.contention_seconds" > $p
11472         save_lustre_params $facets \
11473                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11474         save_lustre_params $facets \
11475                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11476         save_lustre_params $facets \
11477                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11478         clear_osc_stats
11479
11480         # agressive lockless i/o settings
11481         for node in $(osts_nodes); do
11482                 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'
11483         done
11484         lctl set_param -n osc.*.contention_seconds 60
11485
11486         $DIRECTIO write $DIR/$tfile 0 10 4096
11487         $CHECKSTAT -s 40960 $DIR/$tfile
11488
11489         # disable lockless i/o
11490         for node in $(osts_nodes); do
11491                 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'
11492         done
11493         lctl set_param -n osc.*.contention_seconds 0
11494         clear_osc_stats
11495
11496         dd if=/dev/zero of=$DIR/$tfile count=0
11497         $CHECKSTAT -s 0 $DIR/$tfile
11498
11499         restore_lustre_params <$p
11500         rm -f $p
11501         rm $DIR/$tfile
11502 }
11503 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11504
11505 test_217() { # bug 22430
11506         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11507         local node
11508         local nid
11509
11510         for node in $(nodes_list); do
11511                 nid=$(host_nids_address $node $NETTYPE)
11512                 if [[ $nid = *-* ]] ; then
11513                         echo "lctl ping $nid@$NETTYPE"
11514                         lctl ping $nid@$NETTYPE
11515                 else
11516                         echo "skipping $node (no hyphen detected)"
11517                 fi
11518         done
11519 }
11520 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11521
11522 test_218() {
11523        # do directio so as not to populate the page cache
11524        log "creating a 10 Mb file"
11525        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11526        log "starting reads"
11527        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11528        log "truncating the file"
11529        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11530        log "killing dd"
11531        kill %+ || true # reads might have finished
11532        echo "wait until dd is finished"
11533        wait
11534        log "removing the temporary file"
11535        rm -rf $DIR/$tfile || error "tmp file removal failed"
11536 }
11537 run_test 218 "parallel read and truncate should not deadlock ======================="
11538
11539 test_219() {
11540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11541         # write one partial page
11542         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11543         # set no grant so vvp_io_commit_write will do sync write
11544         $LCTL set_param fail_loc=0x411
11545         # write a full page at the end of file
11546         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11547
11548         $LCTL set_param fail_loc=0
11549         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11550         $LCTL set_param fail_loc=0x411
11551         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11552
11553         # LU-4201
11554         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11555         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11556 }
11557 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11558
11559 test_220() { #LU-325
11560         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11561         remote_ost_nodsh && skip "remote OST with nodsh" && return
11562         local OSTIDX=0
11563
11564         test_mkdir -p $DIR/$tdir
11565         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11566                 awk '{print $2}' | sed -e 's/_UUID$//')
11567
11568         # on the mdt's osc
11569         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11570         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11571                         osc.$mdtosc_proc1.prealloc_last_id)
11572         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11573                         osc.$mdtosc_proc1.prealloc_next_id)
11574
11575         $LFS df -i
11576
11577         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11578         #define OBD_FAIL_OST_ENOINO              0x229
11579         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11580         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11581         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11582
11583         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11584
11585         MDSOBJS=$((last_id - next_id))
11586         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11587
11588         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11589         echo "OST still has $count kbytes free"
11590
11591         echo "create $MDSOBJS files @next_id..."
11592         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11593
11594         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11595                         osc.$mdtosc_proc1.prealloc_last_id)
11596         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11597                         osc.$mdtosc_proc1.prealloc_next_id)
11598
11599         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11600         $LFS df -i
11601
11602         echo "cleanup..."
11603
11604         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11605         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11606
11607         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11608         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11609         echo "unlink $MDSOBJS files @$next_id..."
11610         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11611 }
11612 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11613
11614 test_221() {
11615         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11616         dd if=`which date` of=$MOUNT/date oflag=sync
11617         chmod +x $MOUNT/date
11618
11619         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11620         $LCTL set_param fail_loc=0x80001401
11621
11622         $MOUNT/date > /dev/null
11623         rm -f $MOUNT/date
11624 }
11625 run_test 221 "make sure fault and truncate race to not cause OOM"
11626
11627 test_222a () {
11628         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11629        rm -rf $DIR/$tdir
11630        test_mkdir -p $DIR/$tdir
11631        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11632        createmany -o $DIR/$tdir/$tfile 10
11633        cancel_lru_locks mdc
11634        cancel_lru_locks osc
11635        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11636        $LCTL set_param fail_loc=0x31a
11637        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11638        $LCTL set_param fail_loc=0
11639        rm -r $DIR/$tdir
11640 }
11641 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11642
11643 test_222b () {
11644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11645        rm -rf $DIR/$tdir
11646        test_mkdir -p $DIR/$tdir
11647        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11648        createmany -o $DIR/$tdir/$tfile 10
11649        cancel_lru_locks mdc
11650        cancel_lru_locks osc
11651        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11652        $LCTL set_param fail_loc=0x31a
11653        rm -r $DIR/$tdir || "AGL for rmdir failed"
11654        $LCTL set_param fail_loc=0
11655 }
11656 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11657
11658 test_223 () {
11659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11660        rm -rf $DIR/$tdir
11661        test_mkdir -p $DIR/$tdir
11662        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11663        createmany -o $DIR/$tdir/$tfile 10
11664        cancel_lru_locks mdc
11665        cancel_lru_locks osc
11666        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11667        $LCTL set_param fail_loc=0x31b
11668        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11669        $LCTL set_param fail_loc=0
11670        rm -r $DIR/$tdir
11671 }
11672 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11673
11674 test_224a() { # LU-1039, MRP-303
11675         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11676         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11677         $LCTL set_param fail_loc=0x508
11678         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11679         $LCTL set_param fail_loc=0
11680         df $DIR
11681 }
11682 run_test 224a "Don't panic on bulk IO failure"
11683
11684 test_224b() { # LU-1039, MRP-303
11685         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11686         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11687         cancel_lru_locks osc
11688         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11689         $LCTL set_param fail_loc=0x515
11690         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11691         $LCTL set_param fail_loc=0
11692         df $DIR
11693 }
11694 run_test 224b "Don't panic on bulk IO failure"
11695
11696 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11697 test_225a () {
11698         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11699         if [ -z ${MDSSURVEY} ]; then
11700               skip_env "mds-survey not found" && return
11701         fi
11702
11703         [ $MDSCOUNT -ge 2 ] &&
11704                 skip "skipping now for more than one MDT" && return
11705
11706        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11707             { skip "Need MDS version at least 2.2.51"; return; }
11708
11709        local mds=$(facet_host $SINGLEMDS)
11710        local target=$(do_nodes $mds 'lctl dl' | \
11711                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11712
11713        local cmd1="file_count=1000 thrhi=4"
11714        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11715        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11716        local cmd="$cmd1 $cmd2 $cmd3"
11717
11718        rm -f ${TMP}/mds_survey*
11719        echo + $cmd
11720        eval $cmd || error "mds-survey with zero-stripe failed"
11721        cat ${TMP}/mds_survey*
11722        rm -f ${TMP}/mds_survey*
11723 }
11724 run_test 225a "Metadata survey sanity with zero-stripe"
11725
11726 test_225b () {
11727         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11728
11729         if [ -z ${MDSSURVEY} ]; then
11730               skip_env "mds-survey not found" && return
11731         fi
11732         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11733             { skip "Need MDS version at least 2.2.51"; return; }
11734
11735         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11736               skip_env "Need to mount OST to test" && return
11737         fi
11738
11739         [ $MDSCOUNT -ge 2 ] &&
11740                 skip "skipping now for more than one MDT" && return
11741        local mds=$(facet_host $SINGLEMDS)
11742        local target=$(do_nodes $mds 'lctl dl' | \
11743                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11744
11745        local cmd1="file_count=1000 thrhi=4"
11746        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11747        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11748        local cmd="$cmd1 $cmd2 $cmd3"
11749
11750        rm -f ${TMP}/mds_survey*
11751        echo + $cmd
11752        eval $cmd || error "mds-survey with stripe_count failed"
11753        cat ${TMP}/mds_survey*
11754        rm -f ${TMP}/mds_survey*
11755 }
11756 run_test 225b "Metadata survey sanity with stripe_count = 1"
11757
11758 mcreate_path2fid () {
11759         local mode=$1
11760         local major=$2
11761         local minor=$3
11762         local name=$4
11763         local desc=$5
11764         local path=$DIR/$tdir/$name
11765         local fid
11766         local rc
11767         local fid_path
11768
11769         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11770                 error "cannot create $desc"
11771
11772         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11773         rc=$?
11774         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11775
11776         fid_path=$($LFS fid2path $MOUNT $fid)
11777         rc=$?
11778         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11779
11780         [ "$path" == "$fid_path" ] ||
11781                 error "fid2path returned $fid_path, expected $path"
11782
11783         echo "pass with $path and $fid"
11784 }
11785
11786 test_226a () {
11787         rm -rf $DIR/$tdir
11788         mkdir -p $DIR/$tdir
11789
11790         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11791         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11792         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11793         mcreate_path2fid 0040666 0 0 dir "directory"
11794         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11795         mcreate_path2fid 0100666 0 0 file "regular file"
11796         mcreate_path2fid 0120666 0 0 link "symbolic link"
11797         mcreate_path2fid 0140666 0 0 sock "socket"
11798 }
11799 run_test 226a "call path2fid and fid2path on files of all type"
11800
11801 test_226b () {
11802         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11803         rm -rf $DIR/$tdir
11804         local MDTIDX=1
11805
11806         mkdir -p $DIR/$tdir
11807         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
11808                 error "create remote directory failed"
11809         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
11810         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
11811                                 "character special file (null)"
11812         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
11813                                 "character special file (no device)"
11814         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
11815         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
11816                                 "block special file (loop)"
11817         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
11818         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
11819         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
11820 }
11821 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
11822
11823 # LU-1299 Executing or running ldd on a truncated executable does not
11824 # cause an out-of-memory condition.
11825 test_227() {
11826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11827         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
11828         dd if=$(which date) of=$MOUNT/date bs=1k count=1
11829         chmod +x $MOUNT/date
11830
11831         $MOUNT/date > /dev/null
11832         ldd $MOUNT/date > /dev/null
11833         rm -f $MOUNT/date
11834 }
11835 run_test 227 "running truncated executable does not cause OOM"
11836
11837 # LU-1512 try to reuse idle OI blocks
11838 test_228a() {
11839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11840         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11841                 skip "non-ldiskfs backend" && return
11842
11843         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11844         local myDIR=$DIR/$tdir
11845
11846         mkdir -p $myDIR
11847         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11848         $LCTL set_param fail_loc=0x80001002
11849         createmany -o $myDIR/t- 10000
11850         $LCTL set_param fail_loc=0
11851         # The guard is current the largest FID holder
11852         touch $myDIR/guard
11853         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11854                     tr -d '[')
11855         local IDX=$(($SEQ % 64))
11856
11857         do_facet $SINGLEMDS sync
11858         # Make sure journal flushed.
11859         sleep 6
11860         local blk1=$(do_facet $SINGLEMDS \
11861                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11862                      grep Blockcount | awk '{print $4}')
11863
11864         # Remove old files, some OI blocks will become idle.
11865         unlinkmany $myDIR/t- 10000
11866         # Create new files, idle OI blocks should be reused.
11867         createmany -o $myDIR/t- 2000
11868         do_facet $SINGLEMDS sync
11869         # Make sure journal flushed.
11870         sleep 6
11871         local blk2=$(do_facet $SINGLEMDS \
11872                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11873                      grep Blockcount | awk '{print $4}')
11874
11875         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11876 }
11877 run_test 228a "try to reuse idle OI blocks"
11878
11879 test_228b() {
11880         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11881         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11882                 skip "non-ldiskfs backend" && return
11883
11884         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11885         local myDIR=$DIR/$tdir
11886
11887         mkdir -p $myDIR
11888         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11889         $LCTL set_param fail_loc=0x80001002
11890         createmany -o $myDIR/t- 10000
11891         $LCTL set_param fail_loc=0
11892         # The guard is current the largest FID holder
11893         touch $myDIR/guard
11894         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11895                     tr -d '[')
11896         local IDX=$(($SEQ % 64))
11897
11898         do_facet $SINGLEMDS sync
11899         # Make sure journal flushed.
11900         sleep 6
11901         local blk1=$(do_facet $SINGLEMDS \
11902                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11903                      grep Blockcount | awk '{print $4}')
11904
11905         # Remove old files, some OI blocks will become idle.
11906         unlinkmany $myDIR/t- 10000
11907
11908         # stop the MDT
11909         stop $SINGLEMDS || error "Fail to stop MDT."
11910         # remount the MDT
11911         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11912
11913         df $MOUNT || error "Fail to df."
11914         # Create new files, idle OI blocks should be reused.
11915         createmany -o $myDIR/t- 2000
11916         do_facet $SINGLEMDS sync
11917         # Make sure journal flushed.
11918         sleep 6
11919         local blk2=$(do_facet $SINGLEMDS \
11920                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11921                      grep Blockcount | awk '{print $4}')
11922
11923         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11924 }
11925 run_test 228b "idle OI blocks can be reused after MDT restart"
11926
11927 #LU-1881
11928 test_228c() {
11929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11930         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11931                 skip "non-ldiskfs backend" && return
11932
11933         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11934         local myDIR=$DIR/$tdir
11935
11936         mkdir -p $myDIR
11937         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11938         $LCTL set_param fail_loc=0x80001002
11939         # 20000 files can guarantee there are index nodes in the OI file
11940         createmany -o $myDIR/t- 20000
11941         $LCTL set_param fail_loc=0
11942         # The guard is current the largest FID holder
11943         touch $myDIR/guard
11944         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11945                     tr -d '[')
11946         local IDX=$(($SEQ % 64))
11947
11948         do_facet $SINGLEMDS sync
11949         # Make sure journal flushed.
11950         sleep 6
11951         local blk1=$(do_facet $SINGLEMDS \
11952                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11953                      grep Blockcount | awk '{print $4}')
11954
11955         # Remove old files, some OI blocks will become idle.
11956         unlinkmany $myDIR/t- 20000
11957         rm -f $myDIR/guard
11958         # The OI file should become empty now
11959
11960         # Create new files, idle OI blocks should be reused.
11961         createmany -o $myDIR/t- 2000
11962         do_facet $SINGLEMDS sync
11963         # Make sure journal flushed.
11964         sleep 6
11965         local blk2=$(do_facet $SINGLEMDS \
11966                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11967                      grep Blockcount | awk '{print $4}')
11968
11969         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11970 }
11971 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
11972
11973 test_229() { # LU-2482, LU-3448
11974         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
11975                 skip "No HSM support on MDS of $(get_lustre_version)," \
11976                          "need 2.4.53 at least" && return
11977         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11978         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
11979
11980         rm -f $DIR/$tfile
11981
11982         # Create a file with a released layout and stripe count 2.
11983         $MULTIOP $DIR/$tfile H2c ||
11984                 error "failed to create file with released layout"
11985
11986         $GETSTRIPE -v $DIR/$tfile
11987
11988         local pattern=$($GETSTRIPE -L $DIR/$tfile)
11989         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
11990
11991         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
11992         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
11993         stat $DIR/$tfile || error "failed to stat released file"
11994
11995         chown $RUNAS_ID $DIR/$tfile ||
11996                 error "chown $RUNAS_ID $DIR/$tfile failed"
11997
11998         chgrp $RUNAS_ID $DIR/$tfile ||
11999                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12000
12001         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12002         rm $DIR/$tfile || error "failed to remove released file"
12003 }
12004 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12005
12006 test_230a() {
12007         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12008         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12009         local MDTIDX=1
12010
12011         mkdir -p $DIR/$tdir/test_230_local
12012         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12013         [ $mdt_idx -ne 0 ] &&
12014                 error "create local directory on wrong MDT $mdt_idx"
12015
12016         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12017                         error "create remote directory failed"
12018         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12019         [ $mdt_idx -ne $MDTIDX ] &&
12020                 error "create remote directory on wrong MDT $mdt_idx"
12021
12022         createmany -o $DIR/$tdir/test_230/t- 10 ||
12023                 error "create files on remote directory failed"
12024         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12025         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12026         rm -r $DIR/$tdir || error "unlink remote directory failed"
12027 }
12028 run_test 230a "Create remote directory and files under the remote directory"
12029
12030 test_230b() {
12031         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12032         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12033         local MDTIDX=1
12034         local mdt_index
12035         local i
12036         local file
12037         local pid
12038         local stripe_count
12039         local migrate_dir=$DIR/$tdir/migrate_dir
12040         local other_dir=$DIR/$tdir/other_dir
12041
12042         mkdir -p $migrate_dir
12043         mkdir -p $other_dir
12044         for ((i=0; i<10; i++)); do
12045                 mkdir -p $migrate_dir/dir_${i}
12046                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12047                         error "create files under remote dir failed $i"
12048         done
12049
12050         cp /etc/passwd $migrate_dir/$tfile
12051         cp /etc/passwd $other_dir/$tfile
12052         mkdir -p $migrate_dir/dir_default_stripe2
12053         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12054         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12055
12056         mkdir -p $other_dir
12057         ln $migrate_dir/$tfile $other_dir/luna
12058         ln $migrate_dir/$tfile $migrate_dir/sofia
12059         ln $other_dir/$tfile $migrate_dir/david
12060         ln -s $migrate_dir/$tfile $other_dir/zachary
12061         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12062         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12063
12064         $LFS mv -v -M $MDTIDX $migrate_dir ||
12065                         error "migrate remote dir error"
12066
12067         echo "migratate to MDT1, then checking.."
12068         for ((i=0; i<10; i++)); do
12069                 for file in $(find $migrate_dir/dir_${i}); do
12070                         mdt_index=$($LFS getstripe -M $file)
12071                         [ $mdt_index == $MDTIDX ] ||
12072                                 error "$file is not on MDT${MDTIDX}"
12073                 done
12074         done
12075
12076         # the multiple link file should still in MDT0
12077         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12078         [ $mdt_index == 0 ] ||
12079                 error "$file is not on MDT${MDTIDX}"
12080
12081         diff /etc/passwd $migrate_dir/$tfile ||
12082                 error "$tfile different after migration"
12083
12084         diff /etc/passwd $other_dir/luna ||
12085                 error "luna different after migration"
12086
12087         diff /etc/passwd $migrate_dir/sofia ||
12088                 error "sofia different after migration"
12089
12090         diff /etc/passwd $migrate_dir/david ||
12091                 error "david different after migration"
12092
12093         diff /etc/passwd $other_dir/zachary ||
12094                 error "zachary different after migration"
12095
12096         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12097                 error "${tfile}_ln different after migration"
12098
12099         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12100                 error "${tfile}_ln_other different after migration"
12101
12102         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12103         [ $stripe_count = 2 ] ||
12104                         error "dir strpe_count $d != 2 after migration."
12105
12106         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12107         [ $stripe_count = 2 ] ||
12108                         error "file strpe_count $d != 2 after migration."
12109
12110         #migrate back to MDT0
12111         MDTIDX=0
12112         $LFS mv -v -M $MDTIDX $migrate_dir ||
12113                         error "migrate remote dir error"
12114
12115         echo "migrate back to MDT0, checking.."
12116         for file in $(find $migrate_dir); do
12117                 mdt_index=$($LFS getstripe -M $file)
12118                 [ $mdt_index == $MDTIDX ] ||
12119                         error "$file is not on MDT${MDTIDX}"
12120         done
12121
12122         diff /etc/passwd ${migrate_dir}/$tfile ||
12123                 error "$tfile different after migration"
12124
12125         diff /etc/passwd ${other_dir}/luna ||
12126                 error "luna different after migration"
12127
12128         diff /etc/passwd ${migrate_dir}/sofia ||
12129                 error "sofia different after migration"
12130
12131         diff /etc/passwd ${other_dir}/zachary ||
12132                 error "zachary different after migration"
12133
12134         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12135                 error "${tfile}_ln different after migration"
12136
12137         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12138                 error "${tfile}_ln_other different after migration"
12139
12140         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12141         [ $stripe_count = 2 ] ||
12142                 error "dir strpe_count $d != 2 after migration."
12143
12144         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12145         [ $stripe_count = 2 ] ||
12146                 error "file strpe_count $d != 2 after migration."
12147
12148         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12149 }
12150 run_test 230b "migrate directory"
12151
12152 test_230c() {
12153         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12154         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12155         local MDTIDX=1
12156         local mdt_index
12157         local file
12158
12159         #If migrating directory fails in the middle, all entries of
12160         #the directory is still accessiable.
12161         mkdir -p $DIR/$tdir
12162         stat $DIR/$tdir
12163         createmany -o $DIR/$tdir/f 10 ||
12164                 error "create files under ${tdir} failed"
12165
12166         #failed after migrating 5 entries
12167         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12168         do_facet mds1 lctl set_param fail_loc=0x20001801
12169         do_facet mds1 lctl  set_param fail_val=5
12170         local t=`ls $DIR/$tdir | wc -l`
12171         $LFS mv -M $MDTIDX $DIR/$tdir &&
12172                 error "migrate should failed after 5 entries"
12173         local u=`ls $DIR/$tdir | wc -l`
12174         [ "$u" == "$t" ] || error "$u != $t during migration"
12175
12176         for file in $(find $DIR/$tdir); do
12177                 stat $file || error "stat $file failed"
12178         done
12179
12180         do_facet mds1 lctl set_param fail_loc=0
12181         do_facet mds1 lctl set_param fail_val=0
12182
12183         $LFS mv -M $MDTIDX $DIR/$tdir ||
12184                 error "migrate open files should failed with open files"
12185
12186         echo "Finish migration, then checking.."
12187         for file in $(find $DIR/$tdir); do
12188                 mdt_index=$($LFS getstripe -M $file)
12189                 [ $mdt_index == $MDTIDX ] ||
12190                         error "$file is not on MDT${MDTIDX}"
12191         done
12192
12193         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12194 }
12195 run_test 230c "check directory accessiblity if migration is failed"
12196
12197 test_230d() {
12198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12199         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12200         local MDTIDX=1
12201         local mdt_index
12202         local i
12203         local j
12204
12205         mkdir -p $DIR/$tdir
12206
12207         for ((i=0; i<100; i++)); do
12208                 mkdir -p $DIR/$tdir/dir_${i}
12209                 createmany -o $DIR/$tdir/dir_${i}/f 100 ||
12210                         error "create files under remote dir failed $i"
12211         done
12212
12213         $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
12214
12215         echo "Finish migration, then checking.."
12216         for file in $(find $DIR/$tdir); do
12217                 mdt_index=$($LFS getstripe -M $file)
12218                 [ $mdt_index == $MDTIDX ] ||
12219                         error "$file is not on MDT${MDTIDX}"
12220         done
12221
12222         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12223 }
12224 run_test 230d "check migrate big directory"
12225
12226 test_231a()
12227 {
12228         # For simplicity this test assumes that max_pages_per_rpc
12229         # is the same across all OSCs
12230         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12231         local bulk_size=$((max_pages * 4096))
12232
12233         mkdir -p $DIR/$tdir
12234
12235         # clear the OSC stats
12236         $LCTL set_param osc.*.stats=0 &>/dev/null
12237
12238         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12239         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12240                 oflag=direct &>/dev/null || error "dd failed"
12241
12242         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12243         if [ x$nrpcs != "x1" ]; then
12244                 error "found $nrpc ost_write RPCs, not 1 as expected"
12245         fi
12246
12247         # Drop the OSC cache, otherwise we will read from it
12248         cancel_lru_locks osc
12249
12250         # clear the OSC stats
12251         $LCTL set_param osc.*.stats=0 &>/dev/null
12252
12253         # Client reads $bulk_size.
12254         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12255                 iflag=direct &>/dev/null || error "dd failed"
12256
12257         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12258         if [ x$nrpcs != "x1" ]; then
12259                 error "found $nrpc ost_read RPCs, not 1 as expected"
12260         fi
12261 }
12262 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12263
12264 test_231b() {
12265         mkdir -p $DIR/$tdir
12266         local i
12267         for i in {0..1023}; do
12268                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12269                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12270                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12271         done
12272         sync
12273 }
12274 run_test 231b "must not assert on fully utilized OST request buffer"
12275
12276 test_232() {
12277         mkdir -p $DIR/$tdir
12278         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12279         $LCTL set_param fail_loc=0x31c
12280
12281         # ignore dd failure
12282         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12283
12284         $LCTL set_param fail_loc=0
12285         umount_client $MOUNT || error "umount failed"
12286         mount_client $MOUNT || error "mount failed"
12287 }
12288 run_test 232 "failed lock should not block umount"
12289
12290 test_233a() {
12291         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12292         { skip "Need MDS version at least 2.3.64"; return; }
12293
12294         local fid=$($LFS path2fid $MOUNT)
12295         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12296                 error "cannot access $MOUNT using its FID '$fid'"
12297 }
12298 run_test 233a "checking that OBF of the FS root succeeds"
12299
12300 test_233b() {
12301         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12302         { skip "Need MDS version at least 2.5.90"; return; }
12303
12304         local fid=$($LFS path2fid $MOUNT/.lustre)
12305         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12306                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12307
12308         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12309         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12310                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12311 }
12312 run_test 233b "checking that OBF of the FS .lustre succeeds"
12313
12314 test_234() {
12315         local p="$TMP/sanityN-$TESTNAME.parameters"
12316         save_lustre_params client "llite.*.xattr_cache" > $p
12317         lctl set_param llite.*.xattr_cache 1 ||
12318                 { skip "xattr cache is not supported"; return 0; }
12319
12320         mkdir -p $DIR/$tdir || error "mkdir failed"
12321         touch $DIR/$tdir/$tfile || error "touch failed"
12322         # OBD_FAIL_LLITE_XATTR_ENOMEM
12323         $LCTL set_param fail_loc=0x1405
12324         if [ ! -f /etc/SuSE-release ]; then
12325                 # attr pre-2.4.44-7 had a bug with rc
12326                 # LU-3703 - SLES clients have older attr
12327                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12328                         error "getfattr should have failed with ENOMEM"
12329         fi
12330         $LCTL set_param fail_loc=0x0
12331         rm -rf $DIR/$tdir
12332
12333         restore_lustre_params < $p
12334         rm -f $p
12335 }
12336 run_test 234 "xattr cache should not crash on ENOMEM"
12337
12338 test_235() {
12339         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12340                 skip "Need MDS version at least 2.4.52" && return
12341         flock_deadlock $DIR/$tfile
12342         local RC=$?
12343         case $RC in
12344                 0)
12345                 ;;
12346                 124) error "process hangs on a deadlock"
12347                 ;;
12348                 *) error "error executing flock_deadlock $DIR/$tfile"
12349                 ;;
12350         esac
12351 }
12352 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12353
12354 #LU-2935
12355 test_236() {
12356         check_swap_layouts_support && return 0
12357         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12358
12359         local ref1=/etc/passwd
12360         local ref2=/etc/group
12361         local file1=$DIR/$tdir/f1
12362         local file2=$DIR/$tdir/f2
12363
12364         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12365         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12366         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12367         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12368         local fd=$(free_fd)
12369         local cmd="exec $fd<>$file2"
12370         eval $cmd
12371         rm $file2
12372         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12373                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12374         cmd="exec $fd>&-"
12375         eval $cmd
12376         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12377
12378         #cleanup
12379         rm -rf $DIR/$tdir
12380 }
12381 run_test 236 "Layout swap on open unlinked file"
12382
12383 # test to verify file handle related system calls
12384 # (name_to_handle_at/open_by_handle_at)
12385 # The new system calls are supported in glibc >= 2.14.
12386
12387 test_237() {
12388         echo "Test file_handle syscalls" > $DIR/$tfile
12389         check_fhandle_syscalls $DIR/$tfile ||
12390                 error "check_fhandle_syscalls failed"
12391 }
12392 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12393
12394 # LU-4659 linkea consistency
12395 test_238() {
12396         touch $DIR/$tfile
12397         ln $DIR/$tfile $DIR/$tfile.lnk
12398         touch $DIR/$tfile.new
12399         mv $DIR/$tfile.new $DIR/$tfile
12400         local fid1=$(lfs path2fid $DIR/$tfile)
12401         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12402         local path1=$(lfs fid2path $FSNAME $fid1)
12403         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12404         local path2=$(lfs fid2path $FSNAME $fid2)
12405         [ $tfile.lnk == $path2 ] ||
12406                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12407         rm -f $DIR/$tfile*
12408 }
12409 run_test 238 "Verify linkea consistency"
12410
12411 test_striped_dir() {
12412         local mdt_index=$1
12413         local stripe_count
12414         local stripe_index
12415
12416         mkdir -p $DIR/$tdir
12417         $LFS setdirstripe -i $mdt_index -c 2 -t all_char $DIR/$tdir/striped_dir ||
12418                 error "set striped dir error"
12419
12420         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
12421         if [ "$stripe_count" != "2" ]; then
12422                 error "stripe_count is $stripe_count, expect 2"
12423         fi
12424
12425         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
12426         if [ "$stripe_index" != "$mdt_index" ]; then
12427                 error "stripe_index is $stripe_index, expect $mdt_index"
12428         fi
12429
12430         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12431                 error "nlink error after create striped dir"
12432
12433         mkdir $DIR/$tdir/striped_dir/a
12434         mkdir $DIR/$tdir/striped_dir/b
12435
12436         stat $DIR/$tdir/striped_dir/a ||
12437                 error "create dir under striped dir failed"
12438         stat $DIR/$tdir/striped_dir/b ||
12439                 error "create dir under striped dir failed"
12440
12441         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
12442                 error "nlink error after mkdir"
12443
12444         rmdir $DIR/$tdir/striped_dir/a
12445         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
12446                 error "nlink error after rmdir"
12447
12448         rmdir $DIR/$tdir/striped_dir/b
12449         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12450                 error "nlink error after rmdir"
12451
12452         rmdir $DIR/$tdir/striped_dir ||
12453                 error "rmdir striped dir error"
12454         true
12455 }
12456
12457 test_300a() {
12458         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12459         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12460
12461         test_striped_dir 0 || error "failed on striped dir on MDT0"
12462         test_striped_dir 1 || error "failed on striped dir on MDT0"
12463 }
12464 run_test 300a "basic striped dir sanity test"
12465
12466 test_300b() {
12467         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12468         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12469         local i
12470         local mtime1
12471         local mtime2
12472         local mtime3
12473
12474         test_mkdir $DIR/$tdir || error "mkdir fail"
12475         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12476                 error "set striped dir error"
12477         for ((i=0; i<10; i++)); do
12478                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
12479                 sleep 1
12480                 touch $DIR/$tdir/striped_dir/file_$i ||
12481                                         error "touch error $i"
12482                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
12483                 [ $mtime1 -eq $mtime2 ] &&
12484                         error "mtime not change after create"
12485                 sleep 1
12486                 rm -f $DIR/$tdir/striped_dir/file_$i ||
12487                                         error "unlink error $i"
12488                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
12489                 [ $mtime2 -eq $mtime3 ] &&
12490                         error "mtime did not change after unlink"
12491         done
12492         true
12493 }
12494 run_test 300b "check ctime/mtime for striped dir"
12495
12496 test_300c() {
12497         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12498         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12499         local file_count
12500
12501         mkdir -p $DIR/$tdir
12502         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
12503                 error "set striped dir error"
12504
12505         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
12506                 error "chown striped dir failed"
12507
12508         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
12509                 error "create 5k files failed"
12510
12511         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
12512
12513         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
12514
12515         rm -rf $DIR/$tdir
12516 }
12517 run_test 300c "chown && check ls under striped directory"
12518
12519 test_300d() {
12520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12521         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12522         local stripe_count
12523         local file
12524
12525         mkdir -p $DIR/$tdir
12526         $SETSTRIPE -c 2 $DIR/$tdir
12527
12528         #local striped directory
12529         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12530                 error "set striped dir error"
12531         createmany -o $DIR/$tdir/striped_dir/f 10 ||
12532                 error "create 10 files failed"
12533
12534         #remote striped directory
12535         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
12536                 error "set striped dir error"
12537         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
12538                 error "create 10 files failed"
12539
12540         for file in $(find $DIR/$tdir); do
12541                 stripe_count=$($GETSTRIPE -c $file)
12542                 [ $stripe_count -eq 2 ] ||
12543                         error "wrong stripe $stripe_count for $file"
12544         done
12545
12546         rm -rf $DIR/$tdir
12547 }
12548 run_test 300d "check default stripe under striped directory"
12549
12550 test_300e() {
12551         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12552         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12553         local stripe_count
12554         local file
12555
12556         mkdir -p $DIR/$tdir
12557
12558         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12559                 error "set striped dir error"
12560
12561         touch $DIR/$tdir/striped_dir/a
12562         touch $DIR/$tdir/striped_dir/b
12563         touch $DIR/$tdir/striped_dir/c
12564
12565         mkdir $DIR/$tdir/striped_dir/dir_a
12566         mkdir $DIR/$tdir/striped_dir/dir_b
12567         mkdir $DIR/$tdir/striped_dir/dir_c
12568
12569         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
12570                 error "set striped dir under striped dir error"
12571
12572         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
12573                 error "set striped dir under striped dir error"
12574
12575         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
12576                 error "set striped dir under striped dir error"
12577
12578         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
12579                 error "rename file under striped dir should fail"
12580
12581         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
12582                 error "rename dir under striped dir should fail"
12583
12584         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
12585                 error "rename dir under different stripes should fail"
12586
12587         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
12588                 error "rename file under striped dir should succeed"
12589
12590         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
12591                 error "rename dir under striped dir should succeed"
12592
12593         rm -rf $DIR/$tdir
12594 }
12595 run_test 300e "check rename under striped directory"
12596
12597 test_300f() {
12598         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12599         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12600         local stripe_count
12601         local file
12602
12603         rm -rf $DIR/$tdir
12604         mkdir -p $DIR/$tdir
12605
12606         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12607                 error "set striped dir error"
12608
12609         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
12610                 error "set striped dir error"
12611
12612         touch $DIR/$tdir/striped_dir/a
12613         mkdir $DIR/$tdir/striped_dir/dir_a
12614         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
12615                 error "create striped dir under striped dir fails"
12616
12617         touch $DIR/$tdir/striped_dir1/b
12618         mkdir $DIR/$tdir/striped_dir1/dir_b
12619         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
12620                 error "create striped dir under striped dir fails"
12621
12622         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
12623                 error "rename file under different striped dir should fail"
12624
12625         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
12626                 error "rename dir under different striped dir should fail"
12627
12628         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
12629                 error "rename striped dir under diff striped dir should fail"
12630
12631         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
12632                 error "rename file under diff striped dirs fails"
12633
12634         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
12635                 error "rename dir under diff striped dirs fails"
12636
12637         rm -rf $DIR/$tdir
12638 }
12639 run_test 300f "check rename cross striped directory"
12640
12641 #
12642 # tests that do cleanup/setup should be run at the end
12643 #
12644
12645 test_900() {
12646         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12647         local ls
12648         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
12649         $LCTL set_param fail_loc=0x903
12650         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
12651         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
12652                 echo "clear" > $ls
12653         done
12654         FAIL_ON_ERROR=true cleanup
12655         FAIL_ON_ERROR=true setup
12656 }
12657 run_test 900 "umount should not race with any mgc requeue thread"
12658
12659 complete $SECONDS
12660 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
12661 check_and_cleanup_lustre
12662 if [ "$I_MOUNTED" != "yes" ]; then
12663         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
12664 fi
12665 exit_status