Whamcloud - gitweb
e8cca24d8dd13367832326a94e08eed038900126
[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 && TESTS="59 60 61 4062 4063"
488
489         for i in $TESTS; do
490                 local SYMNAME=$(str_repeat 'x' $i)
491                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
492                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
493         done
494 }
495 run_test 17g "symlinks: really long symlink name and inode boundaries"
496
497 test_17h() { #bug 17378
498         remote_mds_nodsh && skip "remote MDS with nodsh" && return
499         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
500         local mdt_idx
501         test_mkdir -p $DIR/$tdir
502         if [ $MDSCOUNT -gt 1 ]; then
503                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
504         else
505                 mdt_idx=0
506         fi
507         $SETSTRIPE -c -1 $DIR/$tdir
508 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
509         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
510         touch $DIR/$tdir/$tfile || true
511 }
512 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
513
514 test_17i() { #bug 20018
515         remote_mds_nodsh && skip "remote MDS with nodsh" && return
516         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
517         test_mkdir -p $DIR/$tdir
518         local foo=$DIR/$tdir/$tfile
519         local mdt_idx
520         if [ $MDSCOUNT -gt 1 ]; then
521                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
522         else
523                 mdt_idx=0
524         fi
525         ln -s $foo $foo || error "create symlink failed"
526 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
527         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
528         ls -l $foo && error "error not detected"
529         return 0
530 }
531 run_test 17i "don't panic on short symlink"
532
533 test_17k() { #bug 22301
534         rsync --help | grep -q xattr ||
535                 skip_env "$(rsync --version | head -n1) does not support xattrs"
536         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
537         test_mkdir -p $DIR/$tdir
538         test_mkdir -p $DIR/$tdir.new
539         touch $DIR/$tdir/$tfile
540         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
541         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
542                 error "rsync failed with xattrs enabled"
543 }
544 run_test 17k "symlinks: rsync with xattrs enabled ========================="
545
546 test_17l() { # LU-279
547         mkdir -p $DIR/$tdir
548         touch $DIR/$tdir/$tfile
549         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
550         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
551                 # -h to not follow symlinks. -m '' to list all the xattrs.
552                 # grep to remove first line: '# file: $path'.
553                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
554                 do
555                         lgetxattr_size_check $path $xattr ||
556                                 error "lgetxattr_size_check $path $xattr failed"
557                 done
558         done
559 }
560 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
561
562 # LU-1540
563 test_17m() {
564         local short_sym="0123456789"
565         local WDIR=$DIR/${tdir}m
566         local mds_index
567         local devname
568         local cmd
569         local i
570         local rc=0
571
572         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
573         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
574                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
575
576         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
577                 skip "only for ldiskfs MDT" && return 0
578
579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
580
581         mkdir -p $WDIR
582         long_sym=$short_sym
583         # create a long symlink file
584         for ((i = 0; i < 4; ++i)); do
585                 long_sym=${long_sym}${long_sym}
586         done
587
588         echo "create 512 short and long symlink files under $WDIR"
589         for ((i = 0; i < 256; ++i)); do
590                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
591                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
592         done
593
594         echo "erase them"
595         rm -f $WDIR/*
596         sync
597         wait_delete_completed
598
599         echo "recreate the 512 symlink files with a shorter string"
600         for ((i = 0; i < 512; ++i)); do
601                 # rewrite the symlink file with a shorter string
602                 ln -sf ${long_sym} $WDIR/long-$i
603                 ln -sf ${short_sym} $WDIR/short-$i
604         done
605
606         mds_index=$($LFS getstripe -M $WDIR)
607         mds_index=$((mds_index+1))
608         devname=$(mdsdevname $mds_index)
609         cmd="$E2FSCK -fnvd $devname"
610
611         echo "stop and checking mds${mds_index}: $cmd"
612         # e2fsck should not return error
613         stop mds${mds_index}
614         do_facet mds${mds_index} $cmd || rc=$?
615
616         start mds${mds_index} $devname $MDS_MOUNT_OPTS
617         df $MOUNT > /dev/null 2>&1
618         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
619                 "short/long symlink MDT: rc=$rc"
620         return $rc
621 }
622 run_test 17m "run e2fsck against MDT which contains short/long symlink"
623
624 check_fs_consistency_17n() {
625         local mdt_index
626         local devname
627         local cmd
628         local rc=0
629
630         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
631         # so it only check MDT1/MDT2 instead of all of MDTs.
632         for mdt_index in $(seq 1 2); do
633                 devname=$(mdsdevname $mdt_index)
634                 cmd="$E2FSCK -fnvd $devname"
635
636                 echo "stop and checking mds${mdt_index}: $cmd"
637                 # e2fsck should not return error
638                 stop mds${mdt_index}
639                 do_facet mds${mdt_index} $cmd || rc=$?
640
641                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
642                 df $MOUNT > /dev/null 2>&1
643                 [ $rc -ne 0 ] && break
644         done
645         return $rc
646 }
647
648 test_17n() {
649         local i
650
651         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
652         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
653                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
654
655         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
656                 skip "only for ldiskfs MDT" && return 0
657
658         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
659
660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
661
662         mkdir -p $DIR/$tdir
663         for ((i=0; i<10; i++)); do
664                 $LFS mkdir -i 1 $DIR/$tdir/remote_dir_${i} ||
665                         error "create remote dir error $i"
666                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
667                         error "create files under remote dir failed $i"
668         done
669
670         check_fs_consistency_17n ||
671                 error "e2fsck report error after create files under remote dir"
672
673         for ((i=0;i<10;i++)); do
674                 rm -rf $DIR/$tdir/remote_dir_${i} ||
675                         error "destroy remote dir error $i"
676         done
677
678         check_fs_consistency_17n ||
679                 error "e2fsck report error after unlink files under remote dir"
680
681         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
682                 skip "lustre < 2.4.50 does not support migrate mv " && return
683
684         for ((i=0; i<10; i++)); do
685                 mkdir -p $DIR/$tdir/remote_dir_${i}
686                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
687                         error "create files under remote dir failed $i"
688                 $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} ||
689                         error "migrate remote dir error $i"
690         done
691         check_fs_consistency_17n || error "e2fsck report error after migration"
692
693         for ((i=0;i<10;i++)); do
694                 rm -rf $DIR/$tdir/remote_dir_${i} ||
695                         error "destroy remote dir error $i"
696         done
697
698         check_fs_consistency_17n || error "e2fsck report error after unlink"
699 }
700 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
701
702 test_17o() {
703         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ]] &&
704                 skip "Need MDS version at least 2.3.64" && return
705
706         local WDIR=$DIR/${tdir}o
707         local mdt_index
708         local mdtdevname
709         local rc=0
710
711         mkdir -p $WDIR
712         mdt_index=$($LFS getstripe -M $WDIR)
713         mdt_index=$((mdt_index+1))
714         mdtdevname=$(mdsdevname $mdt_index)
715
716         touch $WDIR/$tfile
717         stop mds${mdt_index}
718         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS
719
720         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
721         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
722         ls -l $WDIR/$tfile && rc=1
723         do_facet mds${mdt_index} lctl set_param fail_loc=0
724         [[ $rc -ne 0 ]] && error "stat file should fail"
725         true
726 }
727 run_test 17o "stat file with incompat LMA feature"
728
729 test_18() {
730         touch $DIR/f || error "Failed to touch $DIR/f: $?"
731         ls $DIR || error "Failed to ls $DIR: $?"
732 }
733 run_test 18 "touch .../f ; ls ... =============================="
734
735 test_19a() {
736         touch $DIR/$tfile
737         ls -l $DIR
738         rm $DIR/$tfile
739         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
740 }
741 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
742
743 test_19b() {
744         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
745 }
746 run_test 19b "ls -l .../f19 (should return error) =============="
747
748 test_19c() {
749         [ $RUNAS_ID -eq $UID ] &&
750                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
751         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
752 }
753 run_test 19c "$RUNAS touch .../f19 (should return error) =="
754
755 test_19d() {
756         cat $DIR/f19 && error || true
757 }
758 run_test 19d "cat .../f19 (should return error) =============="
759
760 test_20() {
761         touch $DIR/$tfile
762         rm $DIR/$tfile
763         log "1 done"
764         touch $DIR/$tfile
765         rm $DIR/$tfile
766         log "2 done"
767         touch $DIR/$tfile
768         rm $DIR/$tfile
769         log "3 done"
770         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
771 }
772 run_test 20 "touch .../f ; ls -l ... ==========================="
773
774 test_21() {
775         test_mkdir -p $DIR/$tdir
776         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
777         ln -s dangle $DIR/$tdir/link
778         echo foo >> $DIR/$tdir/link
779         cat $DIR/$tdir/dangle
780         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
781         $CHECKSTAT -f -t file $DIR/$tdir/link ||
782                 error "$tdir/link not linked to a file"
783 }
784 run_test 21 "write to dangling link ============================"
785
786 test_22() {
787         WDIR=$DIR/$tdir
788         test_mkdir -p $DIR/$tdir
789         chown $RUNAS_ID:$RUNAS_GID $WDIR
790         (cd $WDIR || error "cd $WDIR failed";
791         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
792         $RUNAS tar xf -)
793         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
794         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
795         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
796 }
797 run_test 22 "unpack tar archive as non-root user ==============="
798
799 # was test_23
800 test_23a() {
801         test_mkdir -p $DIR/$tdir
802         local file=$DIR/$tdir/$tfile
803
804         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
805         openfile -f O_CREAT:O_EXCL $file &&
806                 error "$file recreate succeeded" || true
807 }
808 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
809
810 test_23b() { # bug 18988
811         test_mkdir -p $DIR/$tdir
812         local file=$DIR/$tdir/$tfile
813
814         rm -f $file
815         echo foo > $file || error "write filed"
816         echo bar >> $file || error "append filed"
817         $CHECKSTAT -s 8 $file || error "wrong size"
818         rm $file
819 }
820 run_test 23b "O_APPEND check =========================="
821
822 # rename sanity
823 test_24a() {
824         echo '-- same directory rename'
825         test_mkdir $DIR/$tdir
826         touch $DIR/$tdir/$tfile.1
827         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
828         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
829 }
830 run_test 24a "rename file to non-existent target"
831
832 test_24b() {
833         test_mkdir $DIR/$tdir
834         touch $DIR/$tdir/$tfile.{1,2}
835         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
836         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
837         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
838 }
839 run_test 24b "rename file to existing target"
840
841 test_24c() {
842         test_mkdir $DIR/$tdir
843         test_mkdir $DIR/$tdir/d$testnum.1
844         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
845         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
846         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
847 }
848 run_test 24c "rename directory to non-existent target"
849
850 test_24d() {
851         test_mkdir -c1 $DIR/$tdir
852         test_mkdir -c1 $DIR/$tdir/d$testnum.1
853         test_mkdir -c1 $DIR/$tdir/d$testnum.2
854         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
855         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
856         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
857 }
858 run_test 24d "rename directory to existing target"
859
860 test_24e() {
861         echo '-- cross directory renames --'
862         test_mkdir $DIR/R5a
863         test_mkdir $DIR/R5b
864         touch $DIR/R5a/f
865         mv $DIR/R5a/f $DIR/R5b/g
866         $CHECKSTAT -a $DIR/R5a/f || error
867         $CHECKSTAT -t file $DIR/R5b/g || error
868 }
869 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
870
871 test_24f() {
872         test_mkdir $DIR/R6a
873         test_mkdir $DIR/R6b
874         touch $DIR/R6a/f $DIR/R6b/g
875         mv $DIR/R6a/f $DIR/R6b/g
876         $CHECKSTAT -a $DIR/R6a/f || error
877         $CHECKSTAT -t file $DIR/R6b/g || error
878 }
879 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
880
881 test_24g() {
882         test_mkdir $DIR/R7a
883         test_mkdir $DIR/R7b
884         test_mkdir $DIR/R7a/d
885         mv $DIR/R7a/d $DIR/R7b/e
886         $CHECKSTAT -a $DIR/R7a/d || error
887         $CHECKSTAT -t dir $DIR/R7b/e || error
888 }
889 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
890
891 test_24h() {
892         test_mkdir -c1 $DIR/R8a
893         test_mkdir -c1 $DIR/R8b
894         test_mkdir -c1 $DIR/R8a/d
895         test_mkdir -c1 $DIR/R8b/e
896         mrename $DIR/R8a/d $DIR/R8b/e
897         $CHECKSTAT -a $DIR/R8a/d || error
898         $CHECKSTAT -t dir $DIR/R8b/e || error
899 }
900 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
901
902 test_24i() {
903         echo "-- rename error cases"
904         test_mkdir $DIR/R9
905         test_mkdir $DIR/R9/a
906         touch $DIR/R9/f
907         mrename $DIR/R9/f $DIR/R9/a
908         $CHECKSTAT -t file $DIR/R9/f || error
909         $CHECKSTAT -t dir  $DIR/R9/a || error
910         $CHECKSTAT -a $DIR/R9/a/f || error
911 }
912 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
913
914 test_24j() {
915         test_mkdir $DIR/R10
916         mrename $DIR/R10/f $DIR/R10/g
917         $CHECKSTAT -t dir $DIR/R10 || error
918         $CHECKSTAT -a $DIR/R10/f || error
919         $CHECKSTAT -a $DIR/R10/g || error
920 }
921 run_test 24j "source does not exist ============================"
922
923 test_24k() {
924         test_mkdir $DIR/R11a
925         test_mkdir $DIR/R11a/d
926         touch $DIR/R11a/f
927         mv $DIR/R11a/f $DIR/R11a/d
928         $CHECKSTAT -a $DIR/R11a/f || error
929         $CHECKSTAT -t file $DIR/R11a/d/f || error
930 }
931 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
932
933 # bug 2429 - rename foo foo foo creates invalid file
934 test_24l() {
935         f="$DIR/f24l"
936         $MULTIOP $f OcNs || error
937 }
938 run_test 24l "Renaming a file to itself ========================"
939
940 test_24m() {
941         f="$DIR/f24m"
942         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
943         # on ext3 this does not remove either the source or target files
944         # though the "expected" operation would be to remove the source
945         $CHECKSTAT -t file ${f} || error "${f} missing"
946         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
947 }
948 run_test 24m "Renaming a file to a hard link to itself ========="
949
950 test_24n() {
951     f="$DIR/f24n"
952     # this stats the old file after it was renamed, so it should fail
953     touch ${f}
954     $CHECKSTAT ${f}
955     mv ${f} ${f}.rename
956     $CHECKSTAT ${f}.rename
957     $CHECKSTAT -a ${f}
958 }
959 run_test 24n "Statting the old file after renaming (Posix rename 2)"
960
961 test_24o() {
962         check_kernel_version 37 || return 0
963         test_mkdir -p $DIR/d24o
964         rename_many -s random -v -n 10 $DIR/d24o
965 }
966 run_test 24o "rename of files during htree split ==============="
967
968 test_24p() {
969         test_mkdir $DIR/R12a
970         test_mkdir $DIR/R12b
971         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
972         mrename $DIR/R12a $DIR/R12b
973         $CHECKSTAT -a $DIR/R12a || error
974         $CHECKSTAT -t dir $DIR/R12b || error
975         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
976         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
977 }
978 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
979
980 cleanup_multiop_pause() {
981         trap 0
982         kill -USR1 $MULTIPID
983 }
984
985 test_24q() {
986         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
987         test_mkdir $DIR/R13a
988         test_mkdir $DIR/R13b
989         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
990         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
991         MULTIPID=$!
992
993         trap cleanup_multiop_pause EXIT
994         mrename $DIR/R13a $DIR/R13b
995         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
996         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
997         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
998         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
999         cleanup_multiop_pause
1000         wait $MULTIPID || error "multiop close failed"
1001 }
1002 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
1003
1004 test_24r() { #bug 3789
1005         test_mkdir $DIR/R14a
1006         test_mkdir $DIR/R14a/b
1007         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1008         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1009         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1010 }
1011 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1012
1013 test_24s() {
1014         test_mkdir $DIR/R15a
1015         test_mkdir $DIR/R15a/b
1016         test_mkdir $DIR/R15a/b/c
1017         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1018         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1019         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1020 }
1021 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1022 test_24t() {
1023         test_mkdir $DIR/R16a
1024         test_mkdir $DIR/R16a/b
1025         test_mkdir $DIR/R16a/b/c
1026         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1027         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1028         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1029 }
1030 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1031
1032 test_24u() { # bug12192
1033         rm -rf $DIR/$tfile
1034         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1035         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1036 }
1037 run_test 24u "create stripe file"
1038
1039 page_size() {
1040         getconf PAGE_SIZE
1041 }
1042
1043 simple_cleanup_common() {
1044         trap 0
1045         rm -rf $DIR/$tdir
1046         wait_delete_completed
1047 }
1048
1049 max_pages_per_rpc() {
1050         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1051 }
1052
1053 test_24v() {
1054         local NRFILES=100000
1055         local FREE_INODES=$(mdt_free_inodes 0)
1056         [ $FREE_INODES -lt $NRFILES ] && \
1057                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1058                 return
1059
1060         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1061         trap simple_cleanup_common EXIT
1062
1063         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1064         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1065
1066         mkdir -p $DIR/$tdir
1067         createmany -m $DIR/$tdir/$tfile $NRFILES
1068
1069         cancel_lru_locks mdc
1070         lctl set_param mdc.*.stats clear
1071
1072         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1073
1074         # LU-5 large readdir
1075         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1076         #               8 bytes for name(filename is mostly 5 in this test) +
1077         #               8 bytes for luda_type
1078         # take into account of overhead in lu_dirpage header and end mark in
1079         # each page, plus one in RPC_NUM calculation.
1080         DIRENT_SIZE=48
1081         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1082         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1083         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats | \
1084                                 awk '/^mds_readpage/ {print $2}')
1085         [ $mds_readpage -gt $RPC_NUM ] && \
1086                 error "large readdir doesn't take effect"
1087
1088         simple_cleanup_common
1089 }
1090 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1091
1092 test_24w() { # bug21506
1093         SZ1=234852
1094         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1095         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1096         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1097         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1098         [ "$SZ1" = "$SZ2" ] || \
1099                 error "Error reading at the end of the file $tfile"
1100 }
1101 run_test 24w "Reading a file larger than 4Gb"
1102
1103 test_24x() {
1104         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1105         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1106         local MDTIDX=1
1107         local remote_dir=$DIR/$tdir/remote_dir
1108
1109         mkdir -p $DIR/$tdir
1110         $LFS mkdir -i $MDTIDX $remote_dir ||
1111                 error "create remote directory failed"
1112
1113         mkdir -p $DIR/$tdir/src_dir
1114         touch $DIR/$tdir/src_file
1115         mkdir -p $remote_dir/tgt_dir
1116         touch $remote_dir/tgt_file
1117
1118         mrename $remote_dir $DIR/ &&
1119                 error "rename dir cross MDT works!"
1120
1121         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1122                 error "rename dir cross MDT works!"
1123
1124         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1125                 error "rename file cross MDT works!"
1126
1127         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1128                 error "ln file cross MDT should not work!"
1129
1130         rm -rf $DIR/$tdir || error "Can not delete directories"
1131 }
1132 run_test 24x "cross rename/link should be failed"
1133
1134 test_24y() {
1135         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1137         local MDTIDX=1
1138         local remote_dir=$DIR/$tdir/remote_dir
1139
1140         mkdir -p $DIR/$tdir
1141         $LFS mkdir -i $MDTIDX $remote_dir ||
1142                    error "create remote directory failed"
1143
1144         mkdir -p $remote_dir/src_dir
1145         touch $remote_dir/src_file
1146         mkdir -p $remote_dir/tgt_dir
1147         touch $remote_dir/tgt_file
1148
1149         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1150                 error "rename subdir in the same remote dir failed!"
1151
1152         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1153                 error "rename files in the same remote dir failed!"
1154
1155         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1156                 error "link files in the same remote dir failed!"
1157
1158         rm -rf $DIR/$tdir || error "Can not delete directories"
1159 }
1160 run_test 24y "rename/link on the same dir should succeed"
1161
1162 test_24z() {
1163         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1164         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1165         local MDTIDX=1
1166         local remote_src=$DIR/$tdir/remote_dir
1167         local remote_tgt=$DIR/$tdir/remote_tgt
1168
1169         mkdir -p $DIR/$tdir
1170         $LFS mkdir -i $MDTIDX $remote_src ||
1171                    error "create remote directory failed"
1172
1173         $LFS mkdir -i $MDTIDX $remote_tgt ||
1174                    error "create remote directory failed"
1175
1176         mrename $remote_src $remote_tgt &&
1177                 error "rename remote dirs should not work!"
1178
1179         # If target dir does not exists, it should succeed
1180         rm -rf $remote_tgt
1181         mrename $remote_src $remote_tgt ||
1182                 error "rename remote dirs(tgt dir does not exists) failed!"
1183
1184         rm -rf $DIR/$tdir || error "Can not delete directories"
1185 }
1186 run_test 24z "rename one remote dir to another remote dir should fail"
1187
1188 test_24A() { # LU-3182
1189         local NFILES=5000
1190
1191         rm -rf $DIR/$tdir
1192         mkdir -p $DIR/$tdir
1193         createmany -m $DIR/$tdir/$tfile $NFILES
1194         local t=`ls $DIR/$tdir | wc -l`
1195         local u=`ls $DIR/$tdir | sort -u | wc -l`
1196         if [ $t -ne $NFILES -o $u -ne $NFILES ] ; then
1197                 error "Expected $NFILES files, got $t ($u unique)"
1198         fi
1199
1200         rm -rf $DIR/$tdir || error "Can not delete directories"
1201 }
1202 run_test 24A "readdir() returns correct number of entries."
1203
1204 test_25a() {
1205         echo '== symlink sanity ============================================='
1206
1207         test_mkdir $DIR/d25
1208         ln -s d25 $DIR/s25
1209         touch $DIR/s25/foo || error
1210 }
1211 run_test 25a "create file in symlinked directory ==============="
1212
1213 test_25b() {
1214         [ ! -d $DIR/d25 ] && test_25a
1215         $CHECKSTAT -t file $DIR/s25/foo || error
1216 }
1217 run_test 25b "lookup file in symlinked directory ==============="
1218
1219 test_26a() {
1220         test_mkdir $DIR/d26
1221         test_mkdir $DIR/d26/d26-2
1222         ln -s d26/d26-2 $DIR/s26
1223         touch $DIR/s26/foo || error
1224 }
1225 run_test 26a "multiple component symlink ======================="
1226
1227 test_26b() {
1228         test_mkdir -p $DIR/d26b/d26-2
1229         ln -s d26b/d26-2/foo $DIR/s26-2
1230         touch $DIR/s26-2 || error
1231 }
1232 run_test 26b "multiple component symlink at end of lookup ======"
1233
1234 test_26c() {
1235         test_mkdir $DIR/d26.2
1236         touch $DIR/d26.2/foo
1237         ln -s d26.2 $DIR/s26.2-1
1238         ln -s s26.2-1 $DIR/s26.2-2
1239         ln -s s26.2-2 $DIR/s26.2-3
1240         chmod 0666 $DIR/s26.2-3/foo
1241 }
1242 run_test 26c "chain of symlinks ================================"
1243
1244 # recursive symlinks (bug 439)
1245 test_26d() {
1246         ln -s d26-3/foo $DIR/d26-3
1247 }
1248 run_test 26d "create multiple component recursive symlink ======"
1249
1250 test_26e() {
1251         [ ! -h $DIR/d26-3 ] && test_26d
1252         rm $DIR/d26-3
1253 }
1254 run_test 26e "unlink multiple component recursive symlink ======"
1255
1256 # recursive symlinks (bug 7022)
1257 test_26f() {
1258         test_mkdir -p $DIR/$tdir
1259         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1260         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1261         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1262         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1263         cd $tfile                || error "cd $tfile failed"
1264         ln -s .. dotdot          || error "ln dotdot failed"
1265         ln -s dotdot/lndir lndir || error "ln lndir failed"
1266         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1267         output=`ls $tfile/$tfile/lndir/bar1`
1268         [ "$output" = bar1 ] && error "unexpected output"
1269         rm -r $tfile             || error "rm $tfile failed"
1270         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1271 }
1272 run_test 26f "rm -r of a directory which has recursive symlink ="
1273
1274 test_27a() {
1275         echo '== stripe sanity =============================================='
1276         test_mkdir -p $DIR/d27 || error "mkdir failed"
1277         $GETSTRIPE $DIR/d27
1278         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1279         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1280         pass
1281         log "== test_27a: write to one stripe file ========================="
1282         cp /etc/hosts $DIR/d27/f0 || error
1283 }
1284 run_test 27a "one stripe file =================================="
1285
1286 test_27b() {
1287         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1288         test_mkdir -p $DIR/d27
1289         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1290         $GETSTRIPE -c $DIR/d27/f01
1291         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1292                 error "two-stripe file doesn't have two stripes"
1293
1294         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1295 }
1296 run_test 27b "create and write to two stripe file"
1297
1298 test_27d() {
1299         test_mkdir -p $DIR/d27
1300         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1301         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1302         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1303 }
1304 run_test 27d "create file with default settings ================"
1305
1306 test_27e() {
1307         test_mkdir -p $DIR/d27
1308         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1309         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1310         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1311 }
1312 run_test 27e "setstripe existing file (should return error) ======"
1313
1314 test_27f() {
1315         test_mkdir -p $DIR/d27
1316         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1317         dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed"
1318         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1319 }
1320 run_test 27f "setstripe with bad stripe size (should return error)"
1321
1322 test_27g() {
1323         test_mkdir -p $DIR/d27
1324         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1325         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1326                 error "$DIR/d27/fnone has object"
1327 }
1328 run_test 27g "$GETSTRIPE with no objects"
1329
1330 test_27i() {
1331         touch $DIR/d27/fsome || error "touch failed"
1332         [ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ] || error "missing objects"
1333 }
1334 run_test 27i "$GETSTRIPE with some objects"
1335
1336 test_27j() {
1337         test_mkdir -p $DIR/d27
1338         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1339 }
1340 run_test 27j "setstripe with bad stripe offset (should return error)"
1341
1342 test_27k() { # bug 2844
1343         test_mkdir -p $DIR/d27
1344         FILE=$DIR/d27/f27k
1345         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1346         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1347         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1348         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1349         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1350         dd if=/dev/zero of=$FILE bs=4k count=1
1351         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1352         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1353 }
1354 run_test 27k "limit i_blksize for broken user apps ============="
1355
1356 test_27l() {
1357         test_mkdir -p $DIR/d27
1358         mcreate $DIR/f27l || error "creating file"
1359         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1360                 error "setstripe should have failed" || true
1361 }
1362 run_test 27l "check setstripe permissions (should return error)"
1363
1364 test_27m() {
1365         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1366                 return
1367         if [ $ORIGFREE -gt $MAXFREE ]; then
1368                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1369                 return
1370         fi
1371         trap simple_cleanup_common EXIT
1372         test_mkdir -p $DIR/$tdir
1373         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1374         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1375                 error "dd should fill OST0"
1376         i=2
1377         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1378                 i=`expr $i + 1`
1379                 [ $i -gt 256 ] && break
1380         done
1381         i=`expr $i + 1`
1382         touch $DIR/$tdir/f27m_$i
1383         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1384                 error "OST0 was full but new created file still use it"
1385         i=`expr $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         simple_cleanup_common
1390 }
1391 run_test 27m "create file while OST0 was full =================="
1392
1393 sleep_maxage() {
1394         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1395         sleep $DELAY
1396 }
1397
1398 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1399 # if the OST isn't full anymore.
1400 reset_enospc() {
1401         local OSTIDX=${1:-""}
1402
1403         local list=$(comma_list $(osts_nodes))
1404         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1405
1406         do_nodes $list lctl set_param fail_loc=0
1407         sync    # initiate all OST_DESTROYs from MDS to OST
1408         sleep_maxage
1409 }
1410
1411 exhaust_precreations() {
1412         local OSTIDX=$1
1413         local FAILLOC=$2
1414         local FAILIDX=${3:-$OSTIDX}
1415
1416         test_mkdir -p $DIR/$tdir
1417         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1418         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1419
1420         local OST=$(ostname_from_index $OSTIDX)
1421         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1422                           sed -e 's/_UUID$//;s/^.*-//')
1423
1424         # on the mdt's osc
1425         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1426         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1427                         osc.$mdtosc_proc1.prealloc_last_id)
1428         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1429                         osc.$mdtosc_proc1.prealloc_next_id)
1430
1431         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1432         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1433
1434         test_mkdir -p $DIR/$tdir/${OST}
1435         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1436 #define OBD_FAIL_OST_ENOSPC              0x215
1437         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1438         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1439         echo "Creating to objid $last_id on ost $OST..."
1440         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1441         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1442         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1443         sleep_maxage
1444 }
1445
1446 exhaust_all_precreations() {
1447         local i
1448         for (( i=0; i < OSTCOUNT; i++ )) ; do
1449                 exhaust_precreations $i $1 -1
1450         done
1451 }
1452
1453 test_27n() {
1454         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1455         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1456         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1457         remote_ost_nodsh && skip "remote OST with nodsh" && return
1458
1459         reset_enospc
1460         rm -f $DIR/$tdir/$tfile
1461         exhaust_precreations 0 0x80000215
1462         $SETSTRIPE -c -1 $DIR/$tdir
1463         touch $DIR/$tdir/$tfile || error
1464         $GETSTRIPE $DIR/$tdir/$tfile
1465         reset_enospc
1466 }
1467 run_test 27n "create file with some full OSTs =================="
1468
1469 test_27o() {
1470         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1471         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1472         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1473         remote_ost_nodsh && skip "remote OST with nodsh" && return
1474
1475         reset_enospc
1476         rm -f $DIR/$tdir/$tfile
1477         exhaust_all_precreations 0x215
1478
1479         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1480
1481         reset_enospc
1482         rm -rf $DIR/$tdir/*
1483 }
1484 run_test 27o "create file with all full OSTs (should error) ===="
1485
1486 test_27p() {
1487         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1488         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1489         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1490         remote_ost_nodsh && skip "remote OST with nodsh" && return
1491
1492         reset_enospc
1493         rm -f $DIR/$tdir/$tfile
1494         test_mkdir -p $DIR/$tdir
1495
1496         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1497         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1498         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1499
1500         exhaust_precreations 0 0x80000215
1501         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1502         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1503         $GETSTRIPE $DIR/$tdir/$tfile
1504
1505         reset_enospc
1506 }
1507 run_test 27p "append to a truncated file with some full OSTs ==="
1508
1509 test_27q() {
1510         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1511         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1512         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1513         remote_ost_nodsh && skip "remote OST with nodsh" && return
1514
1515         reset_enospc
1516         rm -f $DIR/$tdir/$tfile
1517
1518         test_mkdir -p $DIR/$tdir
1519         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1520         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1521         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1522
1523         exhaust_all_precreations 0x215
1524
1525         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1526         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1527
1528         reset_enospc
1529 }
1530 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1531
1532 test_27r() {
1533         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1534         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1535         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1536         remote_ost_nodsh && skip "remote OST with nodsh" && return
1537
1538         reset_enospc
1539         rm -f $DIR/$tdir/$tfile
1540         exhaust_precreations 0 0x80000215
1541
1542         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1543
1544         reset_enospc
1545 }
1546 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1547
1548 test_27s() { # bug 10725
1549         test_mkdir -p $DIR/$tdir
1550         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1551         local stripe_count=0
1552         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1553         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1554                 error "stripe width >= 2^32 succeeded" || true
1555
1556 }
1557 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1558
1559 test_27t() { # bug 10864
1560         WDIR=`pwd`
1561         WLFS=`which lfs`
1562         cd $DIR
1563         touch $tfile
1564         $WLFS getstripe $tfile
1565         cd $WDIR
1566 }
1567 run_test 27t "check that utils parse path correctly"
1568
1569 test_27u() { # bug 4900
1570         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1571         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1572         local index
1573         local list=$(comma_list $(mdts_nodes))
1574
1575 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1576         do_nodes $list $LCTL set_param fail_loc=0x139
1577         test_mkdir -p $DIR/$tdir
1578         rm -rf $DIR/$tdir/*
1579         createmany -o $DIR/$tdir/t- 1000
1580         do_nodes $list $LCTL set_param fail_loc=0
1581
1582         TLOG=$DIR/$tfile.getstripe
1583         $GETSTRIPE $DIR/$tdir > $TLOG
1584         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1585         unlinkmany $DIR/$tdir/t- 1000
1586         [ $OBJS -gt 0 ] && \
1587                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1588 }
1589 run_test 27u "skip object creation on OSC w/o objects =========="
1590
1591 test_27v() { # bug 4900
1592         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1593         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1594         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1595         remote_ost_nodsh && skip "remote OST with nodsh" && return
1596
1597         exhaust_all_precreations 0x215
1598         reset_enospc
1599
1600         test_mkdir -p $DIR/$tdir
1601         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1602
1603         touch $DIR/$tdir/$tfile
1604         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1605         # all except ost1
1606         for (( i=1; i < OSTCOUNT; i++ )); do
1607                 do_facet ost$i lctl set_param fail_loc=0x705
1608         done
1609         local START=`date +%s`
1610         createmany -o $DIR/$tdir/$tfile 32
1611
1612         local FINISH=`date +%s`
1613         local TIMEOUT=`lctl get_param -n timeout`
1614         local PROCESS=$((FINISH - START))
1615         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1616                error "$FINISH - $START >= $TIMEOUT / 2"
1617         sleep $((TIMEOUT / 2 - PROCESS))
1618         reset_enospc
1619 }
1620 run_test 27v "skip object creation on slow OST ================="
1621
1622 test_27w() { # bug 10997
1623         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1624         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1625         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1626                 error "stripe size $size != 65536" || true
1627         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1628                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1629 }
1630 run_test 27w "check $SETSTRIPE -S option"
1631
1632 test_27wa() {
1633         [ "$OSTCOUNT" -lt "2" ] &&
1634                 skip_env "skipping multiple stripe count/offset test" && return
1635
1636         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1637         for i in $(seq 1 $OSTCOUNT); do
1638                 offset=$((i - 1))
1639                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1640                         error "setstripe -c $i -i $offset failed"
1641                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1642                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1643                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1644                 [ $index -ne $offset ] &&
1645                         error "stripe offset $index != $offset" || true
1646         done
1647 }
1648 run_test 27wa "check $SETSTRIPE -c -i options"
1649
1650 test_27x() {
1651         remote_ost_nodsh && skip "remote OST with nodsh" && return
1652         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
1653         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1654         OFFSET=$(($OSTCOUNT - 1))
1655         OSTIDX=0
1656         local OST=$(ostname_from_index $OSTIDX)
1657
1658         test_mkdir -p $DIR/$tdir
1659         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1660         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1661         sleep_maxage
1662         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1663         for i in `seq 0 $OFFSET`; do
1664                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1665                 error "OST0 was degraded but new created file still use it"
1666         done
1667         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1668 }
1669 run_test 27x "create files while OST0 is degraded"
1670
1671 test_27y() {
1672         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1673         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1674         remote_ost_nodsh && skip "remote OST with nodsh" && return
1675         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1676
1677         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1678         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1679             osc.$mdtosc.prealloc_last_id)
1680         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1681             osc.$mdtosc.prealloc_next_id)
1682         local fcount=$((last_id - next_id))
1683         [ $fcount -eq 0 ] && skip "not enough space on OST0" && return
1684         [ $fcount -gt $OSTCOUNT ] && fcount=$OSTCOUNT
1685
1686         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1687                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1688         local OST_DEACTIVE_IDX=-1
1689         local OSC
1690         local OSTIDX
1691         local OST
1692
1693         for OSC in $MDS_OSCS; do
1694                 OST=$(osc_to_ost $OSC)
1695                 OSTIDX=$(index_from_ostuuid $OST)
1696                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1697                         OST_DEACTIVE_IDX=$OSTIDX
1698                 fi
1699                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1700                         echo $OSC "is Deactivated:"
1701                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1702                 fi
1703         done
1704
1705         OSTIDX=$(index_from_ostuuid $OST)
1706         mkdir -p $DIR/$tdir
1707         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1708
1709         for OSC in $MDS_OSCS; do
1710                 OST=$(osc_to_ost $OSC)
1711                 OSTIDX=$(index_from_ostuuid $OST)
1712                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1713                         echo $OST "is degraded:"
1714                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1715                                                 obdfilter.$OST.degraded=1
1716                 fi
1717         done
1718
1719         sleep_maxage
1720         createmany -o $DIR/$tdir/$tfile $fcount
1721
1722         for OSC in $MDS_OSCS; do
1723                 OST=$(osc_to_ost $OSC)
1724                 OSTIDX=$(index_from_ostuuid $OST)
1725                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1726                         echo $OST "is recovered from degraded:"
1727                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1728                                                 obdfilter.$OST.degraded=0
1729                 else
1730                         do_facet $SINGLEMDS lctl --device %$OSC activate
1731                 fi
1732         done
1733
1734         # all osp devices get activated, hence -1 stripe count restored
1735         local stripecnt=0
1736
1737         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1738         # devices get activated.
1739         sleep_maxage
1740         $SETSTRIPE -c -1 $DIR/$tfile
1741         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1742         rm -f $DIR/$tfile
1743         [ $stripecnt -ne $OSTCOUNT ] &&
1744                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1745         return 0
1746 }
1747 run_test 27y "create files while OST0 is degraded and the rest inactive"
1748
1749 check_seq_oid()
1750 {
1751         log "check file $1"
1752
1753         lmm_count=$($GETSTRIPE -c $1)
1754         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1755         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1756
1757         local old_ifs="$IFS"
1758         IFS=$'[:]'
1759         fid=($($LFS path2fid $1))
1760         IFS="$old_ifs"
1761
1762         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1763         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1764
1765         # compare lmm_seq and lu_fid->f_seq
1766         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1767         # compare lmm_object_id and lu_fid->oid
1768         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1769
1770         # check the trusted.fid attribute of the OST objects of the file
1771         local have_obdidx=false
1772         local stripe_nr=0
1773         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1774                 # skip lines up to and including "obdidx"
1775                 [ -z "$obdidx" ] && break
1776                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1777                 $have_obdidx || continue
1778
1779                 local ost=$((obdidx + 1))
1780                 local dev=$(ostdevname $ost)
1781                 local oid_hex
1782
1783                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1784
1785                 seq=$(echo $seq | sed -e "s/^0x//g")
1786                 if [ $seq == 0 ]; then
1787                         oid_hex=$(echo $oid)
1788                 else
1789                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1790                 fi
1791                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1792
1793                 local ff
1794                 #
1795                 # Don't unmount/remount the OSTs if we don't need to do that.
1796                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1797                 # update too, until that use mount/ll_decode_filter_fid/mount.
1798                 # Re-enable when debugfs will understand new filter_fid.
1799                 #
1800                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1801                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1802                                 $dev 2>/dev/null" | grep "parent=")
1803                 else
1804                         stop ost$ost
1805                         mount_fstype ost$ost
1806                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1807                                 $(facet_mntpt ost$ost)/$obj_file)
1808                         unmount_fstype ost$ost
1809                         start ost$ost $dev $OST_MOUNT_OPTS
1810                 fi
1811
1812                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1813
1814                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1815
1816                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1817                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1818                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1819                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1820                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1821                 local ff_pstripe
1822                 if echo $ff_parent | grep -q 'stripe='; then
1823                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1824                 else
1825                         #
1826                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1827                         # into f_ver in this case.  See the comment on
1828                         # ff_parent.
1829                         #
1830                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1831                                 sed -e 's/\]//')
1832                 fi
1833
1834                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1835                 [ $ff_pseq = $lmm_seq ] ||
1836                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1837                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1838                 [ $ff_poid = $lmm_oid ] ||
1839                         error "FF parent OID $ff_poid != $lmm_oid"
1840                 (($ff_pstripe == $stripe_nr)) ||
1841                         error "FF stripe $ff_pstripe != $stripe_nr"
1842
1843                 stripe_nr=$((stripe_nr + 1))
1844         done
1845 }
1846
1847 test_27z() {
1848         remote_ost_nodsh && skip "remote OST with nodsh" && return
1849         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1850         test_mkdir -p $DIR/$tdir
1851
1852         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1853                 { error "setstripe -c -1 failed"; return 1; }
1854         # We need to send a write to every object to get parent FID info set.
1855         # This _should_ also work for setattr, but does not currently.
1856         # touch $DIR/$tdir/$tfile-1 ||
1857         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1858                 { error "dd $tfile-1 failed"; return 2; }
1859         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1860                 { error "setstripe -c -1 failed"; return 3; }
1861         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1862                 { error "dd $tfile-2 failed"; return 4; }
1863
1864         # make sure write RPCs have been sent to OSTs
1865         sync; sleep 5; sync
1866
1867         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1868         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1869 }
1870 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1871
1872 test_27A() { # b=19102
1873         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1874         local restore_size=$($GETSTRIPE -S $MOUNT)
1875         local restore_count=$($GETSTRIPE -c $MOUNT)
1876         local restore_offset=$($GETSTRIPE -i $MOUNT)
1877         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1878         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1879                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1880         local default_size=$($GETSTRIPE -S $MOUNT)
1881         local default_offset=$($GETSTRIPE -i $MOUNT)
1882         local dsize=$((1024 * 1024))
1883         [ $default_size -eq $dsize ] ||
1884                 error "stripe size $default_size != $dsize"
1885         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1886         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1887 }
1888 run_test 27A "check filesystem-wide default LOV EA values"
1889
1890 test_27B() { # LU-2523
1891         test_mkdir -p $DIR/$tdir
1892         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1893         touch $DIR/$tdir/f0
1894         # open f1 with O_LOV_DELAY_CREATE
1895         # rename f0 onto f1
1896         # call setstripe ioctl on open file descriptor for f1
1897         # close
1898         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1899                 $DIR/$tdir/f0
1900
1901         rm -f $DIR/$tdir/f1
1902         # open f1 with O_LOV_DELAY_CREATE
1903         # unlink f1
1904         # call setstripe ioctl on open file descriptor for f1
1905         # close
1906         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1907
1908         # Allow multiop to fail in imitation of NFS's busted semantics.
1909         true
1910 }
1911 run_test 27B "call setstripe on open unlinked file/rename victim"
1912
1913 test_27C() { #LU-2871
1914         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1915
1916         declare -a ost_idx
1917         local index
1918         local found
1919         local i
1920         local j
1921
1922         test_mkdir -p $DIR/$tdir
1923         cd $DIR/$tdir
1924         for i in $(seq 0 $((OSTCOUNT - 1))); do
1925                 # set stripe across all OSTs starting from OST$i
1926                 $SETSTRIPE -i $i -c -1 $tfile$i
1927                 # get striping information
1928                 ost_idx=($($GETSTRIPE $tfile$i |
1929                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1930                 echo ${ost_idx[@]}
1931
1932                 # check the layout
1933                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1934                         error "${#ost_idx[@]} != $OSTCOUNT"
1935
1936                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1937                         found=0
1938                         for j in $(echo ${ost_idx[@]}); do
1939                                 if [ $index -eq $j ]; then
1940                                         found=1
1941                                         break
1942                                 fi
1943                         done
1944                         [ $found = 1 ] ||
1945                                 error "Can not find $index in ${ost_idx[@]}"
1946                 done
1947         done
1948 }
1949 run_test 27C "check full striping across all OSTs"
1950
1951 # createtest also checks that device nodes are created and
1952 # then visible correctly (#2091)
1953 test_28() { # bug 2091
1954         test_mkdir $DIR/d28
1955         $CREATETEST $DIR/d28/ct || error
1956 }
1957 run_test 28 "create/mknod/mkdir with bad file types ============"
1958
1959 test_29() {
1960         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1961         cancel_lru_locks mdc
1962         test_mkdir $DIR/d29
1963         touch $DIR/d29/foo
1964         log 'first d29'
1965         ls -l $DIR/d29
1966
1967         declare -i LOCKCOUNTORIG=0
1968         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1969                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1970         done
1971         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1972
1973         declare -i LOCKUNUSEDCOUNTORIG=0
1974         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1975                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1976         done
1977
1978         log 'second d29'
1979         ls -l $DIR/d29
1980         log 'done'
1981
1982         declare -i LOCKCOUNTCURRENT=0
1983         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1984                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1985         done
1986
1987         declare -i LOCKUNUSEDCOUNTCURRENT=0
1988         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1989                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1990         done
1991
1992         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1993                 lctl set_param -n ldlm.dump_namespaces ""
1994                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1995                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1996                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1997                 return 2
1998         fi
1999         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
2000                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2001                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2002                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2003                 return 3
2004         fi
2005 }
2006 run_test 29 "IT_GETATTR regression  ============================"
2007
2008 test_30a() { # was test_30
2009         cp `which ls` $DIR || cp /bin/ls $DIR
2010         $DIR/ls / || error
2011         rm $DIR/ls
2012 }
2013 run_test 30a "execute binary from Lustre (execve) =============="
2014
2015 test_30b() {
2016         cp `which ls` $DIR || cp /bin/ls $DIR
2017         chmod go+rx $DIR/ls
2018         $RUNAS $DIR/ls / || error
2019         rm $DIR/ls
2020 }
2021 run_test 30b "execute binary from Lustre as non-root ==========="
2022
2023 test_30c() { # b=22376
2024         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2025         cp `which ls` $DIR || cp /bin/ls $DIR
2026         chmod a-rw $DIR/ls
2027         cancel_lru_locks mdc
2028         cancel_lru_locks osc
2029         $RUNAS $DIR/ls / || error
2030         rm -f $DIR/ls
2031 }
2032 run_test 30c "execute binary from Lustre without read perms ===="
2033
2034 test_31a() {
2035         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2036         $CHECKSTAT -a $DIR/f31 || error
2037 }
2038 run_test 31a "open-unlink file =================================="
2039
2040 test_31b() {
2041         touch $DIR/f31 || error
2042         ln $DIR/f31 $DIR/f31b || error
2043         $MULTIOP $DIR/f31b Ouc || error
2044         $CHECKSTAT -t file $DIR/f31 || error
2045 }
2046 run_test 31b "unlink file with multiple links while open ======="
2047
2048 test_31c() {
2049         touch $DIR/f31 || error
2050         ln $DIR/f31 $DIR/f31c || error
2051         multiop_bg_pause $DIR/f31 O_uc || return 1
2052         MULTIPID=$!
2053         $MULTIOP $DIR/f31c Ouc
2054         kill -USR1 $MULTIPID
2055         wait $MULTIPID
2056 }
2057 run_test 31c "open-unlink file with multiple links ============="
2058
2059 test_31d() {
2060         opendirunlink $DIR/d31d $DIR/d31d || error
2061         $CHECKSTAT -a $DIR/d31d || error
2062 }
2063 run_test 31d "remove of open directory ========================="
2064
2065 test_31e() { # bug 2904
2066         check_kernel_version 34 || return 0
2067         openfilleddirunlink $DIR/d31e || error
2068 }
2069 run_test 31e "remove of open non-empty directory ==============="
2070
2071 test_31f() { # bug 4554
2072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2073         set -vx
2074         test_mkdir $DIR/d31f
2075         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2076         cp /etc/hosts $DIR/d31f
2077         ls -l $DIR/d31f
2078         $GETSTRIPE $DIR/d31f/hosts
2079         multiop_bg_pause $DIR/d31f D_c || return 1
2080         MULTIPID=$!
2081
2082         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2083         test_mkdir $DIR/d31f
2084         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2085         cp /etc/hosts $DIR/d31f
2086         ls -l $DIR/d31f
2087         $GETSTRIPE $DIR/d31f/hosts
2088         multiop_bg_pause $DIR/d31f D_c || return 1
2089         MULTIPID2=$!
2090
2091         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2092         wait $MULTIPID || error "first opendir $MULTIPID failed"
2093
2094         sleep 6
2095
2096         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2097         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2098         set +vx
2099 }
2100 run_test 31f "remove of open directory with open-unlink file ==="
2101
2102 test_31g() {
2103         echo "-- cross directory link --"
2104         test_mkdir -c1 $DIR/${tdir}ga
2105         test_mkdir -c1 $DIR/${tdir}gb
2106         touch $DIR/${tdir}ga/f
2107         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2108         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2109         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2110         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2111         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2112 }
2113 run_test 31g "cross directory link==============="
2114
2115 test_31h() {
2116         echo "-- cross directory link --"
2117         test_mkdir -c1 $DIR/${tdir}
2118         test_mkdir -c1 $DIR/${tdir}/dir
2119         touch $DIR/${tdir}/f
2120         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2121         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2122         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2123         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2124         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2125 }
2126 run_test 31h "cross directory link under child==============="
2127
2128 test_31i() {
2129         echo "-- cross directory link --"
2130         test_mkdir -c1 $DIR/$tdir
2131         test_mkdir -c1 $DIR/$tdir/dir
2132         touch $DIR/$tdir/dir/f
2133         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2134         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2135         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2136         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2137         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2138 }
2139 run_test 31i "cross directory link under parent==============="
2140
2141 test_31j() {
2142         test_mkdir -c1 -p $DIR/$tdir
2143         test_mkdir -c1 -p $DIR/$tdir/dir1
2144         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2145         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2146         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2147         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2148         return 0
2149 }
2150 run_test 31j "link for directory==============="
2151
2152 test_31k() {
2153         test_mkdir -c1 -p $DIR/$tdir
2154         touch $DIR/$tdir/s
2155         touch $DIR/$tdir/exist
2156         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2157         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2158         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2159         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2160         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2161         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2162         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2163         return 0
2164 }
2165 run_test 31k "link to file: the same, non-existing, dir==============="
2166
2167 test_31m() {
2168         mkdir $DIR/d31m
2169         touch $DIR/d31m/s
2170         mkdir $DIR/d31m2
2171         touch $DIR/d31m2/exist
2172         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2173         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2174         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2175         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2176         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2177         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2178         return 0
2179 }
2180 run_test 31m "link to file: the same, non-existing, dir==============="
2181
2182 test_31n() {
2183         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2184         nlink=$(stat --format=%h $DIR/$tfile)
2185         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2186         local fd=$(free_fd)
2187         local cmd="exec $fd<$DIR/$tfile"
2188         eval $cmd
2189         cmd="exec $fd<&-"
2190         trap "eval $cmd" EXIT
2191         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2192         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2193         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2194         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2195         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2196         eval $cmd
2197 }
2198 run_test 31n "check link count of unlinked file"
2199
2200 link_one() {
2201         local TEMPNAME=$(mktemp $1_XXXXXX)
2202         mlink $TEMPNAME $1 2> /dev/null &&
2203                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2204         munlink $TEMPNAME
2205 }
2206
2207 test_31o() { # LU-2901
2208         mkdir -p $DIR/$tdir
2209         for LOOP in $(seq 100); do
2210                 rm -f $DIR/$tdir/$tfile*
2211                 for THREAD in $(seq 8); do
2212                         link_one $DIR/$tdir/$tfile.$LOOP &
2213                 done
2214                 wait
2215                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2216                 [ $LINKS -gt 1 ] && ls $DIR/$tdir &&
2217                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2218                         break || true
2219         done
2220 }
2221 run_test 31o "duplicate hard links with same filename"
2222
2223 cleanup_test32_mount() {
2224         trap 0
2225         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2226 }
2227
2228 test_32a() {
2229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2230         echo "== more mountpoints and symlinks ================="
2231         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2232         trap cleanup_test32_mount EXIT
2233         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2234         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2235         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2236         cleanup_test32_mount
2237 }
2238 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2239
2240 test_32b() {
2241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2242         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2243         trap cleanup_test32_mount EXIT
2244         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2245         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2246         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2247         cleanup_test32_mount
2248 }
2249 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2250
2251 test_32c() {
2252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2253         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2254         trap cleanup_test32_mount EXIT
2255         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2256         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2257         test_mkdir -p $DIR/$tdir/d2/test_dir
2258         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2259         cleanup_test32_mount
2260 }
2261 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2262
2263 test_32d() {
2264         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2265         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2266         trap cleanup_test32_mount EXIT
2267         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2268         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2269         test_mkdir -p $DIR/$tdir/d2/test_dir
2270         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2271         cleanup_test32_mount
2272 }
2273 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2274
2275 test_32e() {
2276         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2277         test_mkdir -p $DIR/d32e/tmp
2278         TMP_DIR=$DIR/d32e/tmp
2279         ln -s $DIR/d32e $TMP_DIR/symlink11
2280         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2281         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2282         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2283 }
2284 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2285
2286 test_32f() {
2287         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2288         test_mkdir -p $DIR/d32f/tmp
2289         TMP_DIR=$DIR/d32f/tmp
2290         ln -s $DIR/d32f $TMP_DIR/symlink11
2291         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2292         ls $DIR/d32f/tmp/symlink11  || error
2293         ls $DIR/d32f/symlink01 || error
2294 }
2295 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2296
2297 test_32g() {
2298         TMP_DIR=$DIR/$tdir/tmp
2299         test_mkdir -p $DIR/$tdir/tmp
2300         test_mkdir $DIR/${tdir}2
2301         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2302         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2303         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2304         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2305         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2306         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2307 }
2308 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2309
2310 test_32h() {
2311         rm -fr $DIR/$tdir $DIR/${tdir}2
2312         TMP_DIR=$DIR/$tdir/tmp
2313         test_mkdir -p $DIR/$tdir/tmp
2314         test_mkdir $DIR/${tdir}2
2315         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2316         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2317         ls $TMP_DIR/symlink12 || error
2318         ls $DIR/$tdir/symlink02  || error
2319 }
2320 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2321
2322 test_32i() {
2323         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2324         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2325         trap cleanup_test32_mount EXIT
2326         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2327         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2328         touch $DIR/$tdir/test_file
2329         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2330         cleanup_test32_mount
2331 }
2332 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2333
2334 test_32j() {
2335         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2336         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2337         trap cleanup_test32_mount EXIT
2338         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2339         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2340         touch $DIR/$tdir/test_file
2341         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2342         cleanup_test32_mount
2343 }
2344 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2345
2346 test_32k() {
2347         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2348         rm -fr $DIR/$tdir
2349         trap cleanup_test32_mount EXIT
2350         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2351         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2352         test_mkdir -p $DIR/$tdir/d2
2353         touch $DIR/$tdir/d2/test_file || error
2354         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2355         cleanup_test32_mount
2356 }
2357 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2358
2359 test_32l() {
2360         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2361         rm -fr $DIR/$tdir
2362         trap cleanup_test32_mount EXIT
2363         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2364         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2365         test_mkdir -p $DIR/$tdir/d2
2366         touch $DIR/$tdir/d2/test_file
2367         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2368         cleanup_test32_mount
2369 }
2370 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2371
2372 test_32m() {
2373         rm -fr $DIR/d32m
2374         test_mkdir -p $DIR/d32m/tmp
2375         TMP_DIR=$DIR/d32m/tmp
2376         ln -s $DIR $TMP_DIR/symlink11
2377         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2378         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2379         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2380 }
2381 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2382
2383 test_32n() {
2384         rm -fr $DIR/d32n
2385         test_mkdir -p $DIR/d32n/tmp
2386         TMP_DIR=$DIR/d32n/tmp
2387         ln -s $DIR $TMP_DIR/symlink11
2388         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2389         ls -l $DIR/d32n/tmp/symlink11  || error
2390         ls -l $DIR/d32n/symlink01 || error
2391 }
2392 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2393
2394 test_32o() {
2395         rm -fr $DIR/d32o $DIR/$tfile
2396         touch $DIR/$tfile
2397         test_mkdir -p $DIR/d32o/tmp
2398         TMP_DIR=$DIR/d32o/tmp
2399         ln -s $DIR/$tfile $TMP_DIR/symlink12
2400         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2401         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2402         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2403         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2404         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2405 }
2406 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2407
2408 test_32p() {
2409     log 32p_1
2410         rm -fr $DIR/d32p
2411     log 32p_2
2412         rm -f $DIR/$tfile
2413     log 32p_3
2414         touch $DIR/$tfile
2415     log 32p_4
2416         test_mkdir -p $DIR/d32p/tmp
2417     log 32p_5
2418         TMP_DIR=$DIR/d32p/tmp
2419     log 32p_6
2420         ln -s $DIR/$tfile $TMP_DIR/symlink12
2421     log 32p_7
2422         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2423     log 32p_8
2424         cat $DIR/d32p/tmp/symlink12 || error
2425     log 32p_9
2426         cat $DIR/d32p/symlink02 || error
2427     log 32p_10
2428 }
2429 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2430
2431 cleanup_testdir_mount() {
2432         trap 0
2433         $UMOUNT -d $DIR/$tdir
2434 }
2435
2436 test_32q() {
2437         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2438         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2439         trap cleanup_testdir_mount EXIT
2440         test_mkdir -p $DIR/$tdir
2441         touch $DIR/$tdir/under_the_mount
2442         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2443         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2444         cleanup_testdir_mount
2445 }
2446 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2447
2448 test_32r() {
2449         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2450         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2451         trap cleanup_testdir_mount EXIT
2452         test_mkdir -p $DIR/$tdir
2453         touch $DIR/$tdir/under_the_mount
2454         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2455         ls $DIR/$tdir | grep -q under_the_mount && error || true
2456         cleanup_testdir_mount
2457 }
2458 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2459
2460 test_33aa() {
2461         rm -f $DIR/$tfile
2462         touch $DIR/$tfile
2463         chmod 444 $DIR/$tfile
2464         chown $RUNAS_ID $DIR/$tfile
2465         log 33_1
2466         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2467         log 33_2
2468 }
2469 run_test 33aa "write file with mode 444 (should return error) ===="
2470
2471 test_33a() {
2472         rm -fr $DIR/d33
2473         test_mkdir -p $DIR/d33
2474         chown $RUNAS_ID $DIR/d33
2475         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2476         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2477                 error "open RDWR" || true
2478 }
2479 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2480
2481 test_33b() {
2482         rm -fr $DIR/d33
2483         test_mkdir -p $DIR/d33
2484         chown $RUNAS_ID $DIR/d33
2485         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
2486 }
2487 run_test 33b "test open file with malformed flags (No panic and return error)"
2488
2489 test_33c() {
2490         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2491         local ostnum
2492         local ostname
2493         local write_bytes
2494         local all_zeros
2495
2496         remote_ost_nodsh && skip "remote OST with nodsh" && return
2497         all_zeros=:
2498         rm -fr $DIR/d33
2499         test_mkdir -p $DIR/d33
2500         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2501
2502         sync
2503         for ostnum in $(seq $OSTCOUNT); do
2504                 # test-framework's OST numbering is one-based, while Lustre's
2505                 # is zero-based
2506                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2507                 # Parsing llobdstat's output sucks; we could grep the /proc
2508                 # path, but that's likely to not be as portable as using the
2509                 # llobdstat utility.  So we parse lctl output instead.
2510                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2511                         obdfilter/$ostname/stats |
2512                         awk '/^write_bytes/ {print $7}' )
2513                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2514                 if (( ${write_bytes:-0} > 0 ))
2515                 then
2516                         all_zeros=false
2517                         break;
2518                 fi
2519         done
2520
2521         $all_zeros || return 0
2522
2523         # Write four bytes
2524         echo foo > $DIR/d33/bar
2525         # Really write them
2526         sync
2527
2528         # Total up write_bytes after writing.  We'd better find non-zeros.
2529         for ostnum in $(seq $OSTCOUNT); do
2530                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2531                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2532                         obdfilter/$ostname/stats |
2533                         awk '/^write_bytes/ {print $7}' )
2534                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2535                 if (( ${write_bytes:-0} > 0 ))
2536                 then
2537                         all_zeros=false
2538                         break;
2539                 fi
2540         done
2541
2542         if $all_zeros
2543         then
2544                 for ostnum in $(seq $OSTCOUNT); do
2545                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2546                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2547                         do_facet ost$ostnum lctl get_param -n \
2548                                 obdfilter/$ostname/stats
2549                 done
2550                 error "OST not keeping write_bytes stats (b22312)"
2551         fi
2552 }
2553 run_test 33c "test llobdstat and write_bytes"
2554
2555 test_33d() {
2556         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2558         local MDTIDX=1
2559         local remote_dir=$DIR/$tdir/remote_dir
2560
2561         mkdir -p $DIR/$tdir
2562         $LFS mkdir -i $MDTIDX $remote_dir ||
2563                 error "create remote directory failed"
2564
2565         touch $remote_dir/$tfile
2566         chmod 444 $remote_dir/$tfile
2567         chown $RUNAS_ID $remote_dir/$tfile
2568
2569         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2570
2571         chown $RUNAS_ID $remote_dir
2572         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2573                                         error "create" || true
2574         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2575                                     error "open RDWR" || true
2576         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2577                                     error "create" || true
2578 }
2579 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2580
2581 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2582 test_34a() {
2583         rm -f $DIR/f34
2584         $MCREATE $DIR/f34 || error
2585         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2586         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2587         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2588         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2589 }
2590 run_test 34a "truncate file that has not been opened ==========="
2591
2592 test_34b() {
2593         [ ! -f $DIR/f34 ] && test_34a
2594         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2595         $OPENFILE -f O_RDONLY $DIR/f34
2596         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2597         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2598 }
2599 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2600
2601 test_34c() {
2602         [ ! -f $DIR/f34 ] && test_34a
2603         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2604         $OPENFILE -f O_RDWR $DIR/f34
2605         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2606         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2607 }
2608 run_test 34c "O_RDWR opening file-with-size works =============="
2609
2610 test_34d() {
2611         [ ! -f $DIR/f34 ] && test_34a
2612         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2613         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2614         rm $DIR/f34
2615 }
2616 run_test 34d "write to sparse file ============================="
2617
2618 test_34e() {
2619         rm -f $DIR/f34e
2620         $MCREATE $DIR/f34e || error
2621         $TRUNCATE $DIR/f34e 1000 || error
2622         $CHECKSTAT -s 1000 $DIR/f34e || error
2623         $OPENFILE -f O_RDWR $DIR/f34e
2624         $CHECKSTAT -s 1000 $DIR/f34e || error
2625 }
2626 run_test 34e "create objects, some with size and some without =="
2627
2628 test_34f() { # bug 6242, 6243
2629         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2630         SIZE34F=48000
2631         rm -f $DIR/f34f
2632         $MCREATE $DIR/f34f || error
2633         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2634         dd if=$DIR/f34f of=$TMP/f34f
2635         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2636         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2637         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2638         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2639         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2640 }
2641 run_test 34f "read from a file with no objects until EOF ======="
2642
2643 test_34g() {
2644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2645         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2646         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2647         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2648         cancel_lru_locks osc
2649         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2650                 error "wrong size after lock cancel"
2651
2652         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2653         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2654                 error "expanding truncate failed"
2655         cancel_lru_locks osc
2656         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2657                 error "wrong expanded size after lock cancel"
2658 }
2659 run_test 34g "truncate long file ==============================="
2660
2661 test_34h() {
2662         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2663         local gid=10
2664         local sz=1000
2665
2666         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2667         sync # Flush the cache so that multiop below does not block on cache
2668              # flush when getting the group lock
2669         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2670         MULTIPID=$!
2671
2672         # Since just timed wait is not good enough, let's do a sync write
2673         # that way we are sure enough time for a roundtrip + processing
2674         # passed + 2 seconds of extra margin.
2675         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2676         rm $DIR/${tfile}-1
2677         sleep 2
2678
2679         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2680                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2681                 kill -9 $MULTIPID
2682         fi
2683         wait $MULTIPID
2684         local nsz=`stat -c %s $DIR/$tfile`
2685         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2686 }
2687 run_test 34h "ftruncate file under grouplock should not block"
2688
2689 test_35a() {
2690         cp /bin/sh $DIR/f35a
2691         chmod 444 $DIR/f35a
2692         chown $RUNAS_ID $DIR/f35a
2693         $RUNAS $DIR/f35a && error || true
2694         rm $DIR/f35a
2695 }
2696 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2697
2698 test_36a() {
2699         rm -f $DIR/f36
2700         utime $DIR/f36 || error
2701 }
2702 run_test 36a "MDS utime check (mknod, utime) ==================="
2703
2704 test_36b() {
2705         echo "" > $DIR/f36
2706         utime $DIR/f36 || error
2707 }
2708 run_test 36b "OST utime check (open, utime) ===================="
2709
2710 test_36c() {
2711         rm -f $DIR/d36/f36
2712         test_mkdir $DIR/d36
2713         chown $RUNAS_ID $DIR/d36
2714         $RUNAS utime $DIR/d36/f36 || error
2715 }
2716 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2717
2718 test_36d() {
2719         [ ! -d $DIR/d36 ] && test_36c
2720         echo "" > $DIR/d36/f36
2721         $RUNAS utime $DIR/d36/f36 || error
2722 }
2723 run_test 36d "non-root OST utime check (open, utime) ==========="
2724
2725 test_36e() {
2726         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2727         test_mkdir -p $DIR/$tdir
2728         touch $DIR/$tdir/$tfile
2729         $RUNAS utime $DIR/$tdir/$tfile && \
2730                 error "utime worked, expected failure" || true
2731 }
2732 run_test 36e "utime on non-owned file (should return error) ===="
2733
2734 subr_36fh() {
2735         local fl="$1"
2736         local LANG_SAVE=$LANG
2737         local LC_LANG_SAVE=$LC_LANG
2738         export LANG=C LC_LANG=C # for date language
2739
2740         DATESTR="Dec 20  2000"
2741         test_mkdir -p $DIR/$tdir
2742         lctl set_param fail_loc=$fl
2743         date; date +%s
2744         cp /etc/hosts $DIR/$tdir/$tfile
2745         sync & # write RPC generated with "current" inode timestamp, but delayed
2746         sleep 1
2747         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2748         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2749         cancel_lru_locks osc
2750         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2751         date; date +%s
2752         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2753                 echo "BEFORE: $LS_BEFORE" && \
2754                 echo "AFTER : $LS_AFTER" && \
2755                 echo "WANT  : $DATESTR" && \
2756                 error "$DIR/$tdir/$tfile timestamps changed" || true
2757
2758         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2759 }
2760
2761 test_36f() {
2762         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2763         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2764         subr_36fh "0x80000214"
2765 }
2766 run_test 36f "utime on file racing with OST BRW write =========="
2767
2768 test_36g() {
2769         remote_ost_nodsh && skip "remote OST with nodsh" && return
2770         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2771         local fmd_max_age
2772         local fmd_before
2773         local fmd_after
2774
2775         test_mkdir -p $DIR/$tdir
2776         fmd_max_age=$(do_facet ost1 \
2777                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2778                 head -n 1")
2779
2780         fmd_before=$(do_facet ost1 \
2781                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2782         touch $DIR/$tdir/$tfile
2783         sleep $((fmd_max_age + 12))
2784         fmd_after=$(do_facet ost1 \
2785                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2786
2787         echo "fmd_before: $fmd_before"
2788         echo "fmd_after: $fmd_after"
2789         [ "$fmd_after" -gt "$fmd_before" ] && \
2790                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" && \
2791                 error "fmd didn't expire after ping" || true
2792 }
2793 run_test 36g "filter mod data cache expiry ====================="
2794
2795 test_36h() {
2796         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2797         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2798         subr_36fh "0x80000227"
2799 }
2800 run_test 36h "utime on file racing with OST BRW write =========="
2801
2802 # test_37 - duplicate with tests 32q 32r
2803
2804 test_38() {
2805         local file=$DIR/$tfile
2806         touch $file
2807         openfile -f O_DIRECTORY $file
2808         local RC=$?
2809         local ENOTDIR=20
2810         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2811         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2812 }
2813 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2814
2815 test_39() {
2816         touch $DIR/$tfile
2817         touch $DIR/${tfile}2
2818 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2819 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2820 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2821         sleep 2
2822         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2823         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2824                 echo "mtime"
2825                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2826                 echo "atime"
2827                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2828                 echo "ctime"
2829                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2830                 error "O_TRUNC didn't change timestamps"
2831         fi
2832 }
2833 run_test 39 "mtime changed on create ==========================="
2834
2835 test_39b() {
2836         test_mkdir -p $DIR/$tdir
2837         cp -p /etc/passwd $DIR/$tdir/fopen
2838         cp -p /etc/passwd $DIR/$tdir/flink
2839         cp -p /etc/passwd $DIR/$tdir/funlink
2840         cp -p /etc/passwd $DIR/$tdir/frename
2841         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2842
2843         sleep 1
2844         echo "aaaaaa" >> $DIR/$tdir/fopen
2845         echo "aaaaaa" >> $DIR/$tdir/flink
2846         echo "aaaaaa" >> $DIR/$tdir/funlink
2847         echo "aaaaaa" >> $DIR/$tdir/frename
2848
2849         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2850         local link_new=`stat -c %Y $DIR/$tdir/flink`
2851         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2852         local rename_new=`stat -c %Y $DIR/$tdir/frename`
2853
2854         cat $DIR/$tdir/fopen > /dev/null
2855         ln $DIR/$tdir/flink $DIR/$tdir/flink2
2856         rm -f $DIR/$tdir/funlink2
2857         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
2858
2859         for (( i=0; i < 2; i++ )) ; do
2860                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
2861                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
2862                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
2863                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
2864
2865                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
2866                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
2867                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
2868                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
2869
2870                 cancel_lru_locks osc
2871                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2872         done
2873 }
2874 run_test 39b "mtime change on open, link, unlink, rename  ======"
2875
2876 # this should be set to past
2877 TEST_39_MTIME=`date -d "1 year ago" +%s`
2878
2879 # bug 11063
2880 test_39c() {
2881         touch $DIR1/$tfile
2882         sleep 2
2883         local mtime0=`stat -c %Y $DIR1/$tfile`
2884
2885         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2886         local mtime1=`stat -c %Y $DIR1/$tfile`
2887         [ "$mtime1" = $TEST_39_MTIME ] || \
2888                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
2889
2890         local d1=`date +%s`
2891         echo hello >> $DIR1/$tfile
2892         local d2=`date +%s`
2893         local mtime2=`stat -c %Y $DIR1/$tfile`
2894         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
2895                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
2896
2897         mv $DIR1/$tfile $DIR1/$tfile-1
2898
2899         for (( i=0; i < 2; i++ )) ; do
2900                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
2901                 [ "$mtime2" = "$mtime3" ] || \
2902                         error "mtime ($mtime2) changed (to $mtime3) on rename"
2903
2904                 cancel_lru_locks osc
2905                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2906         done
2907 }
2908 run_test 39c "mtime change on rename ==========================="
2909
2910 # bug 21114
2911 test_39d() {
2912         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2913         touch $DIR1/$tfile
2914
2915         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2916
2917         for (( i=0; i < 2; i++ )) ; do
2918                 local mtime=`stat -c %Y $DIR1/$tfile`
2919                 [ $mtime = $TEST_39_MTIME ] || \
2920                         error "mtime($mtime) is not set to $TEST_39_MTIME"
2921
2922                 cancel_lru_locks osc
2923                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2924         done
2925 }
2926 run_test 39d "create, utime, stat =============================="
2927
2928 # bug 21114
2929 test_39e() {
2930         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2931         touch $DIR1/$tfile
2932         local mtime1=`stat -c %Y $DIR1/$tfile`
2933
2934         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2935
2936         for (( i=0; i < 2; i++ )) ; do
2937                 local mtime2=`stat -c %Y $DIR1/$tfile`
2938                 [ $mtime2 = $TEST_39_MTIME ] || \
2939                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2940
2941                 cancel_lru_locks osc
2942                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2943         done
2944 }
2945 run_test 39e "create, stat, utime, stat ========================"
2946
2947 # bug 21114
2948 test_39f() {
2949         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2950         touch $DIR1/$tfile
2951         mtime1=`stat -c %Y $DIR1/$tfile`
2952
2953         sleep 2
2954         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2955
2956         for (( i=0; i < 2; i++ )) ; do
2957                 local mtime2=`stat -c %Y $DIR1/$tfile`
2958                 [ $mtime2 = $TEST_39_MTIME ] || \
2959                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2960
2961                 cancel_lru_locks osc
2962                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2963         done
2964 }
2965 run_test 39f "create, stat, sleep, utime, stat ================="
2966
2967 # bug 11063
2968 test_39g() {
2969         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2970         echo hello >> $DIR1/$tfile
2971         local mtime1=`stat -c %Y $DIR1/$tfile`
2972
2973         sleep 2
2974         chmod o+r $DIR1/$tfile
2975
2976         for (( i=0; i < 2; i++ )) ; do
2977                 local mtime2=`stat -c %Y $DIR1/$tfile`
2978                 [ "$mtime1" = "$mtime2" ] || \
2979                         error "lost mtime: $mtime2, should be $mtime1"
2980
2981                 cancel_lru_locks osc
2982                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2983         done
2984 }
2985 run_test 39g "write, chmod, stat ==============================="
2986
2987 # bug 11063
2988 test_39h() {
2989         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2990         touch $DIR1/$tfile
2991         sleep 1
2992
2993         local d1=`date`
2994         echo hello >> $DIR1/$tfile
2995         local mtime1=`stat -c %Y $DIR1/$tfile`
2996
2997         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2998         local d2=`date`
2999         if [ "$d1" != "$d2" ]; then
3000                 echo "write and touch not within one second"
3001         else
3002                 for (( i=0; i < 2; i++ )) ; do
3003                         local mtime2=`stat -c %Y $DIR1/$tfile`
3004                         [ "$mtime2" = $TEST_39_MTIME ] || \
3005                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3006
3007                         cancel_lru_locks osc
3008                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3009                 done
3010         fi
3011 }
3012 run_test 39h "write, utime within one second, stat ============="
3013
3014 test_39i() {
3015         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3016         touch $DIR1/$tfile
3017         sleep 1
3018
3019         echo hello >> $DIR1/$tfile
3020         local mtime1=`stat -c %Y $DIR1/$tfile`
3021
3022         mv $DIR1/$tfile $DIR1/$tfile-1
3023
3024         for (( i=0; i < 2; i++ )) ; do
3025                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3026
3027                 [ "$mtime1" = "$mtime2" ] || \
3028                         error "lost mtime: $mtime2, should be $mtime1"
3029
3030                 cancel_lru_locks osc
3031                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3032         done
3033 }
3034 run_test 39i "write, rename, stat =============================="
3035
3036 test_39j() {
3037         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3038         start_full_debug_logging
3039         touch $DIR1/$tfile
3040         sleep 1
3041
3042         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3043         lctl set_param fail_loc=0x80000412
3044         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3045                 error "multiop failed"
3046         local multipid=$!
3047         local mtime1=`stat -c %Y $DIR1/$tfile`
3048
3049         mv $DIR1/$tfile $DIR1/$tfile-1
3050
3051         kill -USR1 $multipid
3052         wait $multipid || error "multiop close failed"
3053
3054         for (( i=0; i < 2; i++ )) ; do
3055                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3056                 [ "$mtime1" = "$mtime2" ] ||
3057                         error "mtime is lost on close: $mtime2, " \
3058                               "should be $mtime1"
3059
3060                 cancel_lru_locks osc
3061                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3062         done
3063         lctl set_param fail_loc=0
3064         stop_full_debug_logging
3065 }
3066 run_test 39j "write, rename, close, stat ======================="
3067
3068 test_39k() {
3069         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3070         touch $DIR1/$tfile
3071         sleep 1
3072
3073         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3074         local multipid=$!
3075         local mtime1=`stat -c %Y $DIR1/$tfile`
3076
3077         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3078
3079         kill -USR1 $multipid
3080         wait $multipid || error "multiop close failed"
3081
3082         for (( i=0; i < 2; i++ )) ; do
3083                 local mtime2=`stat -c %Y $DIR1/$tfile`
3084
3085                 [ "$mtime2" = $TEST_39_MTIME ] || \
3086                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3087
3088                 cancel_lru_locks osc
3089                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3090         done
3091 }
3092 run_test 39k "write, utime, close, stat ========================"
3093
3094 # this should be set to future
3095 TEST_39_ATIME=`date -d "1 year" +%s`
3096
3097 test_39l() {
3098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3099         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3100         local atime_diff=$(do_facet $SINGLEMDS \
3101                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3102         rm -rf $DIR/$tdir
3103         mkdir -p $DIR/$tdir
3104
3105         # test setting directory atime to future
3106         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3107         local atime=$(stat -c %X $DIR/$tdir)
3108         [ "$atime" = $TEST_39_ATIME ] || \
3109                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3110
3111         # test setting directory atime from future to now
3112         local d1=$(date +%s)
3113         ls $DIR/$tdir
3114         local d2=$(date +%s)
3115
3116         cancel_lru_locks mdc
3117         atime=$(stat -c %X $DIR/$tdir)
3118         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3119                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3120
3121         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3122         sleep 3
3123
3124         # test setting directory atime when now > dir atime + atime_diff
3125         d1=$(date +%s)
3126         ls $DIR/$tdir
3127         d2=$(date +%s)
3128         cancel_lru_locks mdc
3129         atime=$(stat -c %X $DIR/$tdir)
3130         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3131                 error "atime is not updated  : $atime, should be $d2"
3132
3133         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3134         sleep 3
3135
3136         # test not setting directory atime when now < dir atime + atime_diff
3137         ls $DIR/$tdir
3138         cancel_lru_locks mdc
3139         atime=$(stat -c %X $DIR/$tdir)
3140         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3141                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3142
3143         do_facet $SINGLEMDS \
3144                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3145 }
3146 run_test 39l "directory atime update ==========================="
3147
3148 test_39m() {
3149         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3150         touch $DIR1/$tfile
3151         sleep 2
3152         local far_past_mtime=$(date -d "May 29 1953" +%s)
3153         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3154
3155         touch -m -d @$far_past_mtime $DIR1/$tfile
3156         touch -a -d @$far_past_atime $DIR1/$tfile
3157
3158         for (( i=0; i < 2; i++ )) ; do
3159                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3160                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3161                         error "atime or mtime set incorrectly"
3162
3163                 cancel_lru_locks osc
3164                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3165         done
3166 }
3167 run_test 39m "test atime and mtime before 1970"
3168
3169 test_39n() { # LU-3832
3170         local atime_diff=$(do_facet $SINGLEMDS \
3171                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3172         local atime0
3173         local atime1
3174         local atime2
3175
3176         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3177
3178         rm -rf $DIR/$tfile
3179         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3180         atime0=$(stat -c %X $DIR/$tfile)
3181
3182         sleep 5
3183         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3184         atime1=$(stat -c %X $DIR/$tfile)
3185
3186         sleep 5
3187         cancel_lru_locks mdc
3188         cancel_lru_locks osc
3189         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3190         atime2=$(stat -c %X $DIR/$tfile)
3191
3192         do_facet $SINGLEMDS \
3193                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3194
3195         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3196         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3197 }
3198 run_test 39n "check that O_NOATIME is honored"
3199
3200 test_39o() {
3201         TESTDIR=$DIR/$tdir/$tfile
3202         [ -e $TESTDIR ] && rm -rf $TESTDIR
3203         test_mkdir -p $TESTDIR
3204         cd $TESTDIR
3205         links1=2
3206         ls
3207         mkdir a b
3208         ls
3209         links2=$(stat -c %h .)
3210         [ $(($links1 + 2)) != $links2 ] &&
3211                 error "wrong links count $(($links1 + 2)) != $links2"
3212         rmdir b
3213         links3=$(stat -c %h .)
3214         [ $(($links1 + 1)) != $links3 ] &&
3215                 error "wrong links count $links1 != $links3"
3216         return 0
3217 }
3218 run_test 39o "directory cached attributes updated after create ========"
3219
3220 test_39p() {
3221         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3222         local MDTIDX=1
3223         TESTDIR=$DIR/$tdir/$tfile
3224         [ -e $TESTDIR ] && rm -rf $TESTDIR
3225         mkdir -p $TESTDIR
3226         cd $TESTDIR
3227         links1=2
3228         ls
3229         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3230         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3231         ls
3232         links2=$(stat -c %h .)
3233         [ $(($links1 + 2)) != $links2 ] &&
3234                 error "wrong links count $(($links1 + 2)) != $links2"
3235         rmdir remote_dir2
3236         links3=$(stat -c %h .)
3237         [ $(($links1 + 1)) != $links3 ] &&
3238                 error "wrong links count $links1 != $links3"
3239         return 0
3240 }
3241 run_test 39p "remote directory cached attributes updated after create ========"
3242
3243
3244 test_40() {
3245         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3246         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3247                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3248         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3249                 error "$tfile is not 4096 bytes in size"
3250 }
3251 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3252
3253 test_41() {
3254         # bug 1553
3255         small_write $DIR/f41 18
3256 }
3257 run_test 41 "test small file write + fstat ====================="
3258
3259 count_ost_writes() {
3260         lctl get_param -n osc.*.stats |
3261             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
3262 }
3263
3264 # decent default
3265 WRITEBACK_SAVE=500
3266 DIRTY_RATIO_SAVE=40
3267 MAX_DIRTY_RATIO=50
3268 BG_DIRTY_RATIO_SAVE=10
3269 MAX_BG_DIRTY_RATIO=25
3270
3271 start_writeback() {
3272         trap 0
3273         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3274         # dirty_ratio, dirty_background_ratio
3275         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3276                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3277                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3278                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3279         else
3280                 # if file not here, we are a 2.4 kernel
3281                 kill -CONT `pidof kupdated`
3282         fi
3283 }
3284
3285 stop_writeback() {
3286         # setup the trap first, so someone cannot exit the test at the
3287         # exact wrong time and mess up a machine
3288         trap start_writeback EXIT
3289         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3290         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3291                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3292                 sysctl -w vm.dirty_writeback_centisecs=0
3293                 sysctl -w vm.dirty_writeback_centisecs=0
3294                 # save and increase /proc/sys/vm/dirty_ratio
3295                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3296                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3297                 # save and increase /proc/sys/vm/dirty_background_ratio
3298                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3299                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3300         else
3301                 # if file not here, we are a 2.4 kernel
3302                 kill -STOP `pidof kupdated`
3303         fi
3304 }
3305
3306 # ensure that all stripes have some grant before we test client-side cache
3307 setup_test42() {
3308         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3309                 dd if=/dev/zero of=$i bs=4k count=1
3310                 rm $i
3311         done
3312 }
3313
3314 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3315 # file truncation, and file removal.
3316 test_42a() {
3317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3318         setup_test42
3319         cancel_lru_locks osc
3320         stop_writeback
3321         sync; sleep 1; sync # just to be safe
3322         BEFOREWRITES=`count_ost_writes`
3323         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3324         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3325         AFTERWRITES=`count_ost_writes`
3326         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3327                 error "$BEFOREWRITES < $AFTERWRITES"
3328         start_writeback
3329 }
3330 run_test 42a "ensure that we don't flush on close =============="
3331
3332 test_42b() {
3333         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3334         setup_test42
3335         cancel_lru_locks osc
3336         stop_writeback
3337         sync
3338         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3339         BEFOREWRITES=`count_ost_writes`
3340         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3341         AFTERWRITES=`count_ost_writes`
3342         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3343                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3344         fi
3345         BEFOREWRITES=`count_ost_writes`
3346         sync || error "sync: $?"
3347         AFTERWRITES=`count_ost_writes`
3348         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3349                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3350         fi
3351         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3352         start_writeback
3353         return 0
3354 }
3355 run_test 42b "test destroy of file with cached dirty data ======"
3356
3357 # if these tests just want to test the effect of truncation,
3358 # they have to be very careful.  consider:
3359 # - the first open gets a {0,EOF}PR lock
3360 # - the first write conflicts and gets a {0, count-1}PW
3361 # - the rest of the writes are under {count,EOF}PW
3362 # - the open for truncate tries to match a {0,EOF}PR
3363 #   for the filesize and cancels the PWs.
3364 # any number of fixes (don't get {0,EOF} on open, match
3365 # composite locks, do smarter file size management) fix
3366 # this, but for now we want these tests to verify that
3367 # the cancellation with truncate intent works, so we
3368 # start the file with a full-file pw lock to match against
3369 # until the truncate.
3370 trunc_test() {
3371         test=$1
3372         file=$DIR/$test
3373         offset=$2
3374         cancel_lru_locks osc
3375         stop_writeback
3376         # prime the file with 0,EOF PW to match
3377         touch $file
3378         $TRUNCATE $file 0
3379         sync; sync
3380         # now the real test..
3381         dd if=/dev/zero of=$file bs=1024 count=100
3382         BEFOREWRITES=`count_ost_writes`
3383         $TRUNCATE $file $offset
3384         cancel_lru_locks osc
3385         AFTERWRITES=`count_ost_writes`
3386         start_writeback
3387 }
3388
3389 test_42c() {
3390         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3391         trunc_test 42c 1024
3392         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3393             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3394         rm $file
3395 }
3396 run_test 42c "test partial truncate of file with cached dirty data"
3397
3398 test_42d() {
3399         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3400         trunc_test 42d 0
3401         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3402             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3403         rm $file
3404 }
3405 run_test 42d "test complete truncate of file with cached dirty data"
3406
3407 test_42e() { # bug22074
3408         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3409         local TDIR=$DIR/${tdir}e
3410         local pagesz=$(page_size)
3411         local pages=16 # hardcoded 16 pages, don't change it.
3412         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3413         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3414         local max_dirty_mb
3415         local warmup_files
3416
3417         test_mkdir -p $DIR/${tdir}e
3418         $SETSTRIPE -c 1 $TDIR
3419         createmany -o $TDIR/f $files
3420
3421         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3422
3423         # we assume that with $OSTCOUNT files, at least one of them will
3424         # be allocated on OST0.
3425         warmup_files=$((OSTCOUNT * max_dirty_mb))
3426         createmany -o $TDIR/w $warmup_files
3427
3428         # write a large amount of data into one file and sync, to get good
3429         # avail_grant number from OST.
3430         for ((i=0; i<$warmup_files; i++)); do
3431                 idx=$($GETSTRIPE -i $TDIR/w$i)
3432                 [ $idx -ne 0 ] && continue
3433                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3434                 break
3435         done
3436         [ $i -gt $warmup_files ] && error "OST0 is still cold"
3437         sync
3438         $LCTL get_param $proc_osc0/cur_dirty_bytes
3439         $LCTL get_param $proc_osc0/cur_grant_bytes
3440
3441         # create as much dirty pages as we can while not to trigger the actual
3442         # RPCs directly. but depends on the env, VFS may trigger flush during this
3443         # period, hopefully we are good.
3444         for ((i=0; i<$warmup_files; i++)); do
3445                 idx=$($GETSTRIPE -i $TDIR/w$i)
3446                 [ $idx -ne 0 ] && continue
3447                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3448         done
3449         $LCTL get_param $proc_osc0/cur_dirty_bytes
3450         $LCTL get_param $proc_osc0/cur_grant_bytes
3451
3452         # perform the real test
3453         $LCTL set_param $proc_osc0/rpc_stats 0
3454         for ((;i<$files; i++)); do
3455                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3456                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3457         done
3458         sync
3459         $LCTL get_param $proc_osc0/rpc_stats
3460
3461         local percent=0
3462         local have_ppr=false
3463         $LCTL get_param $proc_osc0/rpc_stats |
3464                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3465                         # skip lines until we are at the RPC histogram data
3466                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3467                         $have_ppr || continue
3468
3469                         # we only want the percent stat for < 16 pages
3470                         [ $(echo $PPR | tr -d ':') -ge $pages ] && break
3471
3472                         percent=$((percent + WPCT))
3473                         if [ $percent -gt 15 ]; then
3474                                 error "less than 16-pages write RPCs" \
3475                                       "$percent% > 15%"
3476                                 break
3477                         fi
3478                 done
3479         rm -rf $TDIR
3480 }
3481 run_test 42e "verify sub-RPC writes are not done synchronously"
3482
3483 test_43() {
3484         test_mkdir -p $DIR/$tdir
3485         cp -p /bin/ls $DIR/$tdir/$tfile
3486         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3487         pid=$!
3488         # give multiop a chance to open
3489         sleep 1
3490
3491         $DIR/$tdir/$tfile && error || true
3492         kill -USR1 $pid
3493 }
3494 run_test 43 "execution of file opened for write should return -ETXTBSY"
3495
3496 test_43a() {
3497         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3498         test_mkdir -p $DIR/$tdir
3499         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3500                         cp -p multiop $DIR/$tdir/multiop
3501         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3502                         return 1
3503         MULTIOP_PID=$!
3504         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3505         kill -USR1 $MULTIOP_PID || return 2
3506         wait $MULTIOP_PID || return 3
3507         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3508 }
3509 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3510
3511 test_43b() {
3512         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3513         test_mkdir -p $DIR/$tdir
3514         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3515                         cp -p multiop $DIR/$tdir/multiop
3516         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3517                         return 1
3518         MULTIOP_PID=$!
3519         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3520         kill -USR1 $MULTIOP_PID || return 2
3521         wait $MULTIOP_PID || return 3
3522         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3523 }
3524 run_test 43b "truncate of file being executed should return -ETXTBSY"
3525
3526 test_43c() {
3527         local testdir="$DIR/$tdir"
3528         test_mkdir -p $DIR/$tdir
3529         cp $SHELL $testdir/
3530         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3531                 ( cd $testdir && md5sum -c)
3532 }
3533 run_test 43c "md5sum of copy into lustre========================"
3534
3535 test_44() {
3536         [  "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
3537         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3538         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3539 }
3540 run_test 44 "zero length read from a sparse stripe ============="
3541
3542 test_44a() {
3543     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
3544                          awk '{print $2}'`
3545     [ -z "$nstripe" ] && skip "can't get stripe info" && return
3546     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
3547     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
3548                       awk '{print $2}'`
3549     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
3550         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
3551     fi
3552
3553     OFFSETS="0 $((stride/2)) $((stride-1))"
3554     for offset in $OFFSETS ; do
3555       for i in `seq 0 $((nstripe-1))`; do
3556         local GLOBALOFFSETS=""
3557         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
3558         local myfn=$DIR/d44a-$size
3559         echo "--------writing $myfn at $size"
3560         ll_sparseness_write $myfn $size  || error "ll_sparseness_write"
3561         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3562         ll_sparseness_verify $myfn $GLOBALOFFSETS \
3563                             || error "ll_sparseness_verify $GLOBALOFFSETS"
3564
3565         for j in `seq 0 $((nstripe-1))`; do
3566             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
3567             ll_sparseness_write $myfn $size || error "ll_sparseness_write"
3568             GLOBALOFFSETS="$GLOBALOFFSETS $size"
3569         done
3570         ll_sparseness_verify $myfn $GLOBALOFFSETS \
3571                             || error "ll_sparseness_verify $GLOBALOFFSETS"
3572         rm -f $myfn
3573       done
3574     done
3575 }
3576 run_test 44a "test sparse pwrite ==============================="
3577
3578 dirty_osc_total() {
3579         tot=0
3580         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3581                 tot=$(($tot + $d))
3582         done
3583         echo $tot
3584 }
3585 do_dirty_record() {
3586         before=`dirty_osc_total`
3587         echo executing "\"$*\""
3588         eval $*
3589         after=`dirty_osc_total`
3590         echo before $before, after $after
3591 }
3592 test_45() {
3593         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3594         f="$DIR/f45"
3595         # Obtain grants from OST if it supports it
3596         echo blah > ${f}_grant
3597         stop_writeback
3598         sync
3599         do_dirty_record "echo blah > $f"
3600         [ $before -eq $after ] && error "write wasn't cached"
3601         do_dirty_record "> $f"
3602         [ $before -gt $after ] || error "truncate didn't lower dirty count"
3603         do_dirty_record "echo blah > $f"
3604         [ $before -eq $after ] && error "write wasn't cached"
3605         do_dirty_record "sync"
3606         [ $before -gt $after ] || error "writeback didn't lower dirty count"
3607         do_dirty_record "echo blah > $f"
3608         [ $before -eq $after ] && error "write wasn't cached"
3609         do_dirty_record "cancel_lru_locks osc"
3610         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
3611         start_writeback
3612 }
3613 run_test 45 "osc io page accounting ============================"
3614
3615 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3616 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3617 # objects offset and an assert hit when an rpc was built with 1023's mapped
3618 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3619 test_46() {
3620         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3621         f="$DIR/f46"
3622         stop_writeback
3623         sync
3624         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3625         sync
3626         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3627         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3628         sync
3629         start_writeback
3630 }
3631 run_test 46 "dirtying a previously written page ================"
3632
3633 # test_47 is removed "Device nodes check" is moved to test_28
3634
3635 test_48a() { # bug 2399
3636         check_kernel_version 34 || return 0
3637         test_mkdir -p $DIR/$tdir
3638         cd $DIR/$tdir
3639         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3640         test_mkdir $DIR/$tdir || error "recreate directory failed"
3641         touch foo || error "'touch foo' failed after recreating cwd"
3642         test_mkdir $DIR/$tdir/bar ||
3643                      error "'mkdir foo' failed after recreating cwd"
3644         if check_kernel_version 44; then
3645                 touch .foo || error "'touch .foo' failed after recreating cwd"
3646                 test_mkdir $DIR/$tdir/.bar ||
3647                               error "'mkdir .foo' failed after recreating cwd"
3648         fi
3649         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3650         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3651         cd . || error "'cd .' failed after recreating cwd"
3652         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3653         rmdir . && error "'rmdir .' worked after recreating cwd"
3654         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3655         cd .. || error "'cd ..' failed after recreating cwd"
3656 }
3657 run_test 48a "Access renamed working dir (should return errors)="
3658
3659 test_48b() { # bug 2399
3660         check_kernel_version 34 || return 0
3661         rm -rf $DIR/$tdir
3662         test_mkdir -p $DIR/$tdir
3663         cd $DIR/$tdir
3664         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3665         touch foo && error "'touch foo' worked after removing cwd"
3666         test_mkdir $DIR/$tdir/foo &&
3667                      error "'mkdir foo' worked after removing cwd"
3668         if check_kernel_version 44; then
3669                 touch .foo && error "'touch .foo' worked after removing cwd"
3670                 test_mkdir $DIR/$tdir/.foo &&
3671                               error "'mkdir .foo' worked after removing cwd"
3672         fi
3673         ls . > /dev/null && error "'ls .' worked after removing cwd"
3674         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3675         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3676         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3677         rmdir . && error "'rmdir .' worked after removing cwd"
3678         ln -s . foo && error "'ln -s .' worked after removing cwd"
3679         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3680 }
3681 run_test 48b "Access removed working dir (should return errors)="
3682
3683 test_48c() { # bug 2350
3684         check_kernel_version 36 || return 0
3685         #lctl set_param debug=-1
3686         #set -vx
3687         rm -rf $DIR/$tdir
3688         test_mkdir -p $DIR/$tdir/dir
3689         cd $DIR/$tdir/dir
3690         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3691         $TRACE touch foo && error "touch foo worked after removing cwd"
3692         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3693         if check_kernel_version 44; then
3694                 touch .foo && error "touch .foo worked after removing cwd"
3695                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3696         fi
3697         $TRACE ls . && error "'ls .' worked after removing cwd"
3698         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3699         is_patchless || ( $TRACE cd . &&
3700                         error "'cd .' worked after removing cwd" )
3701         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3702         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3703         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3704         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3705 }
3706 run_test 48c "Access removed working subdir (should return errors)"
3707
3708 test_48d() { # bug 2350
3709         check_kernel_version 36 || return 0
3710         #lctl set_param debug=-1
3711         #set -vx
3712         rm -rf $DIR/$tdir
3713         test_mkdir -p $DIR/$tdir/dir
3714         cd $DIR/$tdir/dir
3715         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3716         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3717         $TRACE touch foo && error "'touch foo' worked after removing parent"
3718         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3719         if check_kernel_version 44; then
3720                 touch .foo && error "'touch .foo' worked after removing parent"
3721                 test_mkdir .foo &&
3722                               error "mkdir .foo worked after removing parent"
3723         fi
3724         $TRACE ls . && error "'ls .' worked after removing parent"
3725         $TRACE ls .. && error "'ls ..' worked after removing parent"
3726         is_patchless || ( $TRACE cd . &&
3727                         error "'cd .' worked after recreate parent" )
3728         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3729         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3730         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3731         is_patchless || ( $TRACE cd .. &&
3732                         error "'cd ..' worked after removing parent" || true )
3733 }
3734 run_test 48d "Access removed parent subdir (should return errors)"
3735
3736 test_48e() { # bug 4134
3737         check_kernel_version 41 || return 0
3738         #lctl set_param debug=-1
3739         #set -vx
3740         rm -rf $DIR/$tdir
3741         test_mkdir -p $DIR/$tdir/dir
3742         cd $DIR/$tdir/dir
3743         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3744         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3745         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3746         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3747         # On a buggy kernel addition of "touch foo" after cd .. will
3748         # produce kernel oops in lookup_hash_it
3749         touch ../foo && error "'cd ..' worked after recreate parent"
3750         cd $DIR
3751         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3752 }
3753 run_test 48e "Access to recreated parent subdir (should return errors)"
3754
3755 test_49() { # LU-1030
3756         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3757         # get ost1 size - lustre-OST0000
3758         ost1_size=$(do_facet ost1 lfs df |grep ${ost1_svc} |awk '{print $4}')
3759         # write 800M at maximum
3760         [ $ost1_size -gt 819200 ] && ost1_size=819200
3761
3762         lfs setstripe -c 1 -i 0 $DIR/$tfile
3763         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3764         local dd_pid=$!
3765
3766         # change max_pages_per_rpc while writing the file
3767         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3768         local orig_mppc=`$LCTL get_param -n $osc1_mppc`
3769         # loop until dd process exits
3770         while ps ax -opid | grep -wq $dd_pid; do
3771                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3772                 sleep $((RANDOM % 5 + 1))
3773         done
3774         # restore original max_pages_per_rpc
3775         $LCTL set_param $osc1_mppc=$orig_mppc
3776         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3777 }
3778 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3779
3780 test_50() {
3781         # bug 1485
3782         test_mkdir $DIR/$tdir
3783         cd $DIR/$tdir
3784         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3785 }
3786 run_test 50 "special situations: /proc symlinks  ==============="
3787
3788 test_51a() {    # was test_51
3789         # bug 1516 - create an empty entry right after ".." then split dir
3790         test_mkdir -p $DIR/$tdir
3791         touch $DIR/$tdir/foo
3792         $MCREATE $DIR/$tdir/bar
3793         rm $DIR/$tdir/foo
3794         createmany -m $DIR/$tdir/longfile 201
3795         FNUM=202
3796         while [ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]; do
3797                 $MCREATE $DIR/$tdir/longfile$FNUM
3798                 FNUM=$(($FNUM + 1))
3799                 echo -n "+"
3800         done
3801         echo
3802         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3803 }
3804 run_test 51a "special situations: split htree with empty entry =="
3805
3806 export NUMTEST=70000
3807 test_51b() {
3808         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3809         local BASE=$DIR/d${base}.${TESTSUITE}
3810
3811         # cleanup the directory
3812         rm -fr $BASE
3813
3814         test_mkdir -p $BASE
3815
3816         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3817         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3818         [ $numfree -lt 21000 ] && skip "not enough free inodes ($numfree)" &&
3819                 return
3820
3821         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3822                 echo "reduced count to $NUMTEST due to inodes"
3823
3824         # need to check free space for the directories as well
3825         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3826         numfree=$((blkfree / 4))
3827         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3828                 echo "reduced count to $NUMTEST due to blocks"
3829
3830         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3831                 echo "failed" > $BASE/fnum
3832 }
3833 run_test 51b "exceed 64k subdirectory nlink limit"
3834
3835 test_51ba() { # LU-993
3836         local BASE=$DIR/d${base}.${TESTSUITE}
3837         # unlink all but 100 subdirectories, then check it still works
3838         local LEFT=100
3839         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3840
3841         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
3842         local DELETE=$((NUMTEST - LEFT))
3843
3844         # continue on to run this test even if 51b didn't finish,
3845         # just to delete the many subdirectories created.
3846         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
3847
3848         # for ldiskfs the nlink count should be 1, but this is OSD specific
3849         # and so this is listed for informational purposes only
3850         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
3851         unlinkmany -d $BASE/d $DELETE
3852         RC=$?
3853
3854         if [ $RC -ne 0 ]; then
3855                 if [ "$NUMPREV" == "failed" ]; then
3856                         skip "previous setup failed"
3857                         return 0
3858                 else
3859                         error "unlink of first $DELETE subdirs failed"
3860                         return $RC
3861                 fi
3862         fi
3863
3864         echo "nlink between: $(stat -c %h $BASE)"
3865         # trim the first line of ls output
3866         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
3867         [ $FOUND -ne $LEFT ] &&
3868                 error "can't find subdirs: found only $FOUND/$LEFT"
3869
3870         unlinkmany -d $BASE/d $DELETE $LEFT ||
3871                 error "unlink of second $LEFT subdirs failed"
3872         # regardless of whether the backing filesystem tracks nlink accurately
3873         # or not, the nlink count shouldn't be more than "." and ".." here
3874         local AFTER=$(stat -c %h $BASE)
3875         [ $AFTER -gt 2 ] && error "nlink after: $AFTER > 2" ||
3876                 echo "nlink after: $AFTER"
3877 }
3878 run_test 51ba "verify nlink for many subdirectory cleanup"
3879
3880 test_51d() {
3881         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3882         [  "$OSTCOUNT" -lt "3" ] && skip_env "skipping test with few OSTs" && return
3883         test_mkdir -p $DIR/$tdir
3884         createmany -o $DIR/$tdir/t- 1000
3885         $GETSTRIPE $DIR/$tdir > $TMP/files
3886         for N in `seq 0 $((OSTCOUNT - 1))`; do
3887             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
3888             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
3889             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
3890         done
3891         unlinkmany $DIR/$tdir/t- 1000
3892
3893         NLAST=0
3894         for N in `seq 1 $((OSTCOUNT - 1))`; do
3895             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
3896                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3897             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
3898                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3899
3900             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
3901                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3902             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
3903                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3904             NLAST=$N
3905         done
3906 }
3907 run_test 51d "check object distribution ===================="
3908
3909 test_52a() {
3910         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
3911         test_mkdir -p $DIR/$tdir
3912         touch $DIR/$tdir/foo
3913         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
3914         echo bar >> $DIR/$tdir/foo || error "append bar failed"
3915         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3916         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3917         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3918                                         error "link worked"
3919         echo foo >> $DIR/$tdir/foo || error "append foo failed"
3920         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3921         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
3922                                                      error "lsattr"
3923         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
3924         cp -r $DIR/$tdir /tmp/
3925         rm -fr $DIR/$tdir || error "cleanup rm failed"
3926 }
3927 run_test 52a "append-only flag test (should return errors) ====="
3928
3929 test_52b() {
3930         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
3931         test_mkdir -p $DIR/$tdir
3932         touch $DIR/$tdir/foo
3933         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
3934         cat test > $DIR/$tdir/foo && error "cat test worked"
3935         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3936         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3937         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3938                                         error "link worked"
3939         echo foo >> $DIR/$tdir/foo && error "echo worked"
3940         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3941         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
3942         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
3943         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
3944                                                         error "lsattr"
3945         chattr -i $DIR/$tdir/foo || error "chattr failed"
3946
3947         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
3948 }
3949 run_test 52b "immutable flag test (should return errors) ======="
3950
3951 test_53() {
3952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3953         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3954         remote_ost_nodsh && skip "remote OST with nodsh" && return
3955
3956         local param
3957         local param_seq
3958         local ostname
3959         local mds_last
3960         local mds_last_seq
3961         local ost_last
3962         local ost_last_seq
3963         local ost_last_id
3964         local ostnum
3965         local node
3966         local found=false
3967         local support_last_seq=true
3968
3969         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
3970                 support_last_seq=false
3971
3972         # only test MDT0000
3973         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
3974         local value
3975         for value in $(do_facet $SINGLEMDS \
3976                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
3977                 param=$(echo ${value[0]} | cut -d "=" -f1)
3978                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
3979
3980                 if $support_last_seq; then
3981                         param_seq=$(echo $param |
3982                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
3983                         mds_last_seq=$(do_facet $SINGLEMDS \
3984                                        $LCTL get_param -n $param_seq)
3985                 fi
3986                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
3987
3988                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
3989                 node=$(facet_active_host ost$((ostnum+1)))
3990                 param="obdfilter.$ostname.last_id"
3991                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
3992                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
3993                         ost_last_id=$ost_last
3994
3995                         if $support_last_seq; then
3996                                 ost_last_id=$(echo $ost_last |
3997                                               awk -F':' '{print $2}' |
3998                                               sed -e "s/^0x//g")
3999                                 ost_last_seq=$(echo $ost_last |
4000                                                awk -F':' '{print $1}')
4001                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4002                         fi
4003
4004                         if [[ $ost_last_id != $mds_last ]]; then
4005                                 error "$ost_last_id != $mds_last"
4006                         else
4007                                 found=true
4008                                 break
4009                         fi
4010                 done
4011         done
4012         $found || error "can not match last_seq/last_id for $mdtosc"
4013         return 0
4014 }
4015 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4016
4017 test_54a() {
4018         $SOCKETSERVER $DIR/socket ||
4019                 error "$SOCKETSERVER $DIR/socket failed: $?"
4020         $SOCKETCLIENT $DIR/socket ||
4021                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4022         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4023 }
4024 run_test 54a "unix domain socket test =========================="
4025
4026 test_54b() {
4027         f="$DIR/f54b"
4028         mknod $f c 1 3
4029         chmod 0666 $f
4030         dd if=/dev/zero of=$f bs=$(page_size) count=1
4031 }
4032 run_test 54b "char device works in lustre ======================"
4033
4034 find_loop_dev() {
4035         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4036         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4037         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4038
4039         for i in $(seq 3 7); do
4040                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4041                 LOOPDEV=$LOOPBASE$i
4042                 LOOPNUM=$i
4043                 break
4044         done
4045 }
4046
4047 cleanup_54c() {
4048         loopdev="$DIR/loop54c"
4049
4050         trap 0
4051         $UMOUNT -d $tdir || rc=$?
4052         losetup -d $loopdev || true
4053         rm $loopdev
4054         return $rc
4055 }
4056
4057 test_54c() {
4058         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4059         tfile="$DIR/f54c"
4060         tdir="$DIR/d54c"
4061         loopdev="$DIR/loop54c"
4062
4063         find_loop_dev
4064         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4065         mknod $loopdev b 7 $LOOPNUM
4066         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
4067         dd if=/dev/zero of=$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4068         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
4069         trap cleanup_54c EXIT
4070         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4071         test_mkdir -p $tdir
4072         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
4073         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
4074         df $tdir
4075         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
4076         cleanup_54c
4077 }
4078 run_test 54c "block device works in lustre ====================="
4079
4080 test_54d() {
4081         f="$DIR/f54d"
4082         string="aaaaaa"
4083         mknod $f p
4084         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4085 }
4086 run_test 54d "fifo device works in lustre ======================"
4087
4088 test_54e() {
4089         check_kernel_version 46 || return 0
4090         f="$DIR/f54e"
4091         string="aaaaaa"
4092         cp -aL /dev/console $f
4093         echo $string > $f || error "echo $string to $f failed"
4094 }
4095 run_test 54e "console/tty device works in lustre ======================"
4096
4097 #The test_55 used to be iopen test and it was removed by bz#24037.
4098 #run_test 55 "check iopen_connect_dentry() ======================"
4099
4100 test_56a() {    # was test_56
4101         rm -rf $DIR/$tdir
4102         $SETSTRIPE -d $DIR
4103         test_mkdir -p $DIR/$tdir/dir
4104         NUMFILES=3
4105         NUMFILESx2=$(($NUMFILES * 2))
4106         for i in `seq 1 $NUMFILES` ; do
4107                 touch $DIR/$tdir/file$i
4108                 touch $DIR/$tdir/dir/file$i
4109         done
4110
4111         # test lfs getstripe with --recursive
4112         FILENUM=`$GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx`
4113         [ $FILENUM -eq $NUMFILESx2 ] ||
4114                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4115         FILENUM=`$GETSTRIPE $DIR/$tdir | grep -c obdidx`
4116         [ $FILENUM -eq $NUMFILES ] ||
4117                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4118         echo "$GETSTRIPE --recursive passed."
4119
4120         # test lfs getstripe with file instead of dir
4121         FILENUM=`$GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx`
4122         [ $FILENUM  -eq 1 ] || error \
4123                  "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4124         echo "$GETSTRIPE file1 passed."
4125
4126         #test lfs getstripe with --verbose
4127         [ `$GETSTRIPE --verbose $DIR/$tdir |
4128                         grep -c lmm_magic` -eq $NUMFILES ] ||
4129                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4130         [ `$GETSTRIPE $DIR/$tdir | grep -c lmm_magic` -eq 0 ] ||
4131             error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4132         echo "$GETSTRIPE --verbose passed."
4133
4134         #test lfs getstripe with --obd
4135         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4136                                         grep -q "unknown obduuid" ||
4137                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4138
4139         [  "$OSTCOUNT" -lt 2 ] &&
4140                 skip_env "skipping other $GETSTRIPE --obd test" && return
4141
4142         OSTIDX=1
4143         OBDUUID=$(ostuuid_from_index $OSTIDX)
4144         FILENUM=`$GETSTRIPE -ir $DIR/$tdir | grep -x $OSTIDX | wc -l`
4145         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l`
4146         [ $FOUND -eq $FILENUM ] ||
4147                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4148         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4149                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4150                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] ||
4151                 error "$GETSTRIPE --obd: should not show file on other obd"
4152         echo "$GETSTRIPE --obd passed"
4153 }
4154 run_test 56a "check $GETSTRIPE"
4155
4156 NUMFILES=3
4157 NUMDIRS=3
4158 setup_56() {
4159         local LOCAL_NUMFILES="$1"
4160         local LOCAL_NUMDIRS="$2"
4161         local MKDIR_PARAMS="$3"
4162         local DIR_STRIPE_PARAMS="$4"
4163
4164         if [ ! -d "$TDIR" ] ; then
4165                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4166                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4167                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4168                         touch $TDIR/file$i
4169                 done
4170                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4171                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4172                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4173                                 touch $TDIR/dir$i/file$j
4174                         done
4175                 done
4176         fi
4177 }
4178
4179 setup_56_special() {
4180         LOCAL_NUMFILES=$1
4181         LOCAL_NUMDIRS=$2
4182         setup_56 $1 $2
4183         if [ ! -e "$TDIR/loop1b" ] ; then
4184                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4185                         mknod $TDIR/loop${i}b b 7 $i
4186                         mknod $TDIR/null${i}c c 1 3
4187                         ln -s $TDIR/file1 $TDIR/link${i}l
4188                 done
4189                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4190                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4191                         mknod $TDIR/dir$i/null${i}c c 1 3
4192                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4193                 done
4194         fi
4195 }
4196
4197 test_56g() {
4198         $SETSTRIPE -d $DIR
4199
4200         TDIR=$DIR/${tdir}g
4201         setup_56 $NUMFILES $NUMDIRS
4202
4203         EXPECTED=$(($NUMDIRS + 2))
4204         # test lfs find with -name
4205         for i in $(seq 1 $NUMFILES) ; do
4206                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4207                 [ $NUMS -eq $EXPECTED ] ||
4208                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4209                               "found $NUMS, expected $EXPECTED"
4210         done
4211 }
4212 run_test 56g "check lfs find -name ============================="
4213
4214 test_56h() {
4215         $SETSTRIPE -d $DIR
4216
4217         TDIR=$DIR/${tdir}g
4218         setup_56 $NUMFILES $NUMDIRS
4219
4220         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4221         # test lfs find with ! -name
4222         for i in $(seq 1 $NUMFILES) ; do
4223                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4224                 [ $NUMS -eq $EXPECTED ] ||
4225                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4226                               "found $NUMS, expected $EXPECTED"
4227         done
4228 }
4229 run_test 56h "check lfs find ! -name ============================="
4230
4231 test_56i() {
4232        tdir=${tdir}i
4233        test_mkdir -p $DIR/$tdir
4234        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4235        CMD="$LFIND -ost $UUID $DIR/$tdir"
4236        OUT=$($CMD)
4237        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4238 }
4239 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4240
4241 test_56j() {
4242         TDIR=$DIR/${tdir}g
4243         setup_56_special $NUMFILES $NUMDIRS
4244
4245         EXPECTED=$((NUMDIRS + 1))
4246         CMD="$LFIND -type d $TDIR"
4247         NUMS=$($CMD | wc -l)
4248         [ $NUMS -eq $EXPECTED ] ||
4249                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4250 }
4251 run_test 56j "check lfs find -type d ============================="
4252
4253 test_56k() {
4254         TDIR=$DIR/${tdir}g
4255         setup_56_special $NUMFILES $NUMDIRS
4256
4257         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4258         CMD="$LFIND -type f $TDIR"
4259         NUMS=$($CMD | wc -l)
4260         [ $NUMS -eq $EXPECTED ] ||
4261                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4262 }
4263 run_test 56k "check lfs find -type f ============================="
4264
4265 test_56l() {
4266         TDIR=$DIR/${tdir}g
4267         setup_56_special $NUMFILES $NUMDIRS
4268
4269         EXPECTED=$((NUMDIRS + NUMFILES))
4270         CMD="$LFIND -type b $TDIR"
4271         NUMS=$($CMD | wc -l)
4272         [ $NUMS -eq $EXPECTED ] ||
4273                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4274 }
4275 run_test 56l "check lfs find -type b ============================="
4276
4277 test_56m() {
4278         TDIR=$DIR/${tdir}g
4279         setup_56_special $NUMFILES $NUMDIRS
4280
4281         EXPECTED=$((NUMDIRS + NUMFILES))
4282         CMD="$LFIND -type c $TDIR"
4283         NUMS=$($CMD | wc -l)
4284         [ $NUMS -eq $EXPECTED ] ||
4285                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4286 }
4287 run_test 56m "check lfs find -type c ============================="
4288
4289 test_56n() {
4290         TDIR=$DIR/${tdir}g
4291         setup_56_special $NUMFILES $NUMDIRS
4292
4293         EXPECTED=$((NUMDIRS + NUMFILES))
4294         CMD="$LFIND -type l $TDIR"
4295         NUMS=$($CMD | wc -l)
4296         [ $NUMS -eq $EXPECTED ] ||
4297                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4298 }
4299 run_test 56n "check lfs find -type l ============================="
4300
4301 test_56o() {
4302         TDIR=$DIR/${tdir}o
4303         setup_56 $NUMFILES $NUMDIRS
4304         utime $TDIR/file1 > /dev/null || error "utime (1)"
4305         utime $TDIR/file2 > /dev/null || error "utime (2)"
4306         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4307         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4308         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4309         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4310
4311         EXPECTED=4
4312         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4313         [ $NUMS -eq $EXPECTED ] || \
4314                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4315
4316         EXPECTED=12
4317         CMD="$LFIND -mtime 0 $TDIR"
4318         NUMS=$($CMD | wc -l)
4319         [ $NUMS -eq $EXPECTED ] ||
4320                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4321 }
4322 run_test 56o "check lfs find -mtime for old files =========================="
4323
4324 test_56p() {
4325         [ $RUNAS_ID -eq $UID ] &&
4326                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4327
4328         TDIR=$DIR/${tdir}p
4329         setup_56 $NUMFILES $NUMDIRS
4330
4331         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4332         EXPECTED=$NUMFILES
4333         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4334         NUMS=$($CMD | wc -l)
4335         [ $NUMS -eq $EXPECTED ] || \
4336                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4337
4338         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4339         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4340         NUMS=$($CMD | wc -l)
4341         [ $NUMS -eq $EXPECTED ] || \
4342                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4343 }
4344 run_test 56p "check lfs find -uid and ! -uid ==============================="
4345
4346 test_56q() {
4347         [ $RUNAS_ID -eq $UID ] &&
4348                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4349
4350         TDIR=$DIR/${tdir}q
4351         setup_56 $NUMFILES $NUMDIRS
4352
4353         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4354
4355         EXPECTED=$NUMFILES
4356         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4357         NUMS=$($CMD | wc -l)
4358         [ $NUMS -eq $EXPECTED ] ||
4359                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4360
4361         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4362         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4363         NUMS=$($CMD | wc -l)
4364         [ $NUMS -eq $EXPECTED ] ||
4365                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4366 }
4367 run_test 56q "check lfs find -gid and ! -gid ==============================="
4368
4369 test_56r() {
4370         TDIR=$DIR/${tdir}r
4371         setup_56 $NUMFILES $NUMDIRS
4372
4373         EXPECTED=12
4374         CMD="$LFIND -size 0 -type f $TDIR"
4375         NUMS=$($CMD | wc -l)
4376         [ $NUMS -eq $EXPECTED ] ||
4377                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4378         EXPECTED=0
4379         CMD="$LFIND ! -size 0 -type f $TDIR"
4380         NUMS=$($CMD | wc -l)
4381         [ $NUMS -eq $EXPECTED ] ||
4382                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4383         echo "test" > $TDIR/$tfile
4384         echo "test2" > $TDIR/$tfile.2 && sync
4385         EXPECTED=1
4386         CMD="$LFIND -size 5 -type f $TDIR"
4387         NUMS=$($CMD | wc -l)
4388         [ $NUMS -eq $EXPECTED ] ||
4389                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4390         EXPECTED=1
4391         CMD="$LFIND -size +5 -type f $TDIR"
4392         NUMS=$($CMD | wc -l)
4393         [ $NUMS -eq $EXPECTED ] ||
4394                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4395         EXPECTED=2
4396         CMD="$LFIND -size +0 -type f $TDIR"
4397         NUMS=$($CMD | wc -l)
4398         [ $NUMS -eq $EXPECTED ] ||
4399                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4400         EXPECTED=2
4401         CMD="$LFIND ! -size -5 -type f $TDIR"
4402         NUMS=$($CMD | wc -l)
4403         [ $NUMS -eq $EXPECTED ] ||
4404                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4405         EXPECTED=12
4406         CMD="$LFIND -size -5 -type f $TDIR"
4407         NUMS=$($CMD | wc -l)
4408         [ $NUMS -eq $EXPECTED ] ||
4409                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4410 }
4411 run_test 56r "check lfs find -size works =========================="
4412
4413 test_56s() { # LU-611
4414         TDIR=$DIR/${tdir}s
4415         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4416
4417         if [ $OSTCOUNT -gt 1 ]; then
4418                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4419                 ONESTRIPE=4
4420                 EXTRA=4
4421         else
4422                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4423                 EXTRA=0
4424         fi
4425
4426         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4427         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4428         NUMS=$($CMD | wc -l)
4429         [ $NUMS -eq $EXPECTED ] ||
4430                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4431
4432         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4433         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4434         NUMS=$($CMD | wc -l)
4435         [ $NUMS -eq $EXPECTED ] ||
4436                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4437
4438         EXPECTED=$ONESTRIPE
4439         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4440         NUMS=$($CMD | wc -l)
4441         [ $NUMS -eq $EXPECTED ] ||
4442                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4443
4444         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4445         NUMS=$($CMD | wc -l)
4446         [ $NUMS -eq $EXPECTED ] ||
4447                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4448
4449         EXPECTED=0
4450         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4451         NUMS=$($CMD | wc -l)
4452         [ $NUMS -eq $EXPECTED ] ||
4453                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4454 }
4455 run_test 56s "check lfs find -stripe-count works"
4456
4457 test_56t() { # LU-611
4458         TDIR=$DIR/${tdir}t
4459         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4460
4461         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4462
4463         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4464         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4465         NUMS=$($CMD | wc -l)
4466         [ $NUMS -eq $EXPECTED ] ||
4467                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4468
4469         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4470         NUMS=$($CMD | wc -l)
4471         [ $NUMS -eq $EXPECTED ] ||
4472                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4473
4474         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4475         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4476         NUMS=$($CMD | wc -l)
4477         [ $NUMS -eq $EXPECTED ] ||
4478                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4479
4480         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4481         NUMS=$($CMD | wc -l)
4482         [ $NUMS -eq $EXPECTED ] ||
4483                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4484
4485         EXPECTED=4
4486         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4487         NUMS=$($CMD | wc -l)
4488         [ $NUMS -eq $EXPECTED ] ||
4489                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4490
4491         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4492         NUMS=$($CMD | wc -l)
4493         [ $NUMS -eq $EXPECTED ] ||
4494                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4495
4496         EXPECTED=0
4497         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4498         NUMS=$($CMD | wc -l)
4499         [ $NUMS -eq $EXPECTED ] ||
4500                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4501 }
4502 run_test 56t "check lfs find -stripe-size works"
4503
4504 test_56u() { # LU-611
4505         TDIR=$DIR/${tdir}u
4506         setup_56 $NUMFILES $NUMDIRS "-i 0"
4507
4508         if [ $OSTCOUNT -gt 1 ]; then
4509                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4510                 ONESTRIPE=4
4511         else
4512                 ONESTRIPE=0
4513         fi
4514
4515         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4516         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4517         NUMS=$($CMD | wc -l)
4518         [ $NUMS -eq $EXPECTED ] ||
4519                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4520
4521         EXPECTED=$ONESTRIPE
4522         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4523         NUMS=$($CMD | wc -l)
4524         [ $NUMS -eq $EXPECTED ] ||
4525                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4526
4527         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4528         NUMS=$($CMD | wc -l)
4529         [ $NUMS -eq $EXPECTED ] ||
4530                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4531
4532         EXPECTED=0
4533         # This should produce an error and not return any files
4534         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4535         NUMS=$($CMD 2>/dev/null | wc -l)
4536         [ $NUMS -eq $EXPECTED ] ||
4537                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4538
4539         if [ $OSTCOUNT -gt 1 ]; then
4540                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4541                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4542                 NUMS=$($CMD | wc -l)
4543                 [ $NUMS -eq $EXPECTED ] ||
4544                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4545         fi
4546 }
4547 run_test 56u "check lfs find -stripe-index works"
4548
4549 test_56v() {
4550     local MDT_IDX=0
4551
4552     TDIR=$DIR/${tdir}v
4553     rm -rf $TDIR
4554     setup_56 $NUMFILES $NUMDIRS
4555
4556     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4557     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4558
4559     for file in $($LFIND -mdt $UUID $TDIR); do
4560         file_mdt_idx=$($GETSTRIPE -M $file)
4561         [ $file_mdt_idx -eq $MDT_IDX ] ||
4562             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4563     done
4564 }
4565 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4566
4567 # Get and check the actual stripe count of one file.
4568 # Usage: check_stripe_count <file> <expected_stripe_count>
4569 check_stripe_count() {
4570     local file=$1
4571     local expected=$2
4572     local actual
4573
4574     [[ -z "$file" || -z "$expected" ]] &&
4575         error "check_stripe_count: invalid argument!"
4576
4577     local cmd="$GETSTRIPE -c $file"
4578     actual=$($cmd) || error "$cmd failed"
4579     actual=${actual%% *}
4580
4581     if [[ $actual -ne $expected ]]; then
4582         [[ $expected -eq -1 ]] ||
4583             error "$cmd wrong: found $actual, expected $expected"
4584         [[ $actual -eq $OSTCOUNT ]] ||
4585             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4586     fi
4587 }
4588
4589 test_56w() {
4590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4591         TDIR=$DIR/${tdir}w
4592
4593     rm -rf $TDIR || error "remove $TDIR failed"
4594     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4595
4596     local stripe_size
4597     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4598         error "$GETSTRIPE -S -d $TDIR failed"
4599     stripe_size=${stripe_size%% *}
4600
4601     local file_size=$((stripe_size * OSTCOUNT))
4602     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4603     local required_space=$((file_num * file_size))
4604     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4605     [[ $free_space -le $((required_space / 1024)) ]] &&
4606         skip_env "need at least $required_space bytes free space," \
4607                  "have $free_space kbytes" && return
4608
4609     local dd_bs=65536
4610     local dd_count=$((file_size / dd_bs))
4611
4612     # write data into the files
4613     local i
4614     local j
4615     local file
4616     for i in $(seq 1 $NUMFILES); do
4617         file=$TDIR/file$i
4618         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4619             error "write data into $file failed"
4620     done
4621     for i in $(seq 1 $NUMDIRS); do
4622         for j in $(seq 1 $NUMFILES); do
4623             file=$TDIR/dir$i/file$j
4624             yes | dd bs=$dd_bs count=$dd_count of=$file \
4625                 >/dev/null 2>&1 ||
4626                 error "write data into $file failed"
4627         done
4628     done
4629
4630     local expected=-1
4631     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4632
4633     # lfs_migrate file
4634     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4635     echo "$cmd"
4636     eval $cmd || error "$cmd failed"
4637
4638     check_stripe_count $TDIR/file1 $expected
4639
4640     # lfs_migrate dir
4641     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4642     echo "$cmd"
4643     eval $cmd || error "$cmd failed"
4644
4645     for j in $(seq 1 $NUMFILES); do
4646         check_stripe_count $TDIR/dir1/file$j $expected
4647     done
4648
4649     # lfs_migrate works with lfs find
4650     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4651          $LFS_MIGRATE -y -c $expected"
4652     echo "$cmd"
4653     eval $cmd || error "$cmd failed"
4654
4655     for i in $(seq 2 $NUMFILES); do
4656         check_stripe_count $TDIR/file$i $expected
4657     done
4658     for i in $(seq 2 $NUMDIRS); do
4659         for j in $(seq 1 $NUMFILES); do
4660             check_stripe_count $TDIR/dir$i/file$j $expected
4661         done
4662     done
4663 }
4664 run_test 56w "check lfs_migrate -c stripe_count works"
4665
4666 test_56x() {
4667         check_swap_layouts_support && return 0
4668         [ "$OSTCOUNT" -lt "2" ] &&
4669                 skip_env "need 2 OST, skipping test" && return
4670
4671         local dir0=$DIR/$tdir/$testnum
4672         mkdir -p $dir0 || error "creating dir $dir0"
4673
4674         local ref1=/etc/passwd
4675         local file1=$dir0/file1
4676
4677         $SETSTRIPE -c 2 $file1
4678         cp $ref1 $file1
4679         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4680         stripe=$($GETSTRIPE -c $file1)
4681         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4682         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4683
4684         # clean up
4685         rm -f $file1
4686 }
4687 run_test 56x "lfs migration support"
4688
4689 test_56y() {
4690         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4691                 skip "No HSM support on MDS of $(get_lustre_version)," \
4692                          "need 2.4.53 at least" && return
4693         local res=""
4694
4695         local dir0=$DIR/$tdir/$testnum
4696         mkdir -p $dir0 || error "creating dir $dir0"
4697         local f1=$dir0/file1
4698         local f2=$dir0/file2
4699
4700         touch $f1 || error "creating std file $f1"
4701         $MULTIOP $f2 H2c || error "creating released file $f2"
4702
4703         # a directory can be raid0, so ask only for files
4704         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4705         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4706
4707         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4708         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4709
4710         # only files can be released, so no need to force file search
4711         res=$($LFIND $dir0 -L released)
4712         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4713
4714         res=$($LFIND $dir0 \! -L released)
4715         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4716
4717 }
4718 run_test 56y "lfs find -L raid0|released"
4719
4720 test_57a() {
4721         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4722         # note test will not do anything if MDS is not local
4723         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4724                 skip "Only applicable to ldiskfs-based MDTs"
4725                 return
4726         fi
4727
4728         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4729         local MNTDEV="osd*.*MDT*.mntdev"
4730         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4731         [ -z "$DEV" ] && error "can't access $MNTDEV"
4732         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4733                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4734                         error "can't access $DEV"
4735                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
4736                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
4737                 rm $TMP/t57a.dump
4738         done
4739 }
4740 run_test 57a "verify MDS filesystem created with large inodes =="
4741
4742 test_57b() {
4743         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4744         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4745                 skip "Only applicable to ldiskfs-based MDTs"
4746                 return
4747         fi
4748
4749         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4750         local dir=$DIR/d57b
4751
4752         local FILECOUNT=100
4753         local FILE1=$dir/f1
4754         local FILEN=$dir/f$FILECOUNT
4755
4756         rm -rf $dir || error "removing $dir"
4757         test_mkdir -p $dir || error "creating $dir"
4758         local num=$(get_mds_dir $dir)
4759         local mymds=mds$num
4760
4761         echo "mcreating $FILECOUNT files"
4762         createmany -m $dir/f 1 $FILECOUNT || \
4763                 error "creating files in $dir"
4764
4765         # verify that files do not have EAs yet
4766         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4767         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4768
4769         sync
4770         sleep 1
4771         df $dir  #make sure we get new statfs data
4772         local MDSFREE=$(do_facet $mymds \
4773                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4774         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4775         echo "opening files to create objects/EAs"
4776         local FILE
4777         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4778                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4779         done
4780
4781         # verify that files have EAs now
4782         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
4783         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
4784
4785         sleep 1  #make sure we get new statfs data
4786         df $dir
4787         local MDSFREE2=$(do_facet $mymds \
4788                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4789         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4790         if [ "$MDCFREE2" -lt "$((MDCFREE - 16))" ]; then
4791                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
4792                         error "MDC before $MDCFREE != after $MDCFREE2"
4793                 else
4794                         echo "MDC before $MDCFREE != after $MDCFREE2"
4795                         echo "unable to confirm if MDS has large inodes"
4796                 fi
4797         fi
4798         rm -rf $dir
4799 }
4800 run_test 57b "default LOV EAs are stored inside large inodes ==="
4801
4802 test_58() {
4803         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4804         [ -z "$(which wiretest 2>/dev/null)" ] &&
4805                         skip_env "could not find wiretest" && return
4806         wiretest
4807 }
4808 run_test 58 "verify cross-platform wire constants =============="
4809
4810 test_59() {
4811         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4812         echo "touch 130 files"
4813         createmany -o $DIR/f59- 130
4814         echo "rm 130 files"
4815         unlinkmany $DIR/f59- 130
4816         sync
4817         # wait for commitment of removal
4818         wait_delete_completed
4819 }
4820 run_test 59 "verify cancellation of llog records async ========="
4821
4822 TEST60_HEAD="test_60 run $RANDOM"
4823 test_60a() {
4824         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4825         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
4826         do_facet mgs "! which run-llog.sh &> /dev/null" &&
4827                 skip_env "missing subtest run-llog.sh" && return
4828         log "$TEST60_HEAD - from kernel mode"
4829         do_facet mgs sh run-llog.sh
4830 }
4831 run_test 60a "llog sanity tests run from kernel module =========="
4832
4833 test_60b() { # bug 6411
4834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4835         dmesg > $DIR/$tfile
4836         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
4837                                  /llog.test/ {
4838                                          if (marker)
4839                                                  from_marker++
4840                                          from_begin++
4841                                  }
4842                                  END {
4843                                          if (marker)
4844                                                  print from_marker
4845                                          else
4846                                                  print from_begin
4847                                  }"`
4848         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
4849 }
4850 run_test 60b "limit repeated messages from CERROR/CWARN ========"
4851
4852 test_60c() {
4853         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4854         echo "create 5000 files"
4855         createmany -o $DIR/f60c- 5000
4856 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
4857         lctl set_param fail_loc=0x80000137
4858         unlinkmany $DIR/f60c- 5000
4859         lctl set_param fail_loc=0
4860 }
4861 run_test 60c "unlink file when mds full"
4862
4863 test_60d() {
4864         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4865         SAVEPRINTK=$(lctl get_param -n printk)
4866
4867         # verify "lctl mark" is even working"
4868         MESSAGE="test message ID $RANDOM $$"
4869         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4870         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
4871
4872         lctl set_param printk=0 || error "set lnet.printk failed"
4873         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
4874         MESSAGE="new test message ID $RANDOM $$"
4875         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
4876         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4877         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
4878
4879         lctl set_param -n printk="$SAVEPRINTK"
4880 }
4881 run_test 60d "test printk console message masking"
4882
4883 test_61() {
4884         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4885         f="$DIR/f61"
4886         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
4887         cancel_lru_locks osc
4888         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
4889         sync
4890 }
4891 run_test 61 "mmap() writes don't make sync hang ================"
4892
4893 # bug 2330 - insufficient obd_match error checking causes LBUG
4894 test_62() {
4895         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4896         f="$DIR/f62"
4897         echo foo > $f
4898         cancel_lru_locks osc
4899         lctl set_param fail_loc=0x405
4900         cat $f && error "cat succeeded, expect -EIO"
4901         lctl set_param fail_loc=0
4902 }
4903 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
4904 # match every page all of the time.
4905 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
4906
4907 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
4908 # Though this test is irrelevant anymore, it helped to reveal some
4909 # other grant bugs (LU-4482), let's keep it.
4910 test_63a() {   # was test_63
4911         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4912         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
4913         for i in `seq 10` ; do
4914                 dd if=/dev/zero of=$DIR/f63 bs=8k &
4915                 sleep 5
4916                 kill $!
4917                 sleep 1
4918         done
4919
4920         rm -f $DIR/f63 || true
4921 }
4922 run_test 63a "Verify oig_wait interruption does not crash ======="
4923
4924 # bug 2248 - async write errors didn't return to application on sync
4925 # bug 3677 - async write errors left page locked
4926 test_63b() {
4927         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4928         debugsave
4929         lctl set_param debug=-1
4930
4931         # ensure we have a grant to do async writes
4932         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
4933         rm $DIR/$tfile
4934
4935         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4936         lctl set_param fail_loc=0x80000406
4937         $MULTIOP $DIR/$tfile Owy && \
4938                 error "sync didn't return ENOMEM"
4939         sync; sleep 2; sync     # do a real sync this time to flush page
4940         lctl get_param -n llite.*.dump_page_cache | grep locked && \
4941                 error "locked page left in cache after async error" || true
4942         debugrestore
4943 }
4944 run_test 63b "async write errors should be returned to fsync ==="
4945
4946 test_64a () {
4947         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4948         df $DIR
4949         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
4950 }
4951 run_test 64a "verify filter grant calculations (in kernel) ====="
4952
4953 test_64b () {
4954         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4955         sh oos.sh $MOUNT || error "oos.sh failed: $?"
4956 }
4957 run_test 64b "check out-of-space detection on client ==========="
4958
4959 test_64c() {
4960         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
4961 }
4962 run_test 64c "verify grant shrink ========================------"
4963
4964 # bug 1414 - set/get directories' stripe info
4965 test_65a() {
4966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4967         test_mkdir -p $DIR/$tdir
4968         touch $DIR/$tdir/f1
4969         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
4970 }
4971 run_test 65a "directory with no stripe info ===================="
4972
4973 test_65b() {
4974         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4975         test_mkdir -p $DIR/$tdir
4976         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4977                                                 error "setstripe"
4978         touch $DIR/$tdir/f2
4979         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
4980 }
4981 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
4982
4983 test_65c() {
4984         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4985         if [ $OSTCOUNT -gt 1 ]; then
4986                 test_mkdir -p $DIR/$tdir
4987                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
4988                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
4989                 touch $DIR/$tdir/f3
4990                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
4991         fi
4992 }
4993 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
4994
4995 test_65d() {
4996         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4997         test_mkdir -p $DIR/$tdir
4998         if [ $STRIPECOUNT -le 0 ]; then
4999                 sc=1
5000         elif [ $STRIPECOUNT -gt 2000 ]; then
5001 #LOV_MAX_STRIPE_COUNT is 2000
5002                 [ $OSTCOUNT -gt 2000 ] && sc=2000 || sc=$(($OSTCOUNT - 1))
5003         else
5004                 sc=$(($STRIPECOUNT - 1))
5005         fi
5006         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5007         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5008         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5009                                                 error "lverify failed"
5010 }
5011 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5012
5013 test_65e() {
5014         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5015         test_mkdir -p $DIR/$tdir
5016
5017         $SETSTRIPE $DIR/$tdir || error "setstripe"
5018         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5019                                         error "no stripe info failed"
5020         touch $DIR/$tdir/f6
5021         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5022 }
5023 run_test 65e "directory setstripe defaults ======================="
5024
5025 test_65f() {
5026         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5027         test_mkdir -p $DIR/${tdir}f
5028         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5029 }
5030 run_test 65f "dir setstripe permission (should return error) ==="
5031
5032 test_65g() {
5033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5034         test_mkdir -p $DIR/$tdir
5035         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5036                                                         error "setstripe"
5037         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5038         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5039                 error "delete default stripe failed"
5040 }
5041 run_test 65g "directory setstripe -d ==========================="
5042
5043 test_65h() {
5044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5045         test_mkdir -p $DIR/$tdir
5046         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5047                                                         error "setstripe"
5048         test_mkdir -p $DIR/$tdir/dd1
5049         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5050                 error "stripe info inherit failed"
5051 }
5052 run_test 65h "directory stripe info inherit ===================="
5053
5054 test_65i() { # bug6367
5055         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5056         $SETSTRIPE -S 65536 -c -1 $MOUNT
5057 }
5058 run_test 65i "set non-default striping on root directory (bug 6367)="
5059
5060 test_65ia() { # bug12836
5061         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5062         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5063 }
5064 run_test 65ia "getstripe on -1 default directory striping"
5065
5066 test_65ib() { # bug12836
5067         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5068         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5069 }
5070 run_test 65ib "getstripe -v on -1 default directory striping"
5071
5072 test_65ic() { # bug12836
5073         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5074         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5075 }
5076 run_test 65ic "new find on -1 default directory striping"
5077
5078 test_65j() { # bug6367
5079         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5080         sync; sleep 1
5081         # if we aren't already remounting for each test, do so for this test
5082         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5083                 cleanup || error "failed to unmount"
5084                 setup
5085         fi
5086         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5087 }
5088 run_test 65j "set default striping on root directory (bug 6367)="
5089
5090 test_65k() { # bug11679
5091         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5092         [ "$OSTCOUNT" -lt 2 ] && skip_env "too few OSTs" && return
5093         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5094
5095     echo "Check OST status: "
5096     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5097               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5098
5099     for OSC in $MDS_OSCS; do
5100         echo $OSC "is activate"
5101         do_facet $SINGLEMDS lctl --device %$OSC activate
5102     done
5103
5104     mkdir -p $DIR/$tdir
5105     for INACTIVE_OSC in $MDS_OSCS; do
5106         echo "Deactivate: " $INACTIVE_OSC
5107         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5108         for STRIPE_OSC in $MDS_OSCS; do
5109             OST=`osc_to_ost $STRIPE_OSC`
5110             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5111                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5112
5113             [ -f $DIR/$tdir/$IDX ] && continue
5114             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5115             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5116             RC=$?
5117             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5118         done
5119         rm -f $DIR/$tdir/*
5120         echo $INACTIVE_OSC "is Activate."
5121         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5122     done
5123 }
5124 run_test 65k "validate manual striping works properly with deactivated OSCs"
5125
5126 test_65l() { # bug 12836
5127         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5128         test_mkdir -p $DIR/$tdir/test_dir
5129         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5130         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5131 }
5132 run_test 65l "lfs find on -1 stripe dir ========================"
5133
5134 # bug 2543 - update blocks count on client
5135 test_66() {
5136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5137         COUNT=${COUNT:-8}
5138         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5139         sync; sync_all_data; sync; sync_all_data
5140         cancel_lru_locks osc
5141         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5142         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5143 }
5144 run_test 66 "update inode blocks count on client ==============="
5145
5146 LLOOP=
5147 LLITELOOPLOAD=
5148 cleanup_68() {
5149         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5150         trap 0
5151         if [ ! -z "$LLOOP" ]; then
5152                 if swapon -s | grep -q $LLOOP; then
5153                         swapoff $LLOOP || error "swapoff failed"
5154                 fi
5155
5156                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5157                 rm -f $LLOOP
5158                 unset LLOOP
5159         fi
5160         if [ ! -z "$LLITELOOPLOAD" ]; then
5161                 rmmod llite_lloop
5162                 unset LLITELOOPLOAD
5163         fi
5164         rm -f $DIR/f68*
5165 }
5166
5167 meminfo() {
5168         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5169 }
5170
5171 swap_used() {
5172         swapon -s | awk '($1 == "'$1'") { print $4 }'
5173 }
5174
5175 # test case for lloop driver, basic function
5176 test_68a() {
5177         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5178         [ "$UID" != 0 ] && skip_env "must run as root" && return
5179         llite_lloop_enabled || \
5180                 { skip_env "llite_lloop module disabled" && return; }
5181
5182         trap cleanup_68 EXIT
5183
5184         if ! module_loaded llite_lloop; then
5185                 if load_module llite/llite_lloop; then
5186                         LLITELOOPLOAD=yes
5187                 else
5188                         skip_env "can't find module llite_lloop"
5189                         return
5190                 fi
5191         fi
5192
5193         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5194         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5195         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5196
5197         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5198         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5199
5200         cleanup_68
5201 }
5202 run_test 68a "lloop driver - basic test ========================"
5203
5204 # excercise swapping to lustre by adding a high priority swapfile entry
5205 # and then consuming memory until it is used.
5206 test_68b() {  # was test_68
5207         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5208         [ "$UID" != 0 ] && skip_env "must run as root" && return
5209         lctl get_param -n devices | grep -q obdfilter && \
5210                 skip "local OST" && return
5211
5212         grep -q llite_lloop /proc/modules
5213         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5214
5215         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5216                 skip "can't reliably test swap with TCP" && return
5217
5218         MEMTOTAL=`meminfo MemTotal`
5219         NR_BLOCKS=$((MEMTOTAL>>8))
5220         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5221
5222         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5223         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5224         mkswap $DIR/f68b
5225
5226         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5227
5228         trap cleanup_68 EXIT
5229
5230         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5231
5232         echo "before: `swapon -s | grep $LLOOP`"
5233         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5234         echo "after: `swapon -s | grep $LLOOP`"
5235         SWAPUSED=`swap_used $LLOOP`
5236
5237         cleanup_68
5238
5239         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5240 }
5241 run_test 68b "support swapping to Lustre ========================"
5242
5243 # bug5265, obdfilter oa2dentry return -ENOENT
5244 # #define OBD_FAIL_OST_ENOENT 0x217
5245 test_69() {
5246         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5247         remote_ost_nodsh && skip "remote OST with nodsh" && return
5248
5249         f="$DIR/$tfile"
5250         $SETSTRIPE -c 1 -i 0 $f
5251
5252         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5253
5254         do_facet ost1 lctl set_param fail_loc=0x217
5255         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5256         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5257
5258         do_facet ost1 lctl set_param fail_loc=0
5259         $DIRECTIO write $f 0 2 || error "write error"
5260
5261         cancel_lru_locks osc
5262         $DIRECTIO read $f 0 1 || error "read error"
5263
5264         do_facet ost1 lctl set_param fail_loc=0x217
5265         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5266
5267         do_facet ost1 lctl set_param fail_loc=0
5268         rm -f $f
5269 }
5270 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5271
5272 test_71() {
5273     test_mkdir -p $DIR/$tdir
5274     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5275 }
5276 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5277
5278 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5279         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5280         [ "$RUNAS_ID" = "$UID" ] &&
5281                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5282
5283         # Check that testing environment is properly set up. Skip if not
5284         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5285                 skip_env "User $RUNAS_ID does not exist - skipping"
5286                 return 0
5287         }
5288         # We had better clear the $DIR to get enough space for dd
5289         rm -rf $DIR/*
5290         touch $DIR/$tfile
5291         chmod 777 $DIR/$tfile
5292         chmod ug+s $DIR/$tfile
5293         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5294                 error "$RUNAS dd $DIR/$tfile failed"
5295         # See if we are still setuid/sgid
5296         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5297                 error "S/gid is not dropped on write"
5298         # Now test that MDS is updated too
5299         cancel_lru_locks mdc
5300         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5301                 error "S/gid is not dropped on MDS"
5302         rm -f $DIR/$tfile
5303 }
5304 run_test 72a "Test that remove suid works properly (bug5695) ===="
5305
5306 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5307         local perm
5308
5309         [ "$RUNAS_ID" = "$UID" ] && \
5310                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5311         [ "$RUNAS_ID" -eq 0 ] && \
5312                 skip_env "RUNAS_ID = 0 -- skipping" && return
5313
5314         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5315         # Check that testing environment is properly set up. Skip if not
5316         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5317                 skip_env "User $RUNAS_ID does not exist - skipping"
5318                 return 0
5319         }
5320         touch $DIR/${tfile}-f{g,u}
5321         test_mkdir $DIR/${tfile}-dg
5322         test_mkdir $DIR/${tfile}-du
5323         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5324         chmod g+s $DIR/${tfile}-{f,d}g
5325         chmod u+s $DIR/${tfile}-{f,d}u
5326         for perm in 777 2777 4777; do
5327                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5328                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5329                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5330                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5331         done
5332         true
5333 }
5334 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5335
5336 # bug 3462 - multiple simultaneous MDC requests
5337 test_73() {
5338         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5339         test_mkdir $DIR/d73-1
5340         test_mkdir $DIR/d73-2
5341         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5342         pid1=$!
5343
5344         lctl set_param fail_loc=0x80000129
5345         $MULTIOP $DIR/d73-1/f73-2 Oc &
5346         sleep 1
5347         lctl set_param fail_loc=0
5348
5349         $MULTIOP $DIR/d73-2/f73-3 Oc &
5350         pid3=$!
5351
5352         kill -USR1 $pid1
5353         wait $pid1 || return 1
5354
5355         sleep 25
5356
5357         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5358         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5359         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5360
5361         rm -rf $DIR/d73-*
5362 }
5363 run_test 73 "multiple MDC requests (should not deadlock)"
5364
5365 test_74a() { # bug 6149, 6184
5366         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5367         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5368         #
5369         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5370         # will spin in a tight reconnection loop
5371         touch $DIR/f74a
5372         lctl set_param fail_loc=0x8000030e
5373         # get any lock that won't be difficult - lookup works.
5374         ls $DIR/f74a
5375         lctl set_param fail_loc=0
5376         true
5377         rm -f $DIR/f74a
5378 }
5379 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5380
5381 test_74b() { # bug 13310
5382         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5383         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5384         #
5385         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5386         # will spin in a tight reconnection loop
5387         lctl set_param fail_loc=0x8000030e
5388         # get a "difficult" lock
5389         touch $DIR/f74b
5390         lctl set_param fail_loc=0
5391         true
5392         rm -f $DIR/f74b
5393 }
5394 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5395
5396 test_74c() {
5397         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5398 #define OBD_FAIL_LDLM_NEW_LOCK
5399         lctl set_param fail_loc=0x80000319
5400         touch $DIR/$tfile && error "Touch successful"
5401         true
5402 }
5403 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5404
5405 num_inodes() {
5406         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5407 }
5408
5409 get_inode_slab_tunables() {
5410         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5411 }
5412
5413 set_inode_slab_tunables() {
5414         echo "lustre_inode_cache $1" > /proc/slabinfo
5415 }
5416
5417 test_76() { # Now for bug 20433, added originally in bug 1443
5418         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5419         local SLAB_SETTINGS=`get_inode_slab_tunables`
5420         local CPUS=`getconf _NPROCESSORS_ONLN`
5421         # we cannot set limit below 1 which means 1 inode in each
5422         # per-cpu cache is still allowed
5423         set_inode_slab_tunables "1 1 0"
5424         cancel_lru_locks osc
5425         BEFORE_INODES=`num_inodes`
5426         echo "before inodes: $BEFORE_INODES"
5427         local COUNT=1000
5428         [ "$SLOW" = "no" ] && COUNT=100
5429         for i in `seq $COUNT`; do
5430                 touch $DIR/$tfile
5431                 rm -f $DIR/$tfile
5432         done
5433         cancel_lru_locks osc
5434         AFTER_INODES=`num_inodes`
5435         echo "after inodes: $AFTER_INODES"
5436         local wait=0
5437         while [ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]; do
5438                 sleep 2
5439                 AFTER_INODES=`num_inodes`
5440                 wait=$((wait+2))
5441                 echo "wait $wait seconds inodes: $AFTER_INODES"
5442                 if [ $wait -gt 30 ]; then
5443                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5444                 fi
5445         done
5446         set_inode_slab_tunables "$SLAB_SETTINGS"
5447 }
5448 run_test 76 "confirm clients recycle inodes properly ===="
5449
5450
5451 export ORIG_CSUM=""
5452 set_checksums()
5453 {
5454         # Note: in sptlrpc modes which enable its own bulk checksum, the
5455         # original crc32_le bulk checksum will be automatically disabled,
5456         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5457         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5458         # In this case set_checksums() will not be no-op, because sptlrpc
5459         # bulk checksum will be enabled all through the test.
5460
5461         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5462         lctl set_param -n osc.*.checksums $1
5463         return 0
5464 }
5465
5466 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5467                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5468 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5469 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5470 set_checksum_type()
5471 {
5472         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5473         log "set checksum type to $1"
5474         return 0
5475 }
5476 F77_TMP=$TMP/f77-temp
5477 F77SZ=8
5478 setup_f77() {
5479         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5480                 error "error writing to $F77_TMP"
5481 }
5482
5483 test_77a() { # bug 10889
5484         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5485         $GSS && skip "could not run with gss" && return
5486         [ ! -f $F77_TMP ] && setup_f77
5487         set_checksums 1
5488         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5489         set_checksums 0
5490         rm -f $DIR/$tfile
5491 }
5492 run_test 77a "normal checksum read/write operation"
5493
5494 test_77b() { # bug 10889
5495         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5496         $GSS && skip "could not run with gss" && return
5497         [ ! -f $F77_TMP ] && setup_f77
5498         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5499         $LCTL set_param fail_loc=0x80000409
5500         set_checksums 1
5501
5502         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5503                 error "dd error: $?"
5504         $LCTL set_param fail_loc=0
5505
5506         for algo in $CKSUM_TYPES; do
5507                 cancel_lru_locks osc
5508                 set_checksum_type $algo
5509                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5510                 $LCTL set_param fail_loc=0x80000408
5511                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5512                 $LCTL set_param fail_loc=0
5513         done
5514         set_checksums 0
5515         set_checksum_type $ORIG_CSUM_TYPE
5516         rm -f $DIR/$tfile
5517 }
5518 run_test 77b "checksum error on client write, read"
5519
5520 test_77d() { # bug 10889
5521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5522         $GSS && skip "could not run with gss" && return
5523         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5524         $LCTL set_param fail_loc=0x80000409
5525         set_checksums 1
5526         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5527                 error "direct write: rc=$?"
5528         $LCTL set_param fail_loc=0
5529         set_checksums 0
5530
5531         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5532         $LCTL set_param fail_loc=0x80000408
5533         set_checksums 1
5534         cancel_lru_locks osc
5535         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5536                 error "direct read: rc=$?"
5537         $LCTL set_param fail_loc=0
5538         set_checksums 0
5539 }
5540 run_test 77d "checksum error on OST direct write, read"
5541
5542 test_77f() { # bug 10889
5543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5544         $GSS && skip "could not run with gss" && return
5545         set_checksums 1
5546         for algo in $CKSUM_TYPES; do
5547                 cancel_lru_locks osc
5548                 set_checksum_type $algo
5549                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5550                 $LCTL set_param fail_loc=0x409
5551                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5552                         error "direct write succeeded"
5553                 $LCTL set_param fail_loc=0
5554         done
5555         set_checksum_type $ORIG_CSUM_TYPE
5556         set_checksums 0
5557 }
5558 run_test 77f "repeat checksum error on write (expect error)"
5559
5560 test_77g() { # bug 10889
5561         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5562         $GSS && skip "could not run with gss" && return
5563         remote_ost_nodsh && skip "remote OST with nodsh" && return
5564
5565         [ ! -f $F77_TMP ] && setup_f77
5566
5567         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5568         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5569         do_facet ost1 lctl set_param fail_loc=0x8000021a
5570         set_checksums 1
5571         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5572                 error "write error: rc=$?"
5573         do_facet ost1 lctl set_param fail_loc=0
5574         set_checksums 0
5575
5576         cancel_lru_locks osc
5577         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5578         do_facet ost1 lctl set_param fail_loc=0x8000021b
5579         set_checksums 1
5580         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5581         do_facet ost1 lctl set_param fail_loc=0
5582         set_checksums 0
5583 }
5584 run_test 77g "checksum error on OST write, read"
5585
5586 test_77i() { # bug 13805
5587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5588         $GSS && skip "could not run with gss" && return
5589         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5590         lctl set_param fail_loc=0x40b
5591         remount_client $MOUNT
5592         lctl set_param fail_loc=0
5593         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5594                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5595                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5596                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5597         done
5598         remount_client $MOUNT
5599 }
5600 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5601
5602 test_77j() { # bug 13805
5603         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5604         $GSS && skip "could not run with gss" && return
5605         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5606         lctl set_param fail_loc=0x40c
5607         remount_client $MOUNT
5608         lctl set_param fail_loc=0
5609         sleep 2 # wait async osc connect to finish
5610         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5611                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5612                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5613                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5614         done
5615         remount_client $MOUNT
5616 }
5617 run_test 77j "client only supporting ADLER32"
5618
5619 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5620 rm -f $F77_TMP
5621 unset F77_TMP
5622
5623 test_78() { # bug 10901
5624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5625         remote_ost || { skip_env "local OST" && return; }
5626
5627         NSEQ=5
5628         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5629         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5630         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5631         echo "MemTotal: $MEMTOTAL"
5632 # reserve 256MB of memory for the kernel and other running processes,
5633 # and then take 1/2 of the remaining memory for the read/write buffers.
5634     if [ $MEMTOTAL -gt 512 ] ;then
5635         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5636     else
5637         # for those poor memory-starved high-end clusters...
5638         MEMTOTAL=$((MEMTOTAL / 2))
5639     fi
5640         echo "Mem to use for directio: $MEMTOTAL"
5641         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
5642         [ $F78SIZE -gt 512 ] && F78SIZE=512
5643         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
5644         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5645                 head -n1)
5646         echo "Smallest OST: $SMALLESTOST"
5647         [ $SMALLESTOST -lt 10240 ] && \
5648                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5649
5650         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ] && \
5651                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5652
5653         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5654         echo "File size: $F78SIZE"
5655         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5656         for i in `seq 1 $NSEQ`
5657         do
5658                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5659                 echo directIO rdwr round $i of $NSEQ
5660                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5661         done
5662
5663         rm -f $DIR/$tfile
5664 }
5665 run_test 78 "handle large O_DIRECT writes correctly ============"
5666
5667 test_79() { # bug 12743
5668         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5669         wait_delete_completed
5670
5671         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5672         BKFREE=$(calc_osc_kbytes kbytesfree)
5673         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5674
5675         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5676         DFTOTAL=`echo $STRING | cut -d, -f1`
5677         DFUSED=`echo $STRING  | cut -d, -f2`
5678         DFAVAIL=`echo $STRING | cut -d, -f3`
5679         DFFREE=$(($DFTOTAL - $DFUSED))
5680
5681         ALLOWANCE=$((64 * $OSTCOUNT))
5682
5683         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5684            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5685                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5686         fi
5687         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5688            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5689                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5690         fi
5691         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5692            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5693                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5694         fi
5695 }
5696 run_test 79 "df report consistency check ======================="
5697
5698 test_80() { # bug 10718
5699         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5700         # relax strong synchronous semantics for slow backends like ZFS
5701         local soc="obdfilter.*.sync_on_lock_cancel"
5702         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5703         local hosts=
5704         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5705                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5706                           facet_active_host $host; done | sort -u)
5707                 do_nodes $hosts lctl set_param $soc=never
5708         fi
5709
5710         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5711         sync; sleep 1; sync
5712         local BEFORE=`date +%s`
5713         cancel_lru_locks osc
5714         local AFTER=`date +%s`
5715         local DIFF=$((AFTER-BEFORE))
5716         if [ $DIFF -gt 1 ] ; then
5717                 error "elapsed for 1M@1T = $DIFF"
5718         fi
5719
5720         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5721
5722         rm -f $DIR/$tfile
5723 }
5724 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5725
5726 test_81a() { # LU-456
5727         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5728         remote_ost_nodsh && skip "remote OST with nodsh" && return
5729         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5730         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5731         do_facet ost1 lctl set_param fail_loc=0x80000228
5732
5733         # write should trigger a retry and success
5734         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5735         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5736         RC=$?
5737         if [ $RC -ne 0 ] ; then
5738                 error "write should success, but failed for $RC"
5739         fi
5740 }
5741 run_test 81a "OST should retry write when get -ENOSPC ==============="
5742
5743 test_81b() { # LU-456
5744         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5745         remote_ost_nodsh && skip "remote OST with nodsh" && return
5746         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5747         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5748         do_facet ost1 lctl set_param fail_loc=0x228
5749
5750         # write should retry several times and return -ENOSPC finally
5751         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5752         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5753         RC=$?
5754         ENOSPC=28
5755         if [ $RC -ne $ENOSPC ] ; then
5756                 error "dd should fail for -ENOSPC, but succeed."
5757         fi
5758 }
5759 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5760
5761 test_82() { # LU-1031
5762         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5763         local gid1=14091995
5764         local gid2=16022000
5765
5766         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5767         local MULTIPID1=$!
5768         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5769         local MULTIPID2=$!
5770         kill -USR1 $MULTIPID2
5771         sleep 2
5772         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5773                 error "First grouplock does not block second one"
5774         else
5775                 echo "Second grouplock blocks first one"
5776         fi
5777         kill -USR1 $MULTIPID1
5778         wait $MULTIPID1
5779         wait $MULTIPID2
5780 }
5781 run_test 82 "Basic grouplock test ==============================="
5782
5783 test_99a() {
5784         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
5785                 return
5786         test_mkdir -p $DIR/d99cvsroot
5787         chown $RUNAS_ID $DIR/d99cvsroot
5788         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
5789         cd $TMP
5790
5791         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
5792         cd $oldPWD
5793 }
5794 run_test 99a "cvs init ========================================="
5795
5796 test_99b() {
5797         [ -z "$(which cvs 2>/dev/null)" ] &&
5798                 skip_env "could not find cvs" && return
5799         [ ! -d $DIR/d99cvsroot ] && test_99a
5800         cd /etc/init.d
5801         # some versions of cvs import exit(1) when asked to import links or
5802         # files they can't read.  ignore those files.
5803         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
5804                         ! -perm +4 -printf '-I %f\n')
5805         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
5806                 d99reposname vtag rtag
5807 }
5808 run_test 99b "cvs import ======================================="
5809
5810 test_99c() {
5811         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5812         [ ! -d $DIR/d99cvsroot ] && test_99b
5813         cd $DIR
5814         test_mkdir -p $DIR/d99reposname
5815         chown $RUNAS_ID $DIR/d99reposname
5816         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
5817 }
5818 run_test 99c "cvs checkout ====================================="
5819
5820 test_99d() {
5821         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5822         [ ! -d $DIR/d99cvsroot ] && test_99c
5823         cd $DIR/d99reposname
5824         $RUNAS touch foo99
5825         $RUNAS cvs add -m 'addmsg' foo99
5826 }
5827 run_test 99d "cvs add =========================================="
5828
5829 test_99e() {
5830         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5831         [ ! -d $DIR/d99cvsroot ] && test_99c
5832         cd $DIR/d99reposname
5833         $RUNAS cvs update
5834 }
5835 run_test 99e "cvs update ======================================="
5836
5837 test_99f() {
5838         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5839         [ ! -d $DIR/d99cvsroot ] && test_99d
5840         cd $DIR/d99reposname
5841         $RUNAS cvs commit -m 'nomsg' foo99
5842     rm -fr $DIR/d99cvsroot
5843 }
5844 run_test 99f "cvs commit ======================================="
5845
5846 test_100() {
5847         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5848         [ "$NETTYPE" = tcp ] || \
5849                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
5850                         return ; }
5851
5852         remote_ost_nodsh && skip "remote OST with nodsh" && return
5853         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5854         remote_servers || \
5855                 { skip "useless for local single node setup" && return; }
5856
5857         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
5858                 [ "$PROT" != "tcp" ] && continue
5859                 RPORT=$(echo $REMOTE | cut -d: -f2)
5860                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
5861
5862                 rc=0
5863                 LPORT=`echo $LOCAL | cut -d: -f2`
5864                 if [ $LPORT -ge 1024 ]; then
5865                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
5866                         netstat -tna
5867                         error_exit "local: $LPORT > 1024, remote: $RPORT"
5868                 fi
5869         done
5870         [ "$rc" = 0 ] || error_exit "privileged port not found" )
5871 }
5872 run_test 100 "check local port using privileged port ==========="
5873
5874 function get_named_value()
5875 {
5876     local tag
5877
5878     tag=$1
5879     while read ;do
5880         line=$REPLY
5881         case $line in
5882         $tag*)
5883             echo $line | sed "s/^$tag[ ]*//"
5884             break
5885             ;;
5886         esac
5887     done
5888 }
5889
5890 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
5891                    awk '/^max_cached_mb/ { print $2 }')
5892
5893 cleanup_101a() {
5894         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
5895         trap 0
5896 }
5897
5898 test_101a() {
5899         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5900         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
5901         local s
5902         local discard
5903         local nreads=10000
5904         local cache_limit=32
5905
5906         $LCTL set_param -n osc.*-osc*.rpc_stats 0
5907         trap cleanup_101a EXIT
5908         $LCTL set_param -n llite.*.read_ahead_stats 0
5909         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
5910
5911         #
5912         # randomly read 10000 of 64K chunks from file 3x 32MB in size
5913         #
5914         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
5915         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
5916
5917         discard=0
5918         for s in `$LCTL get_param -n llite.*.read_ahead_stats | \
5919                 get_named_value 'read but discarded' | cut -d" " -f1`; do
5920                         discard=$(($discard + $s))
5921         done
5922         cleanup_101a
5923
5924         if [ $(($discard * 10)) -gt $nreads ] ;then
5925                 $LCTL get_param osc.*-osc*.rpc_stats
5926                 $LCTL get_param llite.*.read_ahead_stats
5927                 error "too many ($discard) discarded pages"
5928         fi
5929         rm -f $DIR/$tfile || true
5930 }
5931 run_test 101a "check read-ahead for random reads ================"
5932
5933 setup_test101bc() {
5934         test_mkdir -p $DIR/$tdir
5935         local STRIPE_SIZE=$1
5936         local FILE_LENGTH=$2
5937         STRIPE_OFFSET=0
5938
5939         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
5940
5941         local list=$(comma_list $(osts_nodes))
5942         set_osd_param $list '' read_cache_enable 0
5943         set_osd_param $list '' writethrough_cache_enable 0
5944
5945         trap cleanup_test101bc EXIT
5946         # prepare the read-ahead file
5947         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
5948
5949         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
5950                                 count=$FILE_SIZE_MB 2> /dev/null
5951
5952 }
5953
5954 cleanup_test101bc() {
5955         trap 0
5956         rm -rf $DIR/$tdir
5957         rm -f $DIR/$tfile
5958
5959         local list=$(comma_list $(osts_nodes))
5960         set_osd_param $list '' read_cache_enable 1
5961         set_osd_param $list '' writethrough_cache_enable 1
5962 }
5963
5964 calc_total() {
5965         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
5966 }
5967
5968 ra_check_101() {
5969         local READ_SIZE=$1
5970         local STRIPE_SIZE=$2
5971         local FILE_LENGTH=$3
5972         local RA_INC=1048576
5973         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
5974         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
5975                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
5976         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
5977                         get_named_value 'read but discarded' | \
5978                         cut -d" " -f1 | calc_total`
5979         if [ $DISCARD -gt $discard_limit ]; then
5980                 $LCTL get_param llite.*.read_ahead_stats
5981                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
5982         else
5983                 echo "Read-ahead success for size ${READ_SIZE}"
5984         fi
5985 }
5986
5987 test_101b() {
5988         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5989         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping stride IO stride-ahead test" && return
5990         local STRIPE_SIZE=1048576
5991         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
5992         if [ $SLOW == "yes" ]; then
5993                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
5994         else
5995                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
5996         fi
5997
5998         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
5999
6000         # prepare the read-ahead file
6001         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6002         cancel_lru_locks osc
6003         for BIDX in 2 4 8 16 32 64 128 256
6004         do
6005                 local BSIZE=$((BIDX*4096))
6006                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6007                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6008                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6009                 $LCTL set_param -n llite.*.read_ahead_stats 0
6010                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6011                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6012                 cancel_lru_locks osc
6013                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6014         done
6015         cleanup_test101bc
6016         true
6017 }
6018 run_test 101b "check stride-io mode read-ahead ================="
6019
6020 test_101c() {
6021         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6022         local STRIPE_SIZE=1048576
6023         local FILE_LENGTH=$((STRIPE_SIZE*100))
6024         local nreads=10000
6025         local osc_rpc_stats
6026
6027         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6028
6029         cancel_lru_locks osc
6030         $LCTL set_param osc.*.rpc_stats 0
6031         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6032         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6033                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6034                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6035                 local size
6036
6037                 if [ $lines -le 20 ]; then
6038                         continue
6039                 fi
6040                 for size in 1 2 4 8; do
6041                         local rpc=$(echo "$stats" |
6042                                     awk '($1 == "'$size':") {print $2; exit; }')
6043                         [ $rpc != 0 ] &&
6044                                 error "Small $((size*4))k read IO $rpc !"
6045                 done
6046                 echo "$osc_rpc_stats check passed!"
6047         done
6048         cleanup_test101bc
6049         true
6050 }
6051 run_test 101c "check stripe_size aligned read-ahead ================="
6052
6053 set_read_ahead() {
6054         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6055         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6056 }
6057
6058 test_101d() {
6059         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6060         local file=$DIR/$tfile
6061         local sz_MB=${FILESIZE_101d:-500}
6062         local ra_MB=${READAHEAD_MB:-40}
6063
6064         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6065         [ $free_MB -lt $sz_MB ] &&
6066                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6067
6068         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6069         $SETSTRIPE -c -1 $file || error "setstripe failed"
6070
6071         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6072         echo Cancel LRU locks on lustre client to flush the client cache
6073         cancel_lru_locks osc
6074
6075         echo Disable read-ahead
6076         local old_READAHEAD=$(set_read_ahead 0)
6077
6078         echo Reading the test file $file with read-ahead disabled
6079         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6080
6081         echo Cancel LRU locks on lustre client to flush the client cache
6082         cancel_lru_locks osc
6083         echo Enable read-ahead with ${ra_MB}MB
6084         set_read_ahead $ra_MB
6085
6086         echo Reading the test file $file with read-ahead enabled
6087         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6088
6089         echo "read-ahead disabled time read $raOFF"
6090         echo "read-ahead enabled  time read $raON"
6091
6092         set_read_ahead $old_READAHEAD
6093         rm -f $file
6094         wait_delete_completed
6095
6096         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6097                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6098 }
6099 run_test 101d "file read with and without read-ahead enabled"
6100
6101 test_101e() {
6102         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6103         local file=$DIR/$tfile
6104         local size_KB=500  #KB
6105         local count=100
6106         local bsize=1024
6107
6108         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6109         local need_KB=$((count * size_KB))
6110         [ $free_KB -le $need_KB ] &&
6111                 skip_env "Need free space $need_KB, have $free_KB" && return
6112
6113         echo "Creating $count ${size_KB}K test files"
6114         for ((i = 0; i < $count; i++)); do
6115                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6116         done
6117
6118         echo "Cancel LRU locks on lustre client to flush the client cache"
6119         cancel_lru_locks osc
6120
6121         echo "Reset readahead stats"
6122         $LCTL set_param -n llite.*.read_ahead_stats 0
6123
6124         for ((i = 0; i < $count; i++)); do
6125                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6126         done
6127
6128         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6129                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6130
6131         for ((i = 0; i < $count; i++)); do
6132                 rm -rf $file.$i 2>/dev/null
6133         done
6134
6135         #10000 means 20% reads are missing in readahead
6136         [ $miss -lt 10000 ] ||  error "misses too much for small reads"
6137 }
6138 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6139
6140 cleanup_test101f() {
6141     trap 0
6142     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6143     rm -rf $DIR/$tfile 2>/dev/null
6144 }
6145
6146 test_101f() {
6147         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6148     local file=$DIR/$tfile
6149     local nreads=1000
6150
6151     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6152     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6153     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6154     trap cleanup_test101f EXIT
6155
6156     echo Cancel LRU locks on lustre client to flush the client cache
6157     cancel_lru_locks osc
6158
6159     echo Reset readahead stats
6160     $LCTL set_param -n llite.*.read_ahead_stats 0
6161     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6162     # readahead should read in 2M file on second read, so only miss
6163     # 2 pages.
6164     echo Random 4K reads on 2M file for 1000 times
6165     $READS -f $file -s 2097152 -b 4096 -n $nreads
6166
6167     echo checking missing pages
6168     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6169           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6170
6171     [ $miss -lt 3 ] || error "misses too much pages!"
6172     cleanup_test101f
6173 }
6174 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6175
6176 setup_test102() {
6177         test_mkdir -p $DIR/$tdir
6178         chown $RUNAS_ID $DIR/$tdir
6179         STRIPE_SIZE=65536
6180         STRIPE_OFFSET=1
6181         STRIPE_COUNT=$OSTCOUNT
6182         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
6183
6184         trap cleanup_test102 EXIT
6185         cd $DIR
6186         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6187         cd $DIR/$tdir
6188         for num in 1 2 3 4; do
6189                 for count in $(seq 1 $STRIPE_COUNT); do
6190                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6191                                 local size=`expr $STRIPE_SIZE \* $num`
6192                                 local file=file"$num-$idx-$count"
6193                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6194                         done
6195                 done
6196         done
6197
6198         cd $DIR
6199         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6200 }
6201
6202 cleanup_test102() {
6203         trap 0
6204         rm -f $TMP/f102.tar
6205         rm -rf $DIR/d0.sanity/d102
6206 }
6207
6208 test_102a() {
6209         local testfile=$DIR/xattr_testfile
6210
6211         touch $testfile
6212
6213         [ "$UID" != 0 ] && skip_env "must run as root" && return
6214         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6215                 skip_env "must have user_xattr" && return
6216
6217         [ -z "$(which setfattr 2>/dev/null)" ] &&
6218                 skip_env "could not find setfattr" && return
6219
6220         echo "set/get xattr..."
6221         setfattr -n trusted.name1 -v value1 $testfile ||
6222                 error "setfattr -n trusted.name1=value1 $testfile failed"
6223         getfattr -n trusted.name1 $testfile 2> /dev/null |
6224           grep "trusted.name1=.value1" ||
6225                 error "$testfile missing trusted.name1=value1"
6226
6227         setfattr -n user.author1 -v author1 $testfile ||
6228                 error "setfattr -n user.author1=author1 $testfile failed"
6229         getfattr -n user.author1 $testfile 2> /dev/null |
6230           grep "user.author1=.author1" ||
6231                 error "$testfile missing trusted.author1=author1"
6232
6233         echo "listxattr..."
6234         setfattr -n trusted.name2 -v value2 $testfile ||
6235                 error "$testfile unable to set trusted.name2"
6236         setfattr -n trusted.name3 -v value3 $testfile ||
6237                 error "$testfile unable to set trusted.name3"
6238         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6239             grep "trusted.name" | wc -l) -eq 3 ] ||
6240                 error "$testfile missing 3 trusted.name xattrs"
6241
6242         setfattr -n user.author2 -v author2 $testfile ||
6243                 error "$testfile unable to set user.author2"
6244         setfattr -n user.author3 -v author3 $testfile ||
6245                 error "$testfile unable to set user.author3"
6246         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6247             grep "user.author" | wc -l) -eq 3 ] ||
6248                 error "$testfile missing 3 user.author xattrs"
6249
6250         echo "remove xattr..."
6251         setfattr -x trusted.name1 $testfile ||
6252                 error "$testfile error deleting trusted.name1"
6253         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6254                 error "$testfile did not delete trusted.name1 xattr"
6255
6256         setfattr -x user.author1 $testfile ||
6257                 error "$testfile error deleting user.author1"
6258         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6259                 error "$testfile did not delete trusted.name1 xattr"
6260
6261         # b10667: setting lustre special xattr be silently discarded
6262         echo "set lustre special xattr ..."
6263         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6264                 error "$testfile allowed setting trusted.lov"
6265 }
6266 run_test 102a "user xattr test =================================="
6267
6268 test_102b() {
6269         # b10930: get/set/list trusted.lov xattr
6270         echo "get/set/list trusted.lov xattr ..."
6271         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6272         local testfile=$DIR/$tfile
6273         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6274                 error "setstripe failed"
6275         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6276                 error "getstripe failed"
6277         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
6278         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
6279
6280         local testfile2=${testfile}2
6281         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
6282                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
6283
6284         $MCREATE $testfile2
6285         setfattr -n trusted.lov -v $value $testfile2
6286         local stripe_size=$($GETSTRIPE -S $testfile2)
6287         local stripe_count=$($GETSTRIPE -c $testfile2)
6288         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6289         [ $stripe_count -eq $STRIPECOUNT ] ||
6290                 error "stripe count $stripe_count != $STRIPECOUNT"
6291         rm -f $DIR/$tfile
6292 }
6293 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6294
6295 test_102c() {
6296         # b10930: get/set/list lustre.lov xattr
6297         echo "get/set/list lustre.lov xattr ..."
6298         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6299         test_mkdir -p $DIR/$tdir
6300         chown $RUNAS_ID $DIR/$tdir
6301         local testfile=$DIR/$tdir/$tfile
6302         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6303                 error "setstripe failed"
6304         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6305                 error "getstripe failed"
6306         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6307         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6308
6309         local testfile2=${testfile}2
6310         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6311                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6312
6313         $RUNAS $MCREATE $testfile2
6314         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6315         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6316         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6317         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6318         [ $stripe_count -eq $STRIPECOUNT ] ||
6319                 error "stripe count $stripe_count != $STRIPECOUNT"
6320 }
6321 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6322
6323 compare_stripe_info1() {
6324         local stripe_index_all_zero=true
6325
6326         for num in 1 2 3 4; do
6327                 for count in $(seq 1 $STRIPE_COUNT); do
6328                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6329                                 local size=$((STRIPE_SIZE * num))
6330                                 local file=file"$num-$offset-$count"
6331                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6332                                 [ $stripe_size -ne $size ] &&
6333                                     error "$file: size $stripe_size != $size"
6334                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6335                                 # allow fewer stripes to be created, ORI-601
6336                                 [ $stripe_count -lt $(((3 * count + 3) / 4)) ]&&
6337                                     error "$file: count $stripe_count != $count"
6338                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6339                                 [ $stripe_index -ne 0 ] &&
6340                                         stripe_index_all_zero=false
6341                         done
6342                 done
6343         done
6344         $stripe_index_all_zero &&
6345                 error "all files are being extracted starting from OST index 0"
6346         return 0
6347 }
6348
6349 find_lustre_tar() {
6350         [ -n "$(which tar 2>/dev/null)" ] &&
6351                 strings $(which tar) | grep -q "lustre" && echo tar
6352 }
6353
6354 test_102d() {
6355         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6356         # b10930: tar test for trusted.lov xattr
6357         TAR=$(find_lustre_tar)
6358         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6359         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6360         setup_test102
6361         test_mkdir -p $DIR/d102d
6362         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6363         cd $DIR/d102d/$tdir
6364         compare_stripe_info1
6365 }
6366 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6367
6368 test_102f() {
6369         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6370         # b10930: tar test for trusted.lov xattr
6371         TAR=$(find_lustre_tar)
6372         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6373         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6374         setup_test102
6375         test_mkdir -p $DIR/d102f
6376         cd $DIR
6377         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6378         cd $DIR/d102f/$tdir
6379         compare_stripe_info1
6380 }
6381 run_test 102f "tar copy files, not keep osts ==========="
6382
6383 grow_xattr() {
6384         local xsize=${1:-1024}  # in bytes
6385         local file=$DIR/$tfile
6386
6387         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6388                 skip "must have user_xattr" && return 0
6389         [ -z "$(which setfattr 2>/dev/null)" ] &&
6390                 skip_env "could not find setfattr" && return 0
6391         [ -z "$(which getfattr 2>/dev/null)" ] &&
6392                 skip_env "could not find getfattr" && return 0
6393
6394         touch $file
6395
6396         local value="$(generate_string $xsize)"
6397
6398         local xbig=trusted.big
6399         log "save $xbig on $file"
6400         setfattr -n $xbig -v $value $file ||
6401                 error "saving $xbig on $file failed"
6402
6403         local orig=$(get_xattr_value $xbig $file)
6404         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6405
6406         local xsml=trusted.sml
6407         log "save $xsml on $file"
6408         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6409
6410         local new=$(get_xattr_value $xbig $file)
6411         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6412
6413         log "grow $xsml on $file"
6414         setfattr -n $xsml -v "$value" $file ||
6415                 error "growing $xsml on $file failed"
6416
6417         new=$(get_xattr_value $xbig $file)
6418         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6419         log "$xbig still valid after growing $xsml"
6420
6421         rm -f $file
6422 }
6423
6424 test_102h() { # bug 15777
6425         grow_xattr 1024
6426 }
6427 run_test 102h "grow xattr from inside inode to external block"
6428
6429 test_102ha() {
6430         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6431         grow_xattr $(max_xattr_size)
6432 }
6433 run_test 102ha "grow xattr from inside inode to external inode"
6434
6435 test_102i() { # bug 17038
6436         touch $DIR/$tfile
6437         ln -s $DIR/$tfile $DIR/${tfile}link
6438         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
6439         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 | grep -i "no such attr" || error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6440         rm -f $DIR/$tfile $DIR/${tfile}link
6441 }
6442 run_test 102i "lgetxattr test on symbolic link ============"
6443
6444 test_102j() {
6445         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6446         TAR=$(find_lustre_tar)
6447         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6448         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6449         setup_test102 "$RUNAS"
6450         test_mkdir -p $DIR/d102j
6451         chown $RUNAS_ID $DIR/d102j
6452         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6453         cd $DIR/d102j/$tdir
6454         compare_stripe_info1 "$RUNAS"
6455 }
6456 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6457
6458 test_102k() {
6459         touch $DIR/$tfile
6460         # b22187 just check that does not crash for regular file.
6461         setfattr -n trusted.lov $DIR/$tfile
6462         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6463         local test_kdir=$DIR/d102k
6464         test_mkdir $test_kdir
6465         local default_size=`$GETSTRIPE -S $test_kdir`
6466         local default_count=`$GETSTRIPE -c $test_kdir`
6467         local default_offset=`$GETSTRIPE -i $test_kdir`
6468         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6469                 error 'dir setstripe failed'
6470         setfattr -n trusted.lov $test_kdir
6471         local stripe_size=`$GETSTRIPE -S $test_kdir`
6472         local stripe_count=`$GETSTRIPE -c $test_kdir`
6473         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6474         [ $stripe_size -eq $default_size ] ||
6475                 error "stripe size $stripe_size != $default_size"
6476         [ $stripe_count -eq $default_count ] ||
6477                 error "stripe count $stripe_count != $default_count"
6478         [ $stripe_offset -eq $default_offset ] ||
6479                 error "stripe offset $stripe_offset != $default_offset"
6480         rm -rf $DIR/$tfile $test_kdir
6481 }
6482 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6483
6484 test_102l() {
6485         # LU-532 trusted. xattr is invisible to non-root
6486         local testfile=$DIR/$tfile
6487
6488         touch $testfile
6489
6490         echo "listxattr as user..."
6491         chown $RUNAS_ID $testfile
6492         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6493             grep -q "trusted" &&
6494                 error "$testfile trusted xattrs are user visible"
6495
6496         return 0;
6497 }
6498 run_test 102l "listxattr size test =================================="
6499
6500 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6501         local path=$DIR/$tfile
6502         touch $path
6503
6504         listxattr_size_check $path || error "listattr_size_check $path failed"
6505 }
6506 run_test 102m "Ensure listxattr fails on small bufffer ========"
6507
6508 cleanup_test102
6509
6510 getxattr() { # getxattr path name
6511         # Return the base64 encoding of the value of xattr name on path.
6512         local path=$1
6513         local name=$2
6514
6515         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6516         # file: $path
6517         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6518         #
6519         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6520
6521         getfattr --absolute-names --encoding=base64 --name=$name $path |
6522                 awk -F= -v name=$name '$1 == name {
6523                         print substr($0, index($0, "=") + 1);
6524         }'
6525 }
6526
6527 test_102n() { # LU-4101 mdt: protect internal xattrs
6528         local file0=$DIR/$tfile.0
6529         local file1=$DIR/$tfile.1
6530         local xattr0=$TMP/$tfile.0
6531         local xattr1=$TMP/$tfile.1
6532         local name
6533         local value
6534
6535         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6536         then
6537                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6538                 return
6539         fi
6540
6541         rm -rf $file0 $file1 $xattr0 $xattr1
6542         touch $file0 $file1
6543
6544         # Get 'before' xattrs of $file1.
6545         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6546
6547         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6548                 # Try to copy xattr from $file0 to $file1.
6549                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6550
6551                 setfattr --name=trusted.$name --value="$value" $file1 ||
6552                         error "setxattr 'trusted.$name' failed"
6553
6554                 # Try to set a garbage xattr.
6555                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6556
6557                 setfattr --name=trusted.$name --value="$value" $file1 ||
6558                         error "setxattr 'trusted.$name' failed"
6559
6560                 # Try to remove the xattr from $file1. We don't care if this
6561                 # appears to succeed or fail, we just don't want there to be
6562                 # any changes or crashes.
6563                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6564         done
6565
6566         # Get 'after' xattrs of file1.
6567         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6568
6569         if ! diff $xattr0 $xattr1; then
6570                 error "before and after xattrs of '$file1' differ"
6571         fi
6572
6573         rm -rf $file0 $file1 $xattr0 $xattr1
6574
6575         return 0
6576 }
6577 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6578
6579 test_102p() { # LU-4703 setxattr did not check ownership
6580         local testfile=$DIR/$tfile
6581
6582         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6583                 skip "MDS needs to be at least 2.5.56" && return
6584
6585         touch $testfile
6586
6587         echo "setfacl as user..."
6588         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6589         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6590
6591         echo "setfattr as user..."
6592         setfacl -m "u:$RUNAS_ID:---" $testfile
6593         $RUNAS setfattr -x system.posix_acl_access $testfile
6594         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6595 }
6596 run_test 102p "check setxattr(2) correctly fails without permission"
6597
6598 run_acl_subtest()
6599 {
6600     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6601     return $?
6602 }
6603
6604 test_103 () {
6605         [ "$UID" != 0 ] && skip_env "must run as root" && return
6606         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6607                 skip "must have acl enabled" && return
6608         [ -z "$(which setfacl 2>/dev/null)" ] &&
6609                 skip_env "could not find setfacl" && return
6610         $GSS && skip "could not run under gss" && return
6611
6612         declare -a identity_old
6613
6614         for num in $(seq $MDSCOUNT); do
6615                 switch_identity $num true || identity_old[$num]=$?
6616         done
6617
6618         SAVE_UMASK=$(umask)
6619         umask 0022
6620         cd $DIR
6621
6622         echo "performing cp ..."
6623         run_acl_subtest cp || error "run_acl_subtest cp failed"
6624         echo "performing getfacl-noacl..."
6625         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6626         echo "performing misc..."
6627         run_acl_subtest misc || error  "misc test failed"
6628         echo "performing permissions..."
6629         run_acl_subtest permissions || error "permissions failed"
6630         echo "performing setfacl..."
6631         run_acl_subtest setfacl || error  "setfacl test failed"
6632
6633         # inheritance test got from HP
6634         echo "performing inheritance..."
6635         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6636         chmod +x make-tree || error "chmod +x failed"
6637         run_acl_subtest inheritance || error "inheritance test failed"
6638         rm -f make-tree
6639
6640         echo "LU-974 ignore umask when acl is enabled..."
6641         run_acl_subtest 974 || error "LU-974 umask test failed"
6642         if [ $MDSCOUNT -ge 2 ]; then
6643                 run_acl_subtest 974_remote ||
6644                         error "LU-974 umask test failed under remote dir"
6645         fi
6646
6647         echo "LU-2561 newly created file is same size as directory..."
6648         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6649                 run_acl_subtest 2561 || error "LU-2561 test failed"
6650         else
6651                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6652         fi
6653
6654         cd $SAVE_PWD
6655         umask $SAVE_UMASK
6656
6657         for num in $(seq $MDSCOUNT); do
6658                 if [ "${identity_old[$num]}" = 1 ]; then
6659                         switch_identity $num false || identity_old[$num]=$?
6660                 fi
6661         done
6662 }
6663 run_test 103 "acl test ========================================="
6664
6665 test_104a() {
6666         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6667         touch $DIR/$tfile
6668         lfs df || error "lfs df failed"
6669         lfs df -ih || error "lfs df -ih failed"
6670         lfs df -h $DIR || error "lfs df -h $DIR failed"
6671         lfs df -i $DIR || error "lfs df -i $DIR failed"
6672         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6673         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6674
6675         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6676         lctl --device %$OSC deactivate
6677         lfs df || error "lfs df with deactivated OSC failed"
6678         lctl --device %$OSC activate
6679         # wait the osc back to normal
6680         wait_osc_import_state client ost FULL
6681
6682         lfs df || error "lfs df with reactivated OSC failed"
6683         rm -f $DIR/$tfile
6684 }
6685 run_test 104a "lfs df [-ih] [path] test ========================="
6686
6687 test_104b() {
6688         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6689         [ $RUNAS_ID -eq $UID ] &&
6690                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6691         chmod 666 /dev/obd
6692         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6693                         grep "Permission denied" | wc -l)))
6694         if [ $denied_cnt -ne 0 ]; then
6695                 error "lfs check servers test failed"
6696         fi
6697 }
6698 run_test 104b "$RUNAS lfs check servers test ===================="
6699
6700 test_105a() {
6701         # doesn't work on 2.4 kernels
6702         touch $DIR/$tfile
6703         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6704                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
6705         else
6706                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
6707         fi
6708         rm -f $DIR/$tfile
6709 }
6710 run_test 105a "flock when mounted without -o flock test ========"
6711
6712 test_105b() {
6713         touch $DIR/$tfile
6714         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6715                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
6716         else
6717                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
6718         fi
6719         rm -f $DIR/$tfile
6720 }
6721 run_test 105b "fcntl when mounted without -o flock test ========"
6722
6723 test_105c() {
6724         touch $DIR/$tfile
6725         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6726                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
6727         else
6728                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
6729         fi
6730         rm -f $DIR/$tfile
6731 }
6732 run_test 105c "lockf when mounted without -o flock test ========"
6733
6734 test_105d() { # bug 15924
6735         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6736         test_mkdir -p $DIR/$tdir
6737         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6738                 skip "mount w/o flock enabled" && return
6739         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
6740         $LCTL set_param fail_loc=0x80000315
6741         flocks_test 2 $DIR/$tdir
6742 }
6743 run_test 105d "flock race (should not freeze) ========"
6744
6745 test_105e() { # bug 22660 && 22040
6746         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6747                 skip "mount w/o flock enabled" && return
6748         touch $DIR/$tfile
6749         flocks_test 3 $DIR/$tfile
6750 }
6751 run_test 105e "Two conflicting flocks from same process ======="
6752
6753 test_106() { #bug 10921
6754         test_mkdir -p $DIR/$tdir
6755         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
6756         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
6757 }
6758 run_test 106 "attempt exec of dir followed by chown of that dir"
6759
6760 test_107() {
6761         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6762         CDIR=`pwd`
6763         cd $DIR
6764
6765         local file=core
6766         rm -f $file
6767
6768         local save_pattern=$(sysctl -n kernel.core_pattern)
6769         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
6770         sysctl -w kernel.core_pattern=$file
6771         sysctl -w kernel.core_uses_pid=0
6772
6773         ulimit -c unlimited
6774         sleep 60 &
6775         SLEEPPID=$!
6776
6777         sleep 1
6778
6779         kill -s 11 $SLEEPPID
6780         wait $SLEEPPID
6781         if [ -e $file ]; then
6782                 size=`stat -c%s $file`
6783                 [ $size -eq 0 ] && error "Fail to create core file $file"
6784         else
6785                 error "Fail to create core file $file"
6786         fi
6787         rm -f $file
6788         sysctl -w kernel.core_pattern=$save_pattern
6789         sysctl -w kernel.core_uses_pid=$save_uses_pid
6790         cd $CDIR
6791 }
6792 run_test 107 "Coredump on SIG"
6793
6794 test_110() {
6795         test_mkdir -p $DIR/$tdir
6796         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
6797                 error "mkdir with 255 char failed"
6798         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
6799                 error "mkdir with 256 char should fail, but did not"
6800         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
6801                 error "create with 255 char failed"
6802         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
6803                 error "create with 256 char should fail, but did not"
6804
6805         ls -l $DIR/$tdir
6806         rm -rf $DIR/$tdir
6807 }
6808 run_test 110 "filename length checking"
6809
6810 test_115() {
6811         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6812         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
6813             cut -c11-20)
6814         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
6815             return
6816         echo "Starting with $OSTIO_pre threads"
6817
6818         NUMTEST=20000
6819         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
6820         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
6821         echo "$NUMTEST creates/unlinks"
6822         test_mkdir -p $DIR/$tdir
6823         createmany -o $DIR/$tdir/$tfile $NUMTEST
6824         unlinkmany $DIR/$tdir/$tfile $NUMTEST
6825
6826         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
6827             cut -c11-20)
6828
6829         # don't return an error
6830         [ $OSTIO_post == $OSTIO_pre ] && echo \
6831             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
6832             echo "This may be fine, depending on what ran before this test" &&
6833             echo "and how fast this system is." && return
6834
6835         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
6836 }
6837 run_test 115 "verify dynamic thread creation===================="
6838
6839 free_min_max () {
6840         wait_delete_completed
6841         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
6842         echo OST kbytes available: ${AVAIL[@]}
6843         MAXI=0; MAXV=${AVAIL[0]}
6844         MINI=0; MINV=${AVAIL[0]}
6845         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
6846             #echo OST $i: ${AVAIL[i]}kb
6847             if [ ${AVAIL[i]} -gt $MAXV ]; then
6848                 MAXV=${AVAIL[i]}; MAXI=$i
6849             fi
6850             if [ ${AVAIL[i]} -lt $MINV ]; then
6851                 MINV=${AVAIL[i]}; MINI=$i
6852             fi
6853         done
6854         echo Min free space: OST $MINI: $MINV
6855         echo Max free space: OST $MAXI: $MAXV
6856 }
6857
6858 test_116a() { # was previously test_116()
6859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6860         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
6861
6862         echo -n "Free space priority "
6863         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
6864                 head -n1
6865         declare -a AVAIL
6866         free_min_max
6867
6868         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
6869         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
6870                 && return
6871         trap simple_cleanup_common EXIT
6872
6873
6874         # Check if we need to generate uneven OSTs
6875         test_mkdir -p $DIR/$tdir/OST${MINI}
6876         local FILL=$(($MINV / 4))
6877         local DIFF=$(($MAXV - $MINV))
6878         local DIFF2=$(($DIFF * 100 / $MINV))
6879
6880         local threshold=$(do_facet $SINGLEMDS \
6881                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
6882         threshold=${threshold%%%}
6883         echo -n "Check for uneven OSTs: "
6884         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
6885
6886         if [ $DIFF2 -gt $threshold ]; then
6887                 echo "ok"
6888                 echo "Don't need to fill OST$MINI"
6889         else
6890                 # generate uneven OSTs. Write 2% over the QOS threshold value
6891                 echo "no"
6892                 DIFF=$(($threshold - $DIFF2 + 2))
6893                 DIFF2=$(( ($MINV * $DIFF)/100 ))
6894                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
6895                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
6896                         error "setstripe failed"
6897                 DIFF=$(($DIFF2 / 2048))
6898                 i=0
6899                 while [ $i -lt $DIFF ]; do
6900                         i=$(($i + 1))
6901                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
6902                                 bs=2M count=1 2>/dev/null
6903                         echo -n .
6904                 done
6905                 echo .
6906                 sync
6907                 sleep_maxage
6908                 free_min_max
6909         fi
6910
6911         DIFF=$(($MAXV - $MINV))
6912         DIFF2=$(($DIFF * 100 / $MINV))
6913         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
6914         if [ $DIFF2 -gt $threshold ]; then
6915                 echo "ok"
6916         else
6917                 echo "failed - QOS mode won't be used"
6918                 skip "QOS imbalance criteria not met"
6919                 simple_cleanup_common
6920                 return
6921         fi
6922
6923         MINI1=$MINI; MINV1=$MINV
6924         MAXI1=$MAXI; MAXV1=$MAXV
6925
6926         # now fill using QOS
6927         $SETSTRIPE -c 1 $DIR/$tdir
6928         FILL=$(($FILL / 200))
6929         if [ $FILL -gt 600 ]; then
6930                 FILL=600
6931         fi
6932         echo "writing $FILL files to QOS-assigned OSTs"
6933         i=0
6934         while [ $i -lt $FILL ]; do
6935                 i=$(($i + 1))
6936                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
6937                         count=1 2>/dev/null
6938                 echo -n .
6939         done
6940         echo "wrote $i 200k files"
6941         sync
6942         sleep_maxage
6943
6944         echo "Note: free space may not be updated, so measurements might be off"
6945         free_min_max
6946         DIFF2=$(($MAXV - $MINV))
6947         echo "free space delta: orig $DIFF final $DIFF2"
6948         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
6949         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
6950         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
6951         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
6952         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
6953         FILL=$(($DIFF2 * 100 / $DIFF - 100))
6954         [ $DIFF -gt 0 ] &&
6955                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
6956
6957         # Figure out which files were written where
6958         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6959                   awk '/'$MINI1': / {print $2; exit}')
6960         echo $UUID
6961         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
6962         echo "$MINC files created on smaller OST $MINI1"
6963         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6964                   awk '/'$MAXI1': / {print $2; exit}')
6965         echo $UUID
6966         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
6967         echo "$MAXC files created on larger OST $MAXI1"
6968         FILL=$(($MAXC * 100 / $MINC - 100))
6969         [ $MINC -gt 0 ] &&
6970                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
6971         [ $MAXC -gt $MINC ] ||
6972                 error_ignore LU-9 "stripe QOS didn't balance free space"
6973         simple_cleanup_common
6974 }
6975 run_test 116a "stripe QOS: free space balance ==================="
6976
6977 test_116b() { # LU-2093
6978         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6979 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
6980         local old_rr
6981         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
6982                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
6983         do_facet $SINGLEMDS lctl set_param \
6984                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
6985         mkdir -p $DIR/$tdir
6986         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
6987         createmany -o $DIR/$tdir/f- 20 || error "can't create"
6988         do_facet $SINGLEMDS lctl set_param fail_loc=0
6989         rm -rf $DIR/$tdir
6990         do_facet $SINGLEMDS lctl set_param \
6991                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
6992 }
6993 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
6994
6995 test_117() # bug 10891
6996 {
6997         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6998         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
6999         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7000         lctl set_param fail_loc=0x21e
7001         > $DIR/$tfile || error "truncate failed"
7002         lctl set_param fail_loc=0
7003         echo "Truncate succeeded."
7004         rm -f $DIR/$tfile
7005 }
7006 run_test 117 "verify osd extend =========="
7007
7008 NO_SLOW_RESENDCOUNT=4
7009 export OLD_RESENDCOUNT=""
7010 set_resend_count () {
7011         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7012         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7013         lctl set_param -n $PROC_RESENDCOUNT $1
7014         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7015 }
7016
7017 # for reduce test_118* time (b=14842)
7018 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7019
7020 # Reset async IO behavior after error case
7021 reset_async() {
7022         FILE=$DIR/reset_async
7023
7024         # Ensure all OSCs are cleared
7025         $SETSTRIPE -c -1 $FILE
7026         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7027         sync
7028         rm $FILE
7029 }
7030
7031 test_118a() #bug 11710
7032 {
7033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7034         reset_async
7035
7036         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7037         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7038         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7039
7040         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7041                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7042                 return 1;
7043         fi
7044         rm -f $DIR/$tfile
7045 }
7046 run_test 118a "verify O_SYNC works =========="
7047
7048 test_118b()
7049 {
7050         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7051         remote_ost_nodsh && skip "remote OST with nodsh" && return
7052
7053         reset_async
7054
7055         #define OBD_FAIL_OST_ENOENT 0x217
7056         set_nodes_failloc "$(osts_nodes)" 0x217
7057         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7058         RC=$?
7059         set_nodes_failloc "$(osts_nodes)" 0
7060         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7061         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7062                     grep -c writeback)
7063
7064         if [[ $RC -eq 0 ]]; then
7065                 error "Must return error due to dropped pages, rc=$RC"
7066                 return 1;
7067         fi
7068
7069         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7070                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7071                 return 1;
7072         fi
7073
7074         echo "Dirty pages not leaked on ENOENT"
7075
7076         # Due to the above error the OSC will issue all RPCs syncronously
7077         # until a subsequent RPC completes successfully without error.
7078         $MULTIOP $DIR/$tfile Ow4096yc
7079         rm -f $DIR/$tfile
7080
7081         return 0
7082 }
7083 run_test 118b "Reclaim dirty pages on fatal error =========="
7084
7085 test_118c()
7086 {
7087         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7088
7089         # for 118c, restore the original resend count, LU-1940
7090         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7091                                 set_resend_count $OLD_RESENDCOUNT
7092         remote_ost_nodsh && skip "remote OST with nodsh" && return
7093
7094         reset_async
7095
7096         #define OBD_FAIL_OST_EROFS               0x216
7097         set_nodes_failloc "$(osts_nodes)" 0x216
7098
7099         # multiop should block due to fsync until pages are written
7100         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7101         MULTIPID=$!
7102         sleep 1
7103
7104         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7105                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7106         fi
7107
7108         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7109                     grep -c writeback)
7110         if [[ $WRITEBACK -eq 0 ]]; then
7111                 error "No page in writeback, writeback=$WRITEBACK"
7112         fi
7113
7114         set_nodes_failloc "$(osts_nodes)" 0
7115         wait $MULTIPID
7116         RC=$?
7117         if [[ $RC -ne 0 ]]; then
7118                 error "Multiop fsync failed, rc=$RC"
7119         fi
7120
7121         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7122         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7123                     grep -c writeback)
7124         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7125                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7126         fi
7127
7128         rm -f $DIR/$tfile
7129         echo "Dirty pages flushed via fsync on EROFS"
7130         return 0
7131 }
7132 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7133
7134 # continue to use small resend count to reduce test_118* time (b=14842)
7135 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7136
7137 test_118d()
7138 {
7139         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7140         remote_ost_nodsh && skip "remote OST with nodsh" && return
7141
7142         reset_async
7143
7144         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7145         set_nodes_failloc "$(osts_nodes)" 0x214
7146         # multiop should block due to fsync until pages are written
7147         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7148         MULTIPID=$!
7149         sleep 1
7150
7151         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7152                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7153         fi
7154
7155         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7156                     grep -c writeback)
7157         if [[ $WRITEBACK -eq 0 ]]; then
7158                 error "No page in writeback, writeback=$WRITEBACK"
7159         fi
7160
7161         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7162         set_nodes_failloc "$(osts_nodes)" 0
7163
7164         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7165         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7166                     grep -c writeback)
7167         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7168                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7169         fi
7170
7171         rm -f $DIR/$tfile
7172         echo "Dirty pages gaurenteed flushed via fsync"
7173         return 0
7174 }
7175 run_test 118d "Fsync validation inject a delay of the bulk =========="
7176
7177 test_118f() {
7178         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7179         reset_async
7180
7181         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7182         lctl set_param fail_loc=0x8000040a
7183
7184         # Should simulate EINVAL error which is fatal
7185         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7186         RC=$?
7187         if [[ $RC -eq 0 ]]; then
7188                 error "Must return error due to dropped pages, rc=$RC"
7189         fi
7190
7191         lctl set_param fail_loc=0x0
7192
7193         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7194         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7195         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7196                     grep -c writeback)
7197         if [[ $LOCKED -ne 0 ]]; then
7198                 error "Locked pages remain in cache, locked=$LOCKED"
7199         fi
7200
7201         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7202                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7203         fi
7204
7205         rm -f $DIR/$tfile
7206         echo "No pages locked after fsync"
7207
7208         reset_async
7209         return 0
7210 }
7211 run_test 118f "Simulate unrecoverable OSC side error =========="
7212
7213 test_118g() {
7214         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7215         reset_async
7216
7217         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7218         lctl set_param fail_loc=0x406
7219
7220         # simulate local -ENOMEM
7221         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7222         RC=$?
7223
7224         lctl set_param fail_loc=0
7225         if [[ $RC -eq 0 ]]; then
7226                 error "Must return error due to dropped pages, rc=$RC"
7227         fi
7228
7229         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7230         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7231         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7232                         grep -c writeback)
7233         if [[ $LOCKED -ne 0 ]]; then
7234                 error "Locked pages remain in cache, locked=$LOCKED"
7235         fi
7236
7237         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7238                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7239         fi
7240
7241         rm -f $DIR/$tfile
7242         echo "No pages locked after fsync"
7243
7244         reset_async
7245         return 0
7246 }
7247 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7248
7249 test_118h() {
7250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7251         remote_ost_nodsh && skip "remote OST with nodsh" && return
7252
7253         reset_async
7254
7255         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7256         set_nodes_failloc "$(osts_nodes)" 0x20e
7257         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7258         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7259         RC=$?
7260
7261         set_nodes_failloc "$(osts_nodes)" 0
7262         if [[ $RC -eq 0 ]]; then
7263                 error "Must return error due to dropped pages, rc=$RC"
7264         fi
7265
7266         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7267         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7268         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7269                     grep -c writeback)
7270         if [[ $LOCKED -ne 0 ]]; then
7271                 error "Locked pages remain in cache, locked=$LOCKED"
7272         fi
7273
7274         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7275                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7276         fi
7277
7278         rm -f $DIR/$tfile
7279         echo "No pages locked after fsync"
7280
7281         return 0
7282 }
7283 run_test 118h "Verify timeout in handling recoverables errors  =========="
7284
7285 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7286
7287 test_118i() {
7288         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7289         remote_ost_nodsh && skip "remote OST with nodsh" && return
7290
7291         reset_async
7292
7293         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7294         set_nodes_failloc "$(osts_nodes)" 0x20e
7295
7296         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7297         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7298         PID=$!
7299         sleep 5
7300         set_nodes_failloc "$(osts_nodes)" 0
7301
7302         wait $PID
7303         RC=$?
7304         if [[ $RC -ne 0 ]]; then
7305                 error "got error, but should be not, rc=$RC"
7306         fi
7307
7308         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7309         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7310         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7311         if [[ $LOCKED -ne 0 ]]; then
7312                 error "Locked pages remain in cache, locked=$LOCKED"
7313         fi
7314
7315         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7316                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7317         fi
7318
7319         rm -f $DIR/$tfile
7320         echo "No pages locked after fsync"
7321
7322         return 0
7323 }
7324 run_test 118i "Fix error before timeout in recoverable error  =========="
7325
7326 [ "$SLOW" = "no" ] && set_resend_count 4
7327
7328 test_118j() {
7329         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7330         remote_ost_nodsh && skip "remote OST with nodsh" && return
7331
7332         reset_async
7333
7334         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7335         set_nodes_failloc "$(osts_nodes)" 0x220
7336
7337         # return -EIO from OST
7338         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7339         RC=$?
7340         set_nodes_failloc "$(osts_nodes)" 0x0
7341         if [[ $RC -eq 0 ]]; then
7342                 error "Must return error due to dropped pages, rc=$RC"
7343         fi
7344
7345         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7346         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7347         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7348         if [[ $LOCKED -ne 0 ]]; then
7349                 error "Locked pages remain in cache, locked=$LOCKED"
7350         fi
7351
7352         # in recoverable error on OST we want resend and stay until it finished
7353         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7354                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7355         fi
7356
7357         rm -f $DIR/$tfile
7358         echo "No pages locked after fsync"
7359
7360         return 0
7361 }
7362 run_test 118j "Simulate unrecoverable OST side error =========="
7363
7364 test_118k()
7365 {
7366         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7367         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7368
7369         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7370         set_nodes_failloc "$(osts_nodes)" 0x20e
7371         test_mkdir -p $DIR/$tdir
7372
7373         for ((i=0;i<10;i++)); do
7374                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7375                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7376                 SLEEPPID=$!
7377                 sleep 0.500s
7378                 kill $SLEEPPID
7379                 wait $SLEEPPID
7380         done
7381
7382         set_nodes_failloc "$(osts_nodes)" 0
7383         rm -rf $DIR/$tdir
7384 }
7385 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7386
7387 test_118l()
7388 {
7389         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7390         # LU-646
7391         test_mkdir -p $DIR/$tdir
7392         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7393         rm -rf $DIR/$tdir
7394 }
7395 run_test 118l "fsync dir ========="
7396
7397 test_118m() # LU-3066
7398 {
7399         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7400         test_mkdir -p $DIR/$tdir
7401         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7402         rm -rf $DIR/$tdir
7403 }
7404 run_test 118m "fdatasync dir ========="
7405
7406 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7407
7408 test_119a() # bug 11737
7409 {
7410         BSIZE=$((512 * 1024))
7411         directio write $DIR/$tfile 0 1 $BSIZE
7412         # We ask to read two blocks, which is more than a file size.
7413         # directio will indicate an error when requested and actual
7414         # sizes aren't equeal (a normal situation in this case) and
7415         # print actual read amount.
7416         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7417         if [ "$NOB" != "$BSIZE" ]; then
7418                 error "read $NOB bytes instead of $BSIZE"
7419         fi
7420         rm -f $DIR/$tfile
7421 }
7422 run_test 119a "Short directIO read must return actual read amount"
7423
7424 test_119b() # bug 11737
7425 {
7426         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7427
7428         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7429         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7430         sync
7431         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7432                 error "direct read failed"
7433         rm -f $DIR/$tfile
7434 }
7435 run_test 119b "Sparse directIO read must return actual read amount"
7436
7437 test_119c() # bug 13099
7438 {
7439         BSIZE=1048576
7440         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7441         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7442         rm -f $DIR/$tfile
7443 }
7444 run_test 119c "Testing for direct read hitting hole"
7445
7446 test_119d() # bug 15950
7447 {
7448         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7449         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7450         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7451         BSIZE=1048576
7452         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7453         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7454         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7455         lctl set_param fail_loc=0x40d
7456         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7457         pid_dio=$!
7458         sleep 1
7459         cat $DIR/$tfile > /dev/null &
7460         lctl set_param fail_loc=0
7461         pid_reads=$!
7462         wait $pid_dio
7463         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7464         sleep 2
7465         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7466         error "the read rpcs have not completed in 2s"
7467         rm -f $DIR/$tfile
7468         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7469 }
7470 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7471
7472 test_120a() {
7473         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7474         test_mkdir -p $DIR/$tdir
7475         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7476                skip "no early lock cancel on server" && return 0
7477
7478         lru_resize_disable mdc
7479         lru_resize_disable osc
7480         cancel_lru_locks mdc
7481         # asynchronous object destroy at MDT could cause bl ast to client
7482         cancel_lru_locks osc
7483
7484         stat $DIR/$tdir > /dev/null
7485         can1=$(do_facet $SINGLEMDS \
7486                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7487                awk '/ldlm_cancel/ {print $2}')
7488         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7489                awk '/ldlm_bl_callback/ {print $2}')
7490         test_mkdir -c1 $DIR/$tdir/d1
7491         can2=$(do_facet $SINGLEMDS \
7492                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7493                awk '/ldlm_cancel/ {print $2}')
7494         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7495                awk '/ldlm_bl_callback/ {print $2}')
7496         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7497         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7498         lru_resize_enable mdc
7499         lru_resize_enable osc
7500 }
7501 run_test 120a "Early Lock Cancel: mkdir test"
7502
7503 test_120b() {
7504         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7505         test_mkdir $DIR/$tdir
7506         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7507                skip "no early lock cancel on server" && return 0
7508         lru_resize_disable mdc
7509         lru_resize_disable osc
7510         cancel_lru_locks mdc
7511         stat $DIR/$tdir > /dev/null
7512         can1=$(do_facet $SINGLEMDS \
7513                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7514                awk '/ldlm_cancel/ {print $2}')
7515         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7516                awk '/ldlm_bl_callback/ {print $2}')
7517         touch $DIR/$tdir/f1
7518         can2=$(do_facet $SINGLEMDS \
7519                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7520                awk '/ldlm_cancel/ {print $2}')
7521         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7522                awk '/ldlm_bl_callback/ {print $2}')
7523         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7524         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7525         lru_resize_enable mdc
7526         lru_resize_enable osc
7527 }
7528 run_test 120b "Early Lock Cancel: create test"
7529
7530 test_120c() {
7531         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7532         test_mkdir -c1 $DIR/$tdir
7533         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7534                skip "no early lock cancel on server" && return 0
7535         lru_resize_disable mdc
7536         lru_resize_disable osc
7537         test_mkdir -p -c1 $DIR/$tdir/d1
7538         test_mkdir -p -c1 $DIR/$tdir/d2
7539         touch $DIR/$tdir/d1/f1
7540         cancel_lru_locks mdc
7541         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7542         can1=$(do_facet $SINGLEMDS \
7543                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7544                awk '/ldlm_cancel/ {print $2}')
7545         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7546                awk '/ldlm_bl_callback/ {print $2}')
7547         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7548         can2=$(do_facet $SINGLEMDS \
7549                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7550                awk '/ldlm_cancel/ {print $2}')
7551         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7552                awk '/ldlm_bl_callback/ {print $2}')
7553         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7554         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7555         lru_resize_enable mdc
7556         lru_resize_enable osc
7557 }
7558 run_test 120c "Early Lock Cancel: link test"
7559
7560 test_120d() {
7561         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7562         test_mkdir -p -c1 $DIR/$tdir
7563         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7564                skip "no early lock cancel on server" && return 0
7565         lru_resize_disable mdc
7566         lru_resize_disable osc
7567         touch $DIR/$tdir
7568         cancel_lru_locks mdc
7569         stat $DIR/$tdir > /dev/null
7570         can1=$(do_facet $SINGLEMDS \
7571                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7572                awk '/ldlm_cancel/ {print $2}')
7573         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7574                awk '/ldlm_bl_callback/ {print $2}')
7575         chmod a+x $DIR/$tdir
7576         can2=$(do_facet $SINGLEMDS \
7577                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7578                awk '/ldlm_cancel/ {print $2}')
7579         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7580                awk '/ldlm_bl_callback/ {print $2}')
7581         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7582         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7583         lru_resize_enable mdc
7584         lru_resize_enable osc
7585 }
7586 run_test 120d "Early Lock Cancel: setattr test"
7587
7588 test_120e() {
7589         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7590         test_mkdir -p -c1 $DIR/$tdir
7591         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7592                skip "no early lock cancel on server" && return 0
7593         lru_resize_disable mdc
7594         lru_resize_disable osc
7595         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7596         cancel_lru_locks mdc
7597         cancel_lru_locks osc
7598         dd if=$DIR/$tdir/f1 of=/dev/null
7599         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7600         can1=$(do_facet $SINGLEMDS \
7601                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7602                awk '/ldlm_cancel/ {print $2}')
7603         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7604                awk '/ldlm_bl_callback/ {print $2}')
7605         unlink $DIR/$tdir/f1
7606         can2=$(do_facet $SINGLEMDS \
7607                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7608                awk '/ldlm_cancel/ {print $2}')
7609         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7610                awk '/ldlm_bl_callback/ {print $2}')
7611         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7612         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7613         lru_resize_enable mdc
7614         lru_resize_enable osc
7615 }
7616 run_test 120e "Early Lock Cancel: unlink test"
7617
7618 test_120f() {
7619         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7620         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7621                skip "no early lock cancel on server" && return 0
7622         test_mkdir -p -c1 $DIR/$tdir
7623         lru_resize_disable mdc
7624         lru_resize_disable osc
7625         test_mkdir -p -c1 $DIR/$tdir/d1
7626         test_mkdir -p -c1 $DIR/$tdir/d2
7627         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7628         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7629         cancel_lru_locks mdc
7630         cancel_lru_locks osc
7631         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7632         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7633         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7634         can1=$(do_facet $SINGLEMDS \
7635                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7636                awk '/ldlm_cancel/ {print $2}')
7637         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7638                awk '/ldlm_bl_callback/ {print $2}')
7639         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7640         can2=$(do_facet $SINGLEMDS \
7641                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7642                awk '/ldlm_cancel/ {print $2}')
7643         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7644                awk '/ldlm_bl_callback/ {print $2}')
7645         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7646         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7647         lru_resize_enable mdc
7648         lru_resize_enable osc
7649 }
7650 run_test 120f "Early Lock Cancel: rename test"
7651
7652 test_120g() {
7653         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7654         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7655                skip "no early lock cancel on server" && return 0
7656         lru_resize_disable mdc
7657         lru_resize_disable osc
7658         count=10000
7659         echo create $count files
7660         test_mkdir -p $DIR/$tdir
7661         cancel_lru_locks mdc
7662         cancel_lru_locks osc
7663         t0=`date +%s`
7664
7665         can0=$(do_facet $SINGLEMDS \
7666                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7667                awk '/ldlm_cancel/ {print $2}')
7668         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7669                awk '/ldlm_bl_callback/ {print $2}')
7670         createmany -o $DIR/$tdir/f $count
7671         sync
7672         can1=$(do_facet $SINGLEMDS \
7673                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7674                awk '/ldlm_cancel/ {print $2}')
7675         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7676                awk '/ldlm_bl_callback/ {print $2}')
7677         t1=$(date +%s)
7678         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7679         echo rm $count files
7680         rm -r $DIR/$tdir
7681         sync
7682         can2=$(do_facet $SINGLEMDS \
7683                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7684                awk '/ldlm_cancel/ {print $2}')
7685         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7686                awk '/ldlm_bl_callback/ {print $2}')
7687         t2=$(date +%s)
7688         echo total: $count removes in $((t2-t1))
7689         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7690         sleep 2
7691         # wait for commitment of removal
7692         lru_resize_enable mdc
7693         lru_resize_enable osc
7694 }
7695 run_test 120g "Early Lock Cancel: performance test"
7696
7697 test_121() { #bug #10589
7698         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7699         rm -rf $DIR/$tfile
7700         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
7701 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
7702         lctl set_param fail_loc=0x310
7703         cancel_lru_locks osc > /dev/null
7704         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
7705         lctl set_param fail_loc=0
7706         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
7707 }
7708 run_test 121 "read cancel race ========="
7709
7710 test_123a() { # was test 123, statahead(bug 11401)
7711         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7712         SLOWOK=0
7713         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
7714             log "testing on UP system. Performance may be not as good as expected."
7715                         SLOWOK=1
7716         fi
7717
7718         rm -rf $DIR/$tdir
7719         test_mkdir -p $DIR/$tdir
7720         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
7721         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
7722         MULT=10
7723         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
7724                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
7725
7726                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7727                 lctl set_param -n llite.*.statahead_max 0
7728                 lctl get_param llite.*.statahead_max
7729                 cancel_lru_locks mdc
7730                 cancel_lru_locks osc
7731                 stime=`date +%s`
7732                 time ls -l $DIR/$tdir | wc -l
7733                 etime=`date +%s`
7734                 delta=$((etime - stime))
7735                 log "ls $i files without statahead: $delta sec"
7736                 lctl set_param llite.*.statahead_max=$max
7737
7738                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7739                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
7740                 cancel_lru_locks mdc
7741                 cancel_lru_locks osc
7742                 stime=`date +%s`
7743                 time ls -l $DIR/$tdir | wc -l
7744                 etime=`date +%s`
7745                 delta_sa=$((etime - stime))
7746                 log "ls $i files with statahead: $delta_sa sec"
7747                 lctl get_param -n llite.*.statahead_stats
7748                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7749
7750                 [ $swrong -lt $ewrong ] && log "statahead was stopped, maybe too many locks held!"
7751                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
7752
7753                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7754                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7755                     lctl set_param -n llite.*.statahead_max 0
7756                     lctl get_param llite.*.statahead_max
7757                     cancel_lru_locks mdc
7758                     cancel_lru_locks osc
7759                     stime=`date +%s`
7760                     time ls -l $DIR/$tdir | wc -l
7761                     etime=`date +%s`
7762                     delta=$((etime - stime))
7763                     log "ls $i files again without statahead: $delta sec"
7764                     lctl set_param llite.*.statahead_max=$max
7765                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7766                         if [  $SLOWOK -eq 0 ]; then
7767                                 error "ls $i files is slower with statahead!"
7768                         else
7769                                 log "ls $i files is slower with statahead!"
7770                         fi
7771                         break
7772                     fi
7773                 fi
7774
7775                 [ $delta -gt 20 ] && break
7776                 [ $delta -gt 8 ] && MULT=$((50 / delta))
7777                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
7778         done
7779         log "ls done"
7780
7781         stime=`date +%s`
7782         rm -r $DIR/$tdir
7783         sync
7784         etime=`date +%s`
7785         delta=$((etime - stime))
7786         log "rm -r $DIR/$tdir/: $delta seconds"
7787         log "rm done"
7788         lctl get_param -n llite.*.statahead_stats
7789 }
7790 run_test 123a "verify statahead work"
7791
7792 test_123b () { # statahead(bug 15027)
7793         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7794         test_mkdir -p $DIR/$tdir
7795         createmany -o $DIR/$tdir/$tfile-%d 1000
7796
7797         cancel_lru_locks mdc
7798         cancel_lru_locks osc
7799
7800 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
7801         lctl set_param fail_loc=0x80000803
7802         ls -lR $DIR/$tdir > /dev/null
7803         log "ls done"
7804         lctl set_param fail_loc=0x0
7805         lctl get_param -n llite.*.statahead_stats
7806         rm -r $DIR/$tdir
7807         sync
7808
7809 }
7810 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
7811
7812 test_124a() {
7813         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7814         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
7815                skip "no lru resize on server" && return 0
7816         local NR=2000
7817         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
7818
7819         log "create $NR files at $DIR/$tdir"
7820         createmany -o $DIR/$tdir/f $NR ||
7821                 error "failed to create $NR files in $DIR/$tdir"
7822
7823         cancel_lru_locks mdc
7824         ls -l $DIR/$tdir > /dev/null
7825
7826         local NSDIR=""
7827         local LRU_SIZE=0
7828         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
7829                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
7830                 LRU_SIZE=$(lctl get_param -n $PARAM)
7831                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
7832                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
7833                                                 log "NSDIR=$NSDIR"
7834                         log "NS=$(basename $NSDIR)"
7835                         break
7836                 fi
7837         done
7838
7839         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
7840                 skip "Not enough cached locks created!"
7841                 return 0
7842         fi
7843         log "LRU=$LRU_SIZE"
7844
7845         local SLEEP=30
7846
7847         # We know that lru resize allows one client to hold $LIMIT locks
7848         # for 10h. After that locks begin to be killed by client.
7849         local MAX_HRS=10
7850         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
7851                 log "LIMIT=$LIMIT"
7852
7853         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
7854         # killing locks. Some time was spent for creating locks. This means
7855         # that up to the moment of sleep finish we must have killed some of
7856         # them (10-100 locks). This depends on how fast ther were created.
7857         # Many of them were touched in almost the same moment and thus will
7858         # be killed in groups.
7859         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
7860
7861         # Use $LRU_SIZE_B here to take into account real number of locks
7862         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
7863         local LRU_SIZE_B=$LRU_SIZE
7864         log "LVF=$LVF"
7865         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
7866                 log "OLD_LVF=$OLD_LVF"
7867         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
7868
7869         # Let's make sure that we really have some margin. Client checks
7870         # cached locks every 10 sec.
7871         SLEEP=$((SLEEP+20))
7872         log "Sleep ${SLEEP} sec"
7873         local SEC=0
7874         while ((SEC<$SLEEP)); do
7875                 echo -n "..."
7876                 sleep 5
7877                 SEC=$((SEC+5))
7878                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
7879                 echo -n "$LRU_SIZE"
7880         done
7881         echo ""
7882         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
7883         local LRU_SIZE_A=`lctl get_param -n $NSDIR.lru_size`
7884
7885         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
7886                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
7887                 unlinkmany $DIR/$tdir/f $NR
7888                 return
7889         }
7890
7891         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
7892         log "unlink $NR files at $DIR/$tdir"
7893         unlinkmany $DIR/$tdir/f $NR
7894 }
7895 run_test 124a "lru resize ======================================="
7896
7897 get_max_pool_limit()
7898 {
7899         local limit=`lctl get_param -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit`
7900         local max=0
7901         for l in $limit; do
7902                 if test $l -gt $max; then
7903                         max=$l
7904                 fi
7905         done
7906         echo $max
7907 }
7908
7909 test_124b() {
7910         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7911         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
7912                skip "no lru resize on server" && return 0
7913
7914         LIMIT=`get_max_pool_limit`
7915
7916         NR=$(($(default_lru_size)*20))
7917         if [ $NR -gt $LIMIT ]; then
7918                 log "Limit lock number by $LIMIT locks"
7919                 NR=$LIMIT
7920         fi
7921         lru_resize_disable mdc
7922         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
7923                 error "failed to create $DIR/$tdir/disable_lru_resize"
7924
7925         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
7926         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
7927         cancel_lru_locks mdc
7928         stime=`date +%s`
7929         PID=""
7930         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7931         PID="$PID $!"
7932         sleep 2
7933         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7934         PID="$PID $!"
7935         sleep 2
7936         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7937         PID="$PID $!"
7938         wait $PID
7939         etime=`date +%s`
7940         nolruresize_delta=$((etime-stime))
7941         log "ls -la time: $nolruresize_delta seconds"
7942         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7943         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
7944
7945         lru_resize_enable mdc
7946         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
7947                 error "failed to create $DIR/$tdir/enable_lru_resize"
7948
7949         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
7950         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
7951         cancel_lru_locks mdc
7952         stime=`date +%s`
7953         PID=""
7954         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7955         PID="$PID $!"
7956         sleep 2
7957         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7958         PID="$PID $!"
7959         sleep 2
7960         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7961         PID="$PID $!"
7962         wait $PID
7963         etime=`date +%s`
7964         lruresize_delta=$((etime-stime))
7965         log "ls -la time: $lruresize_delta seconds"
7966         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7967
7968         if [ $lruresize_delta -gt $nolruresize_delta ]; then
7969                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
7970         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
7971                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
7972         else
7973                 log "lru resize performs the same with no lru resize"
7974         fi
7975         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
7976 }
7977 run_test 124b "lru resize (performance test) ======================="
7978
7979 test_125() { # 13358
7980         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7981         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
7982         test_mkdir -p $DIR/d125 || error "mkdir failed"
7983         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
7984         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
7985         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
7986 }
7987 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
7988
7989 test_126() { # bug 12829/13455
7990         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7991         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
7992         $GSS && skip "must run as gss disabled" && return
7993
7994         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
7995         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
7996         rm -f $DIR/$tfile
7997         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
7998 }
7999 run_test 126 "check that the fsgid provided by the client is taken into account"
8000
8001 test_127a() { # bug 15521
8002         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8003         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8004         $LCTL set_param osc.*.stats=0
8005         FSIZE=$((2048 * 1024))
8006         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8007         cancel_lru_locks osc
8008         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8009
8010         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8011         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8012                 echo "got $COUNT $NAME"
8013                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8014                 eval $NAME=$COUNT || error "Wrong proc format"
8015
8016                 case $NAME in
8017                         read_bytes|write_bytes)
8018                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8019                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8020                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8021                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8022                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8023                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8024                                 error "sumsquare is too small: $SUMSQ"
8025                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8026                                 error "sumsquare is too big: $SUMSQ"
8027                         ;;
8028                         *) ;;
8029                 esac
8030         done < $DIR/${tfile}.tmp
8031
8032         #check that we actually got some stats
8033         [ "$read_bytes" ] || error "Missing read_bytes stats"
8034         [ "$write_bytes" ] || error "Missing write_bytes stats"
8035         [ "$read_bytes" != 0 ] || error "no read done"
8036         [ "$write_bytes" != 0 ] || error "no write done"
8037 }
8038 run_test 127a "verify the client stats are sane"
8039
8040 test_127b() { # bug LU-333
8041         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8042         $LCTL set_param llite.*.stats=0
8043         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8044         # perform 2 reads and writes so MAX is different from SUM.
8045         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8046         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8047         cancel_lru_locks osc
8048         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8049         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8050
8051         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8052         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8053                 echo "got $COUNT $NAME"
8054                 eval $NAME=$COUNT || error "Wrong proc format"
8055
8056         case $NAME in
8057                 read_bytes)
8058                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8059                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8060                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8061                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8062                         ;;
8063                 write_bytes)
8064                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8065                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8066                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8067                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8068                         ;;
8069                         *) ;;
8070                 esac
8071         done < $TMP/${tfile}.tmp
8072
8073         #check that we actually got some stats
8074         [ "$read_bytes" ] || error "Missing read_bytes stats"
8075         [ "$write_bytes" ] || error "Missing write_bytes stats"
8076         [ "$read_bytes" != 0 ] || error "no read done"
8077         [ "$write_bytes" != 0 ] || error "no write done"
8078 }
8079 run_test 127b "verify the llite client stats are sane"
8080
8081 test_128() { # bug 15212
8082         touch $DIR/$tfile
8083         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8084                 find $DIR/$tfile
8085                 find $DIR/$tfile
8086         EOF
8087
8088         result=$(grep error $TMP/$tfile.log)
8089         rm -f $DIR/$tfile
8090         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8091 }
8092 run_test 128 "interactive lfs for 2 consecutive find's"
8093
8094 set_dir_limits () {
8095         local mntdev
8096         local canondev
8097         local node
8098
8099         local LDPROC=/proc/fs/ldiskfs
8100         local facets=$(get_facets MDS)
8101
8102         for facet in ${facets//,/ }; do
8103                 canondev=$(ldiskfs_canon \
8104                            *.$(convert_facet2label $facet).mntdev $facet)
8105                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8106                                                 LDPROC=/sys/fs/ldiskfs
8107                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8108         done
8109 }
8110
8111 test_129() {
8112         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8113         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8114                 skip "Only applicable to ldiskfs-based MDTs"
8115                 return
8116         fi
8117         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8118         ENOSPC=28
8119         EFBIG=27
8120
8121         rm -rf $DIR/$tdir
8122         test_mkdir -p $DIR/$tdir
8123
8124         # block size of mds1
8125         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8126         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8127         local MAX=$((MDSBLOCKSIZE * 3))
8128         set_dir_limits $MAX
8129         local I=$(stat -c%s "$DIR/$tdir")
8130         local J=0
8131         local STRIPE_COUNT=1
8132         [ $MDSCOUNT -ge 2 ] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8133         MAX=$((MAX*STRIPE_COUNT))
8134         while [ ! $I -gt $MAX ]; do
8135                 $MULTIOP $DIR/$tdir/$J Oc
8136                 rc=$?
8137                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8138                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8139                 #and EFBIG for previous versions
8140                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8141                         set_dir_limits 0
8142                         echo "return code $rc received as expected"
8143                         multiop $DIR/$tdir/$J Oc ||
8144                                 error_exit "multiop failed w/o dir size limit"
8145
8146                         I=$(stat -c%s "$DIR/$tdir")
8147
8148                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8149                                         $(version_code 2.4.51) ]
8150                         then
8151                                 [ $I -eq $MAX ] && return 0
8152                         else
8153                                 [ $I -gt $MAX ] && return 0
8154                         fi
8155                         error_exit "current dir size $I, previous limit $MAX"
8156                 elif [ $rc -ne 0 ]; then
8157                         set_dir_limits 0
8158                         error_exit "return code $rc received instead of expected " \
8159                                    "$EFBIG or $ENOSPC, files in dir $I"
8160                 fi
8161                 J=$((J+1))
8162                 I=$(stat -c%s "$DIR/$tdir")
8163         done
8164
8165         set_dir_limits 0
8166         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8167 }
8168 run_test 129 "test directory size limit ========================"
8169
8170 OLDIFS="$IFS"
8171 cleanup_130() {
8172         trap 0
8173         IFS="$OLDIFS"
8174 }
8175
8176 test_130a() {
8177         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8178         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8179                 return
8180
8181         trap cleanup_130 EXIT RETURN
8182
8183         local fm_file=$DIR/$tfile
8184         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8185         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8186                 error "dd failed for $fm_file"
8187
8188         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8189         filefrag -ves $fm_file
8190         RC=$?
8191         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8192                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8193         [ $RC != 0 ] && error "filefrag $fm_file failed"
8194
8195         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8196                       grep -v "ext:" | grep -v "found")
8197         lun=$($GETSTRIPE -i $fm_file)
8198
8199         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8200         IFS=$'\n'
8201         tot_len=0
8202         for line in $filefrag_op
8203         do
8204                 frag_lun=`echo $line | cut -d: -f5`
8205                 ext_len=`echo $line | cut -d: -f4`
8206                 if (( $frag_lun != $lun )); then
8207                         cleanup_130
8208                         error "FIEMAP on 1-stripe file($fm_file) failed"
8209                         return
8210                 fi
8211                 (( tot_len += ext_len ))
8212         done
8213
8214         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8215                 cleanup_130
8216                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8217                 return
8218         fi
8219
8220         cleanup_130
8221
8222         echo "FIEMAP on single striped file succeeded"
8223 }
8224 run_test 130a "FIEMAP (1-stripe file)"
8225
8226 test_130b() {
8227         [ "$OSTCOUNT" -lt "2" ] &&
8228                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8229
8230         [ "$OSTCOUNT" -ge "10" ] &&
8231                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8232
8233         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8234         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8235                 return
8236
8237         trap cleanup_130 EXIT RETURN
8238
8239         local fm_file=$DIR/$tfile
8240         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8241         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8242                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8243
8244         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8245                 error "dd failed on $fm_file"
8246
8247         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8248         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8249                       grep -v "ext:" | grep -v "found")
8250
8251         last_lun=$(echo $filefrag_op | cut -d: -f5)
8252
8253         IFS=$'\n'
8254         tot_len=0
8255         num_luns=1
8256         for line in $filefrag_op
8257         do
8258                 frag_lun=`echo $line | cut -d: -f5`
8259                 ext_len=`echo $line | cut -d: -f4`
8260                 if (( $frag_lun != $last_lun )); then
8261                         if (( tot_len != 1024 )); then
8262                                 cleanup_130
8263                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8264                                 return
8265                         else
8266                                 (( num_luns += 1 ))
8267                                 tot_len=0
8268                         fi
8269                 fi
8270                 (( tot_len += ext_len ))
8271                 last_lun=$frag_lun
8272         done
8273         if (( num_luns != 2 || tot_len != 1024 )); then
8274                 cleanup_130
8275                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8276                 return
8277         fi
8278
8279         cleanup_130
8280
8281         echo "FIEMAP on 2-stripe file succeeded"
8282 }
8283 run_test 130b "FIEMAP (2-stripe file)"
8284
8285 test_130c() {
8286         [ "$OSTCOUNT" -lt "2" ] &&
8287                 skip_env "skipping FIEMAP on 2-stripe file" && return
8288
8289         [ "$OSTCOUNT" -ge "10" ] &&
8290                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8291
8292         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8293         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8294                 return
8295
8296         trap cleanup_130 EXIT RETURN
8297
8298         local fm_file=$DIR/$tfile
8299         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8300         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8301                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8302
8303         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8304
8305         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8306         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8307
8308         last_lun=`echo $filefrag_op | cut -d: -f5`
8309
8310         IFS=$'\n'
8311         tot_len=0
8312         num_luns=1
8313         for line in $filefrag_op
8314         do
8315                 frag_lun=`echo $line | cut -d: -f5`
8316                 ext_len=`echo $line | cut -d: -f4`
8317                 if (( $frag_lun != $last_lun )); then
8318                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8319                         if (( logical != 512 )); then
8320                                 cleanup_130
8321                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8322                                 return
8323                         fi
8324                         if (( tot_len != 512 )); then
8325                                 cleanup_130
8326                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8327                                 return
8328                         else
8329                                 (( num_luns += 1 ))
8330                                 tot_len=0
8331                         fi
8332                 fi
8333                 (( tot_len += ext_len ))
8334                 last_lun=$frag_lun
8335         done
8336         if (( num_luns != 2 || tot_len != 512 )); then
8337                 cleanup_130
8338                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8339                 return
8340         fi
8341
8342         cleanup_130
8343
8344         echo "FIEMAP on 2-stripe file with hole succeeded"
8345 }
8346 run_test 130c "FIEMAP (2-stripe file with hole)"
8347
8348 test_130d() {
8349         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8350
8351         [ "$OSTCOUNT" -ge "10" ] &&
8352                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8353
8354         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8355         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8356
8357         trap cleanup_130 EXIT RETURN
8358
8359         local fm_file=$DIR/$tfile
8360         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8361         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8362                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8363
8364         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8365         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8366                 error "dd failed on $fm_file"
8367
8368         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8369         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8370                 grep -v "ext:" | grep -v "found"`
8371
8372         last_lun=`echo $filefrag_op | cut -d: -f5`
8373
8374         IFS=$'\n'
8375         tot_len=0
8376         num_luns=1
8377         for line in $filefrag_op
8378         do
8379                 frag_lun=`echo $line | cut -d: -f5`
8380                 ext_len=`echo $line | cut -d: -f4`
8381                 if (( $frag_lun != $last_lun )); then
8382                         if (( tot_len != 1024 )); then
8383                                 cleanup_130
8384                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8385                                 return
8386                         else
8387                                 (( num_luns += 1 ))
8388                                 tot_len=0
8389                         fi
8390                 fi
8391                 (( tot_len += ext_len ))
8392                 last_lun=$frag_lun
8393         done
8394         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8395                 cleanup_130
8396                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8397                 return
8398         fi
8399
8400         cleanup_130
8401
8402         echo "FIEMAP on N-stripe file succeeded"
8403 }
8404 run_test 130d "FIEMAP (N-stripe file)"
8405
8406 test_130e() {
8407         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8408
8409         [ "$OSTCOUNT" -ge "10" ] &&
8410                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8411
8412         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8413         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8414
8415         trap cleanup_130 EXIT RETURN
8416
8417         local fm_file=$DIR/$tfile
8418         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8419         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8420                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8421
8422         NUM_BLKS=512
8423         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8424         for ((i = 0; i < $NUM_BLKS; i++))
8425         do
8426                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8427         done
8428
8429         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8430         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8431
8432         last_lun=`echo $filefrag_op | cut -d: -f5`
8433
8434         IFS=$'\n'
8435         tot_len=0
8436         num_luns=1
8437         for line in $filefrag_op
8438         do
8439                 frag_lun=`echo $line | cut -d: -f5`
8440                 ext_len=`echo $line | cut -d: -f4`
8441                 if (( $frag_lun != $last_lun )); then
8442                         if (( tot_len != $EXPECTED_LEN )); then
8443                                 cleanup_130
8444                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8445                                 return
8446                         else
8447                                 (( num_luns += 1 ))
8448                                 tot_len=0
8449                         fi
8450                 fi
8451                 (( tot_len += ext_len ))
8452                 last_lun=$frag_lun
8453         done
8454         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8455                 cleanup_130
8456                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8457                 return
8458         fi
8459
8460         cleanup_130
8461
8462         echo "FIEMAP with continuation calls succeeded"
8463 }
8464 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8465
8466 # Test for writev/readv
8467 test_131a() {
8468         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8469         error "writev test failed"
8470         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8471         error "readv failed"
8472         rm -f $DIR/$tfile
8473 }
8474 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8475
8476 test_131b() {
8477         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8478         error "append writev test failed"
8479         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8480         error "append writev test failed"
8481         rm -f $DIR/$tfile
8482 }
8483 run_test 131b "test append writev"
8484
8485 test_131c() {
8486         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8487         error "NOT PASS"
8488 }
8489 run_test 131c "test read/write on file w/o objects"
8490
8491 test_131d() {
8492         rwv -f $DIR/$tfile -w -n 1 1572864
8493         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8494         if [ "$NOB" != 1572864 ]; then
8495                 error "Short read filed: read $NOB bytes instead of 1572864"
8496         fi
8497         rm -f $DIR/$tfile
8498 }
8499 run_test 131d "test short read"
8500
8501 test_131e() {
8502         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8503         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8504         error "read hitting hole failed"
8505         rm -f $DIR/$tfile
8506 }
8507 run_test 131e "test read hitting hole"
8508
8509 get_ost_param() {
8510         local token=$1
8511         local gl_sum=0
8512         for node in $(osts_nodes); do
8513                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8514                 [ x$gl = x"" ] && gl=0
8515                 gl_sum=$((gl_sum + gl))
8516         done
8517         echo $gl_sum
8518 }
8519
8520 som_mode_switch() {
8521         local som=$1
8522         local gl1=$2
8523         local gl2=$3
8524
8525         if [ x$som = x"enabled" ]; then
8526                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8527                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
8528                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8529         else
8530                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8531                 MOUNTOPT="$MOUNTOPT,som_preview"
8532                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8533         fi
8534
8535         # do remount to make new mount-conf parameters actual
8536         echo remounting...
8537         sync
8538         stopall
8539         setupall
8540 }
8541
8542 test_132() { #1028, SOM
8543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8544         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8545         local num=$(get_mds_dir $DIR)
8546         local mymds=mds${num}
8547         local MOUNTOPT_SAVE=$MOUNTOPT
8548
8549         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8550         cancel_lru_locks osc
8551
8552         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8553
8554         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8555         stat $DIR/$tfile >/dev/null
8556         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8557         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8558         rm $DIR/$tfile
8559         som_mode_switch $som1 $gl1 $gl2
8560
8561         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8562         cancel_lru_locks osc
8563
8564         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8565         if [ $som1 == $som2 ]; then
8566             error "som is still "$som2
8567             if [ x$som2 = x"enabled" ]; then
8568                 som2="disabled"
8569             else
8570                 som2="enabled"
8571             fi
8572         fi
8573
8574         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8575         stat $DIR/$tfile >/dev/null
8576         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8577         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8578         som_mode_switch $som2 $gl1 $gl2
8579         MOUNTOPT=$MOUNTOPT_SAVE
8580 }
8581 run_test 132 "som avoids glimpse rpc"
8582
8583 check_stats() {
8584         local res
8585         local count
8586         case $1 in
8587         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8588                  ;;
8589         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8590                  ;;
8591         *) error "Wrong argument $1" ;;
8592         esac
8593         echo $res
8594         count=`echo $res | awk '{print $2}'`
8595         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8596         # if the argument $3 is zero, it means any stat increment is ok.
8597         if [ $3 -gt 0 ] ; then
8598                 [ $count -ne $3 ] && error "The $2 counter on $1 is wrong - expected $3"
8599         fi
8600 }
8601
8602 test_133a() {
8603         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8604         remote_ost_nodsh && skip "remote OST with nodsh" && return
8605         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8606
8607         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8608                 { skip "MDS doesn't support rename stats"; return; }
8609         local testdir=$DIR/${tdir}/stats_testdir
8610         mkdir -p $DIR/${tdir}
8611
8612         # clear stats.
8613         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8614         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8615
8616         # verify mdt stats first.
8617         mkdir ${testdir} || error "mkdir failed"
8618         check_stats $SINGLEMDS "mkdir" 1
8619         touch ${testdir}/${tfile} || "touch failed"
8620         check_stats $SINGLEMDS "open" 1
8621         check_stats $SINGLEMDS "close" 1
8622         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8623         check_stats $SINGLEMDS "mknod" 1
8624         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8625         check_stats $SINGLEMDS "unlink" 1
8626         rm -f ${testdir}/${tfile} || error "file remove failed"
8627         check_stats $SINGLEMDS "unlink" 2
8628
8629         # remove working dir and check mdt stats again.
8630         rmdir ${testdir} || error "rmdir failed"
8631         check_stats $SINGLEMDS "rmdir" 1
8632
8633         local testdir1=$DIR/${tdir}/stats_testdir1
8634         mkdir -p ${testdir}
8635         mkdir -p ${testdir1}
8636         touch ${testdir1}/test1
8637         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8638         check_stats $SINGLEMDS "crossdir_rename" 1
8639
8640         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8641         check_stats $SINGLEMDS "samedir_rename" 1
8642
8643         rm -rf $DIR/${tdir}
8644 }
8645 run_test 133a "Verifying MDT stats ========================================"
8646
8647 test_133b() {
8648         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8649         remote_ost_nodsh && skip "remote OST with nodsh" && return
8650         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8651         local testdir=$DIR/${tdir}/stats_testdir
8652         mkdir -p ${testdir} || error "mkdir failed"
8653         touch ${testdir}/${tfile} || "touch failed"
8654         cancel_lru_locks mdc
8655
8656         # clear stats.
8657         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8658         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8659
8660         # extra mdt stats verification.
8661         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8662         check_stats $SINGLEMDS "setattr" 1
8663         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8664         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8665         then            # LU-1740
8666                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8667                 check_stats $SINGLEMDS "getattr" 1
8668         fi
8669         $LFS df || error "lfs failed"
8670         check_stats $SINGLEMDS "statfs" 1
8671
8672         rm -rf $DIR/${tdir}
8673 }
8674 run_test 133b "Verifying extra MDT stats =================================="
8675
8676 test_133c() {
8677         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8678         remote_ost_nodsh && skip "remote OST with nodsh" && return
8679         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8680         local testdir=$DIR/${tdir}/stats_testdir
8681         test_mkdir -p ${testdir} || error "mkdir failed"
8682
8683         # verify obdfilter stats.
8684         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8685         sync
8686         cancel_lru_locks osc
8687         wait_delete_completed
8688
8689         # clear stats.
8690         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8691         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8692
8693         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
8694         sync
8695         cancel_lru_locks osc
8696         check_stats ost "write" 1
8697
8698         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
8699         check_stats ost "read" 1
8700
8701         > ${testdir}/${tfile} || error "truncate failed"
8702         check_stats ost "punch" 1
8703
8704         rm -f ${testdir}/${tfile} || error "file remove failed"
8705         wait_delete_completed
8706         check_stats ost "destroy" 1
8707
8708         rm -rf $DIR/${tdir}
8709 }
8710 run_test 133c "Verifying OST stats ========================================"
8711
8712 order_2() {
8713     local value=$1
8714     local orig=$value
8715     local order=1
8716
8717     while [ $value -ge 2 ]; do
8718         order=$((order*2))
8719         value=$((value/2))
8720     done
8721
8722     if [ $orig -gt $order ]; then
8723         order=$((order*2))
8724     fi
8725     echo $order
8726 }
8727
8728 size_in_KMGT() {
8729     local value=$1
8730     local size=('K' 'M' 'G' 'T');
8731     local i=0
8732     local size_string=$value
8733
8734     while [ $value -ge 1024 ]; do
8735         if [ $i -gt 3 ]; then
8736             #T is the biggest unit we get here, if that is bigger,
8737             #just return XXXT
8738             size_string=${value}T
8739             break
8740         fi
8741         value=$((value >> 10))
8742         if [ $value -lt 1024 ]; then
8743             size_string=${value}${size[$i]}
8744             break
8745         fi
8746         i=$((i + 1))
8747     done
8748
8749     echo $size_string
8750 }
8751
8752 get_rename_size() {
8753     local size=$1
8754     local context=${2:-.}
8755     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
8756                 grep -A1 $context |
8757                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
8758     echo $sample
8759 }
8760
8761 test_133d() {
8762         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8763         remote_ost_nodsh && skip "remote OST with nodsh" && return
8764         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8765         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8766         { skip "MDS doesn't support rename stats"; return; }
8767
8768         local testdir1=$DIR/${tdir}/stats_testdir1
8769         local testdir2=$DIR/${tdir}/stats_testdir2
8770
8771         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8772
8773         mkdir -p ${testdir1} || error "mkdir failed"
8774         mkdir -p ${testdir2} || error "mkdir failed"
8775
8776         createmany -o $testdir1/test 512 || error "createmany failed"
8777
8778         # check samedir rename size
8779         mv ${testdir1}/test0 ${testdir1}/test_0
8780
8781         local testdir1_size=$(ls -l $DIR/${tdir} |
8782                 awk '/stats_testdir1/ {print $5}')
8783         local testdir2_size=$(ls -l $DIR/${tdir} |
8784                 awk '/stats_testdir2/ {print $5}')
8785
8786         testdir1_size=$(order_2 $testdir1_size)
8787         testdir2_size=$(order_2 $testdir2_size)
8788
8789         testdir1_size=$(size_in_KMGT $testdir1_size)
8790         testdir2_size=$(size_in_KMGT $testdir2_size)
8791
8792         echo "source rename dir size: ${testdir1_size}"
8793         echo "target rename dir size: ${testdir2_size}"
8794
8795         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
8796         eval $cmd || error "$cmd failed"
8797         local samedir=$($cmd | grep 'same_dir')
8798         local same_sample=$(get_rename_size $testdir1_size)
8799         [ -z "$samedir" ] && error "samedir_rename_size count error"
8800         [ "$same_sample" -eq 1 ] || error "samedir_rename_size error $same_sample"
8801         echo "Check same dir rename stats success"
8802
8803         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8804
8805         # check crossdir rename size
8806         mv ${testdir1}/test_0 ${testdir2}/test_0
8807
8808         testdir1_size=$(ls -l $DIR/${tdir} |
8809                 awk '/stats_testdir1/ {print $5}')
8810         testdir2_size=$(ls -l $DIR/${tdir} |
8811                 awk '/stats_testdir2/ {print $5}')
8812
8813         testdir1_size=$(order_2 $testdir1_size)
8814         testdir2_size=$(order_2 $testdir2_size)
8815
8816         testdir1_size=$(size_in_KMGT $testdir1_size)
8817         testdir2_size=$(size_in_KMGT $testdir2_size)
8818
8819         echo "source rename dir size: ${testdir1_size}"
8820         echo "target rename dir size: ${testdir2_size}"
8821
8822         eval $cmd || error "$cmd failed"
8823         local crossdir=$($cmd | grep 'crossdir')
8824         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
8825         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
8826         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
8827         [ "$src_sample" -eq 1 ] || error "crossdir_rename_size error $src_sample"
8828         [ "$tgt_sample" -eq 1 ] || error "crossdir_rename_size error $tgt_sample"
8829         echo "Check cross dir rename stats success"
8830         rm -rf $DIR/${tdir}
8831 }
8832 run_test 133d "Verifying rename_stats ========================================"
8833
8834 test_133e() {
8835         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8836         local testdir=$DIR/${tdir}/stats_testdir
8837         local ctr f0 f1 bs=32768 count=42 sum
8838
8839         remote_ost_nodsh && skip "remote OST with nodsh" && return
8840         mkdir -p ${testdir} || error "mkdir failed"
8841
8842         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8843
8844         for ctr in {write,read}_bytes; do
8845                 sync
8846                 cancel_lru_locks osc
8847
8848                 do_facet ost1 $LCTL set_param -n \
8849                         "obdfilter.*.exports.clear=clear"
8850
8851                 if [ $ctr = write_bytes ]; then
8852                         f0=/dev/zero
8853                         f1=${testdir}/${tfile}
8854                 else
8855                         f0=${testdir}/${tfile}
8856                         f1=/dev/null
8857                 fi
8858
8859                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
8860                         error "dd failed"
8861                 sync
8862                 cancel_lru_locks osc
8863
8864                 sum=$(do_facet ost1 $LCTL get_param \
8865                                 "obdfilter.*.exports.*.stats" | \
8866                           awk -v ctr=$ctr '\
8867                                 BEGIN { sum = 0 }
8868                                 $1 == ctr { sum += $7 }
8869                                 END { print sum }')
8870
8871                 if ((sum != bs * count)); then
8872                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
8873                 fi
8874         done
8875
8876         rm -rf $DIR/${tdir}
8877 }
8878 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
8879
8880 test_133f() {
8881         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
8882         local facet
8883
8884         # First without trusting modes.
8885         find $proc_dirs \
8886                 -exec cat '{}' \; &> /dev/null
8887
8888         # Second verifying readability.
8889         find $proc_dirs \
8890                 -type f \
8891                 -readable \
8892                 -exec cat '{}' \; > /dev/null ||
8893                         error "proc file read failed"
8894
8895         for facet in $SINGLEMDS ost1; do
8896                 do_facet $facet find $proc_dirs \
8897                         -not -name req_history \
8898                         -exec cat '{}' \\\; &> /dev/null
8899
8900             do_facet $facet     find $proc_dirs \
8901                         -not -name req_history \
8902                         -type f \
8903                         -readable \
8904                         -exec cat '{}' \\\; > /dev/null ||
8905                                 error "proc file read failed"
8906         done
8907 }
8908 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
8909
8910 test_140() { #bug-17379
8911         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8912         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
8913         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
8914         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
8915
8916         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
8917         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
8918         local i=0
8919         while i=`expr $i + 1`; do
8920                 test_mkdir -p $i || error "Creating dir $i"
8921                 cd $i || error "Changing to $i"
8922                 ln -s ../stat stat || error "Creating stat symlink"
8923                 # Read the symlink until ELOOP present,
8924                 # not LBUGing the system is considered success,
8925                 # we didn't overrun the stack.
8926                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
8927                 [ $ret -ne 0 ] && {
8928                         if [ $ret -eq 40 ]; then
8929                                 break  # -ELOOP
8930                         else
8931                                 error "Open stat symlink"
8932                                 return
8933                         fi
8934                 }
8935         done
8936         i=`expr $i - 1`
8937         echo "The symlink depth = $i"
8938         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
8939                                         error "Invalid symlink depth"
8940
8941         # Test recursive symlink
8942         ln -s symlink_self symlink_self
8943         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
8944         echo "open symlink_self returns $ret"
8945         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
8946 }
8947 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
8948
8949 test_150() {
8950         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8951         local TF="$TMP/$tfile"
8952
8953         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
8954         cp $TF $DIR/$tfile
8955         cancel_lru_locks osc
8956         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
8957         remount_client $MOUNT
8958         df -P $MOUNT
8959         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
8960
8961         $TRUNCATE $TF 6000
8962         $TRUNCATE $DIR/$tfile 6000
8963         cancel_lru_locks osc
8964         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
8965
8966         echo "12345" >>$TF
8967         echo "12345" >>$DIR/$tfile
8968         cancel_lru_locks osc
8969         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
8970
8971         echo "12345" >>$TF
8972         echo "12345" >>$DIR/$tfile
8973         cancel_lru_locks osc
8974         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
8975
8976         rm -f $TF
8977         true
8978 }
8979 run_test 150 "truncate/append tests"
8980
8981 #LU-2902 roc_hit was not able to read all values from lproc
8982 function roc_hit_init() {
8983         local list=$(comma_list $(osts_nodes))
8984         local dir=$DIR/$tdir-check
8985         local file=$dir/file
8986         local BEFORE
8987         local AFTER
8988         local idx
8989
8990         test_mkdir -p $dir
8991         #use setstripe to do a write to every ost
8992         for i in $(seq 0 $((OSTCOUNT-1))); do
8993                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
8994                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
8995                 idx=$(printf %04x $i)
8996                 BEFORE=$(get_osd_param $list *OST*$idx stats |
8997                     awk '$1 == "cache_access" {sum += $2} END { print sum }')
8998                 if [ -z "$BEFORE" ]; then
8999                         BEFORE=0
9000                 fi
9001
9002                 cancel_lru_locks osc
9003                 cat $file >/dev/null
9004
9005                 AFTER=$(get_osd_param $list *OST*$idx stats |
9006                     awk '$1 == "cache_access" {sum += $2} END { print sum }')
9007
9008                 echo BEFORE:$BEFORE AFTER:$AFTER
9009                 if ! let "AFTER - BEFORE == 4"; then
9010                         rm -rf $dir
9011                         error "roc_hit is not safe to use"
9012                 fi
9013                 rm $file
9014         done
9015
9016         rm -rf $dir
9017 }
9018
9019 function roc_hit() {
9020         local list=$(comma_list $(osts_nodes))
9021         echo $(get_osd_param $list '' stats |
9022                 awk '$1 == "cache_hit" {sum += $2} END { print sum }')
9023 }
9024
9025 function set_cache() {
9026         local on=1
9027
9028         if [ "$2" == "off" ]; then
9029                 on=0;
9030         fi
9031         local list=$(comma_list $(osts_nodes))
9032         set_osd_param $list '' $1_cache_enable $on
9033
9034         cancel_lru_locks osc
9035 }
9036
9037 test_151() {
9038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9039         remote_ost_nodsh && skip "remote OST with nodsh" && return
9040
9041         local CPAGES=3
9042         local list=$(comma_list $(osts_nodes))
9043
9044         # check whether obdfilter is cache capable at all
9045         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9046                 echo "not cache-capable obdfilter"
9047                 return 0
9048         fi
9049
9050         # check cache is enabled on all obdfilters
9051         if get_osd_param $list '' read_cache_enable | grep 0; then
9052                 echo "oss cache is disabled"
9053                 return 0
9054         fi
9055
9056         set_osd_param $list '' writethrough_cache_enable 1
9057
9058         # check write cache is enabled on all obdfilters
9059         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9060                 echo "oss write cache is NOT enabled"
9061                 return 0
9062         fi
9063
9064         roc_hit_init
9065
9066         #define OBD_FAIL_OBD_NO_LRU  0x609
9067         do_nodes $list $LCTL set_param fail_loc=0x609
9068
9069         # pages should be in the case right after write
9070         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9071                 error "dd failed"
9072
9073         local BEFORE=$(roc_hit)
9074         cancel_lru_locks osc
9075         cat $DIR/$tfile >/dev/null
9076         local AFTER=$(roc_hit)
9077
9078         do_nodes $list $LCTL set_param fail_loc=0
9079
9080         if ! let "AFTER - BEFORE == CPAGES"; then
9081                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9082         fi
9083
9084         # the following read invalidates the cache
9085         cancel_lru_locks osc
9086         set_osd_param $list '' read_cache_enable 0
9087         cat $DIR/$tfile >/dev/null
9088
9089         # now data shouldn't be found in the cache
9090         BEFORE=$(roc_hit)
9091         cancel_lru_locks osc
9092         cat $DIR/$tfile >/dev/null
9093         AFTER=$(roc_hit)
9094         if let "AFTER - BEFORE != 0"; then
9095                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9096         fi
9097
9098         set_osd_param $list '' read_cache_enable 1
9099         rm -f $DIR/$tfile
9100 }
9101 run_test 151 "test cache on oss and controls ==============================="
9102
9103 test_152() {
9104         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9105         local TF="$TMP/$tfile"
9106
9107         # simulate ENOMEM during write
9108 #define OBD_FAIL_OST_NOMEM      0x226
9109         lctl set_param fail_loc=0x80000226
9110         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9111         cp $TF $DIR/$tfile
9112         sync || error "sync failed"
9113         lctl set_param fail_loc=0
9114
9115         # discard client's cache
9116         cancel_lru_locks osc
9117
9118         # simulate ENOMEM during read
9119         lctl set_param fail_loc=0x80000226
9120         cmp $TF $DIR/$tfile || error "cmp failed"
9121         lctl set_param fail_loc=0
9122
9123         rm -f $TF
9124 }
9125 run_test 152 "test read/write with enomem ============================"
9126
9127 test_153() {
9128         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9129 }
9130 run_test 153 "test if fdatasync does not crash ======================="
9131
9132 dot_lustre_fid_permission_check() {
9133         local fid=$1
9134         local ffid=$MOUNT/.lustre/fid/$fid
9135         local test_dir=$2
9136
9137         echo "stat fid $fid"
9138         stat $ffid > /dev/null || error "stat $ffid failed."
9139         echo "touch fid $fid"
9140         touch $ffid || error "touch $ffid failed."
9141         echo "write to fid $fid"
9142         cat /etc/hosts > $ffid || error "write $ffid failed."
9143         echo "read fid $fid"
9144         diff /etc/hosts $ffid || error "read $ffid failed."
9145         echo "append write to fid $fid"
9146         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9147         echo "rename fid $fid"
9148         mv $ffid $test_dir/$tfile.1 &&
9149                 error "rename $ffid to $tfile.1 should fail."
9150         touch $test_dir/$tfile.1
9151         mv $test_dir/$tfile.1 $ffid &&
9152                 error "rename $tfile.1 to $ffid should fail."
9153         rm -f $test_dir/$tfile.1
9154         echo "truncate fid $fid"
9155         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9156         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9157                 echo "link fid $fid"
9158                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9159         fi
9160         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9161                 echo "setfacl fid $fid"
9162                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9163                 echo "getfacl fid $fid"
9164                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9165         fi
9166         echo "unlink fid $fid"
9167         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9168         echo "mknod fid $fid"
9169         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9170
9171         fid=[0xf00000400:0x1:0x0]
9172         ffid=$MOUNT/.lustre/fid/$fid
9173
9174         echo "stat non-exist fid $fid"
9175         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9176         echo "write to non-exist fid $fid"
9177         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9178         echo "link new fid $fid"
9179         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9180
9181         mkdir -p $test_dir/$tdir
9182         touch $test_dir/$tdir/$tfile
9183         fid=$($LFS path2fid $test_dir/$tdir)
9184         rc=$?
9185         [ $rc -ne 0 ] &&
9186                 error "error: could not get fid for $test_dir/$dir/$tfile."
9187
9188         ffid=$MOUNT/.lustre/fid/$fid
9189
9190         echo "ls $fid"
9191         ls $ffid > /dev/null || error "ls $ffid failed."
9192         echo "touch $fid/$tfile.1"
9193         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9194
9195         echo "touch $MOUNT/.lustre/fid/$tfile"
9196         touch $MOUNT/.lustre/fid/$tfile && \
9197                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9198
9199         echo "setxattr to $MOUNT/.lustre/fid"
9200         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9201
9202         echo "listxattr for $MOUNT/.lustre/fid"
9203         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9204
9205         echo "delxattr from $MOUNT/.lustre/fid"
9206         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9207
9208         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9209         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9210                 error "touch invalid fid should fail."
9211
9212         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9213         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9214                 error "touch non-normal fid should fail."
9215
9216         echo "rename $tdir to $MOUNT/.lustre/fid"
9217         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9218                 error "rename to $MOUNT/.lustre/fid should fail."
9219
9220         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9221         then            # LU-3547
9222                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9223                 local new_obf_mode=777
9224
9225                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9226                 chmod $new_obf_mode $DIR/.lustre/fid ||
9227                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9228
9229                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9230                 [ $obf_mode -eq $new_obf_mode ] ||
9231                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9232
9233                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9234                 chmod $old_obf_mode $DIR/.lustre/fid ||
9235                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9236         fi
9237
9238         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9239         fid=$($LFS path2fid $test_dir/$tfile-2)
9240         echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9241         cp /etc/passwd $MOUNT/.lustre/fid/$fid &&
9242                 error "create lov data thru .lustre should fail."
9243         echo "cp /etc/passwd $test_dir/$tfile-2"
9244         cp /etc/passwd $test_dir/$tfile-2 ||
9245                 error "copy to $test_dir/$tfile-2 failed."
9246         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9247         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9248                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9249
9250         rm -rf $test_dir/tfile.lnk
9251         rm -rf $test_dir/$tfile-2
9252 }
9253
9254 test_154A() {
9255         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9256                 skip "Need MDS version at least 2.4.1" && return
9257
9258         touch $DIR/$tfile
9259         local FID=$($LFS path2fid $DIR/$tfile)
9260         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9261
9262         # check that we get the same pathname back
9263         local FOUND=$($LFS fid2path $MOUNT $FID)
9264         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9265         [ "$FOUND" != "$DIR/$tfile" ] &&
9266                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9267
9268         rm -rf $DIR/$tfile
9269 }
9270 run_test 154A "lfs path2fid and fid2path basic checks"
9271
9272 test_154a() {
9273         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9274         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9275                 { skip "Need MDS version at least 2.2.51"; return 0; }
9276
9277         cp /etc/hosts $DIR/$tfile
9278
9279         fid=$($LFS path2fid $DIR/$tfile)
9280         rc=$?
9281         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9282
9283         dot_lustre_fid_permission_check "$fid" $DIR ||
9284                 error "dot lustre permission check $fid failed"
9285
9286         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9287
9288         touch $MOUNT/.lustre/file &&
9289                 error "creation is not allowed under .lustre"
9290
9291         mkdir $MOUNT/.lustre/dir &&
9292                 error "mkdir is not allowed under .lustre"
9293
9294         rm -rf $DIR/$tfile
9295 }
9296 run_test 154a "Open-by-FID"
9297
9298 test_154b() {
9299         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9300         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9301                 { skip "Need MDS version at least 2.2.51"; return 0; }
9302
9303         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9304
9305         local remote_dir=$DIR/$tdir/remote_dir
9306         local MDTIDX=1
9307         local rc=0
9308
9309         mkdir -p $DIR/$tdir
9310         $LFS mkdir -i $MDTIDX -c $MDSCOUNT $remote_dir ||
9311                 error "create remote directory failed"
9312
9313         cp /etc/hosts $remote_dir/$tfile
9314
9315         fid=$($LFS path2fid $remote_dir/$tfile)
9316         rc=$?
9317         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9318
9319         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9320                 error "dot lustre permission check $fid failed"
9321         rm -rf $DIR/$tdir
9322 }
9323 run_test 154b "Open-by-FID for remote directory"
9324
9325 test_154c() {
9326         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9327                 skip "Need MDS version at least 2.4.1" && return
9328
9329         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9330         local FID1=$($LFS path2fid $DIR/$tfile.1)
9331         local FID2=$($LFS path2fid $DIR/$tfile.2)
9332         local FID3=$($LFS path2fid $DIR/$tfile.3)
9333
9334         local N=1
9335         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9336                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9337                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9338                 local want=FID$N
9339                 [ "$FID" = "${!want}" ] ||
9340                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9341                 N=$((N + 1))
9342         done
9343
9344         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9345                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9346                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9347                 N=$((N + 1))
9348         done
9349 }
9350 run_test 154c "lfs path2fid and fid2path multiple arguments"
9351
9352 test_154d() {
9353         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9354                 skip "Need MDS version at least 2.5.53" && return
9355
9356         if remote_mds; then
9357                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9358         else
9359                 nid="0@lo"
9360         fi
9361         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9362         local fd
9363         local cmd
9364
9365         rm -f $DIR/$tfile
9366         touch $DIR/$tfile
9367
9368         fid=$($LFS path2fid $DIR/$tfile)
9369         # Open the file
9370         fd=$(free_fd)
9371         cmd="exec $fd<$DIR/$tfile"
9372         eval $cmd
9373         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9374         echo $fid_list | grep $fid
9375         rc=$?
9376
9377         cmd="exec $fd>/dev/null"
9378         eval $cmd
9379         if [ $rc -ne 0 ]; then
9380                 error "FID $fid not found in open files list $fid_list"
9381         fi
9382 }
9383 run_test 154d "Verify open file fid"
9384
9385 test_155_small_load() {
9386     local temp=$TMP/$tfile
9387     local file=$DIR/$tfile
9388
9389     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9390         error "dd of=$temp bs=6096 count=1 failed"
9391     cp $temp $file
9392     cancel_lru_locks osc
9393     cmp $temp $file || error "$temp $file differ"
9394
9395     $TRUNCATE $temp 6000
9396     $TRUNCATE $file 6000
9397     cmp $temp $file || error "$temp $file differ (truncate1)"
9398
9399     echo "12345" >>$temp
9400     echo "12345" >>$file
9401     cmp $temp $file || error "$temp $file differ (append1)"
9402
9403     echo "12345" >>$temp
9404     echo "12345" >>$file
9405     cmp $temp $file || error "$temp $file differ (append2)"
9406
9407     rm -f $temp $file
9408     true
9409 }
9410
9411 test_155_big_load() {
9412     remote_ost_nodsh && skip "remote OST with nodsh" && return
9413     local temp=$TMP/$tfile
9414     local file=$DIR/$tfile
9415
9416     free_min_max
9417     local cache_size=$(do_facet ost$((MAXI+1)) \
9418         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9419     local large_file_size=$((cache_size * 2))
9420
9421     echo "OSS cache size: $cache_size KB"
9422     echo "Large file size: $large_file_size KB"
9423
9424     [ $MAXV -le $large_file_size ] && \
9425         skip_env "max available OST size needs > $large_file_size KB" && \
9426         return 0
9427
9428     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9429
9430     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9431         error "dd of=$temp bs=$large_file_size count=1k failed"
9432     cp $temp $file
9433     ls -lh $temp $file
9434     cancel_lru_locks osc
9435     cmp $temp $file || error "$temp $file differ"
9436
9437     rm -f $temp $file
9438     true
9439 }
9440
9441 test_155a() {
9442         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9443         set_cache read on
9444         set_cache writethrough on
9445         test_155_small_load
9446 }
9447 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9448
9449 test_155b() {
9450         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9451         set_cache read on
9452         set_cache writethrough off
9453         test_155_small_load
9454 }
9455 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9456
9457 test_155c() {
9458         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9459         set_cache read off
9460         set_cache writethrough on
9461         test_155_small_load
9462 }
9463 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9464
9465 test_155d() {
9466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9467         set_cache read off
9468         set_cache writethrough off
9469         test_155_small_load
9470 }
9471 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9472
9473 test_155e() {
9474         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9475         set_cache read on
9476         set_cache writethrough on
9477         test_155_big_load
9478 }
9479 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9480
9481 test_155f() {
9482         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9483         set_cache read on
9484         set_cache writethrough off
9485         test_155_big_load
9486 }
9487 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9488
9489 test_155g() {
9490         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9491         set_cache read off
9492         set_cache writethrough on
9493         test_155_big_load
9494 }
9495 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9496
9497 test_155h() {
9498         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9499         set_cache read off
9500         set_cache writethrough off
9501         test_155_big_load
9502 }
9503 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9504
9505 test_156() {
9506         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9507         local CPAGES=3
9508         local BEFORE
9509         local AFTER
9510         local file="$DIR/$tfile"
9511
9512         [ "$(facet_fstype ost1)" = "zfs" ] &&
9513                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9514                 return
9515
9516         roc_hit_init
9517
9518     log "Turn on read and write cache"
9519     set_cache read on
9520     set_cache writethrough on
9521
9522     log "Write data and read it back."
9523     log "Read should be satisfied from the cache."
9524     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9525     BEFORE=`roc_hit`
9526     cancel_lru_locks osc
9527     cat $file >/dev/null
9528     AFTER=`roc_hit`
9529     if ! let "AFTER - BEFORE == CPAGES"; then
9530         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9531     else
9532         log "cache hits:: before: $BEFORE, after: $AFTER"
9533     fi
9534
9535     log "Read again; it should be satisfied from the cache."
9536     BEFORE=$AFTER
9537     cancel_lru_locks osc
9538     cat $file >/dev/null
9539     AFTER=`roc_hit`
9540     if ! let "AFTER - BEFORE == CPAGES"; then
9541         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9542     else
9543         log "cache hits:: before: $BEFORE, after: $AFTER"
9544     fi
9545
9546
9547     log "Turn off the read cache and turn on the write cache"
9548     set_cache read off
9549     set_cache writethrough on
9550
9551     log "Read again; it should be satisfied from the cache."
9552     BEFORE=`roc_hit`
9553     cancel_lru_locks osc
9554     cat $file >/dev/null
9555     AFTER=`roc_hit`
9556     if ! let "AFTER - BEFORE == CPAGES"; then
9557         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9558     else
9559         log "cache hits:: before: $BEFORE, after: $AFTER"
9560     fi
9561
9562     log "Read again; it should not be satisfied from the cache."
9563     BEFORE=$AFTER
9564     cancel_lru_locks osc
9565     cat $file >/dev/null
9566     AFTER=`roc_hit`
9567     if ! let "AFTER - BEFORE == 0"; then
9568         error "IN CACHE: before: $BEFORE, after: $AFTER"
9569     else
9570         log "cache hits:: before: $BEFORE, after: $AFTER"
9571     fi
9572
9573     log "Write data and read it back."
9574     log "Read should be satisfied from the cache."
9575     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9576     BEFORE=`roc_hit`
9577     cancel_lru_locks osc
9578     cat $file >/dev/null
9579     AFTER=`roc_hit`
9580     if ! let "AFTER - BEFORE == CPAGES"; then
9581         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9582     else
9583         log "cache hits:: before: $BEFORE, after: $AFTER"
9584     fi
9585
9586     log "Read again; it should not be satisfied from the cache."
9587     BEFORE=$AFTER
9588     cancel_lru_locks osc
9589     cat $file >/dev/null
9590     AFTER=`roc_hit`
9591     if ! let "AFTER - BEFORE == 0"; then
9592         error "IN CACHE: before: $BEFORE, after: $AFTER"
9593     else
9594         log "cache hits:: before: $BEFORE, after: $AFTER"
9595     fi
9596
9597
9598     log "Turn off read and write cache"
9599     set_cache read off
9600     set_cache writethrough off
9601
9602     log "Write data and read it back"
9603     log "It should not be satisfied from the cache."
9604     rm -f $file
9605     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9606     cancel_lru_locks osc
9607     BEFORE=`roc_hit`
9608     cat $file >/dev/null
9609     AFTER=`roc_hit`
9610         if ! let "AFTER - BEFORE == 0"; then
9611                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9612         else
9613                 log "cache hits:: before: $BEFORE, after: $AFTER"
9614         fi
9615
9616     log "Turn on the read cache and turn off the write cache"
9617     set_cache read on
9618     set_cache writethrough off
9619
9620     log "Write data and read it back"
9621     log "It should not be satisfied from the cache."
9622     rm -f $file
9623     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9624     BEFORE=`roc_hit`
9625     cancel_lru_locks osc
9626     cat $file >/dev/null
9627     AFTER=`roc_hit`
9628         if ! let "AFTER - BEFORE == 0"; then
9629                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9630         else
9631                 log "cache hits:: before: $BEFORE, after: $AFTER"
9632         fi
9633
9634     log "Read again; it should be satisfied from the cache."
9635     BEFORE=`roc_hit`
9636     cancel_lru_locks osc
9637     cat $file >/dev/null
9638     AFTER=`roc_hit`
9639     if ! let "AFTER - BEFORE == CPAGES"; then
9640         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9641     else
9642         log "cache hits:: before: $BEFORE, after: $AFTER"
9643     fi
9644
9645     rm -f $file
9646 }
9647 run_test 156 "Verification of tunables ============================"
9648
9649 #Changelogs
9650 err17935 () {
9651         if [ $MDSCOUNT -gt 1 ]; then
9652                 error_ignore bz17935 $*
9653         else
9654                 error $*
9655         fi
9656 }
9657
9658 changelog_chmask()
9659 {
9660         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
9661
9662         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
9663
9664         if [ $MASK -eq 1 ]; then
9665                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
9666         else
9667                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
9668         fi
9669 }
9670
9671 changelog_extract_field() {
9672         local mdt=$1
9673         local cltype=$2
9674         local file=$3
9675         local identifier=$4
9676
9677         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
9678                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
9679                 tail -1
9680 }
9681
9682 test_160a() {
9683         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9684         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9685         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9686                 { skip "Need MDS version at least 2.2.0"; return; }
9687
9688         local CL_USERS="mdd.$MDT0.changelog_users"
9689         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9690         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9691         echo "Registered as changelog user $USER"
9692         $GET_CL_USERS | grep -q $USER ||
9693                 error "User $USER not found in changelog_users"
9694
9695         # change something
9696         test_mkdir -p $DIR/$tdir/pics/2008/zachy
9697         touch $DIR/$tdir/pics/2008/zachy/timestamp
9698         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
9699         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
9700         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
9701         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
9702         rm $DIR/$tdir/pics/desktop.jpg
9703
9704         $LFS changelog $MDT0 | tail -5
9705
9706         echo "verifying changelog mask"
9707         changelog_chmask "MKDIR"
9708         changelog_chmask "CLOSE"
9709
9710         test_mkdir -p $DIR/$tdir/pics/zach/sofia
9711         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9712
9713         changelog_chmask "MKDIR"
9714         changelog_chmask "CLOSE"
9715
9716         test_mkdir -p $DIR/$tdir/pics/2008/sofia
9717         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9718
9719         $LFS changelog $MDT0
9720         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
9721         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
9722         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
9723         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
9724
9725         # verify contents
9726         echo "verifying target fid"
9727         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
9728         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
9729         [ "$fidc" == "$fidf" ] ||
9730                 err17935 "fid in changelog $fidc != file fid $fidf"
9731         echo "verifying parent fid"
9732         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
9733         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
9734         [ "$fidc" == "$fidf" ] ||
9735                 err17935 "pfid in changelog $fidc != dir fid $fidf"
9736
9737         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9738         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
9739         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9740         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
9741         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
9742                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
9743
9744         MIN_REC=$($GET_CL_USERS |
9745                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
9746         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
9747         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
9748         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
9749                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
9750
9751         # LU-3446 changelog index reset on MDT restart
9752         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
9753         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9754         $LFS changelog_clear $MDT0 $USER 0
9755         stop $SINGLEMDS || error "Fail to stop MDT."
9756         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
9757         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9758         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
9759         [ $CUR_REC1 == $CUR_REC2 ] ||
9760                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
9761
9762         echo "verifying user deregister"
9763         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9764         $GET_CL_USERS | grep -q $USER &&
9765                 error "User $USER still in changelog_users"
9766
9767         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
9768         if [ $USERS -eq 0 ]; then
9769                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9770                 touch $DIR/$tdir/chloe
9771                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9772                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
9773                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
9774         else
9775                 echo "$USERS other changelog users; can't verify off"
9776         fi
9777 }
9778 run_test 160a "changelog sanity"
9779
9780 test_160b() { # LU-3587
9781         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9782         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9783         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9784                 { skip "Need MDS version at least 2.2.0"; return; }
9785
9786         local CL_USERS="mdd.$MDT0.changelog_users"
9787         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9788         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9789         echo "Registered as changelog user $USER"
9790         $GET_CL_USERS | grep -q $USER ||
9791                 error "User $USER not found in changelog_users"
9792
9793         local LONGNAME1=$(str_repeat a 255)
9794         local LONGNAME2=$(str_repeat b 255)
9795
9796         cd $DIR
9797         echo "creating very long named file"
9798         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
9799         echo "moving very long named file"
9800         mv $LONGNAME1 $LONGNAME2
9801
9802         $LFS changelog $MDT0 | grep RENME
9803
9804         echo "deregistering $USER"
9805         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9806
9807         rm -f $LONGNAME2
9808 }
9809 run_test 160b "Verify that very long rename doesn't crash in changelog"
9810
9811 test_160c() {
9812         local rc=0
9813         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9814
9815         # Registration step
9816         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
9817                 changelog_register -n)
9818
9819         rm -rf $DIR/$tdir
9820         mkdir -p $DIR/$tdir
9821         $MCREATE $DIR/$tdir/foo_160c
9822         changelog_chmask "TRUNC"
9823         $TRUNCATE $DIR/$tdir/foo_160c 200
9824         changelog_chmask "TRUNC"
9825         $TRUNCATE $DIR/$tdir/foo_160c 199
9826         $LFS changelog $MDT0
9827         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
9828         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
9829         $LFS changelog_clear $MDT0 $USER 0
9830
9831         # Deregistration step
9832         echo "deregistering $USER"
9833         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9834 }
9835 run_test 160c "verify that changelog log catch the truncate event"
9836
9837 test_161a() {
9838         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9839         test_mkdir -p -c1 $DIR/$tdir
9840         cp /etc/hosts $DIR/$tdir/$tfile
9841         test_mkdir -c1 $DIR/$tdir/foo1
9842         test_mkdir -c1 $DIR/$tdir/foo2
9843         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
9844         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
9845         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
9846         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
9847         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
9848         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9849                 $LFS fid2path $DIR $FID
9850                 err17935 "bad link ea"
9851         fi
9852     # middle
9853     rm $DIR/$tdir/foo2/zachary
9854     # last
9855     rm $DIR/$tdir/foo2/thor
9856     # first
9857     rm $DIR/$tdir/$tfile
9858     # rename
9859     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
9860     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
9861         then
9862         $LFS fid2path $DIR $FID
9863         err17935 "bad link rename"
9864     fi
9865     rm $DIR/$tdir/foo2/maggie
9866
9867     # overflow the EA
9868     local longname=filename_avg_len_is_thirty_two_
9869     createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
9870         error "failed to hardlink many files"
9871     links=$($LFS fid2path $DIR $FID | wc -l)
9872     echo -n "${links}/1000 links in link EA"
9873     [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
9874     unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
9875         error "failed to unlink many hardlinks"
9876 }
9877 run_test 161a "link ea sanity"
9878
9879 test_161b() {
9880         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9881         [ $MDSCOUNT -lt 2 ] &&
9882                 skip "skipping remote directory test" && return
9883         local MDTIDX=1
9884         local remote_dir=$DIR/$tdir/remote_dir
9885
9886         mkdir -p $DIR/$tdir
9887         $LFS mkdir -i $MDTIDX $remote_dir ||
9888                 error "create remote directory failed"
9889
9890         cp /etc/hosts $remote_dir/$tfile
9891         mkdir -p $remote_dir/foo1
9892         mkdir -p $remote_dir/foo2
9893         ln $remote_dir/$tfile $remote_dir/foo1/sofia
9894         ln $remote_dir/$tfile $remote_dir/foo2/zachary
9895         ln $remote_dir/$tfile $remote_dir/foo1/luna
9896         ln $remote_dir/$tfile $remote_dir/foo2/thor
9897
9898         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
9899                      tr -d ']')
9900         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9901                 $LFS fid2path $DIR $FID
9902                 err17935 "bad link ea"
9903         fi
9904         # middle
9905         rm $remote_dir/foo2/zachary
9906         # last
9907         rm $remote_dir/foo2/thor
9908         # first
9909         rm $remote_dir/$tfile
9910         # rename
9911         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
9912         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
9913         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
9914                 $LFS fid2path $DIR $FID
9915                 err17935 "bad link rename"
9916         fi
9917         rm $remote_dir/foo2/maggie
9918
9919         # overflow the EA
9920         local longname=filename_avg_len_is_thirty_two_
9921         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
9922                 error "failed to hardlink many files"
9923         links=$($LFS fid2path $DIR $FID | wc -l)
9924         echo -n "${links}/1000 links in link EA"
9925         [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
9926         unlinkmany $remote_dir/foo2/$longname 1000 ||
9927         error "failed to unlink many hardlinks"
9928 }
9929 run_test 161b "link ea sanity under remote directory"
9930
9931 test_161c() {
9932         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9933         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
9934                 skip "Need MDS version at least 2.1.5" && return
9935
9936         # define CLF_RENAME_LAST 0x0001
9937         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
9938         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
9939                 changelog_register -n)
9940         rm -rf $DIR/$tdir
9941         mkdir -p $DIR/$tdir
9942         touch $DIR/$tdir/foo_161c
9943         touch $DIR/$tdir/bar_161c
9944         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
9945         $LFS changelog $MDT0 | grep RENME
9946         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
9947                 cut -f5 -d' ')
9948         $LFS changelog_clear $MDT0 $USER 0
9949         if [ x$flags != "x0x1" ]; then
9950                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9951                         $USER
9952                 error "flag $flags is not 0x1"
9953         fi
9954         echo "rename overwrite a target having nlink = 1," \
9955                 "changelog record has flags of $flags"
9956
9957         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
9958         touch $DIR/$tdir/foo_161c
9959         touch $DIR/$tdir/bar_161c
9960         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
9961         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
9962         $LFS changelog $MDT0 | grep RENME
9963         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
9964         $LFS changelog_clear $MDT0 $USER 0
9965         if [ x$flags != "x0x0" ]; then
9966                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9967                         $USER
9968                 error "flag $flags is not 0x0"
9969         fi
9970         echo "rename overwrite a target having nlink > 1," \
9971                 "changelog record has flags of $flags"
9972
9973         # rename doesn't overwrite a target (changelog flag 0x0)
9974         touch $DIR/$tdir/foo_161c
9975         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
9976         $LFS changelog $MDT0 | grep RENME
9977         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
9978         $LFS changelog_clear $MDT0 $USER 0
9979         if [ x$flags != "x0x0" ]; then
9980                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9981                         $USER
9982                 error "flag $flags is not 0x0"
9983         fi
9984         echo "rename doesn't overwrite a target," \
9985                 "changelog record has flags of $flags"
9986
9987         # define CLF_UNLINK_LAST 0x0001
9988         # unlink a file having nlink = 1 (changelog flag 0x1)
9989         rm -f $DIR/$tdir/foo2_161c
9990         $LFS changelog $MDT0 | grep UNLNK
9991         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
9992         $LFS changelog_clear $MDT0 $USER 0
9993         if [ x$flags != "x0x1" ]; then
9994                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9995                         $USER
9996                 error "flag $flags is not 0x1"
9997         fi
9998         echo "unlink a file having nlink = 1," \
9999                 "changelog record has flags of $flags"
10000
10001         # unlink a file having nlink > 1 (changelog flag 0x0)
10002         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10003         rm -f $DIR/$tdir/foobar_161c
10004         $LFS changelog $MDT0 | grep UNLNK
10005         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10006         $LFS changelog_clear $MDT0 $USER 0
10007         if [ x$flags != "x0x0" ]; then
10008                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10009                         $USER
10010                 error "flag $flags is not 0x0"
10011         fi
10012         echo "unlink a file having nlink > 1," \
10013                 "changelog record has flags of $flags"
10014         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10015 }
10016 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10017
10018 check_path() {
10019     local expected=$1
10020     shift
10021     local fid=$2
10022
10023     local path=$(${LFS} fid2path $*)
10024     RC=$?
10025
10026     if [ $RC -ne 0 ]; then
10027         err17935 "path looked up of $expected failed. Error $RC"
10028         return $RC
10029     elif [ "${path}" != "${expected}" ]; then
10030         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10031         return 2
10032     fi
10033     echo "fid $fid resolves to path $path (expected $expected)"
10034 }
10035
10036 test_162() {
10037         # Make changes to filesystem
10038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10039         test_mkdir -p $DIR/$tdir/d2
10040         touch $DIR/$tdir/d2/$tfile
10041         touch $DIR/$tdir/d2/x1
10042         touch $DIR/$tdir/d2/x2
10043         test_mkdir -p $DIR/$tdir/d2/a/b/c
10044         test_mkdir -p $DIR/$tdir/d2/p/q/r
10045         # regular file
10046         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10047         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
10048
10049         # softlink
10050         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10051         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10052         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
10053
10054         # softlink to wrong file
10055         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10056         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10057         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
10058
10059         # hardlink
10060         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10061         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10062         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10063         # fid2path dir/fsname should both work
10064         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
10065         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
10066
10067         # hardlink count: check that there are 2 links
10068         # Doesnt work with CMD yet: 17935
10069         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10070                 err17935 "expected 2 links"
10071
10072         # hardlink indexing: remove the first link
10073         rm $DIR/$tdir/d2/p/q/r/hlink
10074         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
10075
10076         return 0
10077 }
10078 run_test 162 "path lookup sanity"
10079
10080 test_169() {
10081         # do directio so as not to populate the page cache
10082         log "creating a 10 Mb file"
10083         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10084         log "starting reads"
10085         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10086         log "truncating the file"
10087         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10088         log "killing dd"
10089         kill %+ || true # reads might have finished
10090         echo "wait until dd is finished"
10091         wait
10092         log "removing the temporary file"
10093         rm -rf $DIR/$tfile || error "tmp file removal failed"
10094 }
10095 run_test 169 "parallel read and truncate should not deadlock"
10096
10097 test_170() {
10098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10099         $LCTL clear     # bug 18514
10100         $LCTL debug_daemon start $TMP/${tfile}_log_good
10101         touch $DIR/$tfile
10102         $LCTL debug_daemon stop
10103         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10104                error "sed failed to read log_good"
10105
10106         $LCTL debug_daemon start $TMP/${tfile}_log_good
10107         rm -rf $DIR/$tfile
10108         $LCTL debug_daemon stop
10109
10110         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10111                error "lctl df log_bad failed"
10112
10113         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10114         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10115
10116         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10117         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10118
10119         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10120                 error "bad_line good_line1 good_line2 are empty"
10121
10122         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10123         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10124         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10125
10126         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10127         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10128         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10129
10130         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10131                 error "bad_line_new good_line_new are empty"
10132
10133         local expected_good=$((good_line1 + good_line2*2))
10134
10135         rm -f $TMP/${tfile}*
10136         # LU-231, short malformed line may not be counted into bad lines
10137         if [ $bad_line -ne $bad_line_new ] &&
10138                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10139                 error "expected $bad_line bad lines, but got $bad_line_new"
10140                 return 1
10141         fi
10142
10143         if [ $expected_good -ne $good_line_new ]; then
10144                 error "expected $expected_good good lines, but got $good_line_new"
10145                 return 2
10146         fi
10147         true
10148 }
10149 run_test 170 "test lctl df to handle corrupted log ====================="
10150
10151 test_171() { # bug20592
10152         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10153 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10154         $LCTL set_param fail_loc=0x50e
10155         $LCTL set_param fail_val=3000
10156         multiop_bg_pause $DIR/$tfile O_s || true
10157         local MULTIPID=$!
10158         kill -USR1 $MULTIPID
10159         # cause log dump
10160         sleep 3
10161         wait $MULTIPID
10162         if dmesg | grep "recursive fault"; then
10163                 error "caught a recursive fault"
10164         fi
10165         $LCTL set_param fail_loc=0
10166         true
10167 }
10168 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10169
10170 # it would be good to share it with obdfilter-survey/libecho code
10171 setup_obdecho_osc () {
10172         local rc=0
10173         local ost_nid=$1
10174         local obdfilter_name=$2
10175         echo "Creating new osc for $obdfilter_name on $ost_nid"
10176         # make sure we can find loopback nid
10177         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10178
10179         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10180                            ${obdfilter_name}_osc_UUID || rc=2; }
10181         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10182                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10183         return $rc
10184 }
10185
10186 cleanup_obdecho_osc () {
10187         local obdfilter_name=$1
10188         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10189         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10190         return 0
10191 }
10192
10193 obdecho_test() {
10194         local OBD=$1
10195         local node=$2
10196         local pages=${3:-64}
10197         local rc=0
10198         local id
10199
10200         local count=10
10201         local obd_size=$(get_obd_size $node $OBD)
10202         local page_size=$(get_page_size $node)
10203         if [[ -n "$obd_size" ]]; then
10204                 local new_count=$((obd_size / (pages * page_size / 1024)))
10205                 [[ $new_count -ge $count ]] || count=$new_count
10206         fi
10207
10208         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10209         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10210                            rc=2; }
10211         if [ $rc -eq 0 ]; then
10212             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10213             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10214         fi
10215         echo "New object id is $id"
10216         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10217                            rc=4; }
10218         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10219                            "test_brw $count w v $pages $id" || rc=4; }
10220         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10221                            rc=4; }
10222         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10223                                         "cleanup" || rc=5; }
10224         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10225                                         "detach" || rc=6; }
10226         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10227         return $rc
10228 }
10229
10230 test_180a() {
10231         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10232         remote_ost_nodsh && skip "remote OST with nodsh" && return
10233         local rc=0
10234         local rmmod_local=0
10235
10236         if ! module_loaded obdecho; then
10237             load_module obdecho/obdecho
10238             rmmod_local=1
10239         fi
10240
10241         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10242         local host=$(lctl get_param -n osc.$osc.import |
10243                              awk '/current_connection:/ {print $2}' )
10244         local target=$(lctl get_param -n osc.$osc.import |
10245                              awk '/target:/ {print $2}' )
10246         target=${target%_UUID}
10247
10248         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10249         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10250         [[ -n $target ]] && cleanup_obdecho_osc $target
10251         [ $rmmod_local -eq 1 ] && rmmod obdecho
10252         return $rc
10253 }
10254 run_test 180a "test obdecho on osc"
10255
10256 test_180b() {
10257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10258         remote_ost_nodsh && skip "remote OST with nodsh" && return
10259         local rc=0
10260         local rmmod_remote=0
10261
10262         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10263                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10264                       "modprobe obdecho; }" && rmmod_remote=1
10265         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10266         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10267         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10268         return $rc
10269 }
10270 run_test 180b "test obdecho directly on obdfilter"
10271
10272 test_180c() { # LU-2598
10273         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10274         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10275                 skip "Need MDS version at least 2.4.0" && return
10276
10277         local rc=0
10278         local rmmod_remote=false
10279         local pages=16384 # 64MB bulk I/O RPC size
10280         local target
10281
10282         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10283                 rmmod_remote=true || error "failed to load module obdecho"
10284
10285         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10286                 head -n1)
10287         if [[ -n $target ]]; then
10288                 obdecho_test "$target" ost1 "$pages" ||
10289                         rc=${PIPESTATUS[0]}
10290         else
10291                 echo "there is no obdfilter target on ost1"
10292                 rc=2
10293         fi
10294         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10295         return $rc
10296 }
10297 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10298
10299 test_181() { # bug 22177
10300         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10301         # create enough files to index the directory
10302         createmany -o $DIR/$tdir/foobar 4000
10303         # print attributes for debug purpose
10304         lsattr -d .
10305         # open dir
10306         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10307         MULTIPID=$!
10308         # remove the files & current working dir
10309         unlinkmany $DIR/$tdir/foobar 4000
10310         rmdir $DIR/$tdir
10311         kill -USR1 $MULTIPID
10312         wait $MULTIPID
10313         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10314         return 0
10315 }
10316 run_test 181 "Test open-unlinked dir ========================"
10317
10318 test_182() {
10319         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10320         # disable MDC RPC lock wouldn't crash client
10321         local fcount=1000
10322         local tcount=4
10323
10324         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10325 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10326         $LCTL set_param fail_loc=0x804
10327
10328         for (( i=0; i < $tcount; i++ )) ; do
10329                 mkdir $DIR/$tdir/$i
10330                 createmany -o $DIR/$tdir/$i/f- $fcount &
10331         done
10332         wait
10333
10334         for (( i=0; i < $tcount; i++ )) ; do
10335                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10336         done
10337         wait
10338
10339         rm -rf $DIR/$tdir
10340
10341         $LCTL set_param fail_loc=0
10342 }
10343 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10344
10345 test_183() { # LU-2275
10346         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10347                 skip "Need MDS version at least 2.3.56" && return
10348
10349         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10350         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10351         echo aaa > $DIR/$tdir/$tfile
10352
10353 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10354         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10355
10356         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10357         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10358
10359         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10360
10361         # Flush negative dentry cache
10362         touch $DIR/$tdir/$tfile
10363
10364         # We are not checking for any leaked references here, they'll
10365         # become evident next time we do cleanup with module unload.
10366         rm -rf $DIR/$tdir
10367 }
10368 run_test 183 "No crash or request leak in case of strange dispositions ========"
10369
10370 # test suite 184 is for LU-2016, LU-2017
10371 test_184a() {
10372         check_swap_layouts_support && return 0
10373
10374         dir0=$DIR/$tdir/$testnum
10375         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
10376         ref1=/etc/passwd
10377         ref2=/etc/group
10378         file1=$dir0/f1
10379         file2=$dir0/f2
10380         $SETSTRIPE -c1 $file1
10381         cp $ref1 $file1
10382         $SETSTRIPE -c2 $file2
10383         cp $ref2 $file2
10384         gen1=$($GETSTRIPE -g $file1)
10385         gen2=$($GETSTRIPE -g $file2)
10386
10387         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10388         gen=$($GETSTRIPE -g $file1)
10389         [[ $gen1 != $gen ]] ||
10390                 "Layout generation on $file1 does not change"
10391         gen=$($GETSTRIPE -g $file2)
10392         [[ $gen2 != $gen ]] ||
10393                 "Layout generation on $file2 does not change"
10394
10395         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10396         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10397 }
10398 run_test 184a "Basic layout swap"
10399
10400 test_184b() {
10401         check_swap_layouts_support && return 0
10402
10403         dir0=$DIR/$tdir/$testnum
10404         mkdir -p $dir0 || error "creating dir $dir0"
10405         file1=$dir0/f1
10406         file2=$dir0/f2
10407         file3=$dir0/f3
10408         dir1=$dir0/d1
10409         dir2=$dir0/d2
10410         mkdir $dir1 $dir2
10411         $SETSTRIPE -c1 $file1
10412         $SETSTRIPE -c2 $file2
10413         $SETSTRIPE -c1 $file3
10414         chown $RUNAS_ID $file3
10415         gen1=$($GETSTRIPE -g $file1)
10416         gen2=$($GETSTRIPE -g $file2)
10417
10418         $LFS swap_layouts $dir1 $dir2 &&
10419                 error "swap of directories layouts should fail"
10420         $LFS swap_layouts $dir1 $file1 &&
10421                 error "swap of directory and file layouts should fail"
10422         $RUNAS $LFS swap_layouts $file1 $file2 &&
10423                 error "swap of file we cannot write should fail"
10424         $LFS swap_layouts $file1 $file3 &&
10425                 error "swap of file with different owner should fail"
10426         /bin/true # to clear error code
10427 }
10428 run_test 184b "Forbidden layout swap (will generate errors)"
10429
10430 test_184c() {
10431         check_swap_layouts_support && return 0
10432
10433         local dir0=$DIR/$tdir/$testnum
10434         mkdir -p $dir0 || error "creating dir $dir0"
10435
10436         local ref1=$dir0/ref1
10437         local ref2=$dir0/ref2
10438         local file1=$dir0/file1
10439         local file2=$dir0/file2
10440         # create a file large enough for the concurent test
10441         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10442         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10443         echo "ref file size: ref1(`stat -c %s $ref1`), ref2(`stat -c %s $ref2`)"
10444
10445         cp $ref2 $file2
10446         dd if=$ref1 of=$file1 bs=16k &
10447         local DD_PID=$!
10448
10449         # Make sure dd starts to copy file
10450         while [ ! -f $file1 ]; do sleep 0.1; done
10451
10452         $LFS swap_layouts $file1 $file2
10453         local rc=$?
10454         wait $DD_PID
10455         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10456         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10457
10458         # how many bytes copied before swapping layout
10459         local copied=`stat -c %s $file2`
10460         local remaining=`stat -c %s $ref1`
10461         remaining=$((remaining - copied))
10462         echo "Copied $copied bytes before swapping layout..."
10463
10464         cmp -n $copied $file1 $ref2 | grep differ &&
10465                 error "Content mismatch [0, $copied) of ref2 and file1"
10466         cmp -n $copied $file2 $ref1 ||
10467                 error "Content mismatch [0, $copied) of ref1 and file2"
10468         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10469                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10470
10471         # clean up
10472         rm -f $ref1 $ref2 $file1 $file2
10473 }
10474 run_test 184c "Concurrent write and layout swap"
10475
10476 test_184d() {
10477         check_swap_layouts_support && return 0
10478
10479         local file1=$DIR/$tdir/$tfile-1
10480         local file2=$DIR/$tdir/$tfile-2
10481         local file3=$DIR/$tdir/$tfile-3
10482         local lovea1
10483         local lovea2
10484
10485         mkdir -p $DIR/$tdir
10486         touch $file1 || error "create $file1 failed"
10487         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10488                 error "create $file2 failed"
10489         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10490                 error "create $file3 failed"
10491         lovea1=$($LFS getstripe $file1 | sed 1d)
10492
10493         $LFS swap_layouts $file2 $file3 ||
10494                 error "swap $file2 $file3 layouts failed"
10495         $LFS swap_layouts $file1 $file2 ||
10496                 error "swap $file1 $file2 layouts failed"
10497
10498         lovea2=$($LFS getstripe $file2 | sed 1d)
10499         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10500
10501         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10502         [ -z $lovea1 ] || error "$file1 shouldn't have lovea"
10503 }
10504 run_test 184d "allow stripeless layouts swap"
10505
10506
10507 test_185() { # LU-2441
10508         # LU-3553 - no volatile file support in old servers
10509         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10510                 { skip "Need MDS version at least 2.3.60"; return 0; }
10511
10512         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10513         touch $DIR/$tdir/spoo
10514         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10515         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10516                 error "cannot create/write a volatile file"
10517         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10518                 error "FID is still valid after close"
10519
10520         multiop_bg_pause $DIR/$tdir vVw4096_c
10521         local multi_pid=$!
10522
10523         local OLD_IFS=$IFS
10524         IFS=":"
10525         local fidv=($fid)
10526         IFS=$OLD_IFS
10527         # assume that the next FID for this client is sequential, since stdout
10528         # is unfortunately eaten by multiop_bg_pause
10529         local n=$((${fidv[1]} + 1))
10530         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10531         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10532                 error "FID is missing before close"
10533         kill -USR1 $multi_pid
10534         # 1 second delay, so if mtime change we will see it
10535         sleep 1
10536         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10537         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10538 }
10539 run_test 185 "Volatile file support"
10540
10541 test_187a() {
10542         local dir0=$DIR/$tdir/$testnum
10543         mkdir -p $dir0 || error "creating dir $dir0"
10544
10545         local file=$dir0/file1
10546         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10547         local dv1=$($LFS data_version $file)
10548         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10549         local dv2=$($LFS data_version $file)
10550         [[ $dv1 != $dv2 ]] ||
10551                 error "data version did not change on write $dv1 == $dv2"
10552
10553         # clean up
10554         rm -f $file1
10555 }
10556 run_test 187a "Test data version change"
10557
10558 test_187b() {
10559         local dir0=$DIR/$tdir/$testnum
10560         mkdir -p $dir0 || error "creating dir $dir0"
10561
10562         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
10563         [[ ${DV[0]} != ${DV[1]} ]] ||
10564                 error "data version did not change on write"\
10565                       " ${DV[0]} == ${DV[1]}"
10566
10567         # clean up
10568         rm -f $file1
10569 }
10570 run_test 187b "Test data version change on volatile file"
10571
10572 # OST pools tests
10573 check_file_in_pool()
10574 {
10575         local file=$1
10576         local pool=$2
10577         local tlist="$3"
10578         local res=$($GETSTRIPE $file | grep 0x | cut -f2)
10579         for i in $res
10580         do
10581                 for t in $tlist ; do
10582                         [ "$i" -eq "$t" ] && continue 2
10583                 done
10584
10585                 echo "pool list: $tlist"
10586                 echo "striping: $res"
10587                 error_noexit "$file not allocated in $pool"
10588                 return 1
10589         done
10590         return 0
10591 }
10592
10593 pool_add() {
10594         echo "Creating new pool"
10595         local pool=$1
10596
10597         create_pool $FSNAME.$pool ||
10598                 { error_noexit "No pool created, result code $?"; return 1; }
10599         [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
10600                 { error_noexit "$pool not in lfs pool_list"; return 2; }
10601 }
10602
10603 pool_add_targets() {
10604         echo "Adding targets to pool"
10605         local pool=$1
10606         local first=$2
10607         local last=$3
10608         local step=${4:-1}
10609
10610         local list=$(seq $first $step $last)
10611
10612         local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
10613         do_facet mgs $LCTL pool_add \
10614                         $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
10615         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
10616                         | sort -u | tr '\n' ' ' " "$t" || { 
10617                 error_noexit "Add to pool failed"
10618                 return 1
10619         }
10620         local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
10621         local addcount=$(((last - first) / step + 1))
10622         [ $lfscount -eq $addcount ] || {
10623                 error_noexit "lfs pool_list bad ost count" \
10624                                                 "$lfscount != $addcount"
10625                 return 2
10626         }
10627 }
10628
10629 pool_set_dir() {
10630         local pool=$1
10631         local tdir=$2
10632         echo "Setting pool on directory $tdir"
10633
10634         $SETSTRIPE -c 2 -p $pool $tdir && return 0
10635
10636         error_noexit "Cannot set pool $pool to $tdir"
10637         return 1
10638 }
10639
10640 pool_check_dir() {
10641         local pool=$1
10642         local tdir=$2
10643         echo "Checking pool on directory $tdir"
10644
10645         local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
10646         [ "$res" = "$pool" ] && return 0
10647
10648         error_noexit "Pool on '$tdir' is '$res', not '$pool'"
10649         return 1
10650 }
10651
10652 pool_dir_rel_path() {
10653         echo "Testing relative path works well"
10654         local pool=$1
10655         local tdir=$2
10656         local root=$3
10657
10658         mkdir -p $root/$tdir/$tdir
10659         cd $root/$tdir
10660         pool_set_dir $pool $tdir          || return 1
10661         pool_set_dir $pool ./$tdir        || return 2
10662         pool_set_dir $pool ../$tdir       || return 3
10663         pool_set_dir $pool ../$tdir/$tdir || return 4
10664         rm -rf $tdir; cd - > /dev/null
10665 }
10666
10667 pool_alloc_files() {
10668         echo "Checking files allocation from directory pool"
10669         local pool=$1
10670         local tdir=$2
10671         local count=$3
10672         local tlist="$4"
10673
10674         local failed=0
10675         for i in $(seq -w 1 $count)
10676         do
10677                 local file=$tdir/file-$i
10678                 touch $file
10679                 check_file_in_pool $file $pool "$tlist" || \
10680                         failed=$((failed + 1))
10681         done
10682         [ "$failed" = 0 ] && return 0
10683
10684         error_noexit "$failed files not allocated in $pool"
10685         return 1
10686 }
10687
10688 pool_create_files() {
10689         echo "Creating files in pool"
10690         local pool=$1
10691         local tdir=$2
10692         local count=$3
10693         local tlist="$4"
10694
10695         mkdir -p $tdir
10696         local failed=0
10697         for i in $(seq -w 1 $count)
10698         do
10699                 local file=$tdir/spoo-$i
10700                 $SETSTRIPE -p $pool $file
10701                 check_file_in_pool $file $pool "$tlist" || \
10702                         failed=$((failed + 1))
10703         done
10704         [ "$failed" = 0 ] && return 0
10705
10706         error_noexit "$failed files not allocated in $pool"
10707         return 1
10708 }
10709
10710 pool_lfs_df() {
10711         echo "Checking 'lfs df' output"
10712         local pool=$1
10713
10714         local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
10715                         tr '\n' ' ')
10716         local res=$($LFS df --pool $FSNAME.$pool |
10717                         awk '{print $1}' |
10718                         grep "$FSNAME-OST" |
10719                         tr '\n' ' ')
10720         [ "$res" = "$t" ] && return 0
10721
10722         error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
10723         return 1
10724 }
10725
10726 pool_file_rel_path() {
10727         echo "Creating files in a pool with relative pathname"
10728         local pool=$1
10729         local tdir=$2
10730
10731         mkdir -p $tdir ||
10732                 { error_noexit "unable to create $tdir"; return 1 ; }
10733         local file="/..$tdir/$tfile-1"
10734         $SETSTRIPE -p $pool $file ||
10735                 { error_noexit "unable to create $file" ; return 2 ; }
10736
10737         cd $tdir
10738         $SETSTRIPE -p $pool $tfile-2 || {
10739                 error_noexit "unable to create $tfile-2 in $tdir"
10740                 return 3
10741         }
10742 }
10743
10744 pool_remove_first_target() {
10745         echo "Removing first target from a pool"
10746         local pool=$1
10747
10748         local pname="lov.$FSNAME-*.pools.$pool"
10749         local t=$($LCTL get_param -n $pname | head -n1)
10750         do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10751         wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
10752                 error_noexit "$t not removed from $FSNAME.$pool"
10753                 return 1
10754         }
10755 }
10756
10757 pool_remove_all_targets() {
10758         echo "Removing all targets from pool"
10759         local pool=$1
10760         local file=$2
10761         local pname="lov.$FSNAME-*.pools.$pool"
10762         for t in $($LCTL get_param -n $pname | sort -u)
10763         do
10764                 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10765         done
10766         wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
10767                 error_noexit "Pool $FSNAME.$pool cannot be drained"
10768                 return 1
10769         }
10770         # striping on an empty/nonexistant pool should fall back
10771         # to "pool of everything"
10772         touch $file || {
10773                 error_noexit "failed to use fallback striping for empty pool"
10774                 return 2
10775         }
10776         # setstripe on an empty pool should fail
10777         $SETSTRIPE -p $pool $file 2>/dev/null && {
10778                 error_noexit "expected failure when creating file" \
10779                                                         "with empty pool"
10780                 return 3
10781         }
10782         return 0
10783 }
10784
10785 pool_remove() {
10786         echo "Destroying pool"
10787         local pool=$1
10788         local file=$2
10789
10790         do_facet mgs $LCTL pool_destroy $FSNAME.$pool
10791
10792         sleep 2
10793         # striping on an empty/nonexistant pool should fall back 
10794         # to "pool of everything"
10795         touch $file || {
10796                 error_noexit "failed to use fallback striping for missing pool"
10797                 return 1
10798         }
10799         # setstripe on an empty pool should fail
10800         $SETSTRIPE -p $pool $file 2>/dev/null && {
10801                 error_noexit "expected failure when creating file" \
10802                                                         "with missing pool"
10803                 return 2
10804         }
10805
10806         # get param should return err once pool is gone
10807         if wait_update $HOSTNAME "lctl get_param -n \
10808                 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
10809         then
10810                 remove_pool_from_list $FSNAME.$pool
10811                 return 0
10812         fi
10813         error_noexit "Pool $FSNAME.$pool is not destroyed"
10814         return 3
10815 }
10816
10817 test_200() {
10818         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10819         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
10820
10821         local POOL=${POOL:-cea1}
10822         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
10823         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
10824         # Pool OST targets
10825         local first_ost=0
10826         local last_ost=$(($OSTCOUNT - 1))
10827         local ost_step=2
10828         local ost_list=$(seq $first_ost $ost_step $last_ost)
10829         local ost_range="$first_ost $last_ost $ost_step"
10830         local test_path=$POOL_ROOT/$POOL_DIR_NAME
10831         local file_dir=$POOL_ROOT/file_tst
10832
10833         local rc=0
10834         while : ; do
10835                 # former test_200a test_200b
10836                 pool_add $POOL                          || { rc=$? ; break; }
10837                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
10838                 # former test_200c test_200d
10839                 mkdir -p $test_path
10840                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
10841                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
10842                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
10843                                                         || { rc=$? ; break; }
10844                 # former test_200e test_200f
10845                 local files=$((OSTCOUNT*3))
10846                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
10847                                                         || { rc=$? ; break; }
10848                 pool_create_files $POOL $file_dir $files "$ost_list" \
10849                                                         || { rc=$? ; break; }
10850                 # former test_200g test_200h
10851                 pool_lfs_df $POOL                       || { rc=$? ; break; }
10852                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
10853
10854                 # former test_201a test_201b test_201c
10855                 pool_remove_first_target $POOL          || { rc=$? ; break; }
10856
10857                 local f=$test_path/$tfile
10858                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
10859                 pool_remove $POOL $f                    || { rc=$? ; break; }
10860                 break
10861         done
10862
10863         cleanup_pools
10864         return $rc
10865 }
10866 run_test 200 "OST pools"
10867
10868 # usage: default_attr <count | size | offset>
10869 default_attr() {
10870         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
10871 }
10872
10873 # usage: check_default_stripe_attr
10874 check_default_stripe_attr() {
10875         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
10876         case $1 in
10877         --stripe-count|--count)
10878                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
10879         --stripe-size|--size)
10880                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
10881         --stripe-index|--index)
10882                 EXPECTED=-1;;
10883         *)
10884                 error "unknown getstripe attr '$1'"
10885         esac
10886
10887         [ $ACTUAL != $EXPECTED ] &&
10888                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
10889 }
10890
10891 test_204a() {
10892         test_mkdir -p $DIR/$tdir
10893         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
10894
10895         check_default_stripe_attr --stripe-count
10896         check_default_stripe_attr --stripe-size
10897         check_default_stripe_attr --stripe-index
10898
10899         return 0
10900 }
10901 run_test 204a "Print default stripe attributes ================="
10902
10903 test_204b() {
10904         test_mkdir -p $DIR/$tdir
10905         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10906
10907         check_default_stripe_attr --stripe-size
10908         check_default_stripe_attr --stripe-index
10909
10910         return 0
10911 }
10912 run_test 204b "Print default stripe size and offset  ==========="
10913
10914 test_204c() {
10915         test_mkdir -p $DIR/$tdir
10916         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10917
10918         check_default_stripe_attr --stripe-count
10919         check_default_stripe_attr --stripe-index
10920
10921         return 0
10922 }
10923 run_test 204c "Print default stripe count and offset ==========="
10924
10925 test_204d() {
10926         test_mkdir -p $DIR/$tdir
10927         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10928
10929         check_default_stripe_attr --stripe-count
10930         check_default_stripe_attr --stripe-size
10931
10932         return 0
10933 }
10934 run_test 204d "Print default stripe count and size ============="
10935
10936 test_204e() {
10937         test_mkdir -p $DIR/$tdir
10938         $SETSTRIPE -d $DIR/$tdir
10939
10940         check_default_stripe_attr --stripe-count --raw
10941         check_default_stripe_attr --stripe-size --raw
10942         check_default_stripe_attr --stripe-index --raw
10943
10944         return 0
10945 }
10946 run_test 204e "Print raw stripe attributes ================="
10947
10948 test_204f() {
10949         test_mkdir -p $DIR/$tdir
10950         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10951
10952         check_default_stripe_attr --stripe-size --raw
10953         check_default_stripe_attr --stripe-index --raw
10954
10955         return 0
10956 }
10957 run_test 204f "Print raw stripe size and offset  ==========="
10958
10959 test_204g() {
10960         test_mkdir -p $DIR/$tdir
10961         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10962
10963         check_default_stripe_attr --stripe-count --raw
10964         check_default_stripe_attr --stripe-index --raw
10965
10966         return 0
10967 }
10968 run_test 204g "Print raw stripe count and offset ==========="
10969
10970 test_204h() {
10971         test_mkdir -p $DIR/$tdir
10972         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10973
10974         check_default_stripe_attr --stripe-count --raw
10975         check_default_stripe_attr --stripe-size --raw
10976
10977         return 0
10978 }
10979 run_test 204h "Print raw stripe count and size ============="
10980
10981 # Figure out which job scheduler is being used, if any,
10982 # or use a fake one
10983 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
10984         JOBENV=SLURM_JOB_ID
10985 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
10986         JOBENV=LSB_JOBID
10987 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
10988         JOBENV=PBS_JOBID
10989 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
10990         JOBENV=LOADL_STEP_ID
10991 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
10992         JOBENV=JOB_ID
10993 else
10994         JOBENV=FAKE_JOBID
10995 fi
10996
10997 verify_jobstats() {
10998         local cmd=$1
10999         local target=$2
11000
11001         # clear old jobstats
11002         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11003         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11004
11005         # use a new JobID for this test, or we might see an old one
11006         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11007
11008         JOBVAL=${!JOBENV}
11009         log "Test: $cmd"
11010         log "Using JobID environment variable $JOBENV=$JOBVAL"
11011
11012         if [ $JOBENV = "FAKE_JOBID" ]; then
11013                 FAKE_JOBID=$JOBVAL $cmd
11014         else
11015                 $cmd
11016         fi
11017
11018         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11019                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11020                 do_facet $FACET lctl get_param mdt.*.job_stats |
11021                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11022         fi
11023         if [ "$target" = "ost" -o "$target" = "both" ]; then
11024                 FACET=ost1
11025                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11026                         grep $JOBVAL || error "No job stats found on OST $FACET"
11027         fi
11028 }
11029
11030 jobstats_set() {
11031         trap 0
11032         NEW_JOBENV=${1:-$OLD_JOBENV}
11033         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11034         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11035 }
11036
11037 test_205() { # Job stats
11038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11039         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11040                 skip "Server doesn't support jobstats" && return 0
11041
11042         local cmd
11043         OLD_JOBENV=`$LCTL get_param -n jobid_var`
11044         if [ $OLD_JOBENV != $JOBENV ]; then
11045                 jobstats_set $JOBENV
11046                 trap jobstats_set EXIT
11047         fi
11048
11049         # mkdir
11050         cmd="mkdir $DIR/$tfile"
11051         verify_jobstats "$cmd" "mdt"
11052         # rmdir
11053         cmd="rm -fr $DIR/$tfile"
11054         verify_jobstats "$cmd" "mdt"
11055         # mknod
11056         cmd="mknod $DIR/$tfile c 1 3"
11057         verify_jobstats "$cmd" "mdt"
11058         # unlink
11059         cmd="rm -f $DIR/$tfile"
11060         verify_jobstats "$cmd" "mdt"
11061         # open & close
11062         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11063         verify_jobstats "$cmd" "mdt"
11064         # setattr
11065         cmd="touch $DIR/$tfile"
11066         verify_jobstats "$cmd" "both"
11067         # write
11068         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11069         verify_jobstats "$cmd" "ost"
11070         # read
11071         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11072         verify_jobstats "$cmd" "ost"
11073         # truncate
11074         cmd="$TRUNCATE $DIR/$tfile 0"
11075         verify_jobstats "$cmd" "both"
11076         # rename
11077         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11078         verify_jobstats "$cmd" "mdt"
11079
11080         # cleanup
11081         rm -f $DIR/jobstats_test_rename
11082
11083         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11084 }
11085 run_test 205 "Verify job stats"
11086
11087 # LU-1480, LU-1773 and LU-1657
11088 test_206() {
11089         mkdir -p $DIR/$tdir
11090         lfs setstripe -c -1 $DIR/$tdir
11091 #define OBD_FAIL_LOV_INIT 0x1403
11092         $LCTL set_param fail_loc=0xa0001403
11093         $LCTL set_param fail_val=1
11094         touch $DIR/$tdir/$tfile || true
11095 }
11096 run_test 206 "fail lov_init_raid0() doesn't lbug"
11097
11098 test_207a() {
11099         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11100         local fsz=`stat -c %s $DIR/$tfile`
11101         cancel_lru_locks mdc
11102
11103         # do not return layout in getattr intent
11104 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11105         $LCTL set_param fail_loc=0x170
11106         local sz=`stat -c %s $DIR/$tfile`
11107
11108         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11109
11110         rm -rf $DIR/$tfile
11111 }
11112 run_test 207a "can refresh layout at glimpse"
11113
11114 test_207b() {
11115         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11116         local cksum=`md5sum $DIR/$tfile`
11117         local fsz=`stat -c %s $DIR/$tfile`
11118         cancel_lru_locks mdc
11119         cancel_lru_locks osc
11120
11121         # do not return layout in getattr intent
11122 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11123         $LCTL set_param fail_loc=0x171
11124
11125         # it will refresh layout after the file is opened but before read issues
11126         echo checksum is "$cksum"
11127         echo "$cksum" |md5sum -c --quiet || error "file differs"
11128
11129         rm -rf $DIR/$tfile
11130 }
11131 run_test 207b "can refresh layout at open"
11132
11133 test_208() {
11134         # FIXME: in this test suite, only RD lease is used. This is okay
11135         # for now as only exclusive open is supported. After generic lease
11136         # is done, this test suite should be revised. - Jinshan
11137
11138         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11139                 { skip "Need MDS version at least 2.4.52"; return 0; }
11140
11141         echo "==== test 1: verify get lease work"
11142         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11143
11144         echo "==== test 2: verify lease can be broken by upcoming open"
11145         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11146         local PID=$!
11147         sleep 1
11148
11149         $MULTIOP $DIR/$tfile oO_RDONLY:c
11150         kill -USR1 $PID && wait $PID || error "break lease error"
11151
11152         echo "==== test 3: verify lease can't be granted if an open already exists"
11153         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11154         local PID=$!
11155         sleep 1
11156
11157         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11158         kill -USR1 $PID && wait $PID || error "open file error"
11159
11160         echo "==== test 4: lease can sustain over recovery"
11161         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11162         PID=$!
11163         sleep 1
11164
11165         fail mds1
11166
11167         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11168
11169         echo "==== test 5: lease broken can't be regained by replay"
11170         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11171         PID=$!
11172         sleep 1
11173
11174         # open file to break lease and then recovery
11175         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11176         fail mds1
11177
11178         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11179
11180         rm -f $DIR/$tfile
11181 }
11182 run_test 208 "Exclusive open"
11183
11184 test_209() {
11185         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11186                 skip_env "must have disp_stripe" && return
11187
11188         touch $DIR/$tfile
11189         sync; sleep 5; sync;
11190
11191         echo 3 > /proc/sys/vm/drop_caches
11192         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11193
11194         # open/close 500 times
11195         for i in $(seq 500); do
11196                 cat $DIR/$tfile
11197         done
11198
11199         echo 3 > /proc/sys/vm/drop_caches
11200         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11201
11202         echo "before: $req_before, after: $req_after"
11203         [ $((req_after - req_before)) -ge 300 ] &&
11204                 error "open/close requests are not freed"
11205         return 0
11206 }
11207 run_test 209 "read-only open/close requests should be freed promptly"
11208
11209 test_212() {
11210         size=`date +%s`
11211         size=$((size % 8192 + 1))
11212         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11213         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11214         rm -f $DIR/f212 $DIR/f212.xyz
11215 }
11216 run_test 212 "Sendfile test ============================================"
11217
11218 test_213() {
11219         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11220         cancel_lru_locks osc
11221         lctl set_param fail_loc=0x8000040f
11222         # generate a read lock
11223         cat $DIR/$tfile > /dev/null
11224         # write to the file, it will try to cancel the above read lock.
11225         cat /etc/hosts >> $DIR/$tfile
11226 }
11227 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11228
11229 test_214() { # for bug 20133
11230         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11231         for (( i=0; i < 340; i++ )) ; do
11232                 touch $DIR/$tdir/d214c/a$i
11233         done
11234
11235         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11236         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11237         ls $DIR/d214c || error "ls $DIR/d214c failed"
11238         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11239         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11240 }
11241 run_test 214 "hash-indexed directory test - bug 20133"
11242
11243 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11244 create_lnet_proc_files() {
11245         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
11246         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11247
11248         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11249         rm -f "$TMP/lnet_$1.sys_tmp"
11250 }
11251
11252 # counterpart of create_lnet_proc_files
11253 remove_lnet_proc_files() {
11254         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11255 }
11256
11257 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11258 # 3rd arg as regexp for body
11259 check_lnet_proc_stats() {
11260         local l=$(cat "$TMP/lnet_$1" |wc -l)
11261         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11262
11263         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11264 }
11265
11266 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11267 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11268 # optional and can be regexp for 2nd line (lnet.routes case)
11269 check_lnet_proc_entry() {
11270         local blp=2            # blp stands for 'position of 1st line of body'
11271         [ "$5" = "" ] || blp=3 # lnet.routes case
11272
11273         local l=$(cat "$TMP/lnet_$1" |wc -l)
11274         # subtracting one from $blp because the body can be empty
11275         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11276
11277         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11278                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11279
11280         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11281                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11282
11283         # bail out if any unexpected line happened
11284         sed -n "$blp~1 p" "$TMP/lnet_$1" |grep -Ev "$3"
11285         [ "$?" != 0 ] || error "$2 misformatted"
11286 }
11287
11288 test_215() { # for bugs 18102, 21079, 21517
11289         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11290         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11291         local P='[1-9][0-9]*'           # positive numeric
11292         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11293         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11294         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11295         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11296
11297         local L1 # regexp for 1st line
11298         local L2 # regexp for 2nd line (optional)
11299         local BR # regexp for the rest (body)
11300
11301         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
11302         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11303         create_lnet_proc_files "stats"
11304         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
11305         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11306         remove_lnet_proc_files "stats"
11307
11308         # /proc/sys/lnet/routes should look like this:
11309         # Routing disabled/enabled
11310         # net hops priority state router
11311         # where net is a string like tcp0, hops > 0, priority >= 0,
11312         # state is up/down,
11313         # router is a string like 192.168.1.1@tcp2
11314         L1="^Routing (disabled|enabled)$"
11315         L2="^net +hops +priority +state +router$"
11316         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11317         create_lnet_proc_files "routes"
11318         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
11319         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11320         remove_lnet_proc_files "routes"
11321
11322         # /proc/sys/lnet/routers should look like this:
11323         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11324         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11325         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11326         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11327         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11328         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11329         create_lnet_proc_files "routers"
11330         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
11331         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11332         remove_lnet_proc_files "routers"
11333
11334         # /proc/sys/lnet/peers should look like this:
11335         # nid refs state last max rtr min tx min queue
11336         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11337         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11338         # numeric (0 or >0 or <0), queue >= 0.
11339         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11340         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11341         create_lnet_proc_files "peers"
11342         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
11343         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11344         remove_lnet_proc_files "peers"
11345
11346         # /proc/sys/lnet/buffers  should look like this:
11347         # pages count credits min
11348         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11349         L1="^pages +count +credits +min$"
11350         BR="^ +$N +$N +$I +$I$"
11351         create_lnet_proc_files "buffers"
11352         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
11353         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11354         remove_lnet_proc_files "buffers"
11355
11356         # /proc/sys/lnet/nis should look like this:
11357         # nid status alive refs peer rtr max tx min
11358         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11359         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11360         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11361         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11362         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11363         create_lnet_proc_files "nis"
11364         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
11365         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11366         remove_lnet_proc_files "nis"
11367
11368         # can we successfully write to /proc/sys/lnet/stats?
11369         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
11370         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11371 }
11372 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
11373
11374 test_216() { # bug 20317
11375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11376         remote_ost_nodsh && skip "remote OST with nodsh" && return
11377
11378         local node
11379         local facets=$(get_facets OST)
11380         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11381
11382         save_lustre_params client "osc.*.contention_seconds" > $p
11383         save_lustre_params $facets \
11384                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11385         save_lustre_params $facets \
11386                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11387         save_lustre_params $facets \
11388                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11389         clear_osc_stats
11390
11391         # agressive lockless i/o settings
11392         for node in $(osts_nodes); do
11393                 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'
11394         done
11395         lctl set_param -n osc.*.contention_seconds 60
11396
11397         $DIRECTIO write $DIR/$tfile 0 10 4096
11398         $CHECKSTAT -s 40960 $DIR/$tfile
11399
11400         # disable lockless i/o
11401         for node in $(osts_nodes); do
11402                 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'
11403         done
11404         lctl set_param -n osc.*.contention_seconds 0
11405         clear_osc_stats
11406
11407         dd if=/dev/zero of=$DIR/$tfile count=0
11408         $CHECKSTAT -s 0 $DIR/$tfile
11409
11410         restore_lustre_params <$p
11411         rm -f $p
11412         rm $DIR/$tfile
11413 }
11414 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11415
11416 test_217() { # bug 22430
11417         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11418         local node
11419         local nid
11420
11421         for node in $(nodes_list); do
11422                 nid=$(host_nids_address $node $NETTYPE)
11423                 if [[ $nid = *-* ]] ; then
11424                         echo "lctl ping $nid@$NETTYPE"
11425                         lctl ping $nid@$NETTYPE
11426                 else
11427                         echo "skipping $node (no hyphen detected)"
11428                 fi
11429         done
11430 }
11431 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11432
11433 test_218() {
11434        # do directio so as not to populate the page cache
11435        log "creating a 10 Mb file"
11436        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11437        log "starting reads"
11438        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11439        log "truncating the file"
11440        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11441        log "killing dd"
11442        kill %+ || true # reads might have finished
11443        echo "wait until dd is finished"
11444        wait
11445        log "removing the temporary file"
11446        rm -rf $DIR/$tfile || error "tmp file removal failed"
11447 }
11448 run_test 218 "parallel read and truncate should not deadlock ======================="
11449
11450 test_219() {
11451         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11452         # write one partial page
11453         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11454         # set no grant so vvp_io_commit_write will do sync write
11455         $LCTL set_param fail_loc=0x411
11456         # write a full page at the end of file
11457         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11458
11459         $LCTL set_param fail_loc=0
11460         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11461         $LCTL set_param fail_loc=0x411
11462         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11463
11464         # LU-4201
11465         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11466         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11467 }
11468 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11469
11470 test_220() { #LU-325
11471         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11472         remote_ost_nodsh && skip "remote OST with nodsh" && return
11473         local OSTIDX=0
11474
11475         test_mkdir -p $DIR/$tdir
11476         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11477                 awk '{print $2}' | sed -e 's/_UUID$//')
11478
11479         # on the mdt's osc
11480         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11481         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11482                         osc.$mdtosc_proc1.prealloc_last_id)
11483         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11484                         osc.$mdtosc_proc1.prealloc_next_id)
11485
11486         $LFS df -i
11487
11488         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11489         #define OBD_FAIL_OST_ENOINO              0x229
11490         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11491         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11492         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11493
11494         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11495
11496         MDSOBJS=$((last_id - next_id))
11497         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11498
11499         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11500         echo "OST still has $count kbytes free"
11501
11502         echo "create $MDSOBJS files @next_id..."
11503         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11504
11505         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11506                         osc.$mdtosc_proc1.prealloc_last_id)
11507         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11508                         osc.$mdtosc_proc1.prealloc_next_id)
11509
11510         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11511         $LFS df -i
11512
11513         echo "cleanup..."
11514
11515         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11516         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11517
11518         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11519         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11520         echo "unlink $MDSOBJS files @$next_id..."
11521         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11522 }
11523 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11524
11525 test_221() {
11526         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11527         dd if=`which date` of=$MOUNT/date oflag=sync
11528         chmod +x $MOUNT/date
11529
11530         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11531         $LCTL set_param fail_loc=0x80001401
11532
11533         $MOUNT/date > /dev/null
11534         rm -f $MOUNT/date
11535 }
11536 run_test 221 "make sure fault and truncate race to not cause OOM"
11537
11538 test_222a () {
11539         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11540        rm -rf $DIR/$tdir
11541        test_mkdir -p $DIR/$tdir
11542        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11543        createmany -o $DIR/$tdir/$tfile 10
11544        cancel_lru_locks mdc
11545        cancel_lru_locks osc
11546        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11547        $LCTL set_param fail_loc=0x31a
11548        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11549        $LCTL set_param fail_loc=0
11550        rm -r $DIR/$tdir
11551 }
11552 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11553
11554 test_222b () {
11555         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11556        rm -rf $DIR/$tdir
11557        test_mkdir -p $DIR/$tdir
11558        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11559        createmany -o $DIR/$tdir/$tfile 10
11560        cancel_lru_locks mdc
11561        cancel_lru_locks osc
11562        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11563        $LCTL set_param fail_loc=0x31a
11564        rm -r $DIR/$tdir || "AGL for rmdir failed"
11565        $LCTL set_param fail_loc=0
11566 }
11567 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11568
11569 test_223 () {
11570         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11571        rm -rf $DIR/$tdir
11572        test_mkdir -p $DIR/$tdir
11573        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11574        createmany -o $DIR/$tdir/$tfile 10
11575        cancel_lru_locks mdc
11576        cancel_lru_locks osc
11577        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11578        $LCTL set_param fail_loc=0x31b
11579        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11580        $LCTL set_param fail_loc=0
11581        rm -r $DIR/$tdir
11582 }
11583 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11584
11585 test_224a() { # LU-1039, MRP-303
11586         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11587         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11588         $LCTL set_param fail_loc=0x508
11589         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11590         $LCTL set_param fail_loc=0
11591         df $DIR
11592 }
11593 run_test 224a "Don't panic on bulk IO failure"
11594
11595 test_224b() { # LU-1039, MRP-303
11596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11597         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11598         cancel_lru_locks osc
11599         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11600         $LCTL set_param fail_loc=0x515
11601         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11602         $LCTL set_param fail_loc=0
11603         df $DIR
11604 }
11605 run_test 224b "Don't panic on bulk IO failure"
11606
11607 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11608 test_225a () {
11609         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11610         if [ -z ${MDSSURVEY} ]; then
11611               skip_env "mds-survey not found" && return
11612         fi
11613
11614         [ $MDSCOUNT -ge 2 ] &&
11615                 skip "skipping now for more than one MDT" && return
11616
11617        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11618             { skip "Need MDS version at least 2.2.51"; return; }
11619
11620        local mds=$(facet_host $SINGLEMDS)
11621        local target=$(do_nodes $mds 'lctl dl' | \
11622                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11623
11624        local cmd1="file_count=1000 thrhi=4"
11625        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11626        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11627        local cmd="$cmd1 $cmd2 $cmd3"
11628
11629        rm -f ${TMP}/mds_survey*
11630        echo + $cmd
11631        eval $cmd || error "mds-survey with zero-stripe failed"
11632        cat ${TMP}/mds_survey*
11633        rm -f ${TMP}/mds_survey*
11634 }
11635 run_test 225a "Metadata survey sanity with zero-stripe"
11636
11637 test_225b () {
11638         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11639
11640         if [ -z ${MDSSURVEY} ]; then
11641               skip_env "mds-survey not found" && return
11642         fi
11643         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11644             { skip "Need MDS version at least 2.2.51"; return; }
11645
11646         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11647               skip_env "Need to mount OST to test" && return
11648         fi
11649
11650         [ $MDSCOUNT -ge 2 ] &&
11651                 skip "skipping now for more than one MDT" && return
11652        local mds=$(facet_host $SINGLEMDS)
11653        local target=$(do_nodes $mds 'lctl dl' | \
11654                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11655
11656        local cmd1="file_count=1000 thrhi=4"
11657        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11658        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11659        local cmd="$cmd1 $cmd2 $cmd3"
11660
11661        rm -f ${TMP}/mds_survey*
11662        echo + $cmd
11663        eval $cmd || error "mds-survey with stripe_count failed"
11664        cat ${TMP}/mds_survey*
11665        rm -f ${TMP}/mds_survey*
11666 }
11667 run_test 225b "Metadata survey sanity with stripe_count = 1"
11668
11669 mcreate_path2fid () {
11670         local mode=$1
11671         local major=$2
11672         local minor=$3
11673         local name=$4
11674         local desc=$5
11675         local path=$DIR/$tdir/$name
11676         local fid
11677         local rc
11678         local fid_path
11679
11680         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11681                 error "cannot create $desc"
11682
11683         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11684         rc=$?
11685         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11686
11687         fid_path=$($LFS fid2path $MOUNT $fid)
11688         rc=$?
11689         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11690
11691         [ "$path" == "$fid_path" ] ||
11692                 error "fid2path returned $fid_path, expected $path"
11693
11694         echo "pass with $path and $fid"
11695 }
11696
11697 test_226a () {
11698         rm -rf $DIR/$tdir
11699         mkdir -p $DIR/$tdir
11700
11701         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11702         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11703         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11704         mcreate_path2fid 0040666 0 0 dir "directory"
11705         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11706         mcreate_path2fid 0100666 0 0 file "regular file"
11707         mcreate_path2fid 0120666 0 0 link "symbolic link"
11708         mcreate_path2fid 0140666 0 0 sock "socket"
11709 }
11710 run_test 226a "call path2fid and fid2path on files of all type"
11711
11712 test_226b () {
11713         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11714         rm -rf $DIR/$tdir
11715         local MDTIDX=1
11716
11717         mkdir -p $DIR/$tdir
11718         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
11719                 error "create remote directory failed"
11720         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
11721         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
11722                                 "character special file (null)"
11723         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
11724                                 "character special file (no device)"
11725         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
11726         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
11727                                 "block special file (loop)"
11728         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
11729         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
11730         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
11731 }
11732 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
11733
11734 # LU-1299 Executing or running ldd on a truncated executable does not
11735 # cause an out-of-memory condition.
11736 test_227() {
11737         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11738         dd if=`which date` of=$MOUNT/date bs=1k count=1
11739         chmod +x $MOUNT/date
11740
11741         $MOUNT/date > /dev/null
11742         ldd $MOUNT/date > /dev/null
11743         rm -f $MOUNT/date
11744 }
11745 run_test 227 "running truncated executable does not cause OOM"
11746
11747 # LU-1512 try to reuse idle OI blocks
11748 test_228a() {
11749         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11750         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11751                 skip "non-ldiskfs backend" && return
11752
11753         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11754         local myDIR=$DIR/$tdir
11755
11756         mkdir -p $myDIR
11757         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11758         $LCTL set_param fail_loc=0x80001002
11759         createmany -o $myDIR/t- 10000
11760         $LCTL set_param fail_loc=0
11761         # The guard is current the largest FID holder
11762         touch $myDIR/guard
11763         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11764                     tr -d '[')
11765         local IDX=$(($SEQ % 64))
11766
11767         do_facet $SINGLEMDS sync
11768         # Make sure journal flushed.
11769         sleep 6
11770         local blk1=$(do_facet $SINGLEMDS \
11771                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11772                      grep Blockcount | awk '{print $4}')
11773
11774         # Remove old files, some OI blocks will become idle.
11775         unlinkmany $myDIR/t- 10000
11776         # Create new files, idle OI blocks should be reused.
11777         createmany -o $myDIR/t- 2000
11778         do_facet $SINGLEMDS sync
11779         # Make sure journal flushed.
11780         sleep 6
11781         local blk2=$(do_facet $SINGLEMDS \
11782                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11783                      grep Blockcount | awk '{print $4}')
11784
11785         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11786 }
11787 run_test 228a "try to reuse idle OI blocks"
11788
11789 test_228b() {
11790         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11791         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11792                 skip "non-ldiskfs backend" && return
11793
11794         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11795         local myDIR=$DIR/$tdir
11796
11797         mkdir -p $myDIR
11798         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11799         $LCTL set_param fail_loc=0x80001002
11800         createmany -o $myDIR/t- 10000
11801         $LCTL set_param fail_loc=0
11802         # The guard is current the largest FID holder
11803         touch $myDIR/guard
11804         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11805                     tr -d '[')
11806         local IDX=$(($SEQ % 64))
11807
11808         do_facet $SINGLEMDS sync
11809         # Make sure journal flushed.
11810         sleep 6
11811         local blk1=$(do_facet $SINGLEMDS \
11812                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11813                      grep Blockcount | awk '{print $4}')
11814
11815         # Remove old files, some OI blocks will become idle.
11816         unlinkmany $myDIR/t- 10000
11817
11818         # stop the MDT
11819         stop $SINGLEMDS || error "Fail to stop MDT."
11820         # remount the MDT
11821         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11822
11823         df $MOUNT || error "Fail to df."
11824         # Create new files, idle OI blocks should be reused.
11825         createmany -o $myDIR/t- 2000
11826         do_facet $SINGLEMDS sync
11827         # Make sure journal flushed.
11828         sleep 6
11829         local blk2=$(do_facet $SINGLEMDS \
11830                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11831                      grep Blockcount | awk '{print $4}')
11832
11833         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11834 }
11835 run_test 228b "idle OI blocks can be reused after MDT restart"
11836
11837 #LU-1881
11838 test_228c() {
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         # 20000 files can guarantee there are index nodes in the OI file
11850         createmany -o $myDIR/t- 20000
11851         $LCTL set_param fail_loc=0
11852         # The guard is current the largest FID holder
11853         touch $myDIR/guard
11854         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11855                     tr -d '[')
11856         local IDX=$(($SEQ % 64))
11857
11858         do_facet $SINGLEMDS sync
11859         # Make sure journal flushed.
11860         sleep 6
11861         local blk1=$(do_facet $SINGLEMDS \
11862                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11863                      grep Blockcount | awk '{print $4}')
11864
11865         # Remove old files, some OI blocks will become idle.
11866         unlinkmany $myDIR/t- 20000
11867         rm -f $myDIR/guard
11868         # The OI file should become empty now
11869
11870         # Create new files, idle OI blocks should be reused.
11871         createmany -o $myDIR/t- 2000
11872         do_facet $SINGLEMDS sync
11873         # Make sure journal flushed.
11874         sleep 6
11875         local blk2=$(do_facet $SINGLEMDS \
11876                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11877                      grep Blockcount | awk '{print $4}')
11878
11879         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11880 }
11881 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
11882
11883 test_229() { # LU-2482, LU-3448
11884         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
11885                 skip "No HSM support on MDS of $(get_lustre_version)," \
11886                          "need 2.4.53 at least" && return
11887         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11888         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
11889
11890         rm -f $DIR/$tfile
11891
11892         # Create a file with a released layout and stripe count 2.
11893         $MULTIOP $DIR/$tfile H2c ||
11894                 error "failed to create file with released layout"
11895
11896         $GETSTRIPE -v $DIR/$tfile
11897
11898         local pattern=$($GETSTRIPE -L $DIR/$tfile)
11899         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
11900
11901         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
11902         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
11903         stat $DIR/$tfile || error "failed to stat released file"
11904
11905         chown $RUNAS_ID $DIR/$tfile ||
11906                 error "chown $RUNAS_ID $DIR/$tfile failed"
11907
11908         chgrp $RUNAS_ID $DIR/$tfile ||
11909                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
11910
11911         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
11912         rm $DIR/$tfile || error "failed to remove released file"
11913 }
11914 run_test 229 "getstripe/stat/rm/attr changes work on released files"
11915
11916 test_230a() {
11917         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11918         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11919         local MDTIDX=1
11920
11921         mkdir -p $DIR/$tdir/test_230_local
11922         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
11923         [ $mdt_idx -ne 0 ] &&
11924                 error "create local directory on wrong MDT $mdt_idx"
11925
11926         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
11927                         error "create remote directory failed"
11928         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
11929         [ $mdt_idx -ne $MDTIDX ] &&
11930                 error "create remote directory on wrong MDT $mdt_idx"
11931
11932         createmany -o $DIR/$tdir/test_230/t- 10 ||
11933                 error "create files on remote directory failed"
11934         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
11935         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
11936         rm -r $DIR/$tdir || error "unlink remote directory failed"
11937 }
11938 run_test 230a "Create remote directory and files under the remote directory"
11939
11940 test_230b() {
11941         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11942         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11943         local MDTIDX=1
11944         local mdt_index
11945         local i
11946         local file
11947         local pid
11948         local stripe_count
11949         local migrate_dir=$DIR/$tdir/migrate_dir
11950         local other_dir=$DIR/$tdir/other_dir
11951
11952         mkdir -p $migrate_dir
11953         mkdir -p $other_dir
11954         for ((i=0; i<10; i++)); do
11955                 mkdir -p $migrate_dir/dir_${i}
11956                 createmany -o $migrate_dir/dir_${i}/f 10 ||
11957                         error "create files under remote dir failed $i"
11958         done
11959
11960         cp /etc/passwd $migrate_dir/$tfile
11961         cp /etc/passwd $other_dir/$tfile
11962         mkdir -p $migrate_dir/dir_default_stripe2
11963         $LFS setstripe -c 2 $migrate_dir/dir_default_stripe2
11964         $LFS setstripe -c 2 $migrate_dir/${tfile}_stripe2
11965
11966         mkdir -p $other_dir
11967         ln $migrate_dir/$tfile $other_dir/luna
11968         ln $migrate_dir/$tfile $migrate_dir/sofia
11969         ln $other_dir/$tfile $migrate_dir/david
11970         ln -s $migrate_dir/$tfile $other_dir/zachary
11971         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
11972         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
11973
11974         $LFS mv -v -M $MDTIDX $migrate_dir ||
11975                         error "migrate remote dir error"
11976
11977         echo "migratate to MDT1, then checking.."
11978         for ((i=0; i<10; i++)); do
11979                 for file in $(find $migrate_dir/dir_${i}); do
11980                         mdt_index=$($LFS getstripe -M $file)
11981                         [ $mdt_index == $MDTIDX ] ||
11982                                 error "$file is not on MDT${MDTIDX}"
11983                 done
11984         done
11985
11986         # the multiple link file should still in MDT0
11987         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
11988         [ $mdt_index == 0 ] ||
11989                 error "$file is not on MDT${MDTIDX}"
11990
11991         diff /etc/passwd $migrate_dir/$tfile ||
11992                 error "$tfile different after migration"
11993
11994         diff /etc/passwd $other_dir/luna ||
11995                 error "luna different after migration"
11996
11997         diff /etc/passwd $migrate_dir/sofia ||
11998                 error "sofia different after migration"
11999
12000         diff /etc/passwd $migrate_dir/david ||
12001                 error "david different after migration"
12002
12003         diff /etc/passwd $other_dir/zachary ||
12004                 error "zachary different after migration"
12005
12006         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12007                 error "${tfile}_ln different after migration"
12008
12009         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12010                 error "${tfile}_ln_other different after migration"
12011
12012         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12013         [ $stripe_count = 2 ] ||
12014                         error "dir strpe_count $d != 2 after migration."
12015
12016         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12017         [ $stripe_count = 2 ] ||
12018                         error "file strpe_count $d != 2 after migration."
12019
12020         #migrate back to MDT0
12021         MDTIDX=0
12022         $LFS mv -v -M $MDTIDX $migrate_dir ||
12023                         error "migrate remote dir error"
12024
12025         echo "migrate back to MDT0, checking.."
12026         for file in $(find $migrate_dir); do
12027                 mdt_index=$($LFS getstripe -M $file)
12028                 [ $mdt_index == $MDTIDX ] ||
12029                         error "$file is not on MDT${MDTIDX}"
12030         done
12031
12032         diff /etc/passwd ${migrate_dir}/$tfile ||
12033                 error "$tfile different after migration"
12034
12035         diff /etc/passwd ${other_dir}/luna ||
12036                 error "luna different after migration"
12037
12038         diff /etc/passwd ${migrate_dir}/sofia ||
12039                 error "sofia different after migration"
12040
12041         diff /etc/passwd ${other_dir}/zachary ||
12042                 error "zachary different after migration"
12043
12044         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12045                 error "${tfile}_ln different after migration"
12046
12047         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12048                 error "${tfile}_ln_other different after migration"
12049
12050         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12051         [ $stripe_count = 2 ] ||
12052                 error "dir strpe_count $d != 2 after migration."
12053
12054         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12055         [ $stripe_count = 2 ] ||
12056                 error "file strpe_count $d != 2 after migration."
12057
12058         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12059 }
12060 run_test 230b "migrate directory"
12061
12062 test_230c() {
12063         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12064         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12065         local MDTIDX=1
12066         local mdt_index
12067         local file
12068
12069         #If migrating directory fails in the middle, all entries of
12070         #the directory is still accessiable.
12071         mkdir -p $DIR/$tdir
12072         stat $DIR/$tdir
12073         createmany -o $DIR/$tdir/f 10 ||
12074                 error "create files under ${tdir} failed"
12075
12076         #failed after migrating 5 entries
12077         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12078         do_facet mds1 lctl set_param fail_loc=0x20001801
12079         do_facet mds1 lctl  set_param fail_val=5
12080         local t=`ls $DIR/$tdir | wc -l`
12081         $LFS mv -M $MDTIDX $DIR/$tdir &&
12082                 error "migrate should failed after 5 entries"
12083         local u=`ls $DIR/$tdir | wc -l`
12084         [ "$u" == "$t" ] || error "$u != $t during migration"
12085
12086         for file in $(find $DIR/$tdir); do
12087                 stat $file || error "stat $file failed"
12088         done
12089
12090         do_facet mds1 lctl set_param fail_loc=0
12091         do_facet mds1 lctl set_param fail_val=0
12092
12093         $LFS mv -M $MDTIDX $DIR/$tdir ||
12094                 error "migrate open files should failed with open files"
12095
12096         echo "Finish migration, then checking.."
12097         for file in $(find $DIR/$tdir); do
12098                 mdt_index=$($LFS getstripe -M $file)
12099                 [ $mdt_index == $MDTIDX ] ||
12100                         error "$file is not on MDT${MDTIDX}"
12101         done
12102
12103         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12104 }
12105 run_test 230c "check directory accessiblity if migration is failed"
12106
12107 test_230d() {
12108         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12109         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12110         local MDTIDX=1
12111         local mdt_index
12112         local i
12113         local j
12114
12115         mkdir -p $DIR/$tdir
12116
12117         for ((i=0; i<100; i++)); do
12118                 mkdir -p $DIR/$tdir/dir_${i}
12119                 createmany -o $DIR/$tdir/dir_${i}/f 100 ||
12120                         error "create files under remote dir failed $i"
12121         done
12122
12123         $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
12124
12125         echo "Finish migration, then checking.."
12126         for file in $(find $DIR/$tdir); do
12127                 mdt_index=$($LFS getstripe -M $file)
12128                 [ $mdt_index == $MDTIDX ] ||
12129                         error "$file is not on MDT${MDTIDX}"
12130         done
12131
12132         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12133 }
12134 run_test 230d "check migrate big directory"
12135
12136 test_231a()
12137 {
12138         # For simplicity this test assumes that max_pages_per_rpc
12139         # is the same across all OSCs
12140         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12141         local bulk_size=$((max_pages * 4096))
12142
12143         mkdir -p $DIR/$tdir
12144
12145         # clear the OSC stats
12146         $LCTL set_param osc.*.stats=0 &>/dev/null
12147
12148         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12149         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12150                 oflag=direct &>/dev/null || error "dd failed"
12151
12152         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12153         if [ x$nrpcs != "x1" ]; then
12154                 error "found $nrpc ost_write RPCs, not 1 as expected"
12155         fi
12156
12157         # Drop the OSC cache, otherwise we will read from it
12158         cancel_lru_locks osc
12159
12160         # clear the OSC stats
12161         $LCTL set_param osc.*.stats=0 &>/dev/null
12162
12163         # Client reads $bulk_size.
12164         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12165                 iflag=direct &>/dev/null || error "dd failed"
12166
12167         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12168         if [ x$nrpcs != "x1" ]; then
12169                 error "found $nrpc ost_read RPCs, not 1 as expected"
12170         fi
12171 }
12172 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12173
12174 test_231b() {
12175         mkdir -p $DIR/$tdir
12176         local i
12177         for i in {0..1023}; do
12178                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12179                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12180                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12181         done
12182         sync
12183 }
12184 run_test 231b "must not assert on fully utilized OST request buffer"
12185
12186 test_232() {
12187         mkdir -p $DIR/$tdir
12188         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12189         $LCTL set_param fail_loc=0x31c
12190
12191         # ignore dd failure
12192         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12193
12194         $LCTL set_param fail_loc=0
12195         umount_client $MOUNT || error "umount failed"
12196         mount_client $MOUNT || error "mount failed"
12197 }
12198 run_test 232 "failed lock should not block umount"
12199
12200 test_233a() {
12201         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12202         { skip "Need MDS version at least 2.3.64"; return; }
12203
12204         local fid=$($LFS path2fid $MOUNT)
12205         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12206                 error "cannot access $MOUNT using its FID '$fid'"
12207 }
12208 run_test 233a "checking that OBF of the FS root succeeds"
12209
12210 test_233b() {
12211         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12212         { skip "Need MDS version at least 2.5.90"; return; }
12213
12214         local fid=$($LFS path2fid $MOUNT/.lustre)
12215         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12216                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12217
12218         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12219         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12220                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12221 }
12222 run_test 233b "checking that OBF of the FS .lustre succeeds"
12223
12224 test_234() {
12225         local p="$TMP/sanityN-$TESTNAME.parameters"
12226         save_lustre_params client "llite.*.xattr_cache" > $p
12227         lctl set_param llite.*.xattr_cache 1 ||
12228                 { skip "xattr cache is not supported"; return 0; }
12229
12230         mkdir -p $DIR/$tdir || error "mkdir failed"
12231         touch $DIR/$tdir/$tfile || error "touch failed"
12232         # OBD_FAIL_LLITE_XATTR_ENOMEM
12233         $LCTL set_param fail_loc=0x1405
12234         if [ ! -f /etc/SuSE-release ]; then
12235                 # attr pre-2.4.44-7 had a bug with rc
12236                 # LU-3703 - SLES clients have older attr
12237                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12238                         error "getfattr should have failed with ENOMEM"
12239         fi
12240         $LCTL set_param fail_loc=0x0
12241         rm -rf $DIR/$tdir
12242
12243         restore_lustre_params < $p
12244         rm -f $p
12245 }
12246 run_test 234 "xattr cache should not crash on ENOMEM"
12247
12248 test_235() {
12249          [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12250                 skip "Need MDS version at least 2.4.52" && return
12251         flock_deadlock $DIR/$tfile
12252         local RC=$?
12253         case $RC in
12254                 0)
12255                 ;;
12256                 124) error "process hangs on a deadlock"
12257                 ;;
12258                 *) error "error executing flock_deadlock $DIR/$tfile"
12259                 ;;
12260         esac
12261 }
12262 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12263
12264 #LU-2935
12265 test_236() {
12266         check_swap_layouts_support && return 0
12267         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12268
12269         local ref1=/etc/passwd
12270         local ref2=/etc/group
12271         local file1=$DIR/$tdir/f1
12272         local file2=$DIR/$tdir/f2
12273
12274         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12275         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12276         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12277         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12278         local fd=$(free_fd)
12279         local cmd="exec $fd<>$file2"
12280         eval $cmd
12281         rm $file2
12282         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12283                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12284         cmd="exec $fd>&-"
12285         eval $cmd
12286         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12287
12288         #cleanup
12289         rm -rf $DIR/$tdir
12290 }
12291 run_test 236 "Layout swap on open unlinked file"
12292
12293 # test to verify file handle related system calls
12294 # (name_to_handle_at/open_by_handle_at)
12295 # The new system calls are supported in glibc >= 2.14.
12296
12297 test_237() {
12298         echo "Test file_handle syscalls" > $DIR/$tfile
12299         check_fhandle_syscalls $DIR/$tfile ||
12300                 error "check_fhandle_syscalls failed"
12301 }
12302 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12303
12304 # LU-4659 linkea consistency
12305 test_238() {
12306         touch $DIR/$tfile
12307         ln $DIR/$tfile $DIR/$tfile.lnk
12308         touch $DIR/$tfile.new
12309         mv $DIR/$tfile.new $DIR/$tfile
12310         local fid1=$(lfs path2fid $DIR/$tfile)
12311         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12312         local path1=$(lfs fid2path $FSNAME $fid1)
12313         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12314         local path2=$(lfs fid2path $FSNAME $fid2)
12315         [ $tfile.lnk == $path2 ] ||
12316                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12317         rm -f $DIR/$tfile*
12318 }
12319 run_test 238 "Verify linkea consistency"
12320
12321 test_striped_dir() {
12322         local mdt_index=$1
12323         local stripe_count
12324         local stripe_index
12325
12326         mkdir -p $DIR/$tdir
12327         $LFS setdirstripe -i $mdt_index -c 2 -t all_char $DIR/$tdir/striped_dir ||
12328                 error "set striped dir error"
12329
12330         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
12331         if [ "$stripe_count" != "2" ]; then
12332                 error "stripe_count is $stripe_count, expect 2"
12333         fi
12334
12335         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
12336         if [ "$stripe_index" != "$mdt_index" ]; then
12337                 error "stripe_index is $stripe_index, expect $mdt_index"
12338         fi
12339
12340         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12341                 error "nlink error after create striped dir"
12342
12343         mkdir $DIR/$tdir/striped_dir/a
12344         mkdir $DIR/$tdir/striped_dir/b
12345
12346         stat $DIR/$tdir/striped_dir/a ||
12347                 error "create dir under striped dir failed"
12348         stat $DIR/$tdir/striped_dir/b ||
12349                 error "create dir under striped dir failed"
12350
12351         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
12352                 error "nlink error after mkdir"
12353
12354         rmdir $DIR/$tdir/striped_dir/a
12355         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
12356                 error "nlink error after rmdir"
12357
12358         rmdir $DIR/$tdir/striped_dir/b
12359         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12360                 error "nlink error after rmdir"
12361
12362         rmdir $DIR/$tdir/striped_dir ||
12363                 error "rmdir striped dir error"
12364         true
12365 }
12366
12367 test_300a() {
12368         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12369         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12370
12371         test_striped_dir 0 || error "failed on striped dir on MDT0"
12372         test_striped_dir 1 || error "failed on striped dir on MDT0"
12373 }
12374 run_test 300a "basic striped dir sanity test"
12375
12376 test_300b() {
12377         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12378         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12379         local i
12380         local mtime1
12381         local mtime2
12382         local mtime3
12383
12384         test_mkdir $DIR/$tdir || error "mkdir fail"
12385         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12386                 error "set striped dir error"
12387         for ((i=0; i<10; i++)); do
12388                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
12389                 sleep 1
12390                 touch $DIR/$tdir/striped_dir/file_$i ||
12391                                         error "touch error $i"
12392                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
12393                 [ $mtime1 -eq $mtime2 ] &&
12394                         error "mtime not change after create"
12395                 sleep 1
12396                 rm -f $DIR/$tdir/striped_dir/file_$i ||
12397                                         error "unlink error $i"
12398                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
12399                 [ $mtime2 -eq $mtime3 ] &&
12400                         error "mtime did not change after unlink"
12401         done
12402         true
12403 }
12404 run_test 300b "check ctime/mtime for striped dir"
12405
12406 test_300c() {
12407         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12408         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12409         local file_count
12410
12411         mkdir -p $DIR/$tdir
12412         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
12413                 error "set striped dir error"
12414
12415         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
12416                 error "chown striped dir failed"
12417
12418         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
12419                 error "create 5k files failed"
12420
12421         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
12422
12423         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
12424
12425         rm -rf $DIR/$tdir
12426 }
12427 run_test 300c "chown && check ls under striped directory"
12428
12429 test_300d() {
12430         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12431         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12432         local stripe_count
12433         local file
12434
12435         mkdir -p $DIR/$tdir
12436         $SETSTRIPE -c 2 $DIR/$tdir
12437
12438         #local striped directory
12439         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12440                 error "set striped dir error"
12441         createmany -o $DIR/$tdir/striped_dir/f 10 ||
12442                 error "create 10 files failed"
12443
12444         #remote striped directory
12445         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
12446                 error "set striped dir error"
12447         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
12448                 error "create 10 files failed"
12449
12450         for file in $(find $DIR/$tdir); do
12451                 stripe_count=$($GETSTRIPE -c $file)
12452                 [ $stripe_count -eq 2 ] ||
12453                         error "wrong stripe $stripe_count for $file"
12454         done
12455
12456         rm -rf $DIR/$tdir
12457 }
12458 run_test 300d "check default stripe under striped directory"
12459
12460 test_300e() {
12461         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12462         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12463         local stripe_count
12464         local file
12465
12466         mkdir -p $DIR/$tdir
12467
12468         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12469                 error "set striped dir error"
12470
12471         touch $DIR/$tdir/striped_dir/a
12472         touch $DIR/$tdir/striped_dir/b
12473         touch $DIR/$tdir/striped_dir/c
12474
12475         mkdir $DIR/$tdir/striped_dir/dir_a
12476         mkdir $DIR/$tdir/striped_dir/dir_b
12477         mkdir $DIR/$tdir/striped_dir/dir_c
12478
12479         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
12480                 error "set striped dir under striped dir error"
12481
12482         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
12483                 error "set striped dir under striped dir error"
12484
12485         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
12486                 error "set striped dir under striped dir error"
12487
12488         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
12489                 error "rename file under striped dir should fail"
12490
12491         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
12492                 error "rename dir under striped dir should fail"
12493
12494         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
12495                 error "rename dir under different stripes should fail"
12496
12497         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
12498                 error "rename file under striped dir should succeed"
12499
12500         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
12501                 error "rename dir under striped dir should succeed"
12502
12503         rm -rf $DIR/$tdir
12504 }
12505 run_test 300e "check rename under striped directory"
12506
12507 test_300f() {
12508         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12509         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12510         local stripe_count
12511         local file
12512
12513         rm -rf $DIR/$tdir
12514         mkdir -p $DIR/$tdir
12515
12516         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12517                 error "set striped dir error"
12518
12519         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
12520                 error "set striped dir error"
12521
12522         touch $DIR/$tdir/striped_dir/a
12523         mkdir $DIR/$tdir/striped_dir/dir_a
12524         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
12525                 error "create striped dir under striped dir fails"
12526
12527         touch $DIR/$tdir/striped_dir1/b
12528         mkdir $DIR/$tdir/striped_dir1/dir_b
12529         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
12530                 error "create striped dir under striped dir fails"
12531
12532         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
12533                 error "rename file under different striped dir should fail"
12534
12535         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
12536                 error "rename dir under different striped dir should fail"
12537
12538         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
12539                 error "rename striped dir under diff striped dir should fail"
12540
12541         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
12542                 error "rename file under diff striped dirs fails"
12543
12544         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
12545                 error "rename dir under diff striped dirs fails"
12546
12547         rm -rf $DIR/$tdir
12548 }
12549 run_test 300f "check rename cross striped directory"
12550
12551 #
12552 # tests that do cleanup/setup should be run at the end
12553 #
12554
12555 test_900() {
12556         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12557         local ls
12558         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
12559         $LCTL set_param fail_loc=0x903
12560         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
12561         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
12562                 echo "clear" > $ls
12563         done
12564         FAIL_ON_ERROR=true cleanup
12565         FAIL_ON_ERROR=true setup
12566 }
12567 run_test 900 "umount should not race with any mgc requeue thread"
12568
12569 complete $SECONDS
12570 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
12571 check_and_cleanup_lustre
12572 if [ "$I_MOUNTED" != "yes" ]; then
12573         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
12574 fi
12575 exit_status