Whamcloud - gitweb
c53a86463c5477b59b9dc33125fcecb7714940aa
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 4; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
12 ALWAYS_EXCEPT="                42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # with LOD/OSP landing
16 # bug number for skipped tests: LU-2036
17 ALWAYS_EXCEPT="                 76     $ALWAYS_EXCEPT"
18
19
20 SRCDIR=$(cd $(dirname $0); echo $PWD)
21 export PATH=$PATH:/sbin
22
23 TMP=${TMP:-/tmp}
24
25 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
26 CREATETEST=${CREATETEST:-createtest}
27 LFS=${LFS:-lfs}
28 LFIND=${LFIND:-"$LFS find"}
29 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
30 LCTL=${LCTL:-lctl}
31 MCREATE=${MCREATE:-mcreate}
32 OPENFILE=${OPENFILE:-openfile}
33 OPENUNLINK=${OPENUNLINK:-openunlink}
34 export MULTIOP=${MULTIOP:-multiop}
35 READS=${READS:-"reads"}
36 MUNLINK=${MUNLINK:-munlink}
37 SOCKETSERVER=${SOCKETSERVER:-socketserver}
38 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
39 MEMHOG=${MEMHOG:-memhog}
40 DIRECTIO=${DIRECTIO:-directio}
41 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
42 UMOUNT=${UMOUNT:-"umount -d"}
43 STRIPES_PER_OBJ=-1
44 CHECK_GRANT=${CHECK_GRANT:-"yes"}
45 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
46 export PARALLEL=${PARALLEL:-"no"}
47
48 export NAME=${NAME:-local}
49
50 SAVE_PWD=$PWD
51
52 CLEANUP=${CLEANUP:-:}
53 SETUP=${SETUP:-:}
54 TRACE=${TRACE:-""}
55 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
56 . $LUSTRE/tests/test-framework.sh
57 init_test_env $@
58 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
59 init_logging
60
61 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 64b 68 71 77f 78 115 124b"
62
63 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
64 # bug number for skipped test:        LU-1593 LU-2610 LU-2833 LU-1957 LU-2805
65         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h     40      48a     180     184c"
66
67 FAIL_ON_ERROR=false
68
69 cleanup() {
70         echo -n "cln.."
71         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
72         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
73 }
74 setup() {
75         echo -n "mnt.."
76         load_modules
77         setupall || exit 10
78         echo "done"
79 }
80
81 check_kernel_version() {
82         WANT_VER=$1
83         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
84         case $GOT_VER in
85         patchless|patchless_client) return 0;;
86         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
87         esac
88         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
89         return 1
90 }
91
92 check_swap_layouts_support()
93 {
94         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
95                 { skip "Does not support layout lock."; return 0; }
96         return 1
97 }
98
99 if [ "$ONLY" == "cleanup" ]; then
100        sh llmountcleanup.sh
101        exit 0
102 fi
103
104 check_and_setup_lustre
105
106 DIR=${DIR:-$MOUNT}
107 assert_DIR
108
109 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
110     awk '{gsub(/_UUID/,""); print $1}' | head -1)
111 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
112 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
113 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
114 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
115 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
116 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
117
118 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
119 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
120 rm -rf $DIR/[Rdfs][0-9]*
121
122 # $RUNAS_ID may get set incorrectly somewhere else
123 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
124
125 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
126
127 build_test_filter
128
129 if [ "${ONLY}" = "MOUNT" ] ; then
130         echo "Lustre is up, please go on"
131         exit
132 fi
133
134 echo "preparing for tests involving mounts"
135 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
136 touch $EXT2_DEV
137 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
138 echo # add a newline after mke2fs.
139
140 umask 077
141
142 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
143 lctl set_param debug=-1 2> /dev/null || true
144 test_0() {
145         touch $DIR/$tfile
146         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
147         rm $DIR/$tfile
148         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
149 }
150 run_test 0 "touch .../$tfile ; rm .../$tfile ====================="
151
152 test_0b() {
153         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
154         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
155 }
156 run_test 0b "chmod 0755 $DIR ============================="
157
158 test_0c() {
159         $LCTL get_param mdc.*.import | grep "state: FULL" ||
160                 error "import not FULL"
161         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
162                 error "bad target"
163 }
164 run_test 0c "check import proc ============================="
165
166 test_1() {
167         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
168         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
169         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
170         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
171         rmdir $DIR/$tdir/d2
172         rmdir $DIR/$tdir
173         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
174 }
175 run_test 1 "mkdir; remkdir; rmdir =============================="
176
177 test_2() {
178         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
179         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
180         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
181         rm -r $DIR/$tdir
182         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
183 }
184 run_test 2 "mkdir; touch; rmdir; check file ===================="
185
186 test_3() {
187         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
188         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
189         touch $DIR/$tdir/$tfile
190         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
191         rm -r $DIR/$tdir
192         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
193 }
194 run_test 3 "mkdir; touch; rmdir; check dir ====================="
195
196 test_4() {
197         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
198         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
199         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
200         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
201 }
202 run_test 4 "mkdir =============================================="
203
204 test_5() {
205         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
206         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
207         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
208         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
209         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
210 }
211 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
212
213 test_6a() {
214         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
215         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
216         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
217                 error "$tfile does not have perm 0666 or UID $UID"
218 }
219 run_test 6a "touch .../f6a; chmod .../f6a ======================"
220
221 test_6b() {
222         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
223         if [ ! -f $DIR/$tfile ]; then
224                 touch $DIR/$tfile
225                 chmod 0666 $DIR/$tfile
226         fi
227         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
228         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
229                 error "$tfile should be 0666 and owned by UID $UID"
230 }
231 run_test 6b "$RUNAS chmod .../f6a (should return error) =="
232
233 test_6c() {
234         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
235         touch $DIR/$tfile
236         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
237         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
238                 error "$tfile should be owned by UID $RUNAS_ID"
239 }
240 run_test 6c "touch .../f6c; chown .../f6c ======================"
241
242 test_6d() {
243         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
244         if [ ! -f $DIR/$tfile ]; then
245                 touch $DIR/$tfile
246                 chown $RUNAS_ID $DIR/$tfile
247         fi
248         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
249         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
250                 error "$tfile should be owned by UID $RUNAS_ID"
251 }
252 run_test 6d "$RUNAS chown .../f6c (should return error) =="
253
254 test_6e() {
255         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
256         touch $DIR/$tfile
257         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
258         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
259                 error "$tfile should be owned by GID $UID"
260 }
261 run_test 6e "touch .../f6e; chgrp .../f6e ======================"
262
263 test_6f() {
264         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
265         if [ ! -f $DIR/$tfile ]; then
266                 touch $DIR/$tfile
267                 chgrp $RUNAS_ID $DIR/$tfile
268         fi
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 6f "$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         for i in $TESTS; do
486                 local SYMNAME=$(str_repeat 'x' $i)
487                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
488                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
489         done
490 }
491 run_test 17g "symlinks: really long symlink name and inode boundaries"
492
493 test_17h() { #bug 17378
494         remote_mds_nodsh && skip "remote MDS with nodsh" && return
495         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
496         local mdt_idx
497         test_mkdir -p $DIR/$tdir
498         if [ $MDSCOUNT -gt 1 ]; then
499                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
500         else
501                 mdt_idx=0
502         fi
503         $SETSTRIPE -c -1 $DIR/$tdir
504 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
505         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
506         touch $DIR/$tdir/$tfile || true
507 }
508 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
509
510 test_17i() { #bug 20018
511         remote_mds_nodsh && skip "remote MDS with nodsh" && return
512         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
513         test_mkdir -p $DIR/$tdir
514         local foo=$DIR/$tdir/$tfile
515         local mdt_idx
516         if [ $MDSCOUNT -gt 1 ]; then
517                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
518         else
519                 mdt_idx=0
520         fi
521         ln -s $foo $foo || error "create symlink failed"
522 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
523         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
524         ls -l $foo && error "error not detected"
525         return 0
526 }
527 run_test 17i "don't panic on short symlink"
528
529 test_17k() { #bug 22301
530         rsync --help | grep -q xattr ||
531                 skip_env "$(rsync --version| head -1) does not support xattrs"
532         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
533         test_mkdir -p $DIR/$tdir
534         test_mkdir -p $DIR/$tdir.new
535         touch $DIR/$tdir/$tfile
536         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
537         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
538                 error "rsync failed with xattrs enabled"
539 }
540 run_test 17k "symlinks: rsync with xattrs enabled ========================="
541
542 test_17l() { # LU-279
543         mkdir -p $DIR/$tdir
544         touch $DIR/$tdir/$tfile
545         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
546         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
547                 # -h to not follow symlinks. -m '' to list all the xattrs.
548                 # grep to remove first line: '# file: $path'.
549                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
550                 do
551                         lgetxattr_size_check $path $xattr ||
552                                 error "lgetxattr_size_check $path $xattr failed"
553                 done
554         done
555 }
556 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
557
558 # LU-1540
559 test_17m() {
560         local short_sym="0123456789"
561         local WDIR=$DIR/${tdir}m
562         local mds_index
563         local devname
564         local cmd
565         local i
566         local rc=0
567
568         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
569         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
570                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
571
572         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
573                 skip "only for ldiskfs MDT" && return 0
574
575         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
576
577         mkdir -p $WDIR
578         long_sym=$short_sym
579         # create a long symlink file
580         for ((i = 0; i < 4; ++i)); do
581                 long_sym=${long_sym}${long_sym}
582         done
583
584         echo "create 512 short and long symlink files under $WDIR"
585         for ((i = 0; i < 256; ++i)); do
586                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
587                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
588         done
589
590         echo "erase them"
591         rm -f $WDIR/*
592         sync
593         wait_delete_completed
594
595         echo "recreate the 512 symlink files with a shorter string"
596         for ((i = 0; i < 512; ++i)); do
597                 # rewrite the symlink file with a shorter string
598                 ln -sf ${long_sym} $WDIR/long-$i
599                 ln -sf ${short_sym} $WDIR/short-$i
600         done
601
602         mds_index=$($LFS getstripe -M $WDIR)
603         mds_index=$((mds_index+1))
604         devname=$(mdsdevname $mds_index)
605         cmd="$E2FSCK -fnvd $devname"
606
607         echo "stop and checking mds${mds_index}: $cmd"
608         # e2fsck should not return error
609         stop mds${mds_index} -f
610         do_facet mds${mds_index} $cmd || rc=$?
611
612         start mds${mds_index} $devname $MDS_MOUNT_OPTS
613         df $MOUNT > /dev/null 2>&1
614         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
615                 "short/long symlink MDT: rc=$rc"
616         return $rc
617 }
618 run_test 17m "run e2fsck against MDT which contains short/long symlink"
619
620 check_fs_consistency_17n() {
621         local mdt_index
622         local devname
623         local cmd
624         local rc=0
625
626         for mdt_index in $(seq 1 $MDSCOUNT); do
627                 devname=$(mdsdevname $mdt_index)
628                 cmd="$E2FSCK -fnvd $devname"
629
630                 echo "stop and checking mds${mdt_index}: $cmd"
631                 # e2fsck should not return error
632                 stop mds${mdt_index}
633                 do_facet mds${mdt_index} $cmd || rc=$?
634
635                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
636                 df $MOUNT > /dev/null 2>&1
637                 [ $rc -ne 0 ] && break
638         done
639         return $rc
640 }
641
642 test_17n() {
643         local i
644
645         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
646         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
647                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
648
649         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
650                 skip "only for ldiskfs MDT" && return 0
651
652         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
653
654         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
655
656         mkdir -p $DIR/$tdir
657         for ((i=0; i<10; i++)); do
658                 $LFS mkdir -i 1 $DIR/$tdir/remote_dir_${i} ||
659                         error "create remote dir error $i"
660                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
661                         error "create files under remote dir failed $i"
662         done
663
664         check_fs_consistency_17n || error "e2fsck report error"
665
666         for ((i=0;i<10;i++)); do
667                 rm -rf $DIR/$tdir/remote_dir_${i} ||
668                         error "destroy remote dir error $i"
669         done
670
671         check_fs_consistency_17n || error "e2fsck report error"
672 }
673 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
674
675 test_17o() {
676         local WDIR=$DIR/${tdir}o
677         local mdt_index
678         local mdtdevname
679         local rc=0
680
681         mkdir -p $WDIR
682         mdt_index=$($LFS getstripe -M $WDIR)
683         mdt_index=$((mdt_index+1))
684         mdtdevname=$(mdsdevname $mdt_index)
685
686         touch $WDIR/$tfile
687         stop mds${mdt_index}
688         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS
689
690         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
691         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
692         ls -l $WDIR/$tfile && rc=1
693         do_facet mds${mdt_index} lctl set_param fail_loc=0
694         [[ $rc -ne 0 ]] && error "stat file should fail"
695         true
696 }
697 run_test 17o "stat file with incompat LMA feature"
698
699 test_18() {
700         touch $DIR/f || error "Failed to touch $DIR/f: $?"
701         ls $DIR || error "Failed to ls $DIR: $?"
702 }
703 run_test 18 "touch .../f ; ls ... =============================="
704
705 test_19a() {
706         touch $DIR/$tfile
707         ls -l $DIR
708         rm $DIR/$tfile
709         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
710 }
711 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
712
713 test_19b() {
714         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
715 }
716 run_test 19b "ls -l .../f19 (should return error) =============="
717
718 test_19c() {
719         [ $RUNAS_ID -eq $UID ] &&
720                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
721         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
722 }
723 run_test 19c "$RUNAS touch .../f19 (should return error) =="
724
725 test_19d() {
726         cat $DIR/f19 && error || true
727 }
728 run_test 19d "cat .../f19 (should return error) =============="
729
730 test_20() {
731         touch $DIR/$tfile
732         rm $DIR/$tfile
733         log "1 done"
734         touch $DIR/$tfile
735         rm $DIR/$tfile
736         log "2 done"
737         touch $DIR/$tfile
738         rm $DIR/$tfile
739         log "3 done"
740         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
741 }
742 run_test 20 "touch .../f ; ls -l ... ==========================="
743
744 test_21() {
745         test_mkdir -p $DIR/$tdir
746         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
747         ln -s dangle $DIR/$tdir/link
748         echo foo >> $DIR/$tdir/link
749         cat $DIR/$tdir/dangle
750         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
751         $CHECKSTAT -f -t file $DIR/$tdir/link ||
752                 error "$tdir/link not linked to a file"
753 }
754 run_test 21 "write to dangling link ============================"
755
756 test_22() {
757         WDIR=$DIR/$tdir
758         test_mkdir -p $DIR/$tdir
759         chown $RUNAS_ID:$RUNAS_GID $WDIR
760         (cd $WDIR || error "cd $WDIR failed";
761         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
762         $RUNAS tar xf -)
763         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
764         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
765         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
766 }
767 run_test 22 "unpack tar archive as non-root user ==============="
768
769 # was test_23
770 test_23a() {
771         test_mkdir -p $DIR/$tdir
772         local file=$DIR/$tdir/$tfile
773
774         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
775         openfile -f O_CREAT:O_EXCL $file &&
776                 error "$file recreate succeeded" || true
777 }
778 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
779
780 test_23b() { # bug 18988
781         test_mkdir -p $DIR/$tdir
782         local file=$DIR/$tdir/$tfile
783
784         rm -f $file
785         echo foo > $file || error "write filed"
786         echo bar >> $file || error "append filed"
787         $CHECKSTAT -s 8 $file || error "wrong size"
788         rm $file
789 }
790 run_test 23b "O_APPEND check =========================="
791
792 # rename sanity
793 test_24a() {
794         echo '-- same directory rename'
795         test_mkdir $DIR/$tdir
796         touch $DIR/$tdir/$tfile.1
797         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
798         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
799 }
800 run_test 24a "rename file to non-existent target"
801
802 test_24b() {
803         test_mkdir $DIR/$tdir
804         touch $DIR/$tdir/$tfile.{1,2}
805         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
806         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
807         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
808 }
809 run_test 24b "rename file to existing target"
810
811 test_24c() {
812         test_mkdir $DIR/$tdir
813         test_mkdir $DIR/$tdir/d$testnum.1
814         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
815         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
816         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
817 }
818 run_test 24c "rename directory to non-existent target"
819
820 test_24d() {
821         test_mkdir $DIR/$tdir
822         test_mkdir $DIR/$tdir/d$testnum.1
823         test_mkdir $DIR/$tdir/d$ttestnum.2
824         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
825         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
826         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
827 }
828 run_test 24d "rename directory to existing target"
829
830 test_24e() {
831         echo '-- cross directory renames --'
832         test_mkdir $DIR/R5a
833         test_mkdir $DIR/R5b
834         touch $DIR/R5a/f
835         mv $DIR/R5a/f $DIR/R5b/g
836         $CHECKSTAT -a $DIR/R5a/f || error
837         $CHECKSTAT -t file $DIR/R5b/g || error
838 }
839 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
840
841 test_24f() {
842         test_mkdir $DIR/R6a
843         test_mkdir $DIR/R6b
844         touch $DIR/R6a/f $DIR/R6b/g
845         mv $DIR/R6a/f $DIR/R6b/g
846         $CHECKSTAT -a $DIR/R6a/f || error
847         $CHECKSTAT -t file $DIR/R6b/g || error
848 }
849 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
850
851 test_24g() {
852         test_mkdir $DIR/R7a
853         test_mkdir $DIR/R7b
854         test_mkdir $DIR/R7a/d
855         mv $DIR/R7a/d $DIR/R7b/e
856         $CHECKSTAT -a $DIR/R7a/d || error
857         $CHECKSTAT -t dir $DIR/R7b/e || error
858 }
859 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
860
861 test_24h() {
862         test_mkdir $DIR/R8a
863         test_mkdir $DIR/R8b
864         test_mkdir $DIR/R8a/d
865         test_mkdir $DIR/R8b/e
866         mrename $DIR/R8a/d $DIR/R8b/e
867         $CHECKSTAT -a $DIR/R8a/d || error
868         $CHECKSTAT -t dir $DIR/R8b/e || error
869 }
870 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
871
872 test_24i() {
873         echo "-- rename error cases"
874         test_mkdir $DIR/R9
875         test_mkdir $DIR/R9/a
876         touch $DIR/R9/f
877         mrename $DIR/R9/f $DIR/R9/a
878         $CHECKSTAT -t file $DIR/R9/f || error
879         $CHECKSTAT -t dir  $DIR/R9/a || error
880         $CHECKSTAT -a $DIR/R9/a/f || error
881 }
882 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
883
884 test_24j() {
885         test_mkdir $DIR/R10
886         mrename $DIR/R10/f $DIR/R10/g
887         $CHECKSTAT -t dir $DIR/R10 || error
888         $CHECKSTAT -a $DIR/R10/f || error
889         $CHECKSTAT -a $DIR/R10/g || error
890 }
891 run_test 24j "source does not exist ============================"
892
893 test_24k() {
894         test_mkdir $DIR/R11a
895         test_mkdir $DIR/R11a/d
896         touch $DIR/R11a/f
897         mv $DIR/R11a/f $DIR/R11a/d
898         $CHECKSTAT -a $DIR/R11a/f || error
899         $CHECKSTAT -t file $DIR/R11a/d/f || error
900 }
901 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
902
903 # bug 2429 - rename foo foo foo creates invalid file
904 test_24l() {
905         f="$DIR/f24l"
906         $MULTIOP $f OcNs || error
907 }
908 run_test 24l "Renaming a file to itself ========================"
909
910 test_24m() {
911         f="$DIR/f24m"
912         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
913         # on ext3 this does not remove either the source or target files
914         # though the "expected" operation would be to remove the source
915         $CHECKSTAT -t file ${f} || error "${f} missing"
916         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
917 }
918 run_test 24m "Renaming a file to a hard link to itself ========="
919
920 test_24n() {
921     f="$DIR/f24n"
922     # this stats the old file after it was renamed, so it should fail
923     touch ${f}
924     $CHECKSTAT ${f}
925     mv ${f} ${f}.rename
926     $CHECKSTAT ${f}.rename
927     $CHECKSTAT -a ${f}
928 }
929 run_test 24n "Statting the old file after renaming (Posix rename 2)"
930
931 test_24o() {
932         check_kernel_version 37 || return 0
933         test_mkdir -p $DIR/d24o
934         rename_many -s random -v -n 10 $DIR/d24o
935 }
936 run_test 24o "rename of files during htree split ==============="
937
938 test_24p() {
939         test_mkdir $DIR/R12a
940         test_mkdir $DIR/R12b
941         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
942         mrename $DIR/R12a $DIR/R12b
943         $CHECKSTAT -a $DIR/R12a || error
944         $CHECKSTAT -t dir $DIR/R12b || error
945         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
946         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
947 }
948 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
949
950 cleanup_multiop_pause() {
951         trap 0
952         kill -USR1 $MULTIPID
953 }
954
955 test_24q() {
956         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
957         test_mkdir $DIR/R13a
958         test_mkdir $DIR/R13b
959         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
960         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
961         MULTIPID=$!
962
963         trap cleanup_multiop_pause EXIT
964         mrename $DIR/R13a $DIR/R13b
965         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
966         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
967         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
968         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
969         cleanup_multiop_pause
970         wait $MULTIPID || error "multiop close failed"
971 }
972 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
973
974 test_24r() { #bug 3789
975         test_mkdir $DIR/R14a
976         test_mkdir $DIR/R14a/b
977         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
978         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
979         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
980 }
981 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
982
983 test_24s() {
984         test_mkdir $DIR/R15a
985         test_mkdir $DIR/R15a/b
986         test_mkdir $DIR/R15a/b/c
987         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
988         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
989         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
990 }
991 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
992 test_24t() {
993         test_mkdir $DIR/R16a
994         test_mkdir $DIR/R16a/b
995         test_mkdir $DIR/R16a/b/c
996         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
997         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
998         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
999 }
1000 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1001
1002 test_24u() { # bug12192
1003         rm -rf $DIR/$tfile
1004         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1005         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1006 }
1007 run_test 24u "create stripe file"
1008
1009 page_size() {
1010         getconf PAGE_SIZE
1011 }
1012
1013 simple_cleanup_common() {
1014         trap 0
1015         rm -rf $DIR/$tdir
1016         wait_delete_completed
1017 }
1018
1019 max_pages_per_rpc() {
1020         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -1
1021 }
1022
1023 test_24v() {
1024         local NRFILES=100000
1025         local FREE_INODES=$(lfs_df -i | grep "summary" | awk '{print $4}')
1026         [ $FREE_INODES -lt $NRFILES ] && \
1027                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1028                 return
1029
1030         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1031         trap simple_cleanup_common EXIT
1032
1033         mkdir -p $DIR/$tdir
1034         createmany -m $DIR/$tdir/$tfile $NRFILES
1035
1036         cancel_lru_locks mdc
1037         lctl set_param mdc.*.stats clear
1038
1039         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1040
1041         # LU-5 large readdir
1042         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1043         #               8 bytes for name(filename is mostly 5 in this test) +
1044         #               8 bytes for luda_type
1045         # take into account of overhead in lu_dirpage header and end mark in
1046         # each page, plus one in RPC_NUM calculation.
1047         DIRENT_SIZE=48
1048         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1049         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1050         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats | \
1051                                 awk '/^mds_readpage/ {print $2}')
1052         [ $mds_readpage -gt $RPC_NUM ] && \
1053                 error "large readdir doesn't take effect"
1054
1055         simple_cleanup_common
1056 }
1057 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1058
1059 test_24w() { # bug21506
1060         SZ1=234852
1061         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1062         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1063         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1064         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1065         [ "$SZ1" = "$SZ2" ] || \
1066                 error "Error reading at the end of the file $tfile"
1067 }
1068 run_test 24w "Reading a file larger than 4Gb"
1069
1070 test_24x() {
1071         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1073         local MDTIDX=1
1074         local remote_dir=$DIR/$tdir/remote_dir
1075
1076         mkdir -p $DIR/$tdir
1077         $LFS mkdir -i $MDTIDX $remote_dir ||
1078                 error "create remote directory failed"
1079
1080         mkdir -p $DIR/$tdir/src_dir
1081         touch $DIR/$tdir/src_file
1082         mkdir -p $remote_dir/tgt_dir
1083         touch $remote_dir/tgt_file
1084
1085         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1086                 error "rename dir cross MDT works!"
1087
1088         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1089                 error "rename file cross MDT works!"
1090
1091         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1092                 error "ln file cross MDT should not work!"
1093
1094         rm -rf $DIR/$tdir || error "Can not delete directories"
1095 }
1096 run_test 24x "cross rename/link should be failed"
1097
1098 test_24y() {
1099         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1100         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1101         local MDTIDX=1
1102         local remote_dir=$DIR/$tdir/remote_dir
1103
1104         mkdir -p $DIR/$tdir
1105         $LFS mkdir -i $MDTIDX $remote_dir ||
1106                    error "create remote directory failed"
1107
1108         mkdir -p $remote_dir/src_dir
1109         touch $remote_dir/src_file
1110         mkdir -p $remote_dir/tgt_dir
1111         touch $remote_dir/tgt_file
1112
1113         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1114                 error "rename subdir in the same remote dir failed!"
1115
1116         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1117                 error "rename files in the same remote dir failed!"
1118
1119         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1120                 error "link files in the same remote dir failed!"
1121
1122         rm -rf $DIR/$tdir || error "Can not delete directories"
1123 }
1124 run_test 24y "rename/link on the same dir should succeed"
1125
1126 test_24z() {
1127         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1128         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1129         local MDTIDX=1
1130         local remote_src=$DIR/$tdir/remote_dir
1131         local remote_tgt=$DIR/$tdir/remote_tgt
1132
1133         mkdir -p $DIR/$tdir
1134         $LFS mkdir -i $MDTIDX $remote_src ||
1135                    error "create remote directory failed"
1136
1137         $LFS mkdir -i $MDTIDX $remote_tgt ||
1138                    error "create remote directory failed"
1139
1140         mrename $remote_src $remote_tgt &&
1141                 error "rename remote dirs should not work!"
1142
1143         # If target dir does not exists, it should succeed
1144         rm -rf $remote_tgt
1145         mrename $remote_src $remote_tgt ||
1146                 error "rename remote dirs(tgt dir does not exists) failed!"
1147
1148         rm -rf $DIR/$tdir || error "Can not delete directories"
1149 }
1150 run_test 24z "rename one remote dir to another remote dir should fail"
1151
1152 test_25a() {
1153         echo '== symlink sanity ============================================='
1154
1155         test_mkdir $DIR/d25
1156         ln -s d25 $DIR/s25
1157         touch $DIR/s25/foo || error
1158 }
1159 run_test 25a "create file in symlinked directory ==============="
1160
1161 test_25b() {
1162         [ ! -d $DIR/d25 ] && test_25a
1163         $CHECKSTAT -t file $DIR/s25/foo || error
1164 }
1165 run_test 25b "lookup file in symlinked directory ==============="
1166
1167 test_26a() {
1168         test_mkdir $DIR/d26
1169         test_mkdir $DIR/d26/d26-2
1170         ln -s d26/d26-2 $DIR/s26
1171         touch $DIR/s26/foo || error
1172 }
1173 run_test 26a "multiple component symlink ======================="
1174
1175 test_26b() {
1176         test_mkdir -p $DIR/d26b/d26-2
1177         ln -s d26b/d26-2/foo $DIR/s26-2
1178         touch $DIR/s26-2 || error
1179 }
1180 run_test 26b "multiple component symlink at end of lookup ======"
1181
1182 test_26c() {
1183         test_mkdir $DIR/d26.2
1184         touch $DIR/d26.2/foo
1185         ln -s d26.2 $DIR/s26.2-1
1186         ln -s s26.2-1 $DIR/s26.2-2
1187         ln -s s26.2-2 $DIR/s26.2-3
1188         chmod 0666 $DIR/s26.2-3/foo
1189 }
1190 run_test 26c "chain of symlinks ================================"
1191
1192 # recursive symlinks (bug 439)
1193 test_26d() {
1194         ln -s d26-3/foo $DIR/d26-3
1195 }
1196 run_test 26d "create multiple component recursive symlink ======"
1197
1198 test_26e() {
1199         [ ! -h $DIR/d26-3 ] && test_26d
1200         rm $DIR/d26-3
1201 }
1202 run_test 26e "unlink multiple component recursive symlink ======"
1203
1204 # recursive symlinks (bug 7022)
1205 test_26f() {
1206         test_mkdir -p $DIR/$tdir
1207         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1208         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1209         test_mkdir -p lndir bar1      || error "mkdir lndir/bar1 failed"
1210         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1211         cd $tfile                || error "cd $tfile failed"
1212         ln -s .. dotdot          || error "ln dotdot failed"
1213         ln -s dotdot/lndir lndir || error "ln lndir failed"
1214         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1215         output=`ls $tfile/$tfile/lndir/bar1`
1216         [ "$output" = bar1 ] && error "unexpected output"
1217         rm -r $tfile             || error "rm $tfile failed"
1218         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1219 }
1220 run_test 26f "rm -r of a directory which has recursive symlink ="
1221
1222 test_27a() {
1223         echo '== stripe sanity =============================================='
1224         test_mkdir -p $DIR/d27 || error "mkdir failed"
1225         $GETSTRIPE $DIR/d27
1226         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1227         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1228         pass
1229         log "== test_27a: write to one stripe file ========================="
1230         cp /etc/hosts $DIR/d27/f0 || error
1231 }
1232 run_test 27a "one stripe file =================================="
1233
1234 test_27b() {
1235         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1236         test_mkdir -p $DIR/d27
1237         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1238         $GETSTRIPE -c $DIR/d27/f01
1239         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1240                 error "two-stripe file doesn't have two stripes"
1241 }
1242 run_test 27b "create two stripe file"
1243
1244 test_27c() {
1245         [ -f $DIR/d27/f01 ] || skip "test_27b not run" && return
1246
1247         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1248 }
1249 run_test 27c "write to two stripe file"
1250
1251 test_27d() {
1252         test_mkdir -p $DIR/d27
1253         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1254         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1255         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1256 }
1257 run_test 27d "create file with default settings ================"
1258
1259 test_27e() {
1260         test_mkdir -p $DIR/d27
1261         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1262         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1263         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1264 }
1265 run_test 27e "setstripe existing file (should return error) ======"
1266
1267 test_27f() {
1268         test_mkdir -p $DIR/d27
1269         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1270         dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed"
1271         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1272 }
1273 run_test 27f "setstripe with bad stripe size (should return error)"
1274
1275 test_27g() {
1276         test_mkdir -p $DIR/d27
1277         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1278         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1279                 error "$DIR/d27/fnone has object"
1280 }
1281 run_test 27g "$GETSTRIPE with no objects"
1282
1283 test_27i() {
1284         touch $DIR/d27/fsome || error "touch failed"
1285         [ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ] || error "missing objects"
1286 }
1287 run_test 27i "$GETSTRIPE with some objects"
1288
1289 test_27j() {
1290         test_mkdir -p $DIR/d27
1291         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1292 }
1293 run_test 27j "setstripe with bad stripe offset (should return error)"
1294
1295 test_27k() { # bug 2844
1296         test_mkdir -p $DIR/d27
1297         FILE=$DIR/d27/f27k
1298         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1299         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1300         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1301         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1302         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
1303         dd if=/dev/zero of=$FILE bs=4k count=1
1304         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1305         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
1306 }
1307 run_test 27k "limit i_blksize for broken user apps ============="
1308
1309 test_27l() {
1310         test_mkdir -p $DIR/d27
1311         mcreate $DIR/f27l || error "creating file"
1312         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1313                 error "setstripe should have failed" || true
1314 }
1315 run_test 27l "check setstripe permissions (should return error)"
1316
1317 test_27m() {
1318         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1319                 return
1320         if [ $ORIGFREE -gt $MAXFREE ]; then
1321                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1322                 return
1323         fi
1324         trap simple_cleanup_common EXIT
1325         test_mkdir -p $DIR/$tdir
1326         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1327         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1328                 error "dd should fill OST0"
1329         i=2
1330         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1331                 i=`expr $i + 1`
1332                 [ $i -gt 256 ] && break
1333         done
1334         i=`expr $i + 1`
1335         touch $DIR/$tdir/f27m_$i
1336         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1337                 error "OST0 was full but new created file still use it"
1338         i=`expr $i + 1`
1339         touch $DIR/$tdir/f27m_$i
1340         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1341                 error "OST0 was full but new created file still use it"
1342         simple_cleanup_common
1343 }
1344 run_test 27m "create file while OST0 was full =================="
1345
1346 sleep_maxage() {
1347         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1348         sleep $DELAY
1349 }
1350
1351 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1352 # if the OST isn't full anymore.
1353 reset_enospc() {
1354         local OSTIDX=${1:-""}
1355
1356         local list=$(comma_list $(osts_nodes))
1357         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1358
1359         do_nodes $list lctl set_param fail_loc=0
1360         sync    # initiate all OST_DESTROYs from MDS to OST
1361         sleep_maxage
1362 }
1363
1364 exhaust_precreations() {
1365         local OSTIDX=$1
1366         local FAILLOC=$2
1367         local FAILIDX=${3:-$OSTIDX}
1368
1369         test_mkdir -p $DIR/$tdir
1370         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1371         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1372
1373         local OST=$(ostname_from_index $OSTIDX)
1374         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1375                           sed -e 's/_UUID$//;s/^.*-//')
1376
1377         # on the mdt's osc
1378         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1379         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1380         osc.$mdtosc_proc1.prealloc_last_id)
1381         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1382         osc.$mdtosc_proc1.prealloc_next_id)
1383
1384         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1385         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1386
1387         test_mkdir -p $DIR/$tdir/${OST}
1388         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1389 #define OBD_FAIL_OST_ENOSPC              0x215
1390         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1391         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1392         echo "Creating to objid $last_id on ost $OST..."
1393         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1394         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1395         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1396         sleep_maxage
1397 }
1398
1399 exhaust_all_precreations() {
1400         local i
1401         for (( i=0; i < OSTCOUNT; i++ )) ; do
1402                 exhaust_precreations $i $1 -1
1403         done
1404 }
1405
1406 test_27n() {
1407         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1408         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1409         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1410         remote_ost_nodsh && skip "remote OST with nodsh" && return
1411
1412         reset_enospc
1413         rm -f $DIR/$tdir/$tfile
1414         exhaust_precreations 0 0x80000215
1415         $SETSTRIPE -c -1 $DIR/$tdir
1416         touch $DIR/$tdir/$tfile || error
1417         $GETSTRIPE $DIR/$tdir/$tfile
1418         reset_enospc
1419 }
1420 run_test 27n "create file with some full OSTs =================="
1421
1422 test_27o() {
1423         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1424         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1425         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1426         remote_ost_nodsh && skip "remote OST with nodsh" && return
1427
1428         reset_enospc
1429         rm -f $DIR/$tdir/$tfile
1430         exhaust_all_precreations 0x215
1431
1432         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1433
1434         reset_enospc
1435         rm -rf $DIR/$tdir/*
1436 }
1437 run_test 27o "create file with all full OSTs (should error) ===="
1438
1439 test_27p() {
1440         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1441         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1442         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1443         remote_ost_nodsh && skip "remote OST with nodsh" && return
1444
1445         reset_enospc
1446         rm -f $DIR/$tdir/$tfile
1447         test_mkdir -p $DIR/$tdir
1448
1449         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1450         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1451         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1452
1453         exhaust_precreations 0 0x80000215
1454         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1455         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1456         $GETSTRIPE $DIR/$tdir/$tfile
1457
1458         reset_enospc
1459 }
1460 run_test 27p "append to a truncated file with some full OSTs ==="
1461
1462 test_27q() {
1463         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1465         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1466         remote_ost_nodsh && skip "remote OST with nodsh" && return
1467
1468         reset_enospc
1469         rm -f $DIR/$tdir/$tfile
1470
1471         test_mkdir -p $DIR/$tdir
1472         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1473         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1474         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1475
1476         exhaust_all_precreations 0x215
1477
1478         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1479         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1480
1481         reset_enospc
1482 }
1483 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1484
1485 test_27r() {
1486         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1487         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1488         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1489         remote_ost_nodsh && skip "remote OST with nodsh" && return
1490
1491         reset_enospc
1492         rm -f $DIR/$tdir/$tfile
1493         exhaust_precreations 0 0x80000215
1494
1495         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1496
1497         reset_enospc
1498 }
1499 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1500
1501 test_27s() { # bug 10725
1502         test_mkdir -p $DIR/$tdir
1503         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1504         local stripe_count=0
1505         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1506         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1507                 error "stripe width >= 2^32 succeeded" || true
1508
1509 }
1510 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1511
1512 test_27t() { # bug 10864
1513         WDIR=`pwd`
1514         WLFS=`which lfs`
1515         cd $DIR
1516         touch $tfile
1517         $WLFS getstripe $tfile
1518         cd $WDIR
1519 }
1520 run_test 27t "check that utils parse path correctly"
1521
1522 test_27u() { # bug 4900
1523         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1524         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1525         local index
1526         local list=$(comma_list $(mdts_nodes))
1527
1528 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1529         do_nodes $list $LCTL set_param fail_loc=0x139
1530         test_mkdir -p $DIR/$tdir
1531         rm -rf $DIR/$tdir/*
1532         createmany -o $DIR/$tdir/t- 1000
1533         do_nodes $list $LCTL set_param fail_loc=0
1534
1535         TLOG=$DIR/$tfile.getstripe
1536         $GETSTRIPE $DIR/$tdir > $TLOG
1537         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1538         unlinkmany $DIR/$tdir/t- 1000
1539         [ $OBJS -gt 0 ] && \
1540                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1541 }
1542 run_test 27u "skip object creation on OSC w/o objects =========="
1543
1544 test_27v() { # bug 4900
1545         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1546         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1547         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1548         remote_ost_nodsh && skip "remote OST with nodsh" && return
1549
1550         exhaust_all_precreations 0x215
1551         reset_enospc
1552
1553         test_mkdir -p $DIR/$tdir
1554         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1555
1556         touch $DIR/$tdir/$tfile
1557         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1558         # all except ost1
1559         for (( i=1; i < OSTCOUNT; i++ )); do
1560                 do_facet ost$i lctl set_param fail_loc=0x705
1561         done
1562         local START=`date +%s`
1563         createmany -o $DIR/$tdir/$tfile 32
1564
1565         local FINISH=`date +%s`
1566         local TIMEOUT=`lctl get_param -n timeout`
1567         local PROCESS=$((FINISH - START))
1568         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1569                error "$FINISH - $START >= $TIMEOUT / 2"
1570         sleep $((TIMEOUT / 2 - PROCESS))
1571         reset_enospc
1572 }
1573 run_test 27v "skip object creation on slow OST ================="
1574
1575 test_27w() { # bug 10997
1576         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1577         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1578         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1579                 error "stripe size $size != 65536" || true
1580         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1581                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1582 }
1583 run_test 27w "check $SETSTRIPE -S option"
1584
1585 test_27wa() {
1586         [ "$OSTCOUNT" -lt "2" ] &&
1587                 skip_env "skipping multiple stripe count/offset test" && return
1588
1589         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1590         for i in $(seq 1 $OSTCOUNT); do
1591                 offset=$((i - 1))
1592                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1593                         error "setstripe -c $i -i $offset failed"
1594                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1595                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1596                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1597                 [ $index -ne $offset ] &&
1598                         error "stripe offset $index != $offset" || true
1599         done
1600 }
1601 run_test 27wa "check $SETSTRIPE -c -i options"
1602
1603 test_27x() {
1604         remote_ost_nodsh && skip "remote OST with nodsh" && return
1605         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
1606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1607         OFFSET=$(($OSTCOUNT - 1))
1608         OSTIDX=0
1609         local OST=$(ostname_from_index $OSTIDX)
1610
1611         test_mkdir -p $DIR/$tdir
1612         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1613         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1614         sleep_maxage
1615         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1616         for i in `seq 0 $OFFSET`; do
1617                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1618                 error "OST0 was degraded but new created file still use it"
1619         done
1620         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1621 }
1622 run_test 27x "create files while OST0 is degraded"
1623
1624 test_27y() {
1625         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1626         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1627         remote_ost_nodsh && skip "remote OST with nodsh" && return
1628         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1629
1630         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1631         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1632             osc.$mdtosc.prealloc_last_id)
1633         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1634             osc.$mdtosc.prealloc_next_id)
1635         local fcount=$((last_id - next_id))
1636         [ $fcount -eq 0 ] && skip "not enough space on OST0" && return
1637         [ $fcount -gt $OSTCOUNT ] && fcount=$OSTCOUNT
1638
1639         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1640                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1641         local OST_DEACTIVE_IDX=-1
1642         local OSC
1643         local OSTIDX
1644         local OST
1645
1646         for OSC in $MDS_OSCS; do
1647                 OST=$(osc_to_ost $OSC)
1648                 OSTIDX=$(index_from_ostuuid $OST)
1649                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1650                         OST_DEACTIVE_IDX=$OSTIDX
1651                 fi
1652                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1653                         echo $OSC "is Deactivated:"
1654                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1655                 fi
1656         done
1657
1658         OSTIDX=$(index_from_ostuuid $OST)
1659         mkdir -p $DIR/$tdir
1660         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1661
1662         for OSC in $MDS_OSCS; do
1663                 OST=$(osc_to_ost $OSC)
1664                 OSTIDX=$(index_from_ostuuid $OST)
1665                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1666                         echo $OST "is degraded:"
1667                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1668                                                 obdfilter.$OST.degraded=1
1669                 fi
1670         done
1671
1672         sleep_maxage
1673         createmany -o $DIR/$tdir/$tfile $fcount
1674
1675         for OSC in $MDS_OSCS; do
1676                 OST=$(osc_to_ost $OSC)
1677                 OSTIDX=$(index_from_ostuuid $OST)
1678                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1679                         echo $OST "is recovered from degraded:"
1680                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1681                                                 obdfilter.$OST.degraded=0
1682                 else
1683                         do_facet $SINGLEMDS lctl --device %$OSC activate
1684                 fi
1685         done
1686
1687         # all osp devices get activated, hence -1 stripe count restored
1688         local stripecnt=0
1689
1690         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1691         # devices get activated.
1692         sleep_maxage
1693         $SETSTRIPE -c -1 $DIR/$tfile
1694         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1695         rm -f $DIR/$tfile
1696         [ $stripecnt -ne $OSTCOUNT ] &&
1697                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1698         return 0
1699 }
1700 run_test 27y "create files while OST0 is degraded and the rest inactive"
1701
1702 check_seq_oid()
1703 {
1704         log "check file $1"
1705
1706         lmm_count=$($GETSTRIPE -c $1)
1707         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1708         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1709
1710         local old_ifs="$IFS"
1711         IFS=$'[:]'
1712         fid=($($LFS path2fid $1))
1713         IFS="$old_ifs"
1714
1715         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1716         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1717
1718         # compare lmm_seq and lu_fid->f_seq
1719         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1720         # compare lmm_object_id and lu_fid->oid
1721         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1722
1723         # check the trusted.fid attribute of the OST objects of the file
1724         local have_obdidx=false
1725         local stripe_nr=0
1726         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1727                 # skip lines up to and including "obdidx"
1728                 [ -z "$obdidx" ] && break
1729                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1730                 $have_obdidx || continue
1731
1732                 local ost=$((obdidx + 1))
1733                 local dev=$(ostdevname $ost)
1734                 local oid_hex
1735
1736                 if [ $(facet_fstype ost$ost) != ldiskfs ]; then
1737                         echo "Currently only works with ldiskfs-based OSTs"
1738                         continue
1739                 fi
1740
1741                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1742
1743                 #don't unmount/remount the OSTs if we don't need to do that
1744                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1745                 # update too, until that use mount/ll_decode_filter_fid/mount
1746                 local dir=$(facet_mntpt ost$ost)
1747                 local opts=${OST_MOUNT_OPTS}
1748
1749                 if !  do_facet ost$ost test -b ${dev}; then
1750                         opts=$(csa_add "$opts" -o loop)
1751                 fi
1752
1753                 stop ost$ost
1754                 do_facet ost$ost mount -t $(facet_fstype ost$ost) $opts $dev $dir ||
1755                         { error "mounting $dev as $FSTYPE failed"; return 3; }
1756
1757                 seq=$(echo $seq | sed -e "s/^0x//g")
1758                 if [ $seq == 0 ]; then
1759                         oid_hex=$(echo $oid)
1760                 else
1761                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1762                 fi
1763                 local obj_file=$(do_facet ost$ost find $dir/O/$seq -name $oid_hex)
1764                 local ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID $obj_file)
1765                 do_facet ost$ost umount -d $dir
1766                 start ost$ost $dev $OST_MOUNT_OPTS
1767
1768                 # re-enable when debugfs will understand new filter_fid
1769                 #local ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1770                 #           $dev 2>/dev/null" | grep "parent=")
1771
1772                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1773
1774                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1775
1776                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1777                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1778                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1779                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1780                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1781                 local ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1782
1783                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1784                 [ $ff_pseq = $lmm_seq ] ||
1785                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1786                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1787                 [ $ff_poid = $lmm_oid ] ||
1788                         error "FF parent OID $ff_poid != $lmm_oid"
1789                 [ $ff_pstripe = $stripe_nr ] ||
1790                         error "FF stripe $ff_pstripe != $stripe_nr"
1791
1792                 stripe_nr=$((stripe_nr + 1))
1793         done
1794 }
1795
1796 test_27z() {
1797         remote_ost_nodsh && skip "remote OST with nodsh" && return
1798         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1799         test_mkdir -p $DIR/$tdir
1800
1801         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1802                 { error "setstripe -c -1 failed"; return 1; }
1803         # We need to send a write to every object to get parent FID info set.
1804         # This _should_ also work for setattr, but does not currently.
1805         # touch $DIR/$tdir/$tfile-1 ||
1806         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1807                 { error "dd $tfile-1 failed"; return 2; }
1808         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1809                 { error "setstripe -c -1 failed"; return 3; }
1810         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1811                 { error "dd $tfile-2 failed"; return 4; }
1812
1813         # make sure write RPCs have been sent to OSTs
1814         sync; sleep 5; sync
1815
1816         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1817         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1818 }
1819 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1820
1821 test_27A() { # b=19102
1822         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1823         local restore_size=$($GETSTRIPE -S $MOUNT)
1824         local restore_count=$($GETSTRIPE -c $MOUNT)
1825         local restore_offset=$($GETSTRIPE -i $MOUNT)
1826         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1827         local default_size=$($GETSTRIPE -S $MOUNT)
1828         local default_count=$($GETSTRIPE -c $MOUNT)
1829         local default_offset=$($GETSTRIPE -i $MOUNT)
1830         local dsize=$((1024 * 1024))
1831         [ $default_size -eq $dsize ] ||
1832                 error "stripe size $default_size != $dsize"
1833         [ $default_count -eq 1 ] || error "stripe count $default_count != 1"
1834         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1835         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1836 }
1837 run_test 27A "check filesystem-wide default LOV EA values"
1838
1839 test_27B() { # LU-2523
1840         test_mkdir -p $DIR/$tdir
1841         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1842         touch $DIR/$tdir/f0
1843         # open f1 with O_LOV_DELAY_CREATE
1844         # rename f0 onto f1
1845         # call setstripe ioctl on open file descriptor for f1
1846         # close
1847         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1848                 $DIR/$tdir/f0
1849
1850         rm -f $DIR/$tdir/f1
1851         # open f1 with O_LOV_DELAY_CREATE
1852         # unlink f1
1853         # call setstripe ioctl on open file descriptor for f1
1854         # close
1855         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1856
1857         # Allow multiop to fail in imitation of NFS's busted semantics.
1858         true
1859 }
1860 run_test 27B "call setstripe on open unlinked file/rename victim"
1861
1862 test_27C() { #LU-2871
1863         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1864
1865         declare -a ost_idx
1866         local index
1867         local found
1868         local i
1869         local j
1870
1871         test_mkdir -p $DIR/$tdir
1872         cd $DIR/$tdir
1873         for i in $(seq 0 $((OSTCOUNT - 1))); do
1874                 # set stripe across all OSTs starting from OST$i
1875                 $SETSTRIPE -i $i -c -1 $tfile$i
1876                 # get striping information
1877                 ost_idx=($($GETSTRIPE $tfile$i |
1878                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1879                 echo ${ost_idx[@]}
1880
1881                 # check the layout
1882                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1883                         error "${#ost_idx[@]} != $OSTCOUNT"
1884
1885                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1886                         found=0
1887                         for j in $(echo ${ost_idx[@]}); do
1888                                 if [ $index -eq $j ]; then
1889                                         found=1
1890                                         break
1891                                 fi
1892                         done
1893                         [ $found = 1 ] ||
1894                                 error "Can not find $index in ${ost_idx[@]}"
1895                 done
1896         done
1897 }
1898 run_test 27C "check full striping across all OSTs"
1899
1900 # createtest also checks that device nodes are created and
1901 # then visible correctly (#2091)
1902 test_28() { # bug 2091
1903         test_mkdir $DIR/d28
1904         $CREATETEST $DIR/d28/ct || error
1905 }
1906 run_test 28 "create/mknod/mkdir with bad file types ============"
1907
1908 test_29() {
1909         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1910         cancel_lru_locks mdc
1911         test_mkdir $DIR/d29
1912         touch $DIR/d29/foo
1913         log 'first d29'
1914         ls -l $DIR/d29
1915
1916         declare -i LOCKCOUNTORIG=0
1917         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1918                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1919         done
1920         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1921
1922         declare -i LOCKUNUSEDCOUNTORIG=0
1923         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1924                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1925         done
1926
1927         log 'second d29'
1928         ls -l $DIR/d29
1929         log 'done'
1930
1931         declare -i LOCKCOUNTCURRENT=0
1932         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1933                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1934         done
1935
1936         declare -i LOCKUNUSEDCOUNTCURRENT=0
1937         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1938                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1939         done
1940
1941         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1942                 lctl set_param -n ldlm.dump_namespaces ""
1943                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1944                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1945                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1946                 return 2
1947         fi
1948         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1949                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1950                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1951                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1952                 return 3
1953         fi
1954 }
1955 run_test 29 "IT_GETATTR regression  ============================"
1956
1957 test_30a() { # was test_30
1958         cp `which ls` $DIR || cp /bin/ls $DIR
1959         $DIR/ls / || error
1960         rm $DIR/ls
1961 }
1962 run_test 30a "execute binary from Lustre (execve) =============="
1963
1964 test_30b() {
1965         cp `which ls` $DIR || cp /bin/ls $DIR
1966         chmod go+rx $DIR/ls
1967         $RUNAS $DIR/ls / || error
1968         rm $DIR/ls
1969 }
1970 run_test 30b "execute binary from Lustre as non-root ==========="
1971
1972 test_30c() { # b=22376
1973         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1974         cp `which ls` $DIR || cp /bin/ls $DIR
1975         chmod a-rw $DIR/ls
1976         cancel_lru_locks mdc
1977         cancel_lru_locks osc
1978         $RUNAS $DIR/ls / || error
1979         rm -f $DIR/ls
1980 }
1981 run_test 30c "execute binary from Lustre without read perms ===="
1982
1983 test_31a() {
1984         $OPENUNLINK $DIR/f31 $DIR/f31 || error
1985         $CHECKSTAT -a $DIR/f31 || error
1986 }
1987 run_test 31a "open-unlink file =================================="
1988
1989 test_31b() {
1990         touch $DIR/f31 || error
1991         ln $DIR/f31 $DIR/f31b || error
1992         $MULTIOP $DIR/f31b Ouc || error
1993         $CHECKSTAT -t file $DIR/f31 || error
1994 }
1995 run_test 31b "unlink file with multiple links while open ======="
1996
1997 test_31c() {
1998         touch $DIR/f31 || error
1999         ln $DIR/f31 $DIR/f31c || error
2000         multiop_bg_pause $DIR/f31 O_uc || return 1
2001         MULTIPID=$!
2002         $MULTIOP $DIR/f31c Ouc
2003         kill -USR1 $MULTIPID
2004         wait $MULTIPID
2005 }
2006 run_test 31c "open-unlink file with multiple links ============="
2007
2008 test_31d() {
2009         opendirunlink $DIR/d31d $DIR/d31d || error
2010         $CHECKSTAT -a $DIR/d31d || error
2011 }
2012 run_test 31d "remove of open directory ========================="
2013
2014 test_31e() { # bug 2904
2015         check_kernel_version 34 || return 0
2016         openfilleddirunlink $DIR/d31e || error
2017 }
2018 run_test 31e "remove of open non-empty directory ==============="
2019
2020 test_31f() { # bug 4554
2021         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2022         set -vx
2023         test_mkdir $DIR/d31f
2024         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2025         cp /etc/hosts $DIR/d31f
2026         ls -l $DIR/d31f
2027         $GETSTRIPE $DIR/d31f/hosts
2028         multiop_bg_pause $DIR/d31f D_c || return 1
2029         MULTIPID=$!
2030
2031         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2032         test_mkdir $DIR/d31f
2033         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2034         cp /etc/hosts $DIR/d31f
2035         ls -l $DIR/d31f
2036         $GETSTRIPE $DIR/d31f/hosts
2037         multiop_bg_pause $DIR/d31f D_c || return 1
2038         MULTIPID2=$!
2039
2040         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2041         wait $MULTIPID || error "first opendir $MULTIPID failed"
2042
2043         sleep 6
2044
2045         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2046         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2047         set +vx
2048 }
2049 run_test 31f "remove of open directory with open-unlink file ==="
2050
2051 test_31g() {
2052         echo "-- cross directory link --"
2053         test_mkdir $DIR/d31ga
2054         test_mkdir $DIR/d31gb
2055         touch $DIR/d31ga/f
2056         ln $DIR/d31ga/f $DIR/d31gb/g
2057         $CHECKSTAT -t file $DIR/d31ga/f || error "source"
2058         [ `stat -c%h $DIR/d31ga/f` == '2' ] || error "source nlink"
2059         $CHECKSTAT -t file $DIR/d31gb/g || error "target"
2060         [ `stat -c%h $DIR/d31gb/g` == '2' ] || error "target nlink"
2061 }
2062 run_test 31g "cross directory link==============="
2063
2064 test_31h() {
2065         echo "-- cross directory link --"
2066         test_mkdir $DIR/d31h
2067         test_mkdir $DIR/d31h/dir
2068         touch $DIR/d31h/f
2069         ln $DIR/d31h/f $DIR/d31h/dir/g
2070         $CHECKSTAT -t file $DIR/d31h/f || error "source"
2071         [ `stat -c%h $DIR/d31h/f` == '2' ] || error "source nlink"
2072         $CHECKSTAT -t file $DIR/d31h/dir/g || error "target"
2073         [ `stat -c%h $DIR/d31h/dir/g` == '2' ] || error "target nlink"
2074 }
2075 run_test 31h "cross directory link under child==============="
2076
2077 test_31i() {
2078         echo "-- cross directory link --"
2079         test_mkdir $DIR/d31i
2080         test_mkdir $DIR/d31i/dir
2081         touch $DIR/d31i/dir/f
2082         ln $DIR/d31i/dir/f $DIR/d31i/g
2083         $CHECKSTAT -t file $DIR/d31i/dir/f || error "source"
2084         [ `stat -c%h $DIR/d31i/dir/f` == '2' ] || error "source nlink"
2085         $CHECKSTAT -t file $DIR/d31i/g || error "target"
2086         [ `stat -c%h $DIR/d31i/g` == '2' ] || error "target nlink"
2087 }
2088 run_test 31i "cross directory link under parent==============="
2089
2090
2091 test_31j() {
2092         test_mkdir $DIR/d31j
2093         test_mkdir $DIR/d31j/dir1
2094         ln $DIR/d31j/dir1 $DIR/d31j/dir2 && error "ln for dir"
2095         link $DIR/d31j/dir1 $DIR/d31j/dir3 && error "link for dir"
2096         mlink $DIR/d31j/dir1 $DIR/d31j/dir4 && error "mlink for dir"
2097         mlink $DIR/d31j/dir1 $DIR/d31j/dir1 && error "mlink to the same dir"
2098         return 0
2099 }
2100 run_test 31j "link for directory==============="
2101
2102
2103 test_31k() {
2104         test_mkdir $DIR/d31k
2105         touch $DIR/d31k/s
2106         touch $DIR/d31k/exist
2107         mlink $DIR/d31k/s $DIR/d31k/t || error "mlink"
2108         mlink $DIR/d31k/s $DIR/d31k/exist && error "mlink to exist file"
2109         mlink $DIR/d31k/s $DIR/d31k/s && error "mlink to the same file"
2110         mlink $DIR/d31k/s $DIR/d31k && error "mlink to parent dir"
2111         mlink $DIR/d31k $DIR/d31k/s && error "mlink parent dir to target"
2112         mlink $DIR/d31k/not-exist $DIR/d31k/foo && error "mlink non-existing to new"
2113         mlink $DIR/d31k/not-exist $DIR/d31k/s && error "mlink non-existing to exist"
2114         return 0
2115 }
2116 run_test 31k "link to file: the same, non-existing, dir==============="
2117
2118 test_31m() {
2119         test_mkdir $DIR/d31m
2120         touch $DIR/d31m/s
2121         test_mkdir $DIR/d31m2
2122         touch $DIR/d31m2/exist
2123         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2124         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2125         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2126         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2127         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2128         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2129         return 0
2130 }
2131 run_test 31m "link to file: the same, non-existing, dir==============="
2132
2133 test_31n() {
2134         [ -e /proc/self/fd/173 ] && echo "skipping, fd 173 is in use" && return
2135         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2136         nlink=$(stat --format=%h $DIR/$tfile)
2137         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2138         exec 173<$DIR/$tfile
2139         trap "exec 173<&-" EXIT
2140         nlink=$(stat --dereference --format=%h /proc/self/fd/173)
2141         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2142         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2143         nlink=$(stat --dereference --format=%h /proc/self/fd/173)
2144         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2145         exec 173<&-
2146 }
2147 run_test 31n "check link count of unlinked file"
2148
2149 cleanup_test32_mount() {
2150         trap 0
2151         $UMOUNT $DIR/$tdir/ext2-mountpoint
2152 }
2153
2154 test_32a() {
2155         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2156         echo "== more mountpoints and symlinks ================="
2157         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2158         trap cleanup_test32_mount EXIT
2159         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2160         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2161         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2162         cleanup_test32_mount
2163 }
2164 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2165
2166 test_32b() {
2167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2168         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2169         trap cleanup_test32_mount EXIT
2170         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2171         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2172         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2173         cleanup_test32_mount
2174 }
2175 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2176
2177 test_32c() {
2178         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2179         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2180         trap cleanup_test32_mount EXIT
2181         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2182         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2183         test_mkdir -p $DIR/$tdir/d2/test_dir
2184         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2185         cleanup_test32_mount
2186 }
2187 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2188
2189 test_32d() {
2190         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2191         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2192         trap cleanup_test32_mount EXIT
2193         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2194         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2195         test_mkdir -p $DIR/$tdir/d2/test_dir
2196         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2197         cleanup_test32_mount
2198 }
2199 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2200
2201 test_32e() {
2202         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2203         test_mkdir -p $DIR/d32e/tmp
2204         TMP_DIR=$DIR/d32e/tmp
2205         ln -s $DIR/d32e $TMP_DIR/symlink11
2206         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2207         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2208         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2209 }
2210 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2211
2212 test_32f() {
2213         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2214         test_mkdir -p $DIR/d32f/tmp
2215         TMP_DIR=$DIR/d32f/tmp
2216         ln -s $DIR/d32f $TMP_DIR/symlink11
2217         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2218         ls $DIR/d32f/tmp/symlink11  || error
2219         ls $DIR/d32f/symlink01 || error
2220 }
2221 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2222
2223 test_32g() {
2224         TMP_DIR=$DIR/$tdir/tmp
2225         test_mkdir -p $DIR/$tdir/tmp
2226         test_mkdir $DIR/${tdir}2
2227         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2228         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2229         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2230         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2231         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2232         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2233 }
2234 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2235
2236 test_32h() {
2237         rm -fr $DIR/$tdir $DIR/${tdir}2
2238         TMP_DIR=$DIR/$tdir/tmp
2239         test_mkdir -p $DIR/$tdir/tmp
2240         test_mkdir $DIR/${tdir}2
2241         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2242         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2243         ls $TMP_DIR/symlink12 || error
2244         ls $DIR/$tdir/symlink02  || error
2245 }
2246 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2247
2248 test_32i() {
2249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2250         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2251         trap cleanup_test32_mount EXIT
2252         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2253         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2254         touch $DIR/$tdir/test_file
2255         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2256         cleanup_test32_mount
2257 }
2258 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2259
2260 test_32j() {
2261         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2262         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2263         trap cleanup_test32_mount EXIT
2264         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2265         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2266         touch $DIR/$tdir/test_file
2267         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2268         cleanup_test32_mount
2269 }
2270 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2271
2272 test_32k() {
2273         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2274         rm -fr $DIR/$tdir
2275         trap cleanup_test32_mount EXIT
2276         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2277         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2278         test_mkdir -p $DIR/$tdir/d2
2279         touch $DIR/$tdir/d2/test_file || error
2280         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2281         cleanup_test32_mount
2282 }
2283 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2284
2285 test_32l() {
2286         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2287         rm -fr $DIR/$tdir
2288         trap cleanup_test32_mount EXIT
2289         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2290         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2291         test_mkdir -p $DIR/$tdir/d2
2292         touch $DIR/$tdir/d2/test_file
2293         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2294         cleanup_test32_mount
2295 }
2296 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2297
2298 test_32m() {
2299         rm -fr $DIR/d32m
2300         test_mkdir -p $DIR/d32m/tmp
2301         TMP_DIR=$DIR/d32m/tmp
2302         ln -s $DIR $TMP_DIR/symlink11
2303         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2304         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2305         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2306 }
2307 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2308
2309 test_32n() {
2310         rm -fr $DIR/d32n
2311         test_mkdir -p $DIR/d32n/tmp
2312         TMP_DIR=$DIR/d32n/tmp
2313         ln -s $DIR $TMP_DIR/symlink11
2314         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2315         ls -l $DIR/d32n/tmp/symlink11  || error
2316         ls -l $DIR/d32n/symlink01 || error
2317 }
2318 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2319
2320 test_32o() {
2321         rm -fr $DIR/d32o $DIR/$tfile
2322         touch $DIR/$tfile
2323         test_mkdir -p $DIR/d32o/tmp
2324         TMP_DIR=$DIR/d32o/tmp
2325         ln -s $DIR/$tfile $TMP_DIR/symlink12
2326         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2327         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2328         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2329         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2330         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2331 }
2332 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2333
2334 test_32p() {
2335     log 32p_1
2336         rm -fr $DIR/d32p
2337     log 32p_2
2338         rm -f $DIR/$tfile
2339     log 32p_3
2340         touch $DIR/$tfile
2341     log 32p_4
2342         test_mkdir -p $DIR/d32p/tmp
2343     log 32p_5
2344         TMP_DIR=$DIR/d32p/tmp
2345     log 32p_6
2346         ln -s $DIR/$tfile $TMP_DIR/symlink12
2347     log 32p_7
2348         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2349     log 32p_8
2350         cat $DIR/d32p/tmp/symlink12 || error
2351     log 32p_9
2352         cat $DIR/d32p/symlink02 || error
2353     log 32p_10
2354 }
2355 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2356
2357 cleanup_testdir_mount() {
2358         trap 0
2359         $UMOUNT $DIR/$tdir
2360 }
2361
2362 test_32q() {
2363         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2364         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2365         trap cleanup_testdir_mount EXIT
2366         test_mkdir -p $DIR/$tdir
2367         touch $DIR/$tdir/under_the_mount
2368         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2369         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2370         cleanup_testdir_mount
2371 }
2372 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2373
2374 test_32r() {
2375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2376         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2377         trap cleanup_testdir_mount EXIT
2378         test_mkdir -p $DIR/$tdir
2379         touch $DIR/$tdir/under_the_mount
2380         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2381         ls $DIR/$tdir | grep -q under_the_mount && error || true
2382         cleanup_testdir_mount
2383 }
2384 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2385
2386 test_33aa() {
2387         rm -f $DIR/$tfile
2388         touch $DIR/$tfile
2389         chmod 444 $DIR/$tfile
2390         chown $RUNAS_ID $DIR/$tfile
2391         log 33_1
2392         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2393         log 33_2
2394 }
2395 run_test 33aa "write file with mode 444 (should return error) ===="
2396
2397 test_33a() {
2398         rm -fr $DIR/d33
2399         test_mkdir -p $DIR/d33
2400         chown $RUNAS_ID $DIR/d33
2401         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2402         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2403                 error "open RDWR" || true
2404 }
2405 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2406
2407 test_33b() {
2408         rm -fr $DIR/d33
2409         test_mkdir -p $DIR/d33
2410         chown $RUNAS_ID $DIR/d33
2411         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
2412 }
2413 run_test 33b "test open file with malformed flags (No panic and return error)"
2414
2415 test_33c() {
2416         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2417         local ostnum
2418         local ostname
2419         local write_bytes
2420         local all_zeros
2421
2422         remote_ost_nodsh && skip "remote OST with nodsh" && return
2423         all_zeros=:
2424         rm -fr $DIR/d33
2425         test_mkdir -p $DIR/d33
2426         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2427
2428         sync
2429         for ostnum in $(seq $OSTCOUNT); do
2430                 # test-framework's OST numbering is one-based, while Lustre's
2431                 # is zero-based
2432                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2433                 # Parsing llobdstat's output sucks; we could grep the /proc
2434                 # path, but that's likely to not be as portable as using the
2435                 # llobdstat utility.  So we parse lctl output instead.
2436                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2437                         obdfilter/$ostname/stats |
2438                         awk '/^write_bytes/ {print $7}' )
2439                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2440                 if (( ${write_bytes:-0} > 0 ))
2441                 then
2442                         all_zeros=false
2443                         break;
2444                 fi
2445         done
2446
2447         $all_zeros || return 0
2448
2449         # Write four bytes
2450         echo foo > $DIR/d33/bar
2451         # Really write them
2452         sync
2453
2454         # Total up write_bytes after writing.  We'd better find non-zeros.
2455         for ostnum in $(seq $OSTCOUNT); do
2456                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2457                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2458                         obdfilter/$ostname/stats |
2459                         awk '/^write_bytes/ {print $7}' )
2460                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2461                 if (( ${write_bytes:-0} > 0 ))
2462                 then
2463                         all_zeros=false
2464                         break;
2465                 fi
2466         done
2467
2468         if $all_zeros
2469         then
2470                 for ostnum in $(seq $OSTCOUNT); do
2471                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2472                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2473                         do_facet ost$ostnum lctl get_param -n \
2474                                 obdfilter/$ostname/stats
2475                 done
2476                 error "OST not keeping write_bytes stats (b22312)"
2477         fi
2478 }
2479 run_test 33c "test llobdstat and write_bytes"
2480
2481 test_33d() {
2482         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2484         local MDTIDX=1
2485         local remote_dir=$DIR/$tdir/remote_dir
2486
2487         mkdir -p $DIR/$tdir
2488         $LFS mkdir -i $MDTIDX $remote_dir ||
2489                 error "create remote directory failed"
2490
2491         touch $remote_dir/$tfile
2492         chmod 444 $remote_dir/$tfile
2493         chown $RUNAS_ID $remote_dir/$tfile
2494
2495         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2496
2497         chown $RUNAS_ID $remote_dir
2498         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2499                                         error "create" || true
2500         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2501                                     error "open RDWR" || true
2502         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2503                                     error "create" || true
2504 }
2505 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2506
2507 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2508 test_34a() {
2509         rm -f $DIR/f34
2510         $MCREATE $DIR/f34 || error
2511         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2512         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2513         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2514         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2515 }
2516 run_test 34a "truncate file that has not been opened ==========="
2517
2518 test_34b() {
2519         [ ! -f $DIR/f34 ] && test_34a
2520         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2521         $OPENFILE -f O_RDONLY $DIR/f34
2522         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2523         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2524 }
2525 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2526
2527 test_34c() {
2528         [ ! -f $DIR/f34 ] && test_34a
2529         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2530         $OPENFILE -f O_RDWR $DIR/f34
2531         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2532         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2533 }
2534 run_test 34c "O_RDWR opening file-with-size works =============="
2535
2536 test_34d() {
2537         [ ! -f $DIR/f34 ] && test_34a
2538         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2539         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2540         rm $DIR/f34
2541 }
2542 run_test 34d "write to sparse file ============================="
2543
2544 test_34e() {
2545         rm -f $DIR/f34e
2546         $MCREATE $DIR/f34e || error
2547         $TRUNCATE $DIR/f34e 1000 || error
2548         $CHECKSTAT -s 1000 $DIR/f34e || error
2549         $OPENFILE -f O_RDWR $DIR/f34e
2550         $CHECKSTAT -s 1000 $DIR/f34e || error
2551 }
2552 run_test 34e "create objects, some with size and some without =="
2553
2554 test_34f() { # bug 6242, 6243
2555         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2556         SIZE34F=48000
2557         rm -f $DIR/f34f
2558         $MCREATE $DIR/f34f || error
2559         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2560         dd if=$DIR/f34f of=$TMP/f34f
2561         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2562         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2563         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2564         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2565         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2566 }
2567 run_test 34f "read from a file with no objects until EOF ======="
2568
2569 test_34g() {
2570         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2571         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2572         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2573         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2574         cancel_lru_locks osc
2575         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2576                 error "wrong size after lock cancel"
2577
2578         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2579         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2580                 error "expanding truncate failed"
2581         cancel_lru_locks osc
2582         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2583                 error "wrong expanded size after lock cancel"
2584 }
2585 run_test 34g "truncate long file ==============================="
2586
2587 test_34h() {
2588         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2589         local gid=10
2590         local sz=1000
2591
2592         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2593         sync # Flush the cache so that multiop below does not block on cache
2594              # flush when getting the group lock
2595         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2596         MULTIPID=$!
2597
2598         # Since just timed wait is not good enough, let's do a sync write
2599         # that way we are sure enough time for a roundtrip + processing
2600         # passed + 2 seconds of extra margin.
2601         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2602         rm $DIR/${tfile}-1
2603         sleep 2
2604
2605         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2606                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2607                 kill -9 $MULTIPID
2608         fi
2609         wait $MULTIPID
2610         local nsz=`stat -c %s $DIR/$tfile`
2611         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2612 }
2613 run_test 34h "ftruncate file under grouplock should not block"
2614
2615 test_35a() {
2616         cp /bin/sh $DIR/f35a
2617         chmod 444 $DIR/f35a
2618         chown $RUNAS_ID $DIR/f35a
2619         $RUNAS $DIR/f35a && error || true
2620         rm $DIR/f35a
2621 }
2622 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2623
2624 test_36a() {
2625         rm -f $DIR/f36
2626         utime $DIR/f36 || error
2627 }
2628 run_test 36a "MDS utime check (mknod, utime) ==================="
2629
2630 test_36b() {
2631         echo "" > $DIR/f36
2632         utime $DIR/f36 || error
2633 }
2634 run_test 36b "OST utime check (open, utime) ===================="
2635
2636 test_36c() {
2637         rm -f $DIR/d36/f36
2638         test_mkdir $DIR/d36
2639         chown $RUNAS_ID $DIR/d36
2640         $RUNAS utime $DIR/d36/f36 || error
2641 }
2642 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2643
2644 test_36d() {
2645         [ ! -d $DIR/d36 ] && test_36c
2646         echo "" > $DIR/d36/f36
2647         $RUNAS utime $DIR/d36/f36 || error
2648 }
2649 run_test 36d "non-root OST utime check (open, utime) ==========="
2650
2651 test_36e() {
2652         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2653         test_mkdir -p $DIR/$tdir
2654         touch $DIR/$tdir/$tfile
2655         $RUNAS utime $DIR/$tdir/$tfile && \
2656                 error "utime worked, expected failure" || true
2657 }
2658 run_test 36e "utime on non-owned file (should return error) ===="
2659
2660 subr_36fh() {
2661         local fl="$1"
2662         local LANG_SAVE=$LANG
2663         local LC_LANG_SAVE=$LC_LANG
2664         export LANG=C LC_LANG=C # for date language
2665
2666         DATESTR="Dec 20  2000"
2667         test_mkdir -p $DIR/$tdir
2668         lctl set_param fail_loc=$fl
2669         date; date +%s
2670         cp /etc/hosts $DIR/$tdir/$tfile
2671         sync & # write RPC generated with "current" inode timestamp, but delayed
2672         sleep 1
2673         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2674         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2675         cancel_lru_locks osc
2676         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2677         date; date +%s
2678         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2679                 echo "BEFORE: $LS_BEFORE" && \
2680                 echo "AFTER : $LS_AFTER" && \
2681                 echo "WANT  : $DATESTR" && \
2682                 error "$DIR/$tdir/$tfile timestamps changed" || true
2683
2684         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2685 }
2686
2687 test_36f() {
2688         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2689         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2690         subr_36fh "0x80000214"
2691 }
2692 run_test 36f "utime on file racing with OST BRW write =========="
2693
2694 test_36g() {
2695         remote_ost_nodsh && skip "remote OST with nodsh" && return
2696         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2697         local fmd_max_age
2698         local fmd_before
2699         local fmd_after
2700
2701         test_mkdir -p $DIR/$tdir
2702         fmd_max_age=$(do_facet ost1 \
2703                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2704                 head -n 1")
2705
2706         fmd_before=$(do_facet ost1 \
2707                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2708         touch $DIR/$tdir/$tfile
2709         sleep $((fmd_max_age + 12))
2710         fmd_after=$(do_facet ost1 \
2711                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2712
2713         echo "fmd_before: $fmd_before"
2714         echo "fmd_after: $fmd_after"
2715         [ "$fmd_after" -gt "$fmd_before" ] && \
2716                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" && \
2717                 error "fmd didn't expire after ping" || true
2718 }
2719 run_test 36g "filter mod data cache expiry ====================="
2720
2721 test_36h() {
2722         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2723         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2724         subr_36fh "0x80000227"
2725 }
2726 run_test 36h "utime on file racing with OST BRW write =========="
2727
2728 # test_37 - duplicate with tests 32q 32r
2729
2730 test_38() {
2731         local file=$DIR/$tfile
2732         touch $file
2733         openfile -f O_DIRECTORY $file
2734         local RC=$?
2735         local ENOTDIR=20
2736         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2737         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2738 }
2739 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2740
2741 test_39() {
2742         touch $DIR/$tfile
2743         touch $DIR/${tfile}2
2744 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2745 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2746 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2747         sleep 2
2748         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2749         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2750                 echo "mtime"
2751                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2752                 echo "atime"
2753                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2754                 echo "ctime"
2755                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2756                 error "O_TRUNC didn't change timestamps"
2757         fi
2758 }
2759 run_test 39 "mtime changed on create ==========================="
2760
2761 test_39b() {
2762         test_mkdir -p $DIR/$tdir
2763         cp -p /etc/passwd $DIR/$tdir/fopen
2764         cp -p /etc/passwd $DIR/$tdir/flink
2765         cp -p /etc/passwd $DIR/$tdir/funlink
2766         cp -p /etc/passwd $DIR/$tdir/frename
2767         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2768
2769         sleep 1
2770         echo "aaaaaa" >> $DIR/$tdir/fopen
2771         echo "aaaaaa" >> $DIR/$tdir/flink
2772         echo "aaaaaa" >> $DIR/$tdir/funlink
2773         echo "aaaaaa" >> $DIR/$tdir/frename
2774
2775         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2776         local link_new=`stat -c %Y $DIR/$tdir/flink`
2777         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2778         local rename_new=`stat -c %Y $DIR/$tdir/frename`
2779
2780         cat $DIR/$tdir/fopen > /dev/null
2781         ln $DIR/$tdir/flink $DIR/$tdir/flink2
2782         rm -f $DIR/$tdir/funlink2
2783         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
2784
2785         for (( i=0; i < 2; i++ )) ; do
2786                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
2787                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
2788                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
2789                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
2790
2791                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
2792                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
2793                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
2794                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
2795
2796                 cancel_lru_locks osc
2797                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2798         done
2799 }
2800 run_test 39b "mtime change on open, link, unlink, rename  ======"
2801
2802 # this should be set to past
2803 TEST_39_MTIME=`date -d "1 year ago" +%s`
2804
2805 # bug 11063
2806 test_39c() {
2807         touch $DIR1/$tfile
2808         sleep 2
2809         local mtime0=`stat -c %Y $DIR1/$tfile`
2810
2811         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2812         local mtime1=`stat -c %Y $DIR1/$tfile`
2813         [ "$mtime1" = $TEST_39_MTIME ] || \
2814                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
2815
2816         local d1=`date +%s`
2817         echo hello >> $DIR1/$tfile
2818         local d2=`date +%s`
2819         local mtime2=`stat -c %Y $DIR1/$tfile`
2820         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
2821                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
2822
2823         mv $DIR1/$tfile $DIR1/$tfile-1
2824
2825         for (( i=0; i < 2; i++ )) ; do
2826                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
2827                 [ "$mtime2" = "$mtime3" ] || \
2828                         error "mtime ($mtime2) changed (to $mtime3) on rename"
2829
2830                 cancel_lru_locks osc
2831                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2832         done
2833 }
2834 run_test 39c "mtime change on rename ==========================="
2835
2836 # bug 21114
2837 test_39d() {
2838         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2839         touch $DIR1/$tfile
2840
2841         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2842
2843         for (( i=0; i < 2; i++ )) ; do
2844                 local mtime=`stat -c %Y $DIR1/$tfile`
2845                 [ $mtime = $TEST_39_MTIME ] || \
2846                         error "mtime($mtime) is not set to $TEST_39_MTIME"
2847
2848                 cancel_lru_locks osc
2849                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2850         done
2851 }
2852 run_test 39d "create, utime, stat =============================="
2853
2854 # bug 21114
2855 test_39e() {
2856         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2857         touch $DIR1/$tfile
2858         local mtime1=`stat -c %Y $DIR1/$tfile`
2859
2860         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2861
2862         for (( i=0; i < 2; i++ )) ; do
2863                 local mtime2=`stat -c %Y $DIR1/$tfile`
2864                 [ $mtime2 = $TEST_39_MTIME ] || \
2865                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2866
2867                 cancel_lru_locks osc
2868                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2869         done
2870 }
2871 run_test 39e "create, stat, utime, stat ========================"
2872
2873 # bug 21114
2874 test_39f() {
2875         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2876         touch $DIR1/$tfile
2877         mtime1=`stat -c %Y $DIR1/$tfile`
2878
2879         sleep 2
2880         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2881
2882         for (( i=0; i < 2; i++ )) ; do
2883                 local mtime2=`stat -c %Y $DIR1/$tfile`
2884                 [ $mtime2 = $TEST_39_MTIME ] || \
2885                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2886
2887                 cancel_lru_locks osc
2888                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2889         done
2890 }
2891 run_test 39f "create, stat, sleep, utime, stat ================="
2892
2893 # bug 11063
2894 test_39g() {
2895         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2896         echo hello >> $DIR1/$tfile
2897         local mtime1=`stat -c %Y $DIR1/$tfile`
2898
2899         sleep 2
2900         chmod o+r $DIR1/$tfile
2901
2902         for (( i=0; i < 2; i++ )) ; do
2903                 local mtime2=`stat -c %Y $DIR1/$tfile`
2904                 [ "$mtime1" = "$mtime2" ] || \
2905                         error "lost mtime: $mtime2, should be $mtime1"
2906
2907                 cancel_lru_locks osc
2908                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2909         done
2910 }
2911 run_test 39g "write, chmod, stat ==============================="
2912
2913 # bug 11063
2914 test_39h() {
2915         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2916         touch $DIR1/$tfile
2917         sleep 1
2918
2919         local d1=`date`
2920         echo hello >> $DIR1/$tfile
2921         local mtime1=`stat -c %Y $DIR1/$tfile`
2922
2923         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2924         local d2=`date`
2925         if [ "$d1" != "$d2" ]; then
2926                 echo "write and touch not within one second"
2927         else
2928                 for (( i=0; i < 2; i++ )) ; do
2929                         local mtime2=`stat -c %Y $DIR1/$tfile`
2930                         [ "$mtime2" = $TEST_39_MTIME ] || \
2931                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
2932
2933                         cancel_lru_locks osc
2934                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2935                 done
2936         fi
2937 }
2938 run_test 39h "write, utime within one second, stat ============="
2939
2940 test_39i() {
2941         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2942         touch $DIR1/$tfile
2943         sleep 1
2944
2945         echo hello >> $DIR1/$tfile
2946         local mtime1=`stat -c %Y $DIR1/$tfile`
2947
2948         mv $DIR1/$tfile $DIR1/$tfile-1
2949
2950         for (( i=0; i < 2; i++ )) ; do
2951                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2952
2953                 [ "$mtime1" = "$mtime2" ] || \
2954                         error "lost mtime: $mtime2, should be $mtime1"
2955
2956                 cancel_lru_locks osc
2957                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2958         done
2959 }
2960 run_test 39i "write, rename, stat =============================="
2961
2962 test_39j() {
2963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2964         start_full_debug_logging
2965         touch $DIR1/$tfile
2966         sleep 1
2967
2968         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
2969         lctl set_param fail_loc=0x80000412
2970         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
2971                 error "multiop failed"
2972         local multipid=$!
2973         local mtime1=`stat -c %Y $DIR1/$tfile`
2974
2975         mv $DIR1/$tfile $DIR1/$tfile-1
2976
2977         kill -USR1 $multipid
2978         wait $multipid || error "multiop close failed"
2979
2980         for (( i=0; i < 2; i++ )) ; do
2981                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2982                 [ "$mtime1" = "$mtime2" ] ||
2983                         error "mtime is lost on close: $mtime2, " \
2984                               "should be $mtime1"
2985
2986                 cancel_lru_locks osc
2987                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2988         done
2989         lctl set_param fail_loc=0
2990         stop_full_debug_logging
2991 }
2992 run_test 39j "write, rename, close, stat ======================="
2993
2994 test_39k() {
2995         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2996         touch $DIR1/$tfile
2997         sleep 1
2998
2999         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3000         local multipid=$!
3001         local mtime1=`stat -c %Y $DIR1/$tfile`
3002
3003         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3004
3005         kill -USR1 $multipid
3006         wait $multipid || error "multiop close failed"
3007
3008         for (( i=0; i < 2; i++ )) ; do
3009                 local mtime2=`stat -c %Y $DIR1/$tfile`
3010
3011                 [ "$mtime2" = $TEST_39_MTIME ] || \
3012                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3013
3014                 cancel_lru_locks osc
3015                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3016         done
3017 }
3018 run_test 39k "write, utime, close, stat ========================"
3019
3020 # this should be set to future
3021 TEST_39_ATIME=`date -d "1 year" +%s`
3022
3023 test_39l() {
3024         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3025         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3026         local atime_diff=$(do_facet $SINGLEMDS \
3027                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3028         rm -rf $DIR/$tdir
3029         mkdir -p $DIR/$tdir
3030
3031         # test setting directory atime to future
3032         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3033         local atime=$(stat -c %X $DIR/$tdir)
3034         [ "$atime" = $TEST_39_ATIME ] || \
3035                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3036
3037         # test setting directory atime from future to now
3038         local d1=$(date +%s)
3039         ls $DIR/$tdir
3040         local d2=$(date +%s)
3041
3042         cancel_lru_locks mdc
3043         atime=$(stat -c %X $DIR/$tdir)
3044         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3045                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3046
3047         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3048         sleep 3
3049
3050         # test setting directory atime when now > dir atime + atime_diff
3051         d1=$(date +%s)
3052         ls $DIR/$tdir
3053         d2=$(date +%s)
3054         cancel_lru_locks mdc
3055         atime=$(stat -c %X $DIR/$tdir)
3056         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3057                 error "atime is not updated  : $atime, should be $d2"
3058
3059         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3060         sleep 3
3061
3062         # test not setting directory atime when now < dir atime + atime_diff
3063         ls $DIR/$tdir
3064         cancel_lru_locks mdc
3065         atime=$(stat -c %X $DIR/$tdir)
3066         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3067                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3068
3069         do_facet $SINGLEMDS \
3070                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3071 }
3072 run_test 39l "directory atime update ==========================="
3073
3074 test_39m() {
3075         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3076         touch $DIR1/$tfile
3077         sleep 2
3078         local far_past_mtime=$(date -d "May 29 1953" +%s)
3079         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3080
3081         touch -m -d @$far_past_mtime $DIR1/$tfile
3082         touch -a -d @$far_past_atime $DIR1/$tfile
3083
3084         for (( i=0; i < 2; i++ )) ; do
3085                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3086                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3087                         error "atime or mtime set incorrectly"
3088
3089                 cancel_lru_locks osc
3090                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3091         done
3092 }
3093 run_test 39m "test atime and mtime before 1970"
3094
3095 test_40() {
3096         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3097         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3098                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3099         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3100                 error "$tfile is not 4096 bytes in size"
3101 }
3102 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3103
3104 test_41() {
3105         # bug 1553
3106         small_write $DIR/f41 18
3107 }
3108 run_test 41 "test small file write + fstat ====================="
3109
3110 count_ost_writes() {
3111         lctl get_param -n osc.*.stats |
3112             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
3113 }
3114
3115 # decent default
3116 WRITEBACK_SAVE=500
3117 DIRTY_RATIO_SAVE=40
3118 MAX_DIRTY_RATIO=50
3119 BG_DIRTY_RATIO_SAVE=10
3120 MAX_BG_DIRTY_RATIO=25
3121
3122 start_writeback() {
3123         trap 0
3124         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3125         # dirty_ratio, dirty_background_ratio
3126         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3127                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3128                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3129                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3130         else
3131                 # if file not here, we are a 2.4 kernel
3132                 kill -CONT `pidof kupdated`
3133         fi
3134 }
3135
3136 stop_writeback() {
3137         # setup the trap first, so someone cannot exit the test at the
3138         # exact wrong time and mess up a machine
3139         trap start_writeback EXIT
3140         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3141         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3142                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3143                 sysctl -w vm.dirty_writeback_centisecs=0
3144                 sysctl -w vm.dirty_writeback_centisecs=0
3145                 # save and increase /proc/sys/vm/dirty_ratio
3146                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3147                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3148                 # save and increase /proc/sys/vm/dirty_background_ratio
3149                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3150                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3151         else
3152                 # if file not here, we are a 2.4 kernel
3153                 kill -STOP `pidof kupdated`
3154         fi
3155 }
3156
3157 # ensure that all stripes have some grant before we test client-side cache
3158 setup_test42() {
3159         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3160                 dd if=/dev/zero of=$i bs=4k count=1
3161                 rm $i
3162         done
3163 }
3164
3165 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3166 # file truncation, and file removal.
3167 test_42a() {
3168         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3169         setup_test42
3170         cancel_lru_locks osc
3171         stop_writeback
3172         sync; sleep 1; sync # just to be safe
3173         BEFOREWRITES=`count_ost_writes`
3174         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3175         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3176         AFTERWRITES=`count_ost_writes`
3177         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3178                 error "$BEFOREWRITES < $AFTERWRITES"
3179         start_writeback
3180 }
3181 run_test 42a "ensure that we don't flush on close =============="
3182
3183 test_42b() {
3184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3185         setup_test42
3186         cancel_lru_locks osc
3187         stop_writeback
3188         sync
3189         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3190         BEFOREWRITES=`count_ost_writes`
3191         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3192         AFTERWRITES=`count_ost_writes`
3193         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3194                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3195         fi
3196         BEFOREWRITES=`count_ost_writes`
3197         sync || error "sync: $?"
3198         AFTERWRITES=`count_ost_writes`
3199         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3200                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3201         fi
3202         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3203         start_writeback
3204         return 0
3205 }
3206 run_test 42b "test destroy of file with cached dirty data ======"
3207
3208 # if these tests just want to test the effect of truncation,
3209 # they have to be very careful.  consider:
3210 # - the first open gets a {0,EOF}PR lock
3211 # - the first write conflicts and gets a {0, count-1}PW
3212 # - the rest of the writes are under {count,EOF}PW
3213 # - the open for truncate tries to match a {0,EOF}PR
3214 #   for the filesize and cancels the PWs.
3215 # any number of fixes (don't get {0,EOF} on open, match
3216 # composite locks, do smarter file size management) fix
3217 # this, but for now we want these tests to verify that
3218 # the cancellation with truncate intent works, so we
3219 # start the file with a full-file pw lock to match against
3220 # until the truncate.
3221 trunc_test() {
3222         test=$1
3223         file=$DIR/$test
3224         offset=$2
3225         cancel_lru_locks osc
3226         stop_writeback
3227         # prime the file with 0,EOF PW to match
3228         touch $file
3229         $TRUNCATE $file 0
3230         sync; sync
3231         # now the real test..
3232         dd if=/dev/zero of=$file bs=1024 count=100
3233         BEFOREWRITES=`count_ost_writes`
3234         $TRUNCATE $file $offset
3235         cancel_lru_locks osc
3236         AFTERWRITES=`count_ost_writes`
3237         start_writeback
3238 }
3239
3240 test_42c() {
3241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3242         trunc_test 42c 1024
3243         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3244             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3245         rm $file
3246 }
3247 run_test 42c "test partial truncate of file with cached dirty data"
3248
3249 test_42d() {
3250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3251         trunc_test 42d 0
3252         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3253             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3254         rm $file
3255 }
3256 run_test 42d "test complete truncate of file with cached dirty data"
3257
3258 test_42e() { # bug22074
3259         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3260         local TDIR=$DIR/${tdir}e
3261         local pagesz=$(page_size)
3262         local pages=16 # hardcoded 16 pages, don't change it.
3263         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3264         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3265         local max_dirty_mb
3266         local warmup_files
3267
3268         test_mkdir -p $DIR/${tdir}e
3269         $SETSTRIPE -c 1 $TDIR
3270         createmany -o $TDIR/f $files
3271
3272         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3273
3274         # we assume that with $OSTCOUNT files, at least one of them will
3275         # be allocated on OST0.
3276         warmup_files=$((OSTCOUNT * max_dirty_mb))
3277         createmany -o $TDIR/w $warmup_files
3278
3279         # write a large amount of data into one file and sync, to get good
3280         # avail_grant number from OST.
3281         for ((i=0; i<$warmup_files; i++)); do
3282                 idx=$($GETSTRIPE -i $TDIR/w$i)
3283                 [ $idx -ne 0 ] && continue
3284                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3285                 break
3286         done
3287         [ $i -gt $warmup_files ] && error "OST0 is still cold"
3288         sync
3289         $LCTL get_param $proc_osc0/cur_dirty_bytes
3290         $LCTL get_param $proc_osc0/cur_grant_bytes
3291
3292         # create as much dirty pages as we can while not to trigger the actual
3293         # RPCs directly. but depends on the env, VFS may trigger flush during this
3294         # period, hopefully we are good.
3295         for ((i=0; i<$warmup_files; i++)); do
3296                 idx=$($GETSTRIPE -i $TDIR/w$i)
3297                 [ $idx -ne 0 ] && continue
3298                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3299         done
3300         $LCTL get_param $proc_osc0/cur_dirty_bytes
3301         $LCTL get_param $proc_osc0/cur_grant_bytes
3302
3303         # perform the real test
3304         $LCTL set_param $proc_osc0/rpc_stats 0
3305         for ((;i<$files; i++)); do
3306                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3307                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3308         done
3309         sync
3310         $LCTL get_param $proc_osc0/rpc_stats
3311
3312         local percent=0
3313         local have_ppr=false
3314         $LCTL get_param $proc_osc0/rpc_stats |
3315                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3316                         # skip lines until we are at the RPC histogram data
3317                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3318                         $have_ppr || continue
3319
3320                         # we only want the percent stat for < 16 pages
3321                         [ $(echo $PPR | tr -d ':') -ge $pages ] && break
3322
3323                         percent=$((percent + WPCT))
3324                         if [ $percent -gt 15 ]; then
3325                                 error "less than 16-pages write RPCs" \
3326                                       "$percent% > 15%"
3327                                 break
3328                         fi
3329                 done
3330         rm -rf $TDIR
3331 }
3332 run_test 42e "verify sub-RPC writes are not done synchronously"
3333
3334 test_43() {
3335         test_mkdir -p $DIR/$tdir
3336         cp -p /bin/ls $DIR/$tdir/$tfile
3337         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3338         pid=$!
3339         # give multiop a chance to open
3340         sleep 1
3341
3342         $DIR/$tdir/$tfile && error || true
3343         kill -USR1 $pid
3344 }
3345 run_test 43 "execution of file opened for write should return -ETXTBSY"
3346
3347 test_43a() {
3348         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3349         test_mkdir -p $DIR/$tdir
3350         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3351                         cp -p multiop $DIR/$tdir/multiop
3352         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/test43.junk O_c ||
3353                         return 1
3354         MULTIOP_PID=$!
3355         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3356         kill -USR1 $MULTIOP_PID || return 2
3357         wait $MULTIOP_PID || return 3
3358         rm $TMP/test43.junk
3359 }
3360 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3361
3362 test_43b() {
3363         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3364         test_mkdir -p $DIR/$tdir
3365         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3366                         cp -p multiop $DIR/$tdir/multiop
3367         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/test43.junk O_c ||
3368                         return 1
3369         MULTIOP_PID=$!
3370         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3371         kill -USR1 $MULTIOP_PID || return 2
3372         wait $MULTIOP_PID || return 3
3373         rm $TMP/test43.junk
3374 }
3375 run_test 43b "truncate of file being executed should return -ETXTBSY"
3376
3377 test_43c() {
3378         local testdir="$DIR/$tdir"
3379         test_mkdir -p $DIR/$tdir
3380         cp $SHELL $testdir/
3381         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3382                 ( cd $testdir && md5sum -c)
3383 }
3384 run_test 43c "md5sum of copy into lustre========================"
3385
3386 test_44() {
3387         [  "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
3388         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3389         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3390 }
3391 run_test 44 "zero length read from a sparse stripe ============="
3392
3393 test_44a() {
3394     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
3395                          awk '{print $2}'`
3396     [ -z "$nstripe" ] && skip "can't get stripe info" && return
3397     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
3398     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
3399                       awk '{print $2}'`
3400     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
3401         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
3402     fi
3403
3404     OFFSETS="0 $((stride/2)) $((stride-1))"
3405     for offset in $OFFSETS ; do
3406       for i in `seq 0 $((nstripe-1))`; do
3407         local GLOBALOFFSETS=""
3408         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
3409         local myfn=$DIR/d44a-$size
3410         echo "--------writing $myfn at $size"
3411         ll_sparseness_write $myfn $size  || error "ll_sparseness_write"
3412         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3413         ll_sparseness_verify $myfn $GLOBALOFFSETS \
3414                             || error "ll_sparseness_verify $GLOBALOFFSETS"
3415
3416         for j in `seq 0 $((nstripe-1))`; do
3417             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
3418             ll_sparseness_write $myfn $size || error "ll_sparseness_write"
3419             GLOBALOFFSETS="$GLOBALOFFSETS $size"
3420         done
3421         ll_sparseness_verify $myfn $GLOBALOFFSETS \
3422                             || error "ll_sparseness_verify $GLOBALOFFSETS"
3423         rm -f $myfn
3424       done
3425     done
3426 }
3427 run_test 44a "test sparse pwrite ==============================="
3428
3429 dirty_osc_total() {
3430         tot=0
3431         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3432                 tot=$(($tot + $d))
3433         done
3434         echo $tot
3435 }
3436 do_dirty_record() {
3437         before=`dirty_osc_total`
3438         echo executing "\"$*\""
3439         eval $*
3440         after=`dirty_osc_total`
3441         echo before $before, after $after
3442 }
3443 test_45() {
3444         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3445         f="$DIR/f45"
3446         # Obtain grants from OST if it supports it
3447         echo blah > ${f}_grant
3448         stop_writeback
3449         sync
3450         do_dirty_record "echo blah > $f"
3451         [ $before -eq $after ] && error "write wasn't cached"
3452         do_dirty_record "> $f"
3453         [ $before -gt $after ] || error "truncate didn't lower dirty count"
3454         do_dirty_record "echo blah > $f"
3455         [ $before -eq $after ] && error "write wasn't cached"
3456         do_dirty_record "sync"
3457         [ $before -gt $after ] || error "writeback didn't lower dirty count"
3458         do_dirty_record "echo blah > $f"
3459         [ $before -eq $after ] && error "write wasn't cached"
3460         do_dirty_record "cancel_lru_locks osc"
3461         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
3462         start_writeback
3463 }
3464 run_test 45 "osc io page accounting ============================"
3465
3466 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3467 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3468 # objects offset and an assert hit when an rpc was built with 1023's mapped
3469 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3470 test_46() {
3471         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3472         f="$DIR/f46"
3473         stop_writeback
3474         sync
3475         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3476         sync
3477         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3478         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3479         sync
3480         start_writeback
3481 }
3482 run_test 46 "dirtying a previously written page ================"
3483
3484 # test_47 is removed "Device nodes check" is moved to test_28
3485
3486 test_48a() { # bug 2399
3487         check_kernel_version 34 || return 0
3488         test_mkdir -p $DIR/$tdir
3489         cd $DIR/$tdir
3490         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3491         test_mkdir $DIR/$tdir || error "recreate directory failed"
3492         touch foo || error "'touch foo' failed after recreating cwd"
3493         test_mkdir $DIR/$tdir/bar ||
3494                      error "'mkdir foo' failed after recreating cwd"
3495         if check_kernel_version 44; then
3496                 touch .foo || error "'touch .foo' failed after recreating cwd"
3497                 test_mkdir $DIR/$tdir/.bar ||
3498                               error "'mkdir .foo' failed after recreating cwd"
3499         fi
3500         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3501         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3502         cd . || error "'cd .' failed after recreating cwd"
3503         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3504         rmdir . && error "'rmdir .' worked after recreating cwd"
3505         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3506         cd .. || error "'cd ..' failed after recreating cwd"
3507 }
3508 run_test 48a "Access renamed working dir (should return errors)="
3509
3510 test_48b() { # bug 2399
3511         check_kernel_version 34 || return 0
3512         rm -rf $DIR/$tdir
3513         test_mkdir -p $DIR/$tdir
3514         cd $DIR/$tdir
3515         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3516         touch foo && error "'touch foo' worked after removing cwd"
3517         test_mkdir $DIR/$tdir/foo &&
3518                      error "'mkdir foo' worked after removing cwd"
3519         if check_kernel_version 44; then
3520                 touch .foo && error "'touch .foo' worked after removing cwd"
3521                 test_mkdir $DIR/$tdir/.foo &&
3522                               error "'mkdir .foo' worked after removing cwd"
3523         fi
3524         ls . > /dev/null && error "'ls .' worked after removing cwd"
3525         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3526         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3527         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3528         rmdir . && error "'rmdir .' worked after removing cwd"
3529         ln -s . foo && error "'ln -s .' worked after removing cwd"
3530         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3531 }
3532 run_test 48b "Access removed working dir (should return errors)="
3533
3534 test_48c() { # bug 2350
3535         check_kernel_version 36 || return 0
3536         #lctl set_param debug=-1
3537         #set -vx
3538         rm -rf $DIR/$tdir
3539         test_mkdir -p $DIR/$tdir/dir
3540         cd $DIR/$tdir/dir
3541         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3542         $TRACE touch foo && error "touch foo worked after removing cwd"
3543         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3544         if check_kernel_version 44; then
3545                 touch .foo && error "touch .foo worked after removing cwd"
3546                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3547         fi
3548         $TRACE ls . && error "'ls .' worked after removing cwd"
3549         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3550         is_patchless || ( $TRACE cd . &&
3551                         error "'cd .' worked after removing cwd" )
3552         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3553         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3554         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3555         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3556 }
3557 run_test 48c "Access removed working subdir (should return errors)"
3558
3559 test_48d() { # bug 2350
3560         check_kernel_version 36 || return 0
3561         #lctl set_param debug=-1
3562         #set -vx
3563         rm -rf $DIR/$tdir
3564         test_mkdir -p $DIR/$tdir/dir
3565         cd $DIR/$tdir/dir
3566         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3567         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3568         $TRACE touch foo && error "'touch foo' worked after removing parent"
3569         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3570         if check_kernel_version 44; then
3571                 touch .foo && error "'touch .foo' worked after removing parent"
3572                 test_mkdir .foo &&
3573                               error "mkdir .foo worked after removing parent"
3574         fi
3575         $TRACE ls . && error "'ls .' worked after removing parent"
3576         $TRACE ls .. && error "'ls ..' worked after removing parent"
3577         is_patchless || ( $TRACE cd . &&
3578                         error "'cd .' worked after recreate parent" )
3579         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3580         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3581         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3582         is_patchless || ( $TRACE cd .. &&
3583                         error "'cd ..' worked after removing parent" || true )
3584 }
3585 run_test 48d "Access removed parent subdir (should return errors)"
3586
3587 test_48e() { # bug 4134
3588         check_kernel_version 41 || return 0
3589         #lctl set_param debug=-1
3590         #set -vx
3591         rm -rf $DIR/$tdir
3592         test_mkdir -p $DIR/$tdir/dir
3593         cd $DIR/$tdir/dir
3594         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3595         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3596         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3597         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3598         # On a buggy kernel addition of "touch foo" after cd .. will
3599         # produce kernel oops in lookup_hash_it
3600         touch ../foo && error "'cd ..' worked after recreate parent"
3601         cd $DIR
3602         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3603 }
3604 run_test 48e "Access to recreated parent subdir (should return errors)"
3605
3606 test_49() { # LU-1030
3607         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3608         # get ost1 size - lustre-OST0000
3609         ost1_size=$(do_facet ost1 lfs df |grep ${ost1_svc} |awk '{print $4}')
3610         # write 800M at maximum
3611         [ $ost1_size -gt 819200 ] && ost1_size=819200
3612
3613         lfs setstripe -c 1 -i 0 $DIR/$tfile
3614         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3615         local dd_pid=$!
3616
3617         # change max_pages_per_rpc while writing the file
3618         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3619         local orig_mppc=`$LCTL get_param -n $osc1_mppc`
3620         # loop until dd process exits
3621         while ps ax -opid | grep -wq $dd_pid; do
3622                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3623                 sleep $((RANDOM % 5 + 1))
3624         done
3625         # restore original max_pages_per_rpc
3626         $LCTL set_param $osc1_mppc=$orig_mppc
3627         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3628 }
3629 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3630
3631 test_50() {
3632         # bug 1485
3633         test_mkdir $DIR/$tdir
3634         cd $DIR/$tdir
3635         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3636 }
3637 run_test 50 "special situations: /proc symlinks  ==============="
3638
3639 test_51a() {    # was test_51
3640         # bug 1516 - create an empty entry right after ".." then split dir
3641         test_mkdir -p $DIR/$tdir
3642         touch $DIR/$tdir/foo
3643         $MCREATE $DIR/$tdir/bar
3644         rm $DIR/$tdir/foo
3645         createmany -m $DIR/$tdir/longfile 201
3646         FNUM=202
3647         while [ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]; do
3648                 $MCREATE $DIR/$tdir/longfile$FNUM
3649                 FNUM=$(($FNUM + 1))
3650                 echo -n "+"
3651         done
3652         echo
3653         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3654 }
3655 run_test 51a "special situations: split htree with empty entry =="
3656
3657 export NUMTEST=70000
3658 test_51b() {
3659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3660         local BASE=$DIR/$tdir
3661
3662         # cleanup the directory
3663         rm -fr $BASE
3664
3665         test_mkdir -p $BASE
3666
3667         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3668         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3669         [ $numfree -lt 21000 ] && skip "not enough free inodes ($numfree)" &&
3670                 return
3671
3672         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3673                 echo "reduced count to $NUMTEST due to inodes"
3674
3675         # need to check free space for the directories as well
3676         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3677         numfree=$((blkfree / 4))
3678         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3679                 echo "reduced count to $NUMTEST due to blocks"
3680
3681         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3682                 echo "failed" > $BASE/fnum
3683 }
3684 run_test 51b "exceed 64k subdirectory nlink limit"
3685
3686 test_51ba() { # LU-993
3687         local BASE=$DIR/$tdir
3688         # unlink all but 100 subdirectories, then check it still works
3689         local LEFT=100
3690         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3691
3692         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
3693         local DELETE=$((NUMTEST - LEFT))
3694
3695         # continue on to run this test even if 51b didn't finish,
3696         # just to delete the many subdirectories created.
3697         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
3698
3699         # for ldiskfs the nlink count should be 1, but this is OSD specific
3700         # and so this is listed for informational purposes only
3701         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
3702         unlinkmany -d $BASE/d $DELETE
3703         RC=$?
3704
3705         if [ $RC -ne 0 ]; then
3706                 if [ "$NUMPREV" == "failed" ]; then
3707                         skip "previous setup failed"
3708                         return 0
3709                 else
3710                         error "unlink of first $DELETE subdirs failed"
3711                         return $RC
3712                 fi
3713         fi
3714
3715         echo "nlink between: $(stat -c %h $BASE)"
3716         # trim the first line of ls output
3717         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
3718         [ $FOUND -ne $LEFT ] &&
3719                 error "can't find subdirs: found only $FOUND/$LEFT"
3720
3721         unlinkmany -d $BASE/d $DELETE $LEFT ||
3722                 error "unlink of second $LEFT subdirs failed"
3723         # regardless of whether the backing filesystem tracks nlink accurately
3724         # or not, the nlink count shouldn't be more than "." and ".." here
3725         local AFTER=$(stat -c %h $BASE)
3726         [ $AFTER -gt 2 ] && error "nlink after: $AFTER > 2" ||
3727                 echo "nlink after: $AFTER"
3728 }
3729 run_test 51ba "verify nlink for many subdirectory cleanup"
3730
3731 test_51d() {
3732         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3733         [  "$OSTCOUNT" -lt "3" ] && skip_env "skipping test with few OSTs" && return
3734         test_mkdir -p $DIR/$tdir
3735         createmany -o $DIR/$tdir/t- 1000
3736         $GETSTRIPE $DIR/$tdir > $TMP/files
3737         for N in `seq 0 $((OSTCOUNT - 1))`; do
3738             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
3739             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
3740             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
3741         done
3742         unlinkmany $DIR/$tdir/t- 1000
3743
3744         NLAST=0
3745         for N in `seq 1 $((OSTCOUNT - 1))`; do
3746             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
3747                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3748             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
3749                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3750
3751             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
3752                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3753             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
3754                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3755             NLAST=$N
3756         done
3757 }
3758 run_test 51d "check object distribution ===================="
3759
3760 test_52a() {
3761         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
3762         test_mkdir -p $DIR/$tdir
3763         touch $DIR/$tdir/foo
3764         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
3765         echo bar >> $DIR/$tdir/foo || error "append bar failed"
3766         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3767         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3768         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3769                                         error "link worked"
3770         echo foo >> $DIR/$tdir/foo || error "append foo failed"
3771         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3772         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
3773                                                      error "lsattr"
3774         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
3775         cp -r $DIR/$tdir /tmp/
3776         rm -fr $DIR/$tdir || error "cleanup rm failed"
3777 }
3778 run_test 52a "append-only flag test (should return errors) ====="
3779
3780 test_52b() {
3781         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
3782         test_mkdir -p $DIR/$tdir
3783         touch $DIR/$tdir/foo
3784         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
3785         cat test > $DIR/$tdir/foo && error "cat test worked"
3786         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3787         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3788         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3789                                         error "link worked"
3790         echo foo >> $DIR/$tdir/foo && error "echo worked"
3791         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3792         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
3793         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
3794         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
3795                                                         error "lsattr"
3796         chattr -i $DIR/$tdir/foo || error "chattr failed"
3797
3798         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
3799 }
3800 run_test 52b "immutable flag test (should return errors) ======="
3801
3802 test_53() {
3803         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3804         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3805         remote_ost_nodsh && skip "remote OST with nodsh" && return
3806
3807         local param
3808         local param_seq
3809         local ostname
3810         local mds_last
3811         local mds_last_seq
3812         local ost_last
3813         local ost_last_seq
3814         local ost_last_id
3815         local ostnum
3816         local node
3817         local found=0
3818
3819         # only test MDT0000
3820         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
3821         for value in $(do_facet $SINGLEMDS lctl get_param osc.$mdtosc.prealloc_last_id) ; do
3822                 param=$(echo ${value[0]} | cut -d "=" -f1)
3823                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
3824                 param_seq=$(echo ${param} |
3825                             sed -e s/prealloc_last_id/prealloc_last_seq/g)
3826                 mds_last_seq=$(do_facet $SINGLEMDS lctl get_param -n $param_seq)
3827                 mds_last=$(do_facet $SINGLEMDS lctl get_param -n $param)
3828
3829                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
3830                 node=$(facet_active_host ost$((ostnum+1)))
3831                 param="obdfilter.$ostname.last_id"
3832                 for ost_last in $(do_node $node lctl get_param -n $param) ; do
3833                         echo "$ostname.last_id=$ost_last ;MDS.last_id=$mds_last"
3834                         ost_last_id=$(echo $ost_last | awk -F':' '{print $2}' |
3835                                       sed -e "s/^0x//g")
3836                         ost_last_seq=$(echo $ost_last | awk -F':' '{print $1}')
3837                         if [ $ost_last_seq = $mds_last_seq ]; then
3838                                 if [ $ost_last_id != $mds_last ]; then
3839                                         error "$ost_last != $mds_last_id"
3840                                 else
3841                                         found=1
3842                                         break
3843                                 fi
3844                         fi
3845                 done
3846         done
3847         [ $found = 0 ] && error "can not match last_seq/last_id for $mdtosc"
3848         return 0
3849 }
3850 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
3851
3852 test_54a() {
3853         [ ! -f "$SOCKETSERVER" ] &&
3854                 skip_env "no socketserver, skipping" && return
3855         [ ! -f "$SOCKETCLIENT" ] &&
3856                 skip_env "no socketclient, skipping" && return
3857         $SOCKETSERVER $DIR/socket
3858         $SOCKETCLIENT $DIR/socket || error "$SOCKETCLIENT $DIR/socket failed"
3859         $MUNLINK $DIR/socket
3860 }
3861 run_test 54a "unix domain socket test =========================="
3862
3863 test_54b() {
3864         f="$DIR/f54b"
3865         mknod $f c 1 3
3866         chmod 0666 $f
3867         dd if=/dev/zero of=$f bs=$(page_size) count=1
3868 }
3869 run_test 54b "char device works in lustre ======================"
3870
3871 find_loop_dev() {
3872         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
3873         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
3874         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
3875
3876         for i in $(seq 3 7); do
3877                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
3878                 LOOPDEV=$LOOPBASE$i
3879                 LOOPNUM=$i
3880                 break
3881         done
3882 }
3883
3884 test_54c() {
3885         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3886         tfile="$DIR/f54c"
3887         tdir="$DIR/d54c"
3888         loopdev="$DIR/loop54c"
3889
3890         find_loop_dev
3891         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
3892         mknod $loopdev b 7 $LOOPNUM
3893         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
3894         dd if=/dev/zero of=$tfile bs=`page_size` seek=1024 count=1 > /dev/null
3895         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
3896         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
3897         test_mkdir -p $tdir
3898         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
3899         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
3900         df $tdir
3901         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
3902         $UMOUNT $tdir
3903         losetup -d $loopdev
3904         rm $loopdev
3905 }
3906 run_test 54c "block device works in lustre ====================="
3907
3908 test_54d() {
3909         f="$DIR/f54d"
3910         string="aaaaaa"
3911         mknod $f p
3912         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
3913 }
3914 run_test 54d "fifo device works in lustre ======================"
3915
3916 test_54e() {
3917         check_kernel_version 46 || return 0
3918         f="$DIR/f54e"
3919         string="aaaaaa"
3920         cp -aL /dev/console $f
3921         echo $string > $f || error "echo $string to $f failed"
3922 }
3923 run_test 54e "console/tty device works in lustre ======================"
3924
3925 #The test_55 used to be iopen test and it was removed by bz#24037.
3926 #run_test 55 "check iopen_connect_dentry() ======================"
3927
3928 test_56a() {    # was test_56
3929         rm -rf $DIR/$tdir
3930         $SETSTRIPE -d $DIR
3931         test_mkdir $DIR/$tdir
3932         test_mkdir $DIR/$tdir/dir
3933         NUMFILES=3
3934         NUMFILESx2=$(($NUMFILES * 2))
3935         for i in `seq 1 $NUMFILES` ; do
3936                 touch $DIR/$tdir/file$i
3937                 touch $DIR/$tdir/dir/file$i
3938         done
3939
3940         # test lfs getstripe with --recursive
3941         FILENUM=`$GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx`
3942         [ $FILENUM -eq $NUMFILESx2 ] ||
3943                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
3944         FILENUM=`$GETSTRIPE $DIR/$tdir | grep -c obdidx`
3945         [ $FILENUM -eq $NUMFILES ] ||
3946                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
3947         echo "$GETSTRIPE --recursive passed."
3948
3949         # test lfs getstripe with file instead of dir
3950         FILENUM=`$GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx`
3951         [ $FILENUM  -eq 1 ] || error \
3952                  "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
3953         echo "$GETSTRIPE file1 passed."
3954
3955         #test lfs getstripe with --verbose
3956         [ `$GETSTRIPE --verbose $DIR/$tdir |
3957                         grep -c lmm_magic` -eq $NUMFILES ] ||
3958                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
3959         [ `$GETSTRIPE $DIR/$tdir | grep -c lmm_magic` -eq 0 ] ||
3960             error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
3961         echo "$GETSTRIPE --verbose passed."
3962
3963         #test lfs getstripe with --obd
3964         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
3965                                         grep -q "unknown obduuid" ||
3966                 error "$GETSTRIPE --obd wrong_uuid should return error message"
3967
3968         [  "$OSTCOUNT" -lt 2 ] &&
3969                 skip_env "skipping other $GETSTRIPE --obd test" && return
3970
3971         OSTIDX=1
3972         OBDUUID=$(ostuuid_from_index $OSTIDX)
3973         FILENUM=`$GETSTRIPE -ir $DIR/$tdir | grep -x $OSTIDX | wc -l`
3974         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l`
3975         [ $FOUND -eq $FILENUM ] ||
3976                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
3977         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
3978                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
3979                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] ||
3980                 error "$GETSTRIPE --obd: should not show file on other obd"
3981         echo "$GETSTRIPE --obd passed"
3982 }
3983 run_test 56a "check $GETSTRIPE"
3984
3985 NUMFILES=3
3986 NUMDIRS=3
3987 setup_56() {
3988         local LOCAL_NUMFILES="$1"
3989         local LOCAL_NUMDIRS="$2"
3990         local MKDIR_PARAMS="$3"
3991
3992         if [ ! -d "$TDIR" ] ; then
3993                 test_mkdir -p $TDIR
3994                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
3995                 for i in `seq 1 $LOCAL_NUMFILES` ; do
3996                         touch $TDIR/file$i
3997                 done
3998                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
3999                         test_mkdir $TDIR/dir$i
4000                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4001                                 touch $TDIR/dir$i/file$j
4002                         done
4003                 done
4004         fi
4005 }
4006
4007 setup_56_special() {
4008         LOCAL_NUMFILES=$1
4009         LOCAL_NUMDIRS=$2
4010         setup_56 $1 $2
4011         if [ ! -e "$TDIR/loop1b" ] ; then
4012                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4013                         mknod $TDIR/loop${i}b b 7 $i
4014                         mknod $TDIR/null${i}c c 1 3
4015                         ln -s $TDIR/file1 $TDIR/link${i}l
4016                 done
4017                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4018                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4019                         mknod $TDIR/dir$i/null${i}c c 1 3
4020                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4021                 done
4022         fi
4023 }
4024
4025 test_56g() {
4026         $SETSTRIPE -d $DIR
4027
4028         TDIR=$DIR/${tdir}g
4029         setup_56 $NUMFILES $NUMDIRS
4030
4031         EXPECTED=$(($NUMDIRS + 2))
4032         # test lfs find with -name
4033         for i in $(seq 1 $NUMFILES) ; do
4034                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4035                 [ $NUMS -eq $EXPECTED ] ||
4036                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4037                               "found $NUMS, expected $EXPECTED"
4038         done
4039 }
4040 run_test 56g "check lfs find -name ============================="
4041
4042 test_56h() {
4043         $SETSTRIPE -d $DIR
4044
4045         TDIR=$DIR/${tdir}g
4046         setup_56 $NUMFILES $NUMDIRS
4047
4048         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4049         # test lfs find with ! -name
4050         for i in $(seq 1 $NUMFILES) ; do
4051                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4052                 [ $NUMS -eq $EXPECTED ] ||
4053                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4054                               "found $NUMS, expected $EXPECTED"
4055         done
4056 }
4057 run_test 56h "check lfs find ! -name ============================="
4058
4059 test_56i() {
4060        tdir=${tdir}i
4061        test_mkdir -p $DIR/$tdir
4062        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4063        CMD="$LFIND -ost $UUID $DIR/$tdir"
4064        OUT=$($CMD)
4065        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4066 }
4067 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4068
4069 test_56j() {
4070         TDIR=$DIR/${tdir}g
4071         setup_56_special $NUMFILES $NUMDIRS
4072
4073         EXPECTED=$((NUMDIRS + 1))
4074         CMD="$LFIND -type d $TDIR"
4075         NUMS=$($CMD | wc -l)
4076         [ $NUMS -eq $EXPECTED ] ||
4077                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4078 }
4079 run_test 56j "check lfs find -type d ============================="
4080
4081 test_56k() {
4082         TDIR=$DIR/${tdir}g
4083         setup_56_special $NUMFILES $NUMDIRS
4084
4085         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4086         CMD="$LFIND -type f $TDIR"
4087         NUMS=$($CMD | wc -l)
4088         [ $NUMS -eq $EXPECTED ] ||
4089                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4090 }
4091 run_test 56k "check lfs find -type f ============================="
4092
4093 test_56l() {
4094         TDIR=$DIR/${tdir}g
4095         setup_56_special $NUMFILES $NUMDIRS
4096
4097         EXPECTED=$((NUMDIRS + NUMFILES))
4098         CMD="$LFIND -type b $TDIR"
4099         NUMS=$($CMD | wc -l)
4100         [ $NUMS -eq $EXPECTED ] ||
4101                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4102 }
4103 run_test 56l "check lfs find -type b ============================="
4104
4105 test_56m() {
4106         TDIR=$DIR/${tdir}g
4107         setup_56_special $NUMFILES $NUMDIRS
4108
4109         EXPECTED=$((NUMDIRS + NUMFILES))
4110         CMD="$LFIND -type c $TDIR"
4111         NUMS=$($CMD | wc -l)
4112         [ $NUMS -eq $EXPECTED ] ||
4113                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4114 }
4115 run_test 56m "check lfs find -type c ============================="
4116
4117 test_56n() {
4118         TDIR=$DIR/${tdir}g
4119         setup_56_special $NUMFILES $NUMDIRS
4120
4121         EXPECTED=$((NUMDIRS + NUMFILES))
4122         CMD="$LFIND -type l $TDIR"
4123         NUMS=$($CMD | wc -l)
4124         [ $NUMS -eq $EXPECTED ] ||
4125                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4126 }
4127 run_test 56n "check lfs find -type l ============================="
4128
4129 test_56o() {
4130         TDIR=$DIR/${tdir}o
4131         setup_56 $NUMFILES $NUMDIRS
4132
4133         utime $TDIR/file1 > /dev/null || error "utime (1)"
4134         utime $TDIR/file2 > /dev/null || error "utime (2)"
4135         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4136         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4137         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4138         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4139
4140         EXPECTED=4
4141         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4142         [ $NUMS -eq $EXPECTED ] || \
4143                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4144
4145         EXPECTED=12
4146         CMD="$LFIND -mtime 0 $TDIR"
4147         NUMS=$($CMD | wc -l)
4148         [ $NUMS -eq $EXPECTED ] ||
4149                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4150 }
4151 run_test 56o "check lfs find -mtime for old files =========================="
4152
4153 test_56p() {
4154         [ $RUNAS_ID -eq $UID ] &&
4155                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4156
4157         TDIR=$DIR/${tdir}p
4158         setup_56 $NUMFILES $NUMDIRS
4159
4160         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4161         EXPECTED=$NUMFILES
4162         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4163         NUMS=$($CMD | wc -l)
4164         [ $NUMS -eq $EXPECTED ] || \
4165                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4166
4167         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4168         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4169         NUMS=$($CMD | wc -l)
4170         [ $NUMS -eq $EXPECTED ] || \
4171                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4172 }
4173 run_test 56p "check lfs find -uid and ! -uid ==============================="
4174
4175 test_56q() {
4176         [ $RUNAS_ID -eq $UID ] &&
4177                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4178
4179         TDIR=$DIR/${tdir}q
4180         setup_56 $NUMFILES $NUMDIRS
4181
4182         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4183
4184         EXPECTED=$NUMFILES
4185         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4186         NUMS=$($CMD | wc -l)
4187         [ $NUMS -eq $EXPECTED ] ||
4188                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4189
4190         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4191         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4192         NUMS=$($CMD | wc -l)
4193         [ $NUMS -eq $EXPECTED ] ||
4194                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4195 }
4196 run_test 56q "check lfs find -gid and ! -gid ==============================="
4197
4198 test_56r() {
4199         TDIR=$DIR/${tdir}r
4200         setup_56 $NUMFILES $NUMDIRS
4201
4202         EXPECTED=12
4203         CMD="$LFIND -size 0 -type f $TDIR"
4204         NUMS=$($CMD | wc -l)
4205         [ $NUMS -eq $EXPECTED ] ||
4206                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4207         EXPECTED=0
4208         CMD="$LFIND ! -size 0 -type f $TDIR"
4209         NUMS=$($CMD | wc -l)
4210         [ $NUMS -eq $EXPECTED ] ||
4211                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4212         echo "test" > $TDIR/$tfile
4213         echo "test2" > $TDIR/$tfile.2 && sync
4214         EXPECTED=1
4215         CMD="$LFIND -size 5 -type f $TDIR"
4216         NUMS=$($CMD | wc -l)
4217         [ $NUMS -eq $EXPECTED ] ||
4218                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4219         EXPECTED=1
4220         CMD="$LFIND -size +5 -type f $TDIR"
4221         NUMS=$($CMD | wc -l)
4222         [ $NUMS -eq $EXPECTED ] ||
4223                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4224         EXPECTED=2
4225         CMD="$LFIND -size +0 -type f $TDIR"
4226         NUMS=$($CMD | wc -l)
4227         [ $NUMS -eq $EXPECTED ] ||
4228                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4229         EXPECTED=2
4230         CMD="$LFIND ! -size -5 -type f $TDIR"
4231         NUMS=$($CMD | wc -l)
4232         [ $NUMS -eq $EXPECTED ] ||
4233                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4234         EXPECTED=12
4235         CMD="$LFIND -size -5 -type f $TDIR"
4236         NUMS=$($CMD | wc -l)
4237         [ $NUMS -eq $EXPECTED ] ||
4238                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4239 }
4240 run_test 56r "check lfs find -size works =========================="
4241
4242 test_56s() { # LU-611
4243         TDIR=$DIR/${tdir}s
4244         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4245
4246         if [ $OSTCOUNT -gt 1 ]; then
4247                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4248                 ONESTRIPE=4
4249                 EXTRA=4
4250         else
4251                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4252                 EXTRA=0
4253         fi
4254
4255         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4256         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4257         NUMS=$($CMD | wc -l)
4258         [ $NUMS -eq $EXPECTED ] ||
4259                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4260
4261         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4262         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4263         NUMS=$($CMD | wc -l)
4264         [ $NUMS -eq $EXPECTED ] ||
4265                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4266
4267         EXPECTED=$ONESTRIPE
4268         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4269         NUMS=$($CMD | wc -l)
4270         [ $NUMS -eq $EXPECTED ] ||
4271                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4272
4273         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4274         NUMS=$($CMD | wc -l)
4275         [ $NUMS -eq $EXPECTED ] ||
4276                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4277
4278         EXPECTED=0
4279         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4280         NUMS=$($CMD | wc -l)
4281         [ $NUMS -eq $EXPECTED ] ||
4282                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4283 }
4284 run_test 56s "check lfs find -stripe-count works"
4285
4286 test_56t() { # LU-611
4287         TDIR=$DIR/${tdir}t
4288         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4289
4290         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4291
4292         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4293         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4294         NUMS=$($CMD | wc -l)
4295         [ $NUMS -eq $EXPECTED ] ||
4296                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4297
4298         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4299         NUMS=$($CMD | wc -l)
4300         [ $NUMS -eq $EXPECTED ] ||
4301                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4302
4303         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4304         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4305         NUMS=$($CMD | wc -l)
4306         [ $NUMS -eq $EXPECTED ] ||
4307                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4308
4309         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4310         NUMS=$($CMD | wc -l)
4311         [ $NUMS -eq $EXPECTED ] ||
4312                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4313
4314         EXPECTED=4
4315         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4316         NUMS=$($CMD | wc -l)
4317         [ $NUMS -eq $EXPECTED ] ||
4318                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4319
4320         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4321         NUMS=$($CMD | wc -l)
4322         [ $NUMS -eq $EXPECTED ] ||
4323                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4324
4325         EXPECTED=0
4326         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4327         NUMS=$($CMD | wc -l)
4328         [ $NUMS -eq $EXPECTED ] ||
4329                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4330 }
4331 run_test 56t "check lfs find -stripe-size works"
4332
4333 test_56u() { # LU-611
4334         TDIR=$DIR/${tdir}u
4335         setup_56 $NUMFILES $NUMDIRS "-i 0"
4336
4337         if [ $OSTCOUNT -gt 1 ]; then
4338                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4339                 ONESTRIPE=4
4340         else
4341                 ONESTRIPE=0
4342         fi
4343
4344         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4345         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4346         NUMS=$($CMD | wc -l)
4347         [ $NUMS -eq $EXPECTED ] ||
4348                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4349
4350         EXPECTED=$ONESTRIPE
4351         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4352         NUMS=$($CMD | wc -l)
4353         [ $NUMS -eq $EXPECTED ] ||
4354                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4355
4356         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4357         NUMS=$($CMD | wc -l)
4358         [ $NUMS -eq $EXPECTED ] ||
4359                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4360
4361         EXPECTED=0
4362         # This should produce an error and not return any files
4363         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4364         NUMS=$($CMD 2>/dev/null | wc -l)
4365         [ $NUMS -eq $EXPECTED ] ||
4366                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4367
4368         if [ $OSTCOUNT -gt 1 ]; then
4369                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4370                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4371                 NUMS=$($CMD | wc -l)
4372                 [ $NUMS -eq $EXPECTED ] ||
4373                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4374         fi
4375 }
4376 run_test 56u "check lfs find -stripe-index works"
4377
4378 test_56v() {
4379     local MDT_IDX=0
4380
4381     TDIR=$DIR/${tdir}v
4382     rm -rf $TDIR
4383     setup_56 $NUMFILES $NUMDIRS
4384
4385     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4386     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4387
4388     for file in $($LFIND -mdt $UUID $TDIR); do
4389         file_mdt_idx=$($GETSTRIPE -M $file)
4390         [ $file_mdt_idx -eq $MDT_IDX ] ||
4391             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4392     done
4393 }
4394 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4395
4396 # Get and check the actual stripe count of one file.
4397 # Usage: check_stripe_count <file> <expected_stripe_count>
4398 check_stripe_count() {
4399     local file=$1
4400     local expected=$2
4401     local actual
4402
4403     [[ -z "$file" || -z "$expected" ]] &&
4404         error "check_stripe_count: invalid argument!"
4405
4406     local cmd="$GETSTRIPE -c $file"
4407     actual=$($cmd) || error "$cmd failed"
4408     actual=${actual%% *}
4409
4410     if [[ $actual -ne $expected ]]; then
4411         [[ $expected -eq -1 ]] ||
4412             error "$cmd wrong: found $actual, expected $expected"
4413         [[ $actual -eq $OSTCOUNT ]] ||
4414             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4415     fi
4416 }
4417
4418 test_56w() {
4419         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4420         TDIR=$DIR/${tdir}w
4421
4422     rm -rf $TDIR || error "remove $TDIR failed"
4423     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4424
4425     local stripe_size
4426     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4427         error "$GETSTRIPE -S -d $TDIR failed"
4428     stripe_size=${stripe_size%% *}
4429
4430     local file_size=$((stripe_size * OSTCOUNT))
4431     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4432     local required_space=$((file_num * file_size))
4433     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4434     [[ $free_space -le $((required_space / 1024)) ]] &&
4435         skip_env "need at least $required_space bytes free space," \
4436                  "have $free_space kbytes" && return
4437
4438     local dd_bs=65536
4439     local dd_count=$((file_size / dd_bs))
4440
4441     # write data into the files
4442     local i
4443     local j
4444     local file
4445     for i in $(seq 1 $NUMFILES); do
4446         file=$TDIR/file$i
4447         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4448             error "write data into $file failed"
4449     done
4450     for i in $(seq 1 $NUMDIRS); do
4451         for j in $(seq 1 $NUMFILES); do
4452             file=$TDIR/dir$i/file$j
4453             yes | dd bs=$dd_bs count=$dd_count of=$file \
4454                 >/dev/null 2>&1 ||
4455                 error "write data into $file failed"
4456         done
4457     done
4458
4459     local expected=-1
4460     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4461
4462     # lfs_migrate file
4463     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4464     echo "$cmd"
4465     eval $cmd || error "$cmd failed"
4466
4467     check_stripe_count $TDIR/file1 $expected
4468
4469     # lfs_migrate dir
4470     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4471     echo "$cmd"
4472     eval $cmd || error "$cmd failed"
4473
4474     for j in $(seq 1 $NUMFILES); do
4475         check_stripe_count $TDIR/dir1/file$j $expected
4476     done
4477
4478     # lfs_migrate works with lfs find
4479     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4480          $LFS_MIGRATE -y -c $expected"
4481     echo "$cmd"
4482     eval $cmd || error "$cmd failed"
4483
4484     for i in $(seq 2 $NUMFILES); do
4485         check_stripe_count $TDIR/file$i $expected
4486     done
4487     for i in $(seq 2 $NUMDIRS); do
4488         for j in $(seq 1 $NUMFILES); do
4489             check_stripe_count $TDIR/dir$i/file$j $expected
4490         done
4491     done
4492 }
4493 run_test 56w "check lfs_migrate -c stripe_count works"
4494
4495 test_56x() {
4496         check_swap_layouts_support && return 0
4497         [ "$OSTCOUNT" -lt "2" ] &&
4498                 skip_env "need 2 OST, skipping test" && return
4499
4500         local dir0=$DIR/$tdir/$testnum
4501         mkdir -p $dir0 || error "creating dir $dir0"
4502
4503         local ref1=/etc/passwd
4504         local file1=$dir0/file1
4505
4506         $SETSTRIPE -c 2 $file1
4507         cp $ref1 $file1
4508         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4509         stripe=$($GETSTRIPE -c $file1)
4510         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4511         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4512
4513         # clean up
4514         rm -f $file1
4515 }
4516 run_test 56x "lfs migration support"
4517
4518 test_57a() {
4519         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4520         # note test will not do anything if MDS is not local
4521         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4522                 skip "Only applicable to ldiskfs-based MDTs"
4523                 return
4524         fi
4525
4526         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4527         local MNTDEV="osd*.*MDT*.mntdev"
4528         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4529         [ -z "$DEV" ] && error "can't access $MNTDEV"
4530         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4531                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4532                         error "can't access $DEV"
4533                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
4534                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
4535                 rm $TMP/t57a.dump
4536         done
4537 }
4538 run_test 57a "verify MDS filesystem created with large inodes =="
4539
4540 test_57b() {
4541         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4542         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4543                 skip "Only applicable to ldiskfs-based MDTs"
4544                 return
4545         fi
4546
4547         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4548         local dir=$DIR/d57b
4549
4550         local FILECOUNT=100
4551         local FILE1=$dir/f1
4552         local FILEN=$dir/f$FILECOUNT
4553
4554         rm -rf $dir || error "removing $dir"
4555         test_mkdir -p $dir || error "creating $dir"
4556         local num=$(get_mds_dir $dir)
4557         local mymds=mds$num
4558
4559         echo "mcreating $FILECOUNT files"
4560         createmany -m $dir/f 1 $FILECOUNT || \
4561                 error "creating files in $dir"
4562
4563         # verify that files do not have EAs yet
4564         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4565         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4566
4567         sync
4568         sleep 1
4569         df $dir  #make sure we get new statfs data
4570         local MDSFREE=$(do_facet $mymds \
4571                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4572         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4573         echo "opening files to create objects/EAs"
4574         local FILE
4575         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4576                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4577         done
4578
4579         # verify that files have EAs now
4580         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
4581         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
4582
4583         sleep 1  #make sure we get new statfs data
4584         df $dir
4585         local MDSFREE2=$(do_facet $mymds \
4586                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4587         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4588         if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
4589                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
4590                         error "MDC before $MDCFREE != after $MDCFREE2"
4591                 else
4592                         echo "MDC before $MDCFREE != after $MDCFREE2"
4593                         echo "unable to confirm if MDS has large inodes"
4594                 fi
4595         fi
4596         rm -rf $dir
4597 }
4598 run_test 57b "default LOV EAs are stored inside large inodes ==="
4599
4600 test_58() {
4601         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4602         [ -z "$(which wiretest 2>/dev/null)" ] &&
4603                         skip_env "could not find wiretest" && return
4604         wiretest
4605 }
4606 run_test 58 "verify cross-platform wire constants =============="
4607
4608 test_59() {
4609         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4610         echo "touch 130 files"
4611         createmany -o $DIR/f59- 130
4612         echo "rm 130 files"
4613         unlinkmany $DIR/f59- 130
4614         sync
4615         # wait for commitment of removal
4616         wait_delete_completed
4617 }
4618 run_test 59 "verify cancellation of llog records async ========="
4619
4620 TEST60_HEAD="test_60 run $RANDOM"
4621 test_60a() {
4622         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4623         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
4624         [ ! -f run-llog.sh ] && skip_env "missing subtest run-llog.sh" && return
4625         log "$TEST60_HEAD - from kernel mode"
4626         do_facet mgs sh run-llog.sh
4627 }
4628 run_test 60a "llog sanity tests run from kernel module =========="
4629
4630 test_60b() { # bug 6411
4631         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4632         dmesg > $DIR/$tfile
4633         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
4634                                  /llog.test/ {
4635                                          if (marker)
4636                                                  from_marker++
4637                                          from_begin++
4638                                  }
4639                                  END {
4640                                          if (marker)
4641                                                  print from_marker
4642                                          else
4643                                                  print from_begin
4644                                  }"`
4645         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
4646 }
4647 run_test 60b "limit repeated messages from CERROR/CWARN ========"
4648
4649 test_60c() {
4650         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4651         echo "create 5000 files"
4652         createmany -o $DIR/f60c- 5000
4653 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
4654         lctl set_param fail_loc=0x80000137
4655         unlinkmany $DIR/f60c- 5000
4656         lctl set_param fail_loc=0
4657 }
4658 run_test 60c "unlink file when mds full"
4659
4660 test_60d() {
4661         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4662         SAVEPRINTK=$(lctl get_param -n printk)
4663
4664         # verify "lctl mark" is even working"
4665         MESSAGE="test message ID $RANDOM $$"
4666         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4667         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
4668
4669         lctl set_param printk=0 || error "set lnet.printk failed"
4670         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
4671         MESSAGE="new test message ID $RANDOM $$"
4672         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
4673         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4674         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
4675
4676         lctl set_param -n printk="$SAVEPRINTK"
4677 }
4678 run_test 60d "test printk console message masking"
4679
4680 test_61() {
4681         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4682         f="$DIR/f61"
4683         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
4684         cancel_lru_locks osc
4685         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
4686         sync
4687 }
4688 run_test 61 "mmap() writes don't make sync hang ================"
4689
4690 # bug 2330 - insufficient obd_match error checking causes LBUG
4691 test_62() {
4692         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4693         f="$DIR/f62"
4694         echo foo > $f
4695         cancel_lru_locks osc
4696         lctl set_param fail_loc=0x405
4697         cat $f && error "cat succeeded, expect -EIO"
4698         lctl set_param fail_loc=0
4699 }
4700 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
4701 # match every page all of the time.
4702 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
4703
4704 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
4705 test_63a() {    # was test_63
4706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4707         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
4708         lctl set_param -n osc.*.max_dirty_mb 0
4709         for i in `seq 10` ; do
4710                 dd if=/dev/zero of=$DIR/f63 bs=8k &
4711                 sleep 5
4712                 kill $!
4713                 sleep 1
4714         done
4715
4716         lctl set_param -n osc.*.max_dirty_mb $MAX_DIRTY_MB
4717         rm -f $DIR/f63 || true
4718 }
4719 run_test 63a "Verify oig_wait interruption does not crash ======="
4720
4721 # bug 2248 - async write errors didn't return to application on sync
4722 # bug 3677 - async write errors left page locked
4723 test_63b() {
4724         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4725         debugsave
4726         lctl set_param debug=-1
4727
4728         # ensure we have a grant to do async writes
4729         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
4730         rm $DIR/$tfile
4731
4732         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4733         lctl set_param fail_loc=0x80000406
4734         $MULTIOP $DIR/$tfile Owy && \
4735                 error "sync didn't return ENOMEM"
4736         sync; sleep 2; sync     # do a real sync this time to flush page
4737         lctl get_param -n llite.*.dump_page_cache | grep locked && \
4738                 error "locked page left in cache after async error" || true
4739         debugrestore
4740 }
4741 run_test 63b "async write errors should be returned to fsync ==="
4742
4743 test_64a () {
4744         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4745         df $DIR
4746         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
4747 }
4748 run_test 64a "verify filter grant calculations (in kernel) ====="
4749
4750 test_64b () {
4751         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4752         [ ! -f oos.sh ] && skip_env "missing subtest oos.sh" && return
4753         sh oos.sh $MOUNT
4754 }
4755 run_test 64b "check out-of-space detection on client ==========="
4756
4757 test_64c() {
4758         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
4759 }
4760 run_test 64c "verify grant shrink ========================------"
4761
4762 # bug 1414 - set/get directories' stripe info
4763 test_65a() {
4764         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4765         test_mkdir -p $DIR/$tdir
4766         touch $DIR/$tdir/f1
4767         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
4768 }
4769 run_test 65a "directory with no stripe info ===================="
4770
4771 test_65b() {
4772         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4773         test_mkdir -p $DIR/$tdir
4774         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4775                                                 error "setstripe"
4776         touch $DIR/$tdir/f2
4777         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
4778 }
4779 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
4780
4781 test_65c() {
4782         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4783         if [ $OSTCOUNT -gt 1 ]; then
4784                 test_mkdir -p $DIR/$tdir
4785                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
4786                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
4787                 touch $DIR/$tdir/f3
4788                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
4789         fi
4790 }
4791 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
4792
4793 test_65d() {
4794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4795         test_mkdir -p $DIR/$tdir
4796         if [ $STRIPECOUNT -le 0 ]; then
4797                 sc=1
4798         elif [ $STRIPECOUNT -gt 2000 ]; then
4799 #LOV_MAX_STRIPE_COUNT is 2000
4800                 [ $OSTCOUNT -gt 2000 ] && sc=2000 || sc=$(($OSTCOUNT - 1))
4801         else
4802                 sc=$(($STRIPECOUNT - 1))
4803         fi
4804         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
4805         touch $DIR/$tdir/f4 $DIR/$tdir/f5
4806         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
4807                                                 error "lverify failed"
4808 }
4809 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
4810
4811 test_65e() {
4812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4813         test_mkdir -p $DIR/$tdir
4814
4815         $SETSTRIPE $DIR/$tdir || error "setstripe"
4816         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
4817                                         error "no stripe info failed"
4818         touch $DIR/$tdir/f6
4819         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
4820 }
4821 run_test 65e "directory setstripe defaults ======================="
4822
4823 test_65f() {
4824         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4825         test_mkdir -p $DIR/${tdir}f
4826         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
4827 }
4828 run_test 65f "dir setstripe permission (should return error) ==="
4829
4830 test_65g() {
4831         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4832         test_mkdir -p $DIR/$tdir
4833         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4834                                                         error "setstripe"
4835         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
4836         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
4837                 error "delete default stripe failed"
4838 }
4839 run_test 65g "directory setstripe -d ==========================="
4840
4841 test_65h() {
4842         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4843         test_mkdir -p $DIR/$tdir
4844         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4845                                                         error "setstripe"
4846         test_mkdir -p $DIR/$tdir/dd1
4847         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
4848                 error "stripe info inherit failed"
4849 }
4850 run_test 65h "directory stripe info inherit ===================="
4851
4852 test_65i() { # bug6367
4853         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4854         $SETSTRIPE -S 65536 -c -1 $MOUNT
4855 }
4856 run_test 65i "set non-default striping on root directory (bug 6367)="
4857
4858 test_65ia() { # bug12836
4859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4860         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
4861 }
4862 run_test 65ia "getstripe on -1 default directory striping"
4863
4864 test_65ib() { # bug12836
4865         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4866         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
4867 }
4868 run_test 65ib "getstripe -v on -1 default directory striping"
4869
4870 test_65ic() { # bug12836
4871         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4872         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
4873 }
4874 run_test 65ic "new find on -1 default directory striping"
4875
4876 test_65j() { # bug6367
4877         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4878         sync; sleep 1
4879         # if we aren't already remounting for each test, do so for this test
4880         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
4881                 cleanup || error "failed to unmount"
4882                 setup
4883         fi
4884         $SETSTRIPE -d $MOUNT || error "setstripe failed"
4885 }
4886 run_test 65j "set default striping on root directory (bug 6367)="
4887
4888 test_65k() { # bug11679
4889         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4890         [ "$OSTCOUNT" -lt 2 ] && skip_env "too few OSTs" && return
4891         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4892
4893     echo "Check OST status: "
4894     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
4895               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
4896
4897     for OSC in $MDS_OSCS; do
4898         echo $OSC "is activate"
4899         do_facet $SINGLEMDS lctl --device %$OSC activate
4900     done
4901
4902     mkdir -p $DIR/$tdir
4903     for INACTIVE_OSC in $MDS_OSCS; do
4904         echo "Deactivate: " $INACTIVE_OSC
4905         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
4906         for STRIPE_OSC in $MDS_OSCS; do
4907             OST=`osc_to_ost $STRIPE_OSC`
4908             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
4909                  awk -F: /$OST/'{ print $1 }' | head -n 1`
4910
4911             [ -f $DIR/$tdir/$IDX ] && continue
4912             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
4913             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
4914             RC=$?
4915             [ $RC -ne 0 ] && error "setstripe should have succeeded"
4916         done
4917         rm -f $DIR/$tdir/*
4918         echo $INACTIVE_OSC "is Activate."
4919         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
4920     done
4921 }
4922 run_test 65k "validate manual striping works properly with deactivated OSCs"
4923
4924 test_65l() { # bug 12836
4925         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4926         test_mkdir -p $DIR/$tdir/test_dir
4927         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
4928         $LFS find -mtime -1 $DIR/$tdir >/dev/null
4929 }
4930 run_test 65l "lfs find on -1 stripe dir ========================"
4931
4932 # bug 2543 - update blocks count on client
4933 test_66() {
4934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4935         COUNT=${COUNT:-8}
4936         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
4937         sync; sync_all_data; sync; sync_all_data
4938         cancel_lru_locks osc
4939         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
4940         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
4941 }
4942 run_test 66 "update inode blocks count on client ==============="
4943
4944 LLOOP=
4945 LLITELOOPLOAD=
4946 cleanup_68() {
4947         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4948         trap 0
4949         if [ ! -z "$LLOOP" ]; then
4950                 if swapon -s | grep -q $LLOOP; then
4951                         swapoff $LLOOP || error "swapoff failed"
4952                 fi
4953
4954                 $LCTL blockdev_detach $LLOOP || error "detach failed"
4955                 rm -f $LLOOP
4956                 unset LLOOP
4957         fi
4958         if [ ! -z "$LLITELOOPLOAD" ]; then
4959                 rmmod llite_lloop
4960                 unset LLITELOOPLOAD
4961         fi
4962         rm -f $DIR/f68*
4963 }
4964
4965 meminfo() {
4966         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
4967 }
4968
4969 swap_used() {
4970         swapon -s | awk '($1 == "'$1'") { print $4 }'
4971 }
4972
4973 # test case for lloop driver, basic function
4974 test_68a() {
4975         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4976         [ "$UID" != 0 ] && skip_env "must run as root" && return
4977         llite_lloop_enabled || \
4978                 { skip_env "llite_lloop module disabled" && return; }
4979
4980         trap cleanup_68 EXIT
4981
4982         if ! module_loaded llite_lloop; then
4983                 if load_module llite/llite_lloop; then
4984                         LLITELOOPLOAD=yes
4985                 else
4986                         skip_env "can't find module llite_lloop"
4987                         return
4988                 fi
4989         fi
4990
4991         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
4992         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
4993         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
4994
4995         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
4996         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
4997
4998         cleanup_68
4999 }
5000 run_test 68a "lloop driver - basic test ========================"
5001
5002 # excercise swapping to lustre by adding a high priority swapfile entry
5003 # and then consuming memory until it is used.
5004 test_68b() {  # was test_68
5005         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5006         [ "$UID" != 0 ] && skip_env "must run as root" && return
5007         lctl get_param -n devices | grep -q obdfilter && \
5008                 skip "local OST" && return
5009
5010         grep -q llite_lloop /proc/modules
5011         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5012
5013         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5014                 skip "can't reliably test swap with TCP" && return
5015
5016         MEMTOTAL=`meminfo MemTotal`
5017         NR_BLOCKS=$((MEMTOTAL>>8))
5018         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5019
5020         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5021         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5022         mkswap $DIR/f68b
5023
5024         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5025
5026         trap cleanup_68 EXIT
5027
5028         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5029
5030         echo "before: `swapon -s | grep $LLOOP`"
5031         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5032         echo "after: `swapon -s | grep $LLOOP`"
5033         SWAPUSED=`swap_used $LLOOP`
5034
5035         cleanup_68
5036
5037         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5038 }
5039 run_test 68b "support swapping to Lustre ========================"
5040
5041 # bug5265, obdfilter oa2dentry return -ENOENT
5042 # #define OBD_FAIL_OST_ENOENT 0x217
5043 test_69() {
5044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5045         remote_ost_nodsh && skip "remote OST with nodsh" && return
5046
5047         f="$DIR/$tfile"
5048         $SETSTRIPE -c 1 -i 0 $f
5049
5050         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5051
5052         do_facet ost1 lctl set_param fail_loc=0x217
5053         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5054         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5055
5056         do_facet ost1 lctl set_param fail_loc=0
5057         $DIRECTIO write $f 0 2 || error "write error"
5058
5059         cancel_lru_locks osc
5060         $DIRECTIO read $f 0 1 || error "read error"
5061
5062         do_facet ost1 lctl set_param fail_loc=0x217
5063         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5064
5065         do_facet ost1 lctl set_param fail_loc=0
5066         rm -f $f
5067 }
5068 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5069
5070 test_71() {
5071     test_mkdir -p $DIR/$tdir
5072     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5073 }
5074 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5075
5076 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5077         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5078         [ "$RUNAS_ID" = "$UID" ] &&
5079                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5080
5081         # Check that testing environment is properly set up. Skip if not
5082         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5083                 skip_env "User $RUNAS_ID does not exist - skipping"
5084                 return 0
5085         }
5086         # We had better clear the $DIR to get enough space for dd
5087         rm -rf $DIR/*
5088         touch $DIR/$tfile
5089         chmod 777 $DIR/$tfile
5090         chmod ug+s $DIR/$tfile
5091         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5092                 error "$RUNAS dd $DIR/$tfile failed"
5093         # See if we are still setuid/sgid
5094         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5095                 error "S/gid is not dropped on write"
5096         # Now test that MDS is updated too
5097         cancel_lru_locks mdc
5098         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5099                 error "S/gid is not dropped on MDS"
5100         rm -f $DIR/$tfile
5101 }
5102 run_test 72a "Test that remove suid works properly (bug5695) ===="
5103
5104 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5105         local perm
5106
5107         [ "$RUNAS_ID" = "$UID" ] && \
5108                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5109         [ "$RUNAS_ID" -eq 0 ] && \
5110                 skip_env "RUNAS_ID = 0 -- skipping" && return
5111
5112         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5113         # Check that testing environment is properly set up. Skip if not
5114         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5115                 skip_env "User $RUNAS_ID does not exist - skipping"
5116                 return 0
5117         }
5118         touch $DIR/${tfile}-f{g,u}
5119         test_mkdir $DIR/${tfile}-dg
5120         test_mkdir $DIR/${tfile}-du
5121         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5122         chmod g+s $DIR/${tfile}-{f,d}g
5123         chmod u+s $DIR/${tfile}-{f,d}u
5124         for perm in 777 2777 4777; do
5125                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5126                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5127                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5128                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5129         done
5130         true
5131 }
5132 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5133
5134 # bug 3462 - multiple simultaneous MDC requests
5135 test_73() {
5136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5137         test_mkdir $DIR/d73-1
5138         test_mkdir $DIR/d73-2
5139         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5140         pid1=$!
5141
5142         lctl set_param fail_loc=0x80000129
5143         $MULTIOP $DIR/d73-1/f73-2 Oc &
5144         sleep 1
5145         lctl set_param fail_loc=0
5146
5147         $MULTIOP $DIR/d73-2/f73-3 Oc &
5148         pid3=$!
5149
5150         kill -USR1 $pid1
5151         wait $pid1 || return 1
5152
5153         sleep 25
5154
5155         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5156         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5157         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5158
5159         rm -rf $DIR/d73-*
5160 }
5161 run_test 73 "multiple MDC requests (should not deadlock)"
5162
5163 test_74a() { # bug 6149, 6184
5164         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5165         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5166         #
5167         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5168         # will spin in a tight reconnection loop
5169         touch $DIR/f74a
5170         lctl set_param fail_loc=0x8000030e
5171         # get any lock that won't be difficult - lookup works.
5172         ls $DIR/f74a
5173         lctl set_param fail_loc=0
5174         true
5175         rm -f $DIR/f74a
5176 }
5177 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5178
5179 test_74b() { # bug 13310
5180         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5181         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5182         #
5183         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5184         # will spin in a tight reconnection loop
5185         lctl set_param fail_loc=0x8000030e
5186         # get a "difficult" lock
5187         touch $DIR/f74b
5188         lctl set_param fail_loc=0
5189         true
5190         rm -f $DIR/f74b
5191 }
5192 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5193
5194 test_74c() {
5195         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5196 #define OBD_FAIL_LDLM_NEW_LOCK
5197         lctl set_param fail_loc=0x80000319
5198         touch $DIR/$tfile && error "Touch successful"
5199         true
5200 }
5201 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5202
5203 num_inodes() {
5204         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5205 }
5206
5207 get_inode_slab_tunables() {
5208         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5209 }
5210
5211 set_inode_slab_tunables() {
5212         echo "lustre_inode_cache $1" > /proc/slabinfo
5213 }
5214
5215 test_76() { # Now for bug 20433, added originally in bug 1443
5216         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5217         local SLAB_SETTINGS=`get_inode_slab_tunables`
5218         local CPUS=`getconf _NPROCESSORS_ONLN`
5219         # we cannot set limit below 1 which means 1 inode in each
5220         # per-cpu cache is still allowed
5221         set_inode_slab_tunables "1 1 0"
5222         cancel_lru_locks osc
5223         BEFORE_INODES=`num_inodes`
5224         echo "before inodes: $BEFORE_INODES"
5225         local COUNT=1000
5226         [ "$SLOW" = "no" ] && COUNT=100
5227         for i in `seq $COUNT`; do
5228                 touch $DIR/$tfile
5229                 rm -f $DIR/$tfile
5230         done
5231         cancel_lru_locks osc
5232         AFTER_INODES=`num_inodes`
5233         echo "after inodes: $AFTER_INODES"
5234         local wait=0
5235         while [ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]; do
5236                 sleep 2
5237                 AFTER_INODES=`num_inodes`
5238                 wait=$((wait+2))
5239                 echo "wait $wait seconds inodes: $AFTER_INODES"
5240                 if [ $wait -gt 30 ]; then
5241                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5242                 fi
5243         done
5244         set_inode_slab_tunables "$SLAB_SETTINGS"
5245 }
5246 run_test 76 "confirm clients recycle inodes properly ===="
5247
5248
5249 export ORIG_CSUM=""
5250 set_checksums()
5251 {
5252         # Note: in sptlrpc modes which enable its own bulk checksum, the
5253         # original crc32_le bulk checksum will be automatically disabled,
5254         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5255         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5256         # In this case set_checksums() will not be no-op, because sptlrpc
5257         # bulk checksum will be enabled all through the test.
5258
5259         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5260         lctl set_param -n osc.*.checksums $1
5261         return 0
5262 }
5263
5264 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5265                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5266 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5267 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5268 set_checksum_type()
5269 {
5270         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5271         log "set checksum type to $1"
5272         return 0
5273 }
5274 F77_TMP=$TMP/f77-temp
5275 F77SZ=8
5276 setup_f77() {
5277         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5278                 error "error writing to $F77_TMP"
5279 }
5280
5281 test_77a() { # bug 10889
5282         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5283         $GSS && skip "could not run with gss" && return
5284         [ ! -f $F77_TMP ] && setup_f77
5285         set_checksums 1
5286         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5287         set_checksums 0
5288         rm -f $DIR/$tfile
5289 }
5290 run_test 77a "normal checksum read/write operation ============="
5291
5292 test_77b() { # bug 10889
5293         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5294         $GSS && skip "could not run with gss" && return
5295         [ ! -f $F77_TMP ] && setup_f77
5296         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5297         lctl set_param fail_loc=0x80000409
5298         set_checksums 1
5299         dd if=$F77_TMP of=$DIR/f77b bs=1M count=$F77SZ conv=sync || \
5300                 error "dd error: $?"
5301         lctl set_param fail_loc=0
5302         set_checksums 0
5303 }
5304 run_test 77b "checksum error on client write ===================="
5305
5306 test_77c() { # bug 10889
5307         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5308         $GSS && skip "could not run with gss" && return
5309         [ ! -f $DIR/f77b ] && skip "requires 77b - skipping" && return
5310         set_checksums 1
5311         for algo in $CKSUM_TYPES; do
5312                 cancel_lru_locks osc
5313                 set_checksum_type $algo
5314                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5315                 lctl set_param fail_loc=0x80000408
5316                 cmp $F77_TMP $DIR/f77b || error "file compare failed"
5317                 lctl set_param fail_loc=0
5318         done
5319         set_checksums 0
5320         set_checksum_type $ORIG_CSUM_TYPE
5321         rm -f $DIR/f77b
5322 }
5323 run_test 77c "checksum error on client read ==================="
5324
5325 test_77d() { # bug 10889
5326         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5327         $GSS && skip "could not run with gss" && return
5328         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5329         lctl set_param fail_loc=0x80000409
5330         set_checksums 1
5331         directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
5332                 error "direct write: rc=$?"
5333         lctl set_param fail_loc=0
5334         set_checksums 0
5335 }
5336 run_test 77d "checksum error on OST direct write ==============="
5337
5338 test_77e() { # bug 10889
5339         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5340         $GSS && skip "could not run with gss" && return
5341         [ ! -f $DIR/f77 ] && skip "requires 77d - skipping" && return
5342         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5343         lctl set_param fail_loc=0x80000408
5344         set_checksums 1
5345         cancel_lru_locks osc
5346         directio read $DIR/f77 0 $F77SZ $((1024 * 1024)) || \
5347                 error "direct read: rc=$?"
5348         lctl set_param fail_loc=0
5349         set_checksums 0
5350 }
5351 run_test 77e "checksum error on OST direct read ================"
5352
5353 test_77f() { # bug 10889
5354         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5355         $GSS && skip "could not run with gss" && return
5356         set_checksums 1
5357         for algo in $CKSUM_TYPES; do
5358                 cancel_lru_locks osc
5359                 set_checksum_type $algo
5360                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5361                 lctl set_param fail_loc=0x409
5362                 directio write $DIR/f77 0 $F77SZ $((1024 * 1024)) && \
5363                         error "direct write succeeded"
5364                 lctl set_param fail_loc=0
5365         done
5366         set_checksum_type $ORIG_CSUM_TYPE
5367         set_checksums 0
5368 }
5369 run_test 77f "repeat checksum error on write (expect error) ===="
5370
5371 test_77g() { # bug 10889
5372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5373         $GSS && skip "could not run with gss" && return
5374         remote_ost_nodsh && skip "remote OST with nodsh" && return
5375
5376         [ ! -f $F77_TMP ] && setup_f77
5377
5378         $SETSTRIPE -c 1 -i 0 $DIR/f77g
5379         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5380         do_facet ost1 lctl set_param fail_loc=0x8000021a
5381         set_checksums 1
5382         dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
5383                 error "write error: rc=$?"
5384         do_facet ost1 lctl set_param fail_loc=0
5385         set_checksums 0
5386 }
5387 run_test 77g "checksum error on OST write ======================"
5388
5389 test_77h() { # bug 10889
5390         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5391         $GSS && skip "could not run with gss" && return
5392         remote_ost_nodsh && skip "remote OST with nodsh" && return
5393
5394         [ ! -f $DIR/f77g ] && skip "requires 77g - skipping" && return
5395         cancel_lru_locks osc
5396         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5397         do_facet ost1 lctl set_param fail_loc=0x8000021b
5398         set_checksums 1
5399         cmp $F77_TMP $DIR/f77g || error "file compare failed"
5400         do_facet ost1 lctl set_param fail_loc=0
5401         set_checksums 0
5402 }
5403 run_test 77h "checksum error on OST read ======================="
5404
5405 test_77i() { # bug 13805
5406         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5407         $GSS && skip "could not run with gss" && return
5408         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5409         lctl set_param fail_loc=0x40b
5410         remount_client $MOUNT
5411         lctl set_param fail_loc=0
5412         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5413                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5414                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5415                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5416         done
5417         remount_client $MOUNT
5418 }
5419 run_test 77i "client not supporting OSD_CONNECT_CKSUM =========="
5420
5421 test_77j() { # bug 13805
5422         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5423         $GSS && skip "could not run with gss" && return
5424         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5425         lctl set_param fail_loc=0x40c
5426         remount_client $MOUNT
5427         lctl set_param fail_loc=0
5428         sleep 2 # wait async osc connect to finish
5429         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5430                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5431                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5432                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5433         done
5434         remount_client $MOUNT
5435 }
5436 run_test 77j "client only supporting ADLER32 ===================="
5437
5438 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5439 rm -f $F77_TMP
5440 unset F77_TMP
5441
5442 test_78() { # bug 10901
5443         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5444         remote_ost || { skip_env "local OST" && return; }
5445
5446         NSEQ=5
5447         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5448         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5449         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5450         echo "MemTotal: $MEMTOTAL"
5451 # reserve 256MB of memory for the kernel and other running processes,
5452 # and then take 1/2 of the remaining memory for the read/write buffers.
5453     if [ $MEMTOTAL -gt 512 ] ;then
5454         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5455     else
5456         # for those poor memory-starved high-end clusters...
5457         MEMTOTAL=$((MEMTOTAL / 2))
5458     fi
5459         echo "Mem to use for directio: $MEMTOTAL"
5460         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
5461         [ $F78SIZE -gt 512 ] && F78SIZE=512
5462         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
5463         SMALLESTOST=`lfs df $DIR |grep OST | awk '{print $4}' |sort -n |head -1`
5464         echo "Smallest OST: $SMALLESTOST"
5465         [ $SMALLESTOST -lt 10240 ] && \
5466                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5467
5468         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ] && \
5469                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5470
5471         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5472         echo "File size: $F78SIZE"
5473         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5474         for i in `seq 1 $NSEQ`
5475         do
5476                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5477                 echo directIO rdwr round $i of $NSEQ
5478                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5479         done
5480
5481         rm -f $DIR/$tfile
5482 }
5483 run_test 78 "handle large O_DIRECT writes correctly ============"
5484
5485 test_79() { # bug 12743
5486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5487         wait_delete_completed
5488
5489         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5490         BKFREE=$(calc_osc_kbytes kbytesfree)
5491         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5492
5493         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5494         DFTOTAL=`echo $STRING | cut -d, -f1`
5495         DFUSED=`echo $STRING  | cut -d, -f2`
5496         DFAVAIL=`echo $STRING | cut -d, -f3`
5497         DFFREE=$(($DFTOTAL - $DFUSED))
5498
5499         ALLOWANCE=$((64 * $OSTCOUNT))
5500
5501         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5502            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5503                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5504         fi
5505         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5506            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5507                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5508         fi
5509         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5510            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5511                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5512         fi
5513 }
5514 run_test 79 "df report consistency check ======================="
5515
5516 test_80() { # bug 10718
5517         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5518         # relax strong synchronous semantics for slow backends like ZFS
5519         local soc="obdfilter.*.sync_on_lock_cancel"
5520         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5521         local hosts=
5522         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5523                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5524                           facet_active_host $host; done | sort -u)
5525                 do_nodes $hosts lctl set_param $soc=never
5526         fi
5527
5528         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5529         sync; sleep 1; sync
5530         local BEFORE=`date +%s`
5531         cancel_lru_locks osc
5532         local AFTER=`date +%s`
5533         local DIFF=$((AFTER-BEFORE))
5534         if [ $DIFF -gt 1 ] ; then
5535                 error "elapsed for 1M@1T = $DIFF"
5536         fi
5537
5538         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5539
5540         rm -f $DIR/$tfile
5541 }
5542 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5543
5544 test_81a() { # LU-456
5545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5546         remote_ost_nodsh && skip "remote OST with nodsh" && return
5547         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5548         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5549         do_facet ost1 lctl set_param fail_loc=0x80000228
5550
5551         # write should trigger a retry and success
5552         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5553         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5554         RC=$?
5555         if [ $RC -ne 0 ] ; then
5556                 error "write should success, but failed for $RC"
5557         fi
5558 }
5559 run_test 81a "OST should retry write when get -ENOSPC ==============="
5560
5561 test_81b() { # LU-456
5562         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5563         remote_ost_nodsh && skip "remote OST with nodsh" && return
5564         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5565         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5566         do_facet ost1 lctl set_param fail_loc=0x228
5567
5568         # write should retry several times and return -ENOSPC finally
5569         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5570         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5571         RC=$?
5572         ENOSPC=28
5573         if [ $RC -ne $ENOSPC ] ; then
5574                 error "dd should fail for -ENOSPC, but succeed."
5575         fi
5576 }
5577 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5578
5579 test_82() { # LU-1031
5580         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5581         local gid1=14091995
5582         local gid2=16022000
5583
5584         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5585         local MULTIPID1=$!
5586         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5587         local MULTIPID2=$!
5588         kill -USR1 $MULTIPID2
5589         sleep 2
5590         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5591                 error "First grouplock does not block second one"
5592         else
5593                 echo "Second grouplock blocks first one"
5594         fi
5595         kill -USR1 $MULTIPID1
5596         wait $MULTIPID1
5597         wait $MULTIPID2
5598 }
5599 run_test 82 "Basic grouplock test ==============================="
5600
5601 test_99a() {
5602         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
5603                 return
5604         test_mkdir -p $DIR/d99cvsroot
5605         chown $RUNAS_ID $DIR/d99cvsroot
5606         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
5607         cd $TMP
5608
5609         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
5610         cd $oldPWD
5611 }
5612 run_test 99a "cvs init ========================================="
5613
5614 test_99b() {
5615         [ -z "$(which cvs 2>/dev/null)" ] &&
5616                 skip_env "could not find cvs" && return
5617         [ ! -d $DIR/d99cvsroot ] && test_99a
5618         cd /etc/init.d
5619         # some versions of cvs import exit(1) when asked to import links or
5620         # files they can't read.  ignore those files.
5621         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
5622                         ! -perm +4 -printf '-I %f\n')
5623         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
5624                 d99reposname vtag rtag
5625 }
5626 run_test 99b "cvs import ======================================="
5627
5628 test_99c() {
5629         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5630         [ ! -d $DIR/d99cvsroot ] && test_99b
5631         cd $DIR
5632         test_mkdir -p $DIR/d99reposname
5633         chown $RUNAS_ID $DIR/d99reposname
5634         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
5635 }
5636 run_test 99c "cvs checkout ====================================="
5637
5638 test_99d() {
5639         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5640         [ ! -d $DIR/d99cvsroot ] && test_99c
5641         cd $DIR/d99reposname
5642         $RUNAS touch foo99
5643         $RUNAS cvs add -m 'addmsg' foo99
5644 }
5645 run_test 99d "cvs add =========================================="
5646
5647 test_99e() {
5648         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5649         [ ! -d $DIR/d99cvsroot ] && test_99c
5650         cd $DIR/d99reposname
5651         $RUNAS cvs update
5652 }
5653 run_test 99e "cvs update ======================================="
5654
5655 test_99f() {
5656         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5657         [ ! -d $DIR/d99cvsroot ] && test_99d
5658         cd $DIR/d99reposname
5659         $RUNAS cvs commit -m 'nomsg' foo99
5660     rm -fr $DIR/d99cvsroot
5661 }
5662 run_test 99f "cvs commit ======================================="
5663
5664 test_100() {
5665         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5666         [ "$NETTYPE" = tcp ] || \
5667                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
5668                         return ; }
5669
5670         remote_ost_nodsh && skip "remote OST with nodsh" && return
5671         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5672         remote_servers || \
5673                 { skip "useless for local single node setup" && return; }
5674
5675         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
5676                 [ "$PROT" != "tcp" ] && continue
5677                 RPORT=$(echo $REMOTE | cut -d: -f2)
5678                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
5679
5680                 rc=0
5681                 LPORT=`echo $LOCAL | cut -d: -f2`
5682                 if [ $LPORT -ge 1024 ]; then
5683                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
5684                         netstat -tna
5685                         error_exit "local: $LPORT > 1024, remote: $RPORT"
5686                 fi
5687         done
5688         [ "$rc" = 0 ] || error_exit "privileged port not found" )
5689 }
5690 run_test 100 "check local port using privileged port ==========="
5691
5692 function get_named_value()
5693 {
5694     local tag
5695
5696     tag=$1
5697     while read ;do
5698         line=$REPLY
5699         case $line in
5700         $tag*)
5701             echo $line | sed "s/^$tag[ ]*//"
5702             break
5703             ;;
5704         esac
5705     done
5706 }
5707
5708 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
5709                    awk '/^max_cached_mb/ { print $2 }')
5710
5711 cleanup_101a() {
5712         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
5713         trap 0
5714 }
5715
5716 test_101a() {
5717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5718         local s
5719         local discard
5720         local nreads=10000
5721         local cache_limit=32
5722
5723         $LCTL set_param -n osc.*-osc*.rpc_stats 0
5724         trap cleanup_101a EXIT
5725         $LCTL set_param -n llite.*.read_ahead_stats 0
5726         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
5727
5728         #
5729         # randomly read 10000 of 64K chunks from file 3x 32MB in size
5730         #
5731         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
5732         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
5733
5734         discard=0
5735         for s in `$LCTL get_param -n llite.*.read_ahead_stats | \
5736                 get_named_value 'read but discarded' | cut -d" " -f1`; do
5737                         discard=$(($discard + $s))
5738         done
5739         cleanup_101a
5740
5741         if [ $(($discard * 10)) -gt $nreads ] ;then
5742                 $LCTL get_param osc.*-osc*.rpc_stats
5743                 $LCTL get_param llite.*.read_ahead_stats
5744                 error "too many ($discard) discarded pages"
5745         fi
5746         rm -f $DIR/$tfile || true
5747 }
5748 run_test 101a "check read-ahead for random reads ================"
5749
5750 setup_test101bc() {
5751         test_mkdir -p $DIR/$tdir
5752         STRIPE_SIZE=1048576
5753         STRIPE_COUNT=$OSTCOUNT
5754         STRIPE_OFFSET=0
5755
5756         local list=$(comma_list $(osts_nodes))
5757         set_osd_param $list '' read_cache_enable 0
5758         set_osd_param $list '' writethrough_cache_enable 0
5759
5760         trap cleanup_test101bc EXIT
5761         # prepare the read-ahead file
5762         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
5763
5764         dd if=/dev/zero of=$DIR/$tfile bs=1024k count=100 2> /dev/null
5765 }
5766
5767 cleanup_test101bc() {
5768         trap 0
5769         rm -rf $DIR/$tdir
5770         rm -f $DIR/$tfile
5771
5772         local list=$(comma_list $(osts_nodes))
5773         set_osd_param $list '' read_cache_enable 1
5774         set_osd_param $list '' writethrough_cache_enable 1
5775 }
5776
5777 calc_total() {
5778         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
5779 }
5780
5781 ra_check_101() {
5782         local READ_SIZE=$1
5783         local STRIPE_SIZE=1048576
5784         local RA_INC=1048576
5785         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
5786         local FILE_LENGTH=$((64*100))
5787         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
5788                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
5789         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
5790                         get_named_value 'read but discarded' | \
5791                         cut -d" " -f1 | calc_total`
5792         if [ $DISCARD -gt $discard_limit ]; then
5793                 $LCTL get_param llite.*.read_ahead_stats
5794                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
5795         else
5796                 echo "Read-ahead success for size ${READ_SIZE}"
5797         fi
5798 }
5799
5800 test_101b() {
5801         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5802         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping stride IO stride-ahead test" && return
5803         local STRIPE_SIZE=1048576
5804         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
5805         local FILE_LENGTH=$((STRIPE_SIZE*100))
5806         local ITERATION=$((FILE_LENGTH/STRIDE_SIZE))
5807         # prepare the read-ahead file
5808         setup_test101bc
5809         cancel_lru_locks osc
5810         for BIDX in 2 4 8 16 32 64 128 256
5811         do
5812                 local BSIZE=$((BIDX*4096))
5813                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
5814                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
5815                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
5816                 $LCTL set_param -n llite.*.read_ahead_stats 0
5817                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
5818                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
5819                 cancel_lru_locks osc
5820                 ra_check_101 $BSIZE
5821         done
5822         cleanup_test101bc
5823         true
5824 }
5825 run_test 101b "check stride-io mode read-ahead ================="
5826
5827 test_101c() {
5828         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5829         local STRIPE_SIZE=1048576
5830         local FILE_LENGTH=$((STRIPE_SIZE*100))
5831         local nreads=10000
5832         local osc
5833
5834     setup_test101bc
5835
5836     cancel_lru_locks osc
5837     $LCTL set_param osc.*.rpc_stats 0
5838     $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
5839     for osc in $($LCTL get_param -N osc.*); do
5840         if [ "$osc" == "osc.num_refs" ]; then
5841             continue
5842         fi
5843
5844         local lines=$($LCTL get_param -n ${osc}.rpc_stats | wc | awk '{print $1}')
5845         if [ $lines -le 20 ]; then
5846             continue
5847         fi
5848
5849         local rpc4k=$($LCTL get_param -n ${osc}.rpc_stats |
5850                                      awk '$1 == "1:" { print $2; exit; }')
5851         local rpc8k=$($LCTL get_param -n ${osc}.rpc_stats |
5852                                      awk '$1 == "2:" { print $2; exit; }')
5853         local rpc16k=$($LCTL get_param -n ${osc}.rpc_stats |
5854                                      awk '$1 == "4:" { print $2; exit; }')
5855         local rpc32k=$($LCTL get_param -n ${osc}.rpc_stats |
5856                                      awk '$1 == "8:" { print $2; exit; }')
5857
5858         [ $rpc4k != 0 ]  && error "Small 4k read IO ${rpc4k}!"
5859         [ $rpc8k != 0 ]  && error "Small 8k read IO ${rpc8k}!"
5860         [ $rpc16k != 0 ] && error "Small 16k read IO ${rpc16k}!"
5861         [ $rpc32k != 0 ] && error "Small 32k read IO ${rpc32k}!"
5862         echo "${osc} rpc check passed!"
5863     done
5864     cleanup_test101bc
5865     true
5866 }
5867 run_test 101c "check stripe_size aligned read-ahead ================="
5868
5869 set_read_ahead() {
5870    $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
5871    $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
5872 }
5873
5874 test_101d() {
5875         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5876         local file=$DIR/$tfile
5877         local size=${FILESIZE_101c:-500}
5878         local ra_MB=${READAHEAD_MB:-40}
5879
5880         local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
5881         [ $space -gt $((size * 1024)) ] ||
5882                 { skip "Need free space ${size}M, have $space" && return; }
5883
5884     echo Creating ${size}M test file $file
5885     dd if=/dev/zero of=$file bs=1M count=$size || error "dd failed"
5886     echo Cancel LRU locks on lustre client to flush the client cache
5887     cancel_lru_locks osc
5888
5889     echo Disable read-ahead
5890     local old_READAHEAD=$(set_read_ahead 0)
5891
5892     echo Reading the test file $file with read-ahead disabled
5893     time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
5894
5895     echo Cancel LRU locks on lustre client to flush the client cache
5896     cancel_lru_locks osc
5897     echo Enable read-ahead with ${ra_MB}MB
5898     set_read_ahead $ra_MB
5899
5900     echo Reading the test file $file with read-ahead enabled
5901     time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
5902
5903     echo read-ahead disabled time read $time_ra_OFF
5904     echo read-ahead enabled  time read $time_ra_ON
5905
5906         set_read_ahead $old_READAHEAD
5907         rm -f $file
5908         wait_delete_completed
5909
5910     [ $time_ra_ON -lt $time_ra_OFF ] ||
5911         error "read-ahead enabled  time read (${time_ra_ON}s) is more than
5912                read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
5913 }
5914 run_test 101d "file read with and without read-ahead enabled  ================="
5915
5916 test_101e() {
5917         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5918     local file=$DIR/$tfile
5919     local size=500  #KB
5920     local count=100
5921     local blksize=1024
5922
5923     local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
5924     local need_space=$((count * size))
5925     [ $space -gt $need_space ] ||
5926         { skip_env "Need free space $need_space, have $space" && return; }
5927
5928     echo Creating $count ${size}K test files
5929     for ((i = 0; i < $count; i++)); do
5930         dd if=/dev/zero of=${file}_${i} bs=$blksize count=$size 2>/dev/null
5931     done
5932
5933     echo Cancel LRU locks on lustre client to flush the client cache
5934     cancel_lru_locks osc
5935
5936     echo Reset readahead stats
5937     $LCTL set_param -n llite.*.read_ahead_stats 0
5938
5939     for ((i = 0; i < $count; i++)); do
5940         dd if=${file}_${i} of=/dev/null bs=$blksize count=$size 2>/dev/null
5941     done
5942
5943     local miss=$($LCTL get_param -n llite.*.read_ahead_stats | \
5944           get_named_value 'misses' | cut -d" " -f1 | calc_total)
5945
5946     for ((i = 0; i < $count; i++)); do
5947         rm -rf ${file}_${i} 2>/dev/null
5948     done
5949
5950     #10000 means 20% reads are missing in readahead
5951     [ $miss -lt 10000 ] ||  error "misses too much for small reads"
5952 }
5953 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
5954
5955 cleanup_test101f() {
5956     trap 0
5957     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
5958     rm -rf $DIR/$tfile 2>/dev/null
5959 }
5960
5961 test_101f() {
5962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5963     local file=$DIR/$tfile
5964     local nreads=1000
5965
5966     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
5967     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
5968     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
5969     trap cleanup_test101f EXIT
5970
5971     echo Cancel LRU locks on lustre client to flush the client cache
5972     cancel_lru_locks osc
5973
5974     echo Reset readahead stats
5975     $LCTL set_param -n llite.*.read_ahead_stats 0
5976     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
5977     # readahead should read in 2M file on second read, so only miss
5978     # 2 pages.
5979     echo Random 4K reads on 2M file for 1000 times
5980     $READS -f $file -s 2097152 -b 4096 -n $nreads
5981
5982     echo checking missing pages
5983     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
5984           get_named_value 'misses' | cut -d" " -f1 | calc_total)
5985
5986     [ $miss -lt 3 ] || error "misses too much pages!"
5987     cleanup_test101f
5988 }
5989 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
5990
5991 setup_test102() {
5992         test_mkdir -p $DIR/$tdir
5993         chown $RUNAS_ID $DIR/$tdir
5994         STRIPE_SIZE=65536
5995         STRIPE_OFFSET=1
5996         STRIPE_COUNT=$OSTCOUNT
5997         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
5998
5999         trap cleanup_test102 EXIT
6000         cd $DIR
6001         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6002         cd $DIR/$tdir
6003         for num in 1 2 3 4; do
6004                 for count in $(seq 1 $STRIPE_COUNT); do
6005                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6006                                 local size=`expr $STRIPE_SIZE \* $num`
6007                                 local file=file"$num-$idx-$count"
6008                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6009                         done
6010                 done
6011         done
6012
6013         cd $DIR
6014         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6015 }
6016
6017 cleanup_test102() {
6018         trap 0
6019         rm -f $TMP/f102.tar
6020         rm -rf $DIR/d0.sanity/d102
6021 }
6022
6023 test_102a() {
6024         local testfile=$DIR/xattr_testfile
6025
6026         touch $testfile
6027
6028         [ "$UID" != 0 ] && skip_env "must run as root" && return
6029         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6030                 skip_env "must have user_xattr" && return
6031
6032         [ -z "$(which setfattr 2>/dev/null)" ] &&
6033                 skip_env "could not find setfattr" && return
6034
6035         echo "set/get xattr..."
6036         setfattr -n trusted.name1 -v value1 $testfile ||
6037                 error "setfattr -n trusted.name1=value1 $testfile failed"
6038         getfattr -n trusted.name1 $testfile 2> /dev/null |
6039           grep "trusted.name1=.value1" ||
6040                 error "$testfile missing trusted.name1=value1"
6041
6042         setfattr -n user.author1 -v author1 $testfile ||
6043                 error "setfattr -n user.author1=author1 $testfile failed"
6044         getfattr -n user.author1 $testfile 2> /dev/null |
6045           grep "user.author1=.author1" ||
6046                 error "$testfile missing trusted.author1=author1"
6047
6048         echo "listxattr..."
6049         setfattr -n trusted.name2 -v value2 $testfile ||
6050                 error "$testfile unable to set trusted.name2"
6051         setfattr -n trusted.name3 -v value3 $testfile ||
6052                 error "$testfile unable to set trusted.name3"
6053         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6054             grep "trusted.name" | wc -l) -eq 3 ] ||
6055                 error "$testfile missing 3 trusted.name xattrs"
6056
6057         setfattr -n user.author2 -v author2 $testfile ||
6058                 error "$testfile unable to set user.author2"
6059         setfattr -n user.author3 -v author3 $testfile ||
6060                 error "$testfile unable to set user.author3"
6061         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6062             grep "user.author" | wc -l) -eq 3 ] ||
6063                 error "$testfile missing 3 user.author xattrs"
6064
6065         echo "remove xattr..."
6066         setfattr -x trusted.name1 $testfile ||
6067                 error "$testfile error deleting trusted.name1"
6068         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6069                 error "$testfile did not delete trusted.name1 xattr"
6070
6071         setfattr -x user.author1 $testfile ||
6072                 error "$testfile error deleting user.author1"
6073         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6074                 error "$testfile did not delete trusted.name1 xattr"
6075
6076         # b10667: setting lustre special xattr be silently discarded
6077         echo "set lustre special xattr ..."
6078         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6079                 error "$testfile allowed setting trusted.lov"
6080 }
6081 run_test 102a "user xattr test =================================="
6082
6083 test_102b() {
6084         # b10930: get/set/list trusted.lov xattr
6085         echo "get/set/list trusted.lov xattr ..."
6086         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6087         local testfile=$DIR/$tfile
6088         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6089                 error "setstripe failed"
6090         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6091                 error "getstripe failed"
6092         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
6093         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
6094
6095         local testfile2=${testfile}2
6096         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
6097                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
6098
6099         $MCREATE $testfile2
6100         setfattr -n trusted.lov -v $value $testfile2
6101         local stripe_size=$($GETSTRIPE -S $testfile2)
6102         local stripe_count=$($GETSTRIPE -c $testfile2)
6103         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6104         [ $stripe_count -eq $STRIPECOUNT ] ||
6105                 error "stripe count $stripe_count != $STRIPECOUNT"
6106         rm -f $DIR/$tfile
6107 }
6108 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6109
6110 test_102c() {
6111         # b10930: get/set/list lustre.lov xattr
6112         echo "get/set/list lustre.lov xattr ..."
6113         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6114         test_mkdir -p $DIR/$tdir
6115         chown $RUNAS_ID $DIR/$tdir
6116         local testfile=$DIR/$tdir/$tfile
6117         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6118                 error "setstripe failed"
6119         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6120                 error "getstripe failed"
6121         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6122         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6123
6124         local testfile2=${testfile}2
6125         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6126                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6127
6128         $RUNAS $MCREATE $testfile2
6129         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6130         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6131         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6132         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6133         [ $stripe_count -eq $STRIPECOUNT ] ||
6134                 error "stripe count $stripe_count != $STRIPECOUNT"
6135 }
6136 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6137
6138 compare_stripe_info1() {
6139         local stripe_index_all_zero=true
6140
6141         for num in 1 2 3 4; do
6142                 for count in $(seq 1 $STRIPE_COUNT); do
6143                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6144                                 local size=$((STRIPE_SIZE * num))
6145                                 local file=file"$num-$offset-$count"
6146                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6147                                 [ $stripe_size -ne $size ] &&
6148                                     error "$file: size $stripe_size != $size"
6149                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6150                                 # allow fewer stripes to be created, ORI-601
6151                                 [ $stripe_count -lt $(((3 * count + 3) / 4)) ]&&
6152                                     error "$file: count $stripe_count != $count"
6153                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6154                                 [ $stripe_index -ne 0 ] &&
6155                                         stripe_index_all_zero=false
6156                         done
6157                 done
6158         done
6159         $stripe_index_all_zero &&
6160                 error "all files are being extracted starting from OST index 0"
6161         return 0
6162 }
6163
6164 find_lustre_tar() {
6165         [ -n "$(which tar 2>/dev/null)" ] &&
6166                 strings $(which tar) | grep -q "lustre" && echo tar
6167 }
6168
6169 test_102d() {
6170         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6171         # b10930: tar test for trusted.lov xattr
6172         TAR=$(find_lustre_tar)
6173         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6174         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6175         setup_test102
6176         test_mkdir -p $DIR/d102d
6177         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6178         cd $DIR/d102d/$tdir
6179         compare_stripe_info1
6180 }
6181 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6182
6183 test_102f() {
6184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6185         # b10930: tar test for trusted.lov xattr
6186         TAR=$(find_lustre_tar)
6187         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6188         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6189         setup_test102
6190         test_mkdir -p $DIR/d102f
6191         cd $DIR
6192         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6193         cd $DIR/d102f/$tdir
6194         compare_stripe_info1
6195 }
6196 run_test 102f "tar copy files, not keep osts ==========="
6197
6198 grow_xattr() {
6199         local xsize=${1:-1024}  # in bytes
6200         local file=$DIR/$tfile
6201
6202         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6203                 skip "must have user_xattr" && return 0
6204         [ -z "$(which setfattr 2>/dev/null)" ] &&
6205                 skip_env "could not find setfattr" && return 0
6206         [ -z "$(which getfattr 2>/dev/null)" ] &&
6207                 skip_env "could not find getfattr" && return 0
6208
6209         touch $file
6210
6211         local value="$(generate_string $xsize)"
6212
6213         local xbig=trusted.big
6214         log "save $xbig on $file"
6215         setfattr -n $xbig -v $value $file ||
6216                 error "saving $xbig on $file failed"
6217
6218         local orig=$(get_xattr_value $xbig $file)
6219         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6220
6221         local xsml=trusted.sml
6222         log "save $xsml on $file"
6223         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6224
6225         local new=$(get_xattr_value $xbig $file)
6226         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6227
6228         log "grow $xsml on $file"
6229         setfattr -n $xsml -v "$value" $file ||
6230                 error "growing $xsml on $file failed"
6231
6232         new=$(get_xattr_value $xbig $file)
6233         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6234         log "$xbig still valid after growing $xsml"
6235
6236         rm -f $file
6237 }
6238
6239 test_102h() { # bug 15777
6240         grow_xattr 1024
6241 }
6242 run_test 102h "grow xattr from inside inode to external block"
6243
6244 test_102ha() {
6245         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6246         grow_xattr $(max_xattr_size)
6247 }
6248 run_test 102ha "grow xattr from inside inode to external inode"
6249
6250 test_102i() { # bug 17038
6251         touch $DIR/$tfile
6252         ln -s $DIR/$tfile $DIR/${tfile}link
6253         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
6254         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"
6255         rm -f $DIR/$tfile $DIR/${tfile}link
6256 }
6257 run_test 102i "lgetxattr test on symbolic link ============"
6258
6259 test_102j() {
6260         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6261         TAR=$(find_lustre_tar)
6262         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6263         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6264         setup_test102 "$RUNAS"
6265         test_mkdir -p $DIR/d102j
6266         chown $RUNAS_ID $DIR/d102j
6267         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6268         cd $DIR/d102j/$tdir
6269         compare_stripe_info1 "$RUNAS"
6270 }
6271 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6272
6273 test_102k() {
6274         touch $DIR/$tfile
6275         # b22187 just check that does not crash for regular file.
6276         setfattr -n trusted.lov $DIR/$tfile
6277         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6278         local test_kdir=$DIR/d102k
6279         test_mkdir $test_kdir
6280         local default_size=`$GETSTRIPE -S $test_kdir`
6281         local default_count=`$GETSTRIPE -c $test_kdir`
6282         local default_offset=`$GETSTRIPE -i $test_kdir`
6283         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6284                 error 'dir setstripe failed'
6285         setfattr -n trusted.lov $test_kdir
6286         local stripe_size=`$GETSTRIPE -S $test_kdir`
6287         local stripe_count=`$GETSTRIPE -c $test_kdir`
6288         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6289         [ $stripe_size -eq $default_size ] ||
6290                 error "stripe size $stripe_size != $default_size"
6291         [ $stripe_count -eq $default_count ] ||
6292                 error "stripe count $stripe_count != $default_count"
6293         [ $stripe_offset -eq $default_offset ] ||
6294                 error "stripe offset $stripe_offset != $default_offset"
6295         rm -rf $DIR/$tfile $test_kdir
6296 }
6297 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6298
6299 test_102l() {
6300         # LU-532 trusted. xattr is invisible to non-root
6301         local testfile=$DIR/$tfile
6302
6303         touch $testfile
6304
6305         echo "listxattr as user..."
6306         chown $RUNAS_ID $testfile
6307         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6308             grep -q "trusted" &&
6309                 error "$testfile trusted xattrs are user visible"
6310
6311         return 0;
6312 }
6313 run_test 102l "listxattr filter test =================================="
6314
6315 cleanup_test102
6316
6317 run_acl_subtest()
6318 {
6319     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6320     return $?
6321 }
6322
6323 test_103 () {
6324         [ "$UID" != 0 ] && skip_env "must run as root" && return
6325         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6326                 skip "must have acl enabled" && return
6327         [ -z "$(which setfacl 2>/dev/null)" ] &&
6328                 skip_env "could not find setfacl" && return
6329         $GSS && skip "could not run under gss" && return
6330
6331         declare -a identity_old
6332
6333         for num in $(seq $MDSCOUNT); do
6334                 switch_identity $num true || identity_old[$num]=$?
6335         done
6336
6337         SAVE_UMASK=$(umask)
6338         umask 0022
6339         cd $DIR
6340
6341         echo "performing cp ..."
6342         run_acl_subtest cp || error "run_acl_subtest cp failed"
6343         echo "performing getfacl-noacl..."
6344         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6345         echo "performing misc..."
6346         run_acl_subtest misc || error  "misc test failed"
6347         echo "performing permissions..."
6348         run_acl_subtest permissions || error "permissions failed"
6349         echo "performing setfacl..."
6350         run_acl_subtest setfacl || error  "setfacl test failed"
6351
6352         # inheritance test got from HP
6353         echo "performing inheritance..."
6354         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6355         chmod +x make-tree || error "chmod +x failed"
6356         run_acl_subtest inheritance || error "inheritance test failed"
6357         rm -f make-tree
6358
6359         echo "LU-974 ignore umask when acl is enabled..."
6360         run_acl_subtest 974 || error "LU-974 umask test failed"
6361         if [ $MDSCOUNT -ge 2 ]; then
6362                 run_acl_subtest 974_remote ||
6363                         error "LU-974 umask test failed under remote dir"
6364         fi
6365
6366         echo "LU-2561 newly created file is same size as directory..."
6367         run_acl_subtest 2561 || error "LU-2561 test failed"
6368
6369         cd $SAVE_PWD
6370         umask $SAVE_UMASK
6371
6372         for num in $(seq $MDSCOUNT); do
6373                 if [ "${identity_old[$num]}" = 1 ]; then
6374                         switch_identity $num false || identity_old[$num]=$?
6375                 fi
6376         done
6377 }
6378 run_test 103 "acl test ========================================="
6379
6380 test_104a() {
6381         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6382         touch $DIR/$tfile
6383         lfs df || error "lfs df failed"
6384         lfs df -ih || error "lfs df -ih failed"
6385         lfs df -h $DIR || error "lfs df -h $DIR failed"
6386         lfs df -i $DIR || error "lfs df -i $DIR failed"
6387         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6388         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6389
6390         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6391         lctl --device %$OSC deactivate
6392         lfs df || error "lfs df with deactivated OSC failed"
6393         lctl --device %$OSC activate
6394         # wait the osc back to normal
6395         wait_osc_import_state client ost FULL
6396
6397         lfs df || error "lfs df with reactivated OSC failed"
6398         rm -f $DIR/$tfile
6399 }
6400 run_test 104a "lfs df [-ih] [path] test ========================="
6401
6402 test_104b() {
6403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6404         [ $RUNAS_ID -eq $UID ] &&
6405                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6406         chmod 666 /dev/obd
6407         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6408                         grep "Permission denied" | wc -l)))
6409         if [ $denied_cnt -ne 0 ]; then
6410                 error "lfs check servers test failed"
6411         fi
6412 }
6413 run_test 104b "$RUNAS lfs check servers test ===================="
6414
6415 test_105a() {
6416         # doesn't work on 2.4 kernels
6417         touch $DIR/$tfile
6418         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6419                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
6420         else
6421                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
6422         fi
6423         rm -f $DIR/$tfile
6424 }
6425 run_test 105a "flock when mounted without -o flock test ========"
6426
6427 test_105b() {
6428         touch $DIR/$tfile
6429         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6430                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
6431         else
6432                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
6433         fi
6434         rm -f $DIR/$tfile
6435 }
6436 run_test 105b "fcntl when mounted without -o flock test ========"
6437
6438 test_105c() {
6439         touch $DIR/$tfile
6440         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6441                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
6442         else
6443                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
6444         fi
6445         rm -f $DIR/$tfile
6446 }
6447 run_test 105c "lockf when mounted without -o flock test ========"
6448
6449 test_105d() { # bug 15924
6450         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6451         test_mkdir -p $DIR/$tdir
6452         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6453                 skip "mount w/o flock enabled" && return
6454         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
6455         $LCTL set_param fail_loc=0x80000315
6456         flocks_test 2 $DIR/$tdir
6457 }
6458 run_test 105d "flock race (should not freeze) ========"
6459
6460 test_105e() { # bug 22660 && 22040
6461         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6462                 skip "mount w/o flock enabled" && return
6463         touch $DIR/$tfile
6464         flocks_test 3 $DIR/$tfile
6465 }
6466 run_test 105e "Two conflicting flocks from same process ======="
6467
6468 test_106() { #bug 10921
6469         test_mkdir -p $DIR/$tdir
6470         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
6471         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
6472 }
6473 run_test 106 "attempt exec of dir followed by chown of that dir"
6474
6475 test_107() {
6476         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6477         CDIR=`pwd`
6478         cd $DIR
6479
6480         local file=core
6481         rm -f $file
6482
6483         local save_pattern=$(sysctl -n kernel.core_pattern)
6484         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
6485         sysctl -w kernel.core_pattern=$file
6486         sysctl -w kernel.core_uses_pid=0
6487
6488         ulimit -c unlimited
6489         sleep 60 &
6490         SLEEPPID=$!
6491
6492         sleep 1
6493
6494         kill -s 11 $SLEEPPID
6495         wait $SLEEPPID
6496         if [ -e $file ]; then
6497                 size=`stat -c%s $file`
6498                 [ $size -eq 0 ] && error "Fail to create core file $file"
6499         else
6500                 error "Fail to create core file $file"
6501         fi
6502         rm -f $file
6503         sysctl -w kernel.core_pattern=$save_pattern
6504         sysctl -w kernel.core_uses_pid=$save_uses_pid
6505         cd $CDIR
6506 }
6507 run_test 107 "Coredump on SIG"
6508
6509 test_110() {
6510         test_mkdir -p $DIR/$tdir
6511         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
6512                 error "mkdir with 255 char failed"
6513         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
6514                 error "mkdir with 256 char should fail, but did not"
6515         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
6516                 error "create with 255 char failed"
6517         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
6518                 error "create with 256 char should fail, but did not"
6519
6520         ls -l $DIR/$tdir
6521         rm -rf $DIR/$tdir
6522 }
6523 run_test 110 "filename length checking"
6524
6525 test_115() {
6526         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6527         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
6528             cut -c11-20)
6529         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
6530             return
6531         echo "Starting with $OSTIO_pre threads"
6532
6533         NUMTEST=20000
6534         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
6535         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
6536         echo "$NUMTEST creates/unlinks"
6537         test_mkdir -p $DIR/$tdir
6538         createmany -o $DIR/$tdir/$tfile $NUMTEST
6539         unlinkmany $DIR/$tdir/$tfile $NUMTEST
6540
6541         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
6542             cut -c11-20)
6543
6544         # don't return an error
6545         [ $OSTIO_post == $OSTIO_pre ] && echo \
6546             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
6547             echo "This may be fine, depending on what ran before this test" &&
6548             echo "and how fast this system is." && return
6549
6550         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
6551 }
6552 run_test 115 "verify dynamic thread creation===================="
6553
6554 free_min_max () {
6555         wait_delete_completed
6556         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
6557         echo OST kbytes available: ${AVAIL[@]}
6558         MAXI=0; MAXV=${AVAIL[0]}
6559         MINI=0; MINV=${AVAIL[0]}
6560         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
6561             #echo OST $i: ${AVAIL[i]}kb
6562             if [ ${AVAIL[i]} -gt $MAXV ]; then
6563                 MAXV=${AVAIL[i]}; MAXI=$i
6564             fi
6565             if [ ${AVAIL[i]} -lt $MINV ]; then
6566                 MINV=${AVAIL[i]}; MINI=$i
6567             fi
6568         done
6569         echo Min free space: OST $MINI: $MINV
6570         echo Max free space: OST $MAXI: $MAXV
6571 }
6572
6573 test_116a() { # was previously test_116()
6574         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6575         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
6576
6577         echo -n "Free space priority "
6578         lctl get_param -n lov.*-clilov-*.qos_prio_free
6579         declare -a AVAIL
6580         free_min_max
6581         [ $MINV -gt 960000 ] && skip "too much free space in OST$MINI, skip" &&\
6582                 return
6583
6584         # generate uneven OSTs
6585         test_mkdir -p $DIR/$tdir/OST${MINI}
6586         declare -i FILL
6587         FILL=$(($MINV / 4))
6588         echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
6589         $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI}||error "setstripe failed"
6590         i=0
6591         while [ $FILL -gt 0 ]; do
6592             i=$(($i + 1))
6593             dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i bs=2M count=1 2>/dev/null
6594             FILL=$(($FILL - 2048))
6595             echo -n .
6596         done
6597         FILL=$(($MINV / 4))
6598         sync
6599         sleep_maxage
6600
6601         free_min_max
6602         DIFF=$(($MAXV - $MINV))
6603         DIFF2=$(($DIFF * 100 / $MINV))
6604         echo -n "diff=${DIFF}=${DIFF2}% must be > 20% for QOS mode..."
6605         if [ $DIFF2 -gt 20 ]; then
6606             echo "ok"
6607         else
6608             echo "failed - QOS mode won't be used"
6609             error_ignore "QOS imbalance criteria not met"
6610             return
6611         fi
6612
6613         MINI1=$MINI; MINV1=$MINV
6614         MAXI1=$MAXI; MAXV1=$MAXV
6615
6616         # now fill using QOS
6617         echo writing a bunch of files to QOS-assigned OSTs
6618         $SETSTRIPE -c 1 $DIR/$tdir
6619         i=0
6620         while [ $FILL -gt 0 ]; do
6621             i=$(($i + 1))
6622             dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1024 count=200 2>/dev/null
6623             FILL=$(($FILL - 200))
6624             echo -n .
6625         done
6626         echo "wrote $i 200k files"
6627         sync
6628         sleep_maxage
6629
6630         echo "Note: free space may not be updated, so measurements might be off"
6631         free_min_max
6632         DIFF2=$(($MAXV - $MINV))
6633         echo "free space delta: orig $DIFF final $DIFF2"
6634         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
6635         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
6636         echo "Wrote $DIFF to smaller OST $MINI1"
6637         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
6638         echo "Wrote $DIFF2 to larger OST $MAXI1"
6639         [ $DIFF -gt 0 ] && echo "Wrote $(($DIFF2 * 100 / $DIFF - 100))% more data to larger OST $MAXI1"
6640
6641         # Figure out which files were written where
6642         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6643                awk '/'$MINI1': / {print $2; exit}')
6644         echo $UUID
6645         MINC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
6646         echo "$MINC files created on smaller OST $MINI1"
6647         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6648                awk '/'$MAXI1': / {print $2; exit}')
6649         echo $UUID
6650         MAXC=$($GETSTRIPE --obd $UUID $DIR/$tdir | wc -l)
6651         echo "$MAXC files created on larger OST $MAXI1"
6652         [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
6653         [ $MAXC -gt $MINC ] || error_ignore "stripe QOS didn't balance free space"
6654
6655         rm -rf $DIR/$tdir
6656 }
6657 run_test 116a "stripe QOS: free space balance ==================="
6658
6659 test_116b() { # LU-2093
6660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6661 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
6662         local old_rr
6663         old_rr=$(do_facet $SINGLEMDS lctl get_param -n lov.*mdtlov*.qos_threshold_rr)
6664         do_facet $SINGLEMDS lctl set_param lov.*mdtlov*.qos_threshold_rr 0
6665         mkdir -p $DIR/$tdir
6666         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
6667         createmany -o $DIR/$tdir/f- 20 || error "can't create"
6668         do_facet $SINGLEMDS lctl set_param fail_loc=0
6669         rm -rf $DIR/$tdir
6670         do_facet $SINGLEMDS lctl set_param lov.*mdtlov*.qos_threshold_rr $old_rr
6671 }
6672 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
6673
6674 test_117() # bug 10891
6675 {
6676         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6677         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
6678         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
6679         lctl set_param fail_loc=0x21e
6680         > $DIR/$tfile || error "truncate failed"
6681         lctl set_param fail_loc=0
6682         echo "Truncate succeeded."
6683         rm -f $DIR/$tfile
6684 }
6685 run_test 117 "verify fsfilt_extend =========="
6686
6687 NO_SLOW_RESENDCOUNT=4
6688 export OLD_RESENDCOUNT=""
6689 set_resend_count () {
6690         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
6691         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -1)
6692         lctl set_param -n $PROC_RESENDCOUNT $1
6693         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
6694 }
6695
6696 # for reduce test_118* time (b=14842)
6697 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
6698
6699 # Reset async IO behavior after error case
6700 reset_async() {
6701         FILE=$DIR/reset_async
6702
6703         # Ensure all OSCs are cleared
6704         $SETSTRIPE -c -1 $FILE
6705         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
6706         sync
6707         rm $FILE
6708 }
6709
6710 test_118a() #bug 11710
6711 {
6712         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6713         reset_async
6714
6715         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6716         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6717         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6718
6719         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6720                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6721                 return 1;
6722         fi
6723         rm -f $DIR/$tfile
6724 }
6725 run_test 118a "verify O_SYNC works =========="
6726
6727 test_118b()
6728 {
6729         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6730         remote_ost_nodsh && skip "remote OST with nodsh" && return
6731
6732         reset_async
6733
6734         #define OBD_FAIL_OST_ENOENT 0x217
6735         set_nodes_failloc "$(osts_nodes)" 0x217
6736         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6737         RC=$?
6738         set_nodes_failloc "$(osts_nodes)" 0
6739         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6740         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6741                     grep -c writeback)
6742
6743         if [[ $RC -eq 0 ]]; then
6744                 error "Must return error due to dropped pages, rc=$RC"
6745                 return 1;
6746         fi
6747
6748         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6749                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6750                 return 1;
6751         fi
6752
6753         echo "Dirty pages not leaked on ENOENT"
6754
6755         # Due to the above error the OSC will issue all RPCs syncronously
6756         # until a subsequent RPC completes successfully without error.
6757         $MULTIOP $DIR/$tfile Ow4096yc
6758         rm -f $DIR/$tfile
6759
6760         return 0
6761 }
6762 run_test 118b "Reclaim dirty pages on fatal error =========="
6763
6764 test_118c()
6765 {
6766         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6767
6768         # for 118c, restore the original resend count, LU-1940
6769         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
6770                                 set_resend_count $OLD_RESENDCOUNT
6771         remote_ost_nodsh && skip "remote OST with nodsh" && return
6772
6773         reset_async
6774
6775         #define OBD_FAIL_OST_EROFS               0x216
6776         set_nodes_failloc "$(osts_nodes)" 0x216
6777
6778         # multiop should block due to fsync until pages are written
6779         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6780         MULTIPID=$!
6781         sleep 1
6782
6783         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
6784                 error "Multiop failed to block on fsync, pid=$MULTIPID"
6785         fi
6786
6787         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6788                     grep -c writeback)
6789         if [[ $WRITEBACK -eq 0 ]]; then
6790                 error "No page in writeback, writeback=$WRITEBACK"
6791         fi
6792
6793         set_nodes_failloc "$(osts_nodes)" 0
6794         wait $MULTIPID
6795         RC=$?
6796         if [[ $RC -ne 0 ]]; then
6797                 error "Multiop fsync failed, rc=$RC"
6798         fi
6799
6800         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6801         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6802                     grep -c writeback)
6803         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6804                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6805         fi
6806
6807         rm -f $DIR/$tfile
6808         echo "Dirty pages flushed via fsync on EROFS"
6809         return 0
6810 }
6811 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
6812
6813 # continue to use small resend count to reduce test_118* time (b=14842)
6814 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
6815
6816 test_118d()
6817 {
6818         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6819         remote_ost_nodsh && skip "remote OST with nodsh" && return
6820
6821         reset_async
6822
6823         #define OBD_FAIL_OST_BRW_PAUSE_BULK
6824         set_nodes_failloc "$(osts_nodes)" 0x214
6825         # multiop should block due to fsync until pages are written
6826         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6827         MULTIPID=$!
6828         sleep 1
6829
6830         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
6831                 error "Multiop failed to block on fsync, pid=$MULTIPID"
6832         fi
6833
6834         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6835                     grep -c writeback)
6836         if [[ $WRITEBACK -eq 0 ]]; then
6837                 error "No page in writeback, writeback=$WRITEBACK"
6838         fi
6839
6840         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
6841         set_nodes_failloc "$(osts_nodes)" 0
6842
6843         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6844         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6845                     grep -c writeback)
6846         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6847                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6848         fi
6849
6850         rm -f $DIR/$tfile
6851         echo "Dirty pages gaurenteed flushed via fsync"
6852         return 0
6853 }
6854 run_test 118d "Fsync validation inject a delay of the bulk =========="
6855
6856 test_118f() {
6857         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6858         reset_async
6859
6860         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
6861         lctl set_param fail_loc=0x8000040a
6862
6863         # Should simulate EINVAL error which is fatal
6864         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6865         RC=$?
6866         if [[ $RC -eq 0 ]]; then
6867                 error "Must return error due to dropped pages, rc=$RC"
6868         fi
6869
6870         lctl set_param fail_loc=0x0
6871
6872         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6873         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6874         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6875                     grep -c writeback)
6876         if [[ $LOCKED -ne 0 ]]; then
6877                 error "Locked pages remain in cache, locked=$LOCKED"
6878         fi
6879
6880         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6881                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6882         fi
6883
6884         rm -f $DIR/$tfile
6885         echo "No pages locked after fsync"
6886
6887         reset_async
6888         return 0
6889 }
6890 run_test 118f "Simulate unrecoverable OSC side error =========="
6891
6892 test_118g() {
6893         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6894         reset_async
6895
6896         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
6897         lctl set_param fail_loc=0x406
6898
6899         # simulate local -ENOMEM
6900         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6901         RC=$?
6902
6903         lctl set_param fail_loc=0
6904         if [[ $RC -eq 0 ]]; then
6905                 error "Must return error due to dropped pages, rc=$RC"
6906         fi
6907
6908         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6909         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6910         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6911                         grep -c writeback)
6912         if [[ $LOCKED -ne 0 ]]; then
6913                 error "Locked pages remain in cache, locked=$LOCKED"
6914         fi
6915
6916         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6917                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6918         fi
6919
6920         rm -f $DIR/$tfile
6921         echo "No pages locked after fsync"
6922
6923         reset_async
6924         return 0
6925 }
6926 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
6927
6928 test_118h() {
6929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6930         remote_ost_nodsh && skip "remote OST with nodsh" && return
6931
6932         reset_async
6933
6934         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6935         set_nodes_failloc "$(osts_nodes)" 0x20e
6936         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
6937         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6938         RC=$?
6939
6940         set_nodes_failloc "$(osts_nodes)" 0
6941         if [[ $RC -eq 0 ]]; then
6942                 error "Must return error due to dropped pages, rc=$RC"
6943         fi
6944
6945         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6946         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6947         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
6948                     grep -c writeback)
6949         if [[ $LOCKED -ne 0 ]]; then
6950                 error "Locked pages remain in cache, locked=$LOCKED"
6951         fi
6952
6953         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6954                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6955         fi
6956
6957         rm -f $DIR/$tfile
6958         echo "No pages locked after fsync"
6959
6960         return 0
6961 }
6962 run_test 118h "Verify timeout in handling recoverables errors  =========="
6963
6964 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
6965
6966 test_118i() {
6967         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6968         remote_ost_nodsh && skip "remote OST with nodsh" && return
6969
6970         reset_async
6971
6972         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
6973         set_nodes_failloc "$(osts_nodes)" 0x20e
6974
6975         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
6976         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
6977         PID=$!
6978         sleep 5
6979         set_nodes_failloc "$(osts_nodes)" 0
6980
6981         wait $PID
6982         RC=$?
6983         if [[ $RC -ne 0 ]]; then
6984                 error "got error, but should be not, rc=$RC"
6985         fi
6986
6987         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
6988         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
6989         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
6990         if [[ $LOCKED -ne 0 ]]; then
6991                 error "Locked pages remain in cache, locked=$LOCKED"
6992         fi
6993
6994         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
6995                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
6996         fi
6997
6998         rm -f $DIR/$tfile
6999         echo "No pages locked after fsync"
7000
7001         return 0
7002 }
7003 run_test 118i "Fix error before timeout in recoverable error  =========="
7004
7005 [ "$SLOW" = "no" ] && set_resend_count 4
7006
7007 test_118j() {
7008         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7009         remote_ost_nodsh && skip "remote OST with nodsh" && return
7010
7011         reset_async
7012
7013         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7014         set_nodes_failloc "$(osts_nodes)" 0x220
7015
7016         # return -EIO from OST
7017         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7018         RC=$?
7019         set_nodes_failloc "$(osts_nodes)" 0x0
7020         if [[ $RC -eq 0 ]]; then
7021                 error "Must return error due to dropped pages, rc=$RC"
7022         fi
7023
7024         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7025         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7026         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7027         if [[ $LOCKED -ne 0 ]]; then
7028                 error "Locked pages remain in cache, locked=$LOCKED"
7029         fi
7030
7031         # in recoverable error on OST we want resend and stay until it finished
7032         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7033                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7034         fi
7035
7036         rm -f $DIR/$tfile
7037         echo "No pages locked after fsync"
7038
7039         return 0
7040 }
7041 run_test 118j "Simulate unrecoverable OST side error =========="
7042
7043 test_118k()
7044 {
7045         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7046         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7047
7048         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7049         set_nodes_failloc "$(osts_nodes)" 0x20e
7050         test_mkdir -p $DIR/$tdir
7051
7052         for ((i=0;i<10;i++)); do
7053                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7054                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7055                 SLEEPPID=$!
7056                 sleep 0.500s
7057                 kill $SLEEPPID
7058                 wait $SLEEPPID
7059         done
7060
7061         set_nodes_failloc "$(osts_nodes)" 0
7062         rm -rf $DIR/$tdir
7063 }
7064 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7065
7066 test_118l()
7067 {
7068         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7069         # LU-646
7070         test_mkdir -p $DIR/$tdir
7071         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7072         rm -rf $DIR/$tdir
7073 }
7074 run_test 118l "fsync dir ========="
7075
7076 test_118m() # LU-3066
7077 {
7078         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7079         test_mkdir -p $DIR/$tdir
7080         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7081         rm -rf $DIR/$tdir
7082 }
7083 run_test 118m "fdatasync dir ========="
7084
7085 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7086
7087 test_119a() # bug 11737
7088 {
7089         BSIZE=$((512 * 1024))
7090         directio write $DIR/$tfile 0 1 $BSIZE
7091         # We ask to read two blocks, which is more than a file size.
7092         # directio will indicate an error when requested and actual
7093         # sizes aren't equeal (a normal situation in this case) and
7094         # print actual read amount.
7095         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7096         if [ "$NOB" != "$BSIZE" ]; then
7097                 error "read $NOB bytes instead of $BSIZE"
7098         fi
7099         rm -f $DIR/$tfile
7100 }
7101 run_test 119a "Short directIO read must return actual read amount"
7102
7103 test_119b() # bug 11737
7104 {
7105         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7106
7107         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7108         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7109         sync
7110         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7111                 error "direct read failed"
7112         rm -f $DIR/$tfile
7113 }
7114 run_test 119b "Sparse directIO read must return actual read amount"
7115
7116 test_119c() # bug 13099
7117 {
7118         BSIZE=1048576
7119         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7120         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7121         rm -f $DIR/$tfile
7122 }
7123 run_test 119c "Testing for direct read hitting hole"
7124
7125 test_119d() # bug 15950
7126 {
7127         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7128         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7129         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7130         BSIZE=1048576
7131         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7132         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7133         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7134         lctl set_param fail_loc=0x40d
7135         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7136         pid_dio=$!
7137         sleep 1
7138         cat $DIR/$tfile > /dev/null &
7139         lctl set_param fail_loc=0
7140         pid_reads=$!
7141         wait $pid_dio
7142         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7143         sleep 2
7144         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7145         error "the read rpcs have not completed in 2s"
7146         rm -f $DIR/$tfile
7147         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7148 }
7149 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7150
7151 test_120a() {
7152         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7153         test_mkdir -p $DIR/$tdir
7154         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7155                skip "no early lock cancel on server" && return 0
7156
7157         lru_resize_disable mdc
7158         lru_resize_disable osc
7159         cancel_lru_locks mdc
7160         # asynchronous object destroy at MDT could cause bl ast to client
7161         cancel_lru_locks osc
7162
7163         stat $DIR/$tdir > /dev/null
7164         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7165         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7166         test_mkdir $DIR/$tdir/d1
7167         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7168         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7169         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7170         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7171         lru_resize_enable mdc
7172         lru_resize_enable osc
7173 }
7174 run_test 120a "Early Lock Cancel: mkdir test"
7175
7176 test_120b() {
7177         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7178         test_mkdir -p $DIR/$tdir
7179         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7180                skip "no early lock cancel on server" && return 0
7181         lru_resize_disable mdc
7182         lru_resize_disable osc
7183         cancel_lru_locks mdc
7184         stat $DIR/$tdir > /dev/null
7185         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7186         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7187         touch $DIR/$tdir/f1
7188         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7189         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7190         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7191         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7192         lru_resize_enable mdc
7193         lru_resize_enable osc
7194 }
7195 run_test 120b "Early Lock Cancel: create test"
7196
7197 test_120c() {
7198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7199         test_mkdir -p $DIR/$tdir
7200         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7201                skip "no early lock cancel on server" && return 0
7202         lru_resize_disable mdc
7203         lru_resize_disable osc
7204         test_mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
7205         touch $DIR/$tdir/d1/f1
7206         cancel_lru_locks mdc
7207         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7208         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7209         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7210         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7211         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7212         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7213         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7214         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7215         lru_resize_enable mdc
7216         lru_resize_enable osc
7217 }
7218 run_test 120c "Early Lock Cancel: link test"
7219
7220 test_120d() {
7221         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7222         test_mkdir -p $DIR/$tdir
7223         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7224                skip "no early lock cancel on server" && return 0
7225         lru_resize_disable mdc
7226         lru_resize_disable osc
7227         touch $DIR/$tdir
7228         cancel_lru_locks mdc
7229         stat $DIR/$tdir > /dev/null
7230         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7231         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7232         chmod a+x $DIR/$tdir
7233         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats | awk '/ldlm_cancel/ {print $2}'`
7234         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
7235         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7236         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7237         lru_resize_enable mdc
7238         lru_resize_enable osc
7239 }
7240 run_test 120d "Early Lock Cancel: setattr test"
7241
7242 test_120e() {
7243         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7244         test_mkdir -p $DIR/$tdir
7245         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7246                skip "no early lock cancel on server" && return 0
7247         lru_resize_disable mdc
7248         lru_resize_disable osc
7249         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7250         cancel_lru_locks mdc
7251         cancel_lru_locks osc
7252         dd if=$DIR/$tdir/f1 of=/dev/null
7253         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7254         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7255               awk '/ldlm_cancel/ {print $2}'`
7256         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7257               awk '/ldlm_bl_callback/ {print $2}'`
7258         unlink $DIR/$tdir/f1
7259         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7260               awk '/ldlm_cancel/ {print $2}'`
7261         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7262               awk '/ldlm_bl_callback/ {print $2}'`
7263         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7264         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7265         lru_resize_enable mdc
7266         lru_resize_enable osc
7267 }
7268 run_test 120e "Early Lock Cancel: unlink test"
7269
7270 test_120f() {
7271         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7272         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7273                skip "no early lock cancel on server" && return 0
7274         test_mkdir -p $DIR/$tdir
7275         lru_resize_disable mdc
7276         lru_resize_disable osc
7277         test_mkdir -p $DIR/$tdir/d1 $DIR/$tdir/d2
7278         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7279         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7280         cancel_lru_locks mdc
7281         cancel_lru_locks osc
7282         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7283         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7284         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7285         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7286               awk '/ldlm_cancel/ {print $2}'`
7287         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7288               awk '/ldlm_bl_callback/ {print $2}'`
7289         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7290         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7291               awk '/ldlm_cancel/ {print $2}'`
7292         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7293               awk '/ldlm_bl_callback/ {print $2}'`
7294         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7295         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7296         lru_resize_enable mdc
7297         lru_resize_enable osc
7298 }
7299 run_test 120f "Early Lock Cancel: rename test"
7300
7301 test_120g() {
7302         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7303         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7304                skip "no early lock cancel on server" && return 0
7305         lru_resize_disable mdc
7306         lru_resize_disable osc
7307         count=10000
7308         echo create $count files
7309         test_mkdir -p $DIR/$tdir
7310         cancel_lru_locks mdc
7311         cancel_lru_locks osc
7312         t0=`date +%s`
7313
7314         can0=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7315               awk '/ldlm_cancel/ {print $2}'`
7316         blk0=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7317               awk '/ldlm_bl_callback/ {print $2}'`
7318         createmany -o $DIR/$tdir/f $count
7319         sync
7320         can1=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7321               awk '/ldlm_cancel/ {print $2}'`
7322         blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7323               awk '/ldlm_bl_callback/ {print $2}'`
7324         t1=`date +%s`
7325         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7326         echo rm $count files
7327         rm -r $DIR/$tdir
7328         sync
7329         can2=`lctl get_param -n ldlm.services.ldlm_canceld.stats |
7330               awk '/ldlm_cancel/ {print $2}'`
7331         blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats |
7332               awk '/ldlm_bl_callback/ {print $2}'`
7333         t2=`date +%s`
7334         echo total: $count removes in $((t2-t1))
7335         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7336         sleep 2
7337         # wait for commitment of removal
7338         lru_resize_enable mdc
7339         lru_resize_enable osc
7340 }
7341 run_test 120g "Early Lock Cancel: performance test"
7342
7343 test_121() { #bug #10589
7344         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7345         rm -rf $DIR/$tfile
7346         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
7347 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
7348         lctl set_param fail_loc=0x310
7349         cancel_lru_locks osc > /dev/null
7350         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
7351         lctl set_param fail_loc=0
7352         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
7353 }
7354 run_test 121 "read cancel race ========="
7355
7356 test_123a() { # was test 123, statahead(bug 11401)
7357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7358         SLOWOK=0
7359         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
7360             log "testing on UP system. Performance may be not as good as expected."
7361                         SLOWOK=1
7362         fi
7363
7364         rm -rf $DIR/$tdir
7365         test_mkdir -p $DIR/$tdir
7366         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
7367         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
7368         MULT=10
7369         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
7370                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
7371
7372                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7373                 lctl set_param -n llite.*.statahead_max 0
7374                 lctl get_param llite.*.statahead_max
7375                 cancel_lru_locks mdc
7376                 cancel_lru_locks osc
7377                 stime=`date +%s`
7378                 time ls -l $DIR/$tdir | wc -l
7379                 etime=`date +%s`
7380                 delta=$((etime - stime))
7381                 log "ls $i files without statahead: $delta sec"
7382                 lctl set_param llite.*.statahead_max=$max
7383
7384                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7385                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
7386                 cancel_lru_locks mdc
7387                 cancel_lru_locks osc
7388                 stime=`date +%s`
7389                 time ls -l $DIR/$tdir | wc -l
7390                 etime=`date +%s`
7391                 delta_sa=$((etime - stime))
7392                 log "ls $i files with statahead: $delta_sa sec"
7393                 lctl get_param -n llite.*.statahead_stats
7394                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7395
7396                 [ $swrong -lt $ewrong ] && log "statahead was stopped, maybe too many locks held!"
7397                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
7398
7399                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7400                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7401                     lctl set_param -n llite.*.statahead_max 0
7402                     lctl get_param llite.*.statahead_max
7403                     cancel_lru_locks mdc
7404                     cancel_lru_locks osc
7405                     stime=`date +%s`
7406                     time ls -l $DIR/$tdir | wc -l
7407                     etime=`date +%s`
7408                     delta=$((etime - stime))
7409                     log "ls $i files again without statahead: $delta sec"
7410                     lctl set_param llite.*.statahead_max=$max
7411                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7412                         if [  $SLOWOK -eq 0 ]; then
7413                                 error "ls $i files is slower with statahead!"
7414                         else
7415                                 log "ls $i files is slower with statahead!"
7416                         fi
7417                         break
7418                     fi
7419                 fi
7420
7421                 [ $delta -gt 20 ] && break
7422                 [ $delta -gt 8 ] && MULT=$((50 / delta))
7423                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
7424         done
7425         log "ls done"
7426
7427         stime=`date +%s`
7428         rm -r $DIR/$tdir
7429         sync
7430         etime=`date +%s`
7431         delta=$((etime - stime))
7432         log "rm -r $DIR/$tdir/: $delta seconds"
7433         log "rm done"
7434         lctl get_param -n llite.*.statahead_stats
7435 }
7436 run_test 123a "verify statahead work"
7437
7438 test_123b () { # statahead(bug 15027)
7439         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7440         test_mkdir -p $DIR/$tdir
7441         createmany -o $DIR/$tdir/$tfile-%d 1000
7442
7443         cancel_lru_locks mdc
7444         cancel_lru_locks osc
7445
7446 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
7447         lctl set_param fail_loc=0x80000803
7448         ls -lR $DIR/$tdir > /dev/null
7449         log "ls done"
7450         lctl set_param fail_loc=0x0
7451         lctl get_param -n llite.*.statahead_stats
7452         rm -r $DIR/$tdir
7453         sync
7454
7455 }
7456 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
7457
7458 test_124a() {
7459         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7460         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
7461                skip "no lru resize on server" && return 0
7462         local NR=2000
7463         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
7464
7465         log "create $NR files at $DIR/$tdir"
7466         createmany -o $DIR/$tdir/f $NR ||
7467                 error "failed to create $NR files in $DIR/$tdir"
7468
7469         cancel_lru_locks mdc
7470         ls -l $DIR/$tdir > /dev/null
7471
7472         local NSDIR=""
7473         local LRU_SIZE=0
7474         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
7475                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
7476                 LRU_SIZE=$(lctl get_param -n $PARAM)
7477                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
7478                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
7479                                                 log "NSDIR=$NSDIR"
7480                         log "NS=$(basename $NSDIR)"
7481                         break
7482                 fi
7483         done
7484
7485         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
7486                 skip "Not enough cached locks created!"
7487                 return 0
7488         fi
7489         log "LRU=$LRU_SIZE"
7490
7491         local SLEEP=30
7492
7493         # We know that lru resize allows one client to hold $LIMIT locks
7494         # for 10h. After that locks begin to be killed by client.
7495         local MAX_HRS=10
7496         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
7497                 log "LIMIT=$LIMIT"
7498
7499         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
7500         # killing locks. Some time was spent for creating locks. This means
7501         # that up to the moment of sleep finish we must have killed some of
7502         # them (10-100 locks). This depends on how fast ther were created.
7503         # Many of them were touched in almost the same moment and thus will
7504         # be killed in groups.
7505         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
7506
7507         # Use $LRU_SIZE_B here to take into account real number of locks
7508         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
7509         local LRU_SIZE_B=$LRU_SIZE
7510         log "LVF=$LVF"
7511         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
7512                 log "OLD_LVF=$OLD_LVF"
7513         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
7514
7515         # Let's make sure that we really have some margin. Client checks
7516         # cached locks every 10 sec.
7517         SLEEP=$((SLEEP+20))
7518         log "Sleep ${SLEEP} sec"
7519         local SEC=0
7520         while ((SEC<$SLEEP)); do
7521                 echo -n "..."
7522                 sleep 5
7523                 SEC=$((SEC+5))
7524                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
7525                 echo -n "$LRU_SIZE"
7526         done
7527         echo ""
7528         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
7529         local LRU_SIZE_A=`lctl get_param -n $NSDIR.lru_size`
7530
7531         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
7532                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
7533                 unlinkmany $DIR/$tdir/f $NR
7534                 return
7535         }
7536
7537         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
7538         log "unlink $NR files at $DIR/$tdir"
7539         unlinkmany $DIR/$tdir/f $NR
7540 }
7541 run_test 124a "lru resize ======================================="
7542
7543 get_max_pool_limit()
7544 {
7545         local limit=`lctl get_param -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit`
7546         local max=0
7547         for l in $limit; do
7548                 if test $l -gt $max; then
7549                         max=$l
7550                 fi
7551         done
7552         echo $max
7553 }
7554
7555 test_124b() {
7556         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7557         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
7558                skip "no lru resize on server" && return 0
7559
7560         LIMIT=`get_max_pool_limit`
7561
7562         NR=$(($(default_lru_size)*20))
7563         if [ $NR -gt $LIMIT ]; then
7564                 log "Limit lock number by $LIMIT locks"
7565                 NR=$LIMIT
7566         fi
7567         lru_resize_disable mdc
7568         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
7569                 error "failed to create $DIR/$tdir/disable_lru_resize"
7570
7571         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
7572         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
7573         cancel_lru_locks mdc
7574         stime=`date +%s`
7575         PID=""
7576         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7577         PID="$PID $!"
7578         sleep 2
7579         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7580         PID="$PID $!"
7581         sleep 2
7582         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7583         PID="$PID $!"
7584         wait $PID
7585         etime=`date +%s`
7586         nolruresize_delta=$((etime-stime))
7587         log "ls -la time: $nolruresize_delta seconds"
7588         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7589         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
7590
7591         lru_resize_enable mdc
7592         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
7593                 error "failed to create $DIR/$tdir/enable_lru_resize"
7594
7595         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
7596         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
7597         cancel_lru_locks mdc
7598         stime=`date +%s`
7599         PID=""
7600         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7601         PID="$PID $!"
7602         sleep 2
7603         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7604         PID="$PID $!"
7605         sleep 2
7606         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7607         PID="$PID $!"
7608         wait $PID
7609         etime=`date +%s`
7610         lruresize_delta=$((etime-stime))
7611         log "ls -la time: $lruresize_delta seconds"
7612         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7613
7614         if [ $lruresize_delta -gt $nolruresize_delta ]; then
7615                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
7616         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
7617                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
7618         else
7619                 log "lru resize performs the same with no lru resize"
7620         fi
7621         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
7622 }
7623 run_test 124b "lru resize (performance test) ======================="
7624
7625 test_125() { # 13358
7626         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7627         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
7628         test_mkdir -p $DIR/d125 || error "mkdir failed"
7629         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
7630         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
7631         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
7632 }
7633 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
7634
7635 test_126() { # bug 12829/13455
7636         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7637         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
7638         $GSS && skip "must run as gss disabled" && return
7639
7640         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
7641         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
7642         rm -f $DIR/$tfile
7643         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
7644 }
7645 run_test 126 "check that the fsgid provided by the client is taken into account"
7646
7647 test_127a() { # bug 15521
7648         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7649         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
7650         $LCTL set_param osc.*.stats=0
7651         FSIZE=$((2048 * 1024))
7652         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7653         cancel_lru_locks osc
7654         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
7655
7656         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
7657         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
7658                 echo "got $COUNT $NAME"
7659                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
7660                 eval $NAME=$COUNT || error "Wrong proc format"
7661
7662                 case $NAME in
7663                         read_bytes|write_bytes)
7664                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
7665                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
7666                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
7667                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
7668                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
7669                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
7670                                 error "sumsquare is too small: $SUMSQ"
7671                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
7672                                 error "sumsquare is too big: $SUMSQ"
7673                         ;;
7674                         *) ;;
7675                 esac
7676         done < $DIR/${tfile}.tmp
7677
7678         #check that we actually got some stats
7679         [ "$read_bytes" ] || error "Missing read_bytes stats"
7680         [ "$write_bytes" ] || error "Missing write_bytes stats"
7681         [ "$read_bytes" != 0 ] || error "no read done"
7682         [ "$write_bytes" != 0 ] || error "no write done"
7683 }
7684 run_test 127a "verify the client stats are sane"
7685
7686 test_127b() { # bug LU-333
7687         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7688         $LCTL set_param llite.*.stats=0
7689         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
7690         # perform 2 reads and writes so MAX is different from SUM.
7691         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7692         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7693         cancel_lru_locks osc
7694         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
7695         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
7696
7697         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
7698         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
7699                 echo "got $COUNT $NAME"
7700                 eval $NAME=$COUNT || error "Wrong proc format"
7701
7702         case $NAME in
7703                 read_bytes)
7704                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
7705                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
7706                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
7707                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
7708                         ;;
7709                 write_bytes)
7710                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
7711                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
7712                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
7713                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
7714                         ;;
7715                         *) ;;
7716                 esac
7717         done < $TMP/${tfile}.tmp
7718
7719         #check that we actually got some stats
7720         [ "$read_bytes" ] || error "Missing read_bytes stats"
7721         [ "$write_bytes" ] || error "Missing write_bytes stats"
7722         [ "$read_bytes" != 0 ] || error "no read done"
7723         [ "$write_bytes" != 0 ] || error "no write done"
7724 }
7725 run_test 127b "verify the llite client stats are sane"
7726
7727 test_128() { # bug 15212
7728         touch $DIR/$tfile
7729         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
7730                 find $DIR/$tfile
7731                 find $DIR/$tfile
7732         EOF
7733
7734         result=$(grep error $TMP/$tfile.log)
7735         rm -f $DIR/$tfile
7736         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
7737 }
7738 run_test 128 "interactive lfs for 2 consecutive find's"
7739
7740 set_dir_limits () {
7741         local mntdev
7742         local canondev
7743         local node
7744
7745         local LDPROC=/proc/fs/ldiskfs
7746         local facets=$(get_facets MDS)
7747
7748         for facet in ${facets//,/ }; do
7749                 canondev=$(ldiskfs_canon \
7750                            *.$(convert_facet2label $facet).mntdev $facet)
7751                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
7752                                                 LDPROC=/sys/fs/ldiskfs
7753                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
7754         done
7755 }
7756
7757 test_129() {
7758         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7759         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
7760                 skip "Only applicable to ldiskfs-based MDTs"
7761                 return
7762         fi
7763         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7764
7765         EFBIG=27
7766         MAX=16384
7767
7768         set_dir_limits $MAX
7769         test_mkdir -p $DIR/$tdir
7770
7771         local I=0
7772         local J=0
7773         while [ ! $I -gt $((MAX * MDSCOUNT)) ]; do
7774                 $MULTIOP $DIR/$tdir/$J Oc
7775                 rc=$?
7776                 if [ $rc -eq $EFBIG ]; then
7777                         set_dir_limits 0
7778                         echo "return code $rc received as expected"
7779                         return 0
7780                 elif [ $rc -ne 0 ]; then
7781                         set_dir_limits 0
7782                         error_exit "return code $rc received instead of expected $EFBIG"
7783                 fi
7784                 J=$((J+1))
7785                 I=$(stat -c%s "$DIR/$tdir")
7786         done
7787
7788         set_dir_limits 0
7789         error "exceeded dir size limit $MAX x $MDSCOUNT $((MAX * MDSCOUNT)) : $I bytes"
7790 }
7791 run_test 129 "test directory size limit ========================"
7792
7793 OLDIFS="$IFS"
7794 cleanup_130() {
7795         trap 0
7796         IFS="$OLDIFS"
7797 }
7798
7799 test_130a() {
7800         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7801         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
7802                 return
7803
7804         trap cleanup_130 EXIT RETURN
7805
7806         local fm_file=$DIR/$tfile
7807         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
7808         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
7809                 error "dd failed for $fm_file"
7810
7811         # LU-1795: test filefrag/FIEMAP once, even if unsupported
7812         filefrag -ves $fm_file
7813         RC=$?
7814         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7815                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7816         [ $RC != 0 ] && error "filefrag $fm_file failed"
7817
7818         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
7819                       grep -v "ext:" | grep -v "found")
7820         lun=$($GETSTRIPE -i $fm_file)
7821
7822         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
7823         IFS=$'\n'
7824         tot_len=0
7825         for line in $filefrag_op
7826         do
7827                 frag_lun=`echo $line | cut -d: -f5`
7828                 ext_len=`echo $line | cut -d: -f4`
7829                 if (( $frag_lun != $lun )); then
7830                         cleanup_130
7831                         error "FIEMAP on 1-stripe file($fm_file) failed"
7832                         return
7833                 fi
7834                 (( tot_len += ext_len ))
7835         done
7836
7837         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
7838                 cleanup_130
7839                 error "FIEMAP on 1-stripe file($fm_file) failed;"
7840                 return
7841         fi
7842
7843         cleanup_130
7844
7845         echo "FIEMAP on single striped file succeeded"
7846 }
7847 run_test 130a "FIEMAP (1-stripe file)"
7848
7849 test_130b() {
7850         [ "$OSTCOUNT" -lt "2" ] &&
7851                 skip_env "skipping FIEMAP on 2-stripe file test" && return
7852
7853         [ "$OSTCOUNT" -ge "10" ] &&
7854                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
7855
7856         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7857         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
7858                 return
7859
7860         trap cleanup_130 EXIT RETURN
7861
7862         local fm_file=$DIR/$tfile
7863         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
7864         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7865                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7866
7867         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
7868                 error "dd failed on $fm_file"
7869
7870         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7871         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
7872                       grep -v "ext:" | grep -v "found")
7873
7874         last_lun=$(echo $filefrag_op | cut -d: -f5)
7875
7876         IFS=$'\n'
7877         tot_len=0
7878         num_luns=1
7879         for line in $filefrag_op
7880         do
7881                 frag_lun=`echo $line | cut -d: -f5`
7882                 ext_len=`echo $line | cut -d: -f4`
7883                 if (( $frag_lun != $last_lun )); then
7884                         if (( tot_len != 1024 )); then
7885                                 cleanup_130
7886                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
7887                                 return
7888                         else
7889                                 (( num_luns += 1 ))
7890                                 tot_len=0
7891                         fi
7892                 fi
7893                 (( tot_len += ext_len ))
7894                 last_lun=$frag_lun
7895         done
7896         if (( num_luns != 2 || tot_len != 1024 )); then
7897                 cleanup_130
7898                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7899                 return
7900         fi
7901
7902         cleanup_130
7903
7904         echo "FIEMAP on 2-stripe file succeeded"
7905 }
7906 run_test 130b "FIEMAP (2-stripe file)"
7907
7908 test_130c() {
7909         [ "$OSTCOUNT" -lt "2" ] &&
7910                 skip_env "skipping FIEMAP on 2-stripe file" && return
7911
7912         [ "$OSTCOUNT" -ge "10" ] &&
7913                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
7914
7915         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7916         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
7917                 return
7918
7919         trap cleanup_130 EXIT RETURN
7920
7921         local fm_file=$DIR/$tfile
7922         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
7923         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7924                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7925
7926         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
7927
7928         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7929         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7930
7931         last_lun=`echo $filefrag_op | cut -d: -f5`
7932
7933         IFS=$'\n'
7934         tot_len=0
7935         num_luns=1
7936         for line in $filefrag_op
7937         do
7938                 frag_lun=`echo $line | cut -d: -f5`
7939                 ext_len=`echo $line | cut -d: -f4`
7940                 if (( $frag_lun != $last_lun )); then
7941                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
7942                         if (( logical != 512 )); then
7943                                 cleanup_130
7944                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
7945                                 return
7946                         fi
7947                         if (( tot_len != 512 )); then
7948                                 cleanup_130
7949                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
7950                                 return
7951                         else
7952                                 (( num_luns += 1 ))
7953                                 tot_len=0
7954                         fi
7955                 fi
7956                 (( tot_len += ext_len ))
7957                 last_lun=$frag_lun
7958         done
7959         if (( num_luns != 2 || tot_len != 512 )); then
7960                 cleanup_130
7961                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
7962                 return
7963         fi
7964
7965         cleanup_130
7966
7967         echo "FIEMAP on 2-stripe file with hole succeeded"
7968 }
7969 run_test 130c "FIEMAP (2-stripe file with hole)"
7970
7971 test_130d() {
7972         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
7973
7974         [ "$OSTCOUNT" -ge "10" ] &&
7975                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
7976
7977         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
7978         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
7979
7980         trap cleanup_130 EXIT RETURN
7981
7982         local fm_file=$DIR/$tfile
7983         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
7984         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
7985                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
7986         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT || error "dd failed on $fm_file"
7987
7988         filefrag -ves $fm_file || error "filefrag $fm_file failed"
7989         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
7990
7991         last_lun=`echo $filefrag_op | cut -d: -f5`
7992
7993         IFS=$'\n'
7994         tot_len=0
7995         num_luns=1
7996         for line in $filefrag_op
7997         do
7998                 frag_lun=`echo $line | cut -d: -f5`
7999                 ext_len=`echo $line | cut -d: -f4`
8000                 if (( $frag_lun != $last_lun )); then
8001                         if (( tot_len != 1024 )); then
8002                                 cleanup_130
8003                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8004                                 return
8005                         else
8006                                 (( num_luns += 1 ))
8007                                 tot_len=0
8008                         fi
8009                 fi
8010                 (( tot_len += ext_len ))
8011                 last_lun=$frag_lun
8012         done
8013         if (( num_luns != OSTCOUNT || tot_len != 1024 )); then
8014                 cleanup_130
8015                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8016                 return
8017         fi
8018
8019         cleanup_130
8020
8021         echo "FIEMAP on N-stripe file succeeded"
8022 }
8023 run_test 130d "FIEMAP (N-stripe file)"
8024
8025 test_130e() {
8026         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8027
8028         [ "$OSTCOUNT" -ge "10" ] &&
8029                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8030
8031         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8032         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8033
8034         trap cleanup_130 EXIT RETURN
8035
8036         local fm_file=$DIR/$tfile
8037         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8038         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8039                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8040
8041         NUM_BLKS=512
8042         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8043         for ((i = 0; i < $NUM_BLKS; i++))
8044         do
8045                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8046         done
8047
8048         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8049         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8050
8051         last_lun=`echo $filefrag_op | cut -d: -f5`
8052
8053         IFS=$'\n'
8054         tot_len=0
8055         num_luns=1
8056         for line in $filefrag_op
8057         do
8058                 frag_lun=`echo $line | cut -d: -f5`
8059                 ext_len=`echo $line | cut -d: -f4`
8060                 if (( $frag_lun != $last_lun )); then
8061                         if (( tot_len != $EXPECTED_LEN )); then
8062                                 cleanup_130
8063                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8064                                 return
8065                         else
8066                                 (( num_luns += 1 ))
8067                                 tot_len=0
8068                         fi
8069                 fi
8070                 (( tot_len += ext_len ))
8071                 last_lun=$frag_lun
8072         done
8073         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8074                 cleanup_130
8075                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8076                 return
8077         fi
8078
8079         cleanup_130
8080
8081         echo "FIEMAP with continuation calls succeeded"
8082 }
8083 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8084
8085 # Test for writev/readv
8086 test_131a() {
8087         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8088         error "writev test failed"
8089         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8090         error "readv failed"
8091         rm -f $DIR/$tfile
8092 }
8093 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8094
8095 test_131b() {
8096         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8097         error "append writev test failed"
8098         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8099         error "append writev test failed"
8100         rm -f $DIR/$tfile
8101 }
8102 run_test 131b "test append writev"
8103
8104 test_131c() {
8105         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8106         error "NOT PASS"
8107 }
8108 run_test 131c "test read/write on file w/o objects"
8109
8110 test_131d() {
8111         rwv -f $DIR/$tfile -w -n 1 1572864
8112         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8113         if [ "$NOB" != 1572864 ]; then
8114                 error "Short read filed: read $NOB bytes instead of 1572864"
8115         fi
8116         rm -f $DIR/$tfile
8117 }
8118 run_test 131d "test short read"
8119
8120 test_131e() {
8121         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8122         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8123         error "read hitting hole failed"
8124         rm -f $DIR/$tfile
8125 }
8126 run_test 131e "test read hitting hole"
8127
8128 get_ost_param() {
8129         local token=$1
8130         local gl_sum=0
8131         for node in $(osts_nodes); do
8132                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8133                 [ x$gl = x"" ] && gl=0
8134                 gl_sum=$((gl_sum + gl))
8135         done
8136         echo $gl_sum
8137 }
8138
8139 som_mode_switch() {
8140         local som=$1
8141         local gl1=$2
8142         local gl2=$3
8143
8144         if [ x$som = x"enabled" ]; then
8145                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8146                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
8147                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8148         else
8149                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8150                 MOUNTOPT="$MOUNTOPT,som_preview"
8151                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8152         fi
8153
8154         # do remount to make new mount-conf parameters actual
8155         echo remounting...
8156         sync
8157         stopall
8158         setupall
8159 }
8160
8161 test_132() { #1028, SOM
8162         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8163         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8164         local num=$(get_mds_dir $DIR)
8165         local mymds=mds${num}
8166         local MOUNTOPT_SAVE=$MOUNTOPT
8167
8168         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8169         cancel_lru_locks osc
8170
8171         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8172
8173         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8174         stat $DIR/$tfile >/dev/null
8175         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8176         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8177         rm $DIR/$tfile
8178         som_mode_switch $som1 $gl1 $gl2
8179
8180         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8181         cancel_lru_locks osc
8182
8183         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8184         if [ $som1 == $som2 ]; then
8185             error "som is still "$som2
8186             if [ x$som2 = x"enabled" ]; then
8187                 som2="disabled"
8188             else
8189                 som2="enabled"
8190             fi
8191         fi
8192
8193         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8194         stat $DIR/$tfile >/dev/null
8195         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8196         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8197         som_mode_switch $som2 $gl1 $gl2
8198         MOUNTOPT=$MOUNTOPT_SAVE
8199 }
8200 run_test 132 "som avoids glimpse rpc"
8201
8202 check_stats() {
8203         local res
8204         local count
8205         case $1 in
8206         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8207                  ;;
8208         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8209                  ;;
8210         *) error "Wrong argument $1" ;;
8211         esac
8212         echo $res
8213         count=`echo $res | awk '{print $2}'`
8214         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8215         # if the argument $3 is zero, it means any stat increment is ok.
8216         if [ $3 -gt 0 ] ; then
8217                 [ $count -ne $3 ] && error "The $2 counter on $1 is wrong - expected $3"
8218         fi
8219 }
8220
8221 test_133a() {
8222         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8223         remote_ost_nodsh && skip "remote OST with nodsh" && return
8224         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8225
8226         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8227                 { skip "MDS doesn't support rename stats"; return; }
8228         local testdir=$DIR/${tdir}/stats_testdir
8229         mkdir -p $DIR/${tdir}
8230
8231         # clear stats.
8232         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8233         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8234
8235         # verify mdt stats first.
8236         mkdir ${testdir} || error "mkdir failed"
8237         check_stats $SINGLEMDS "mkdir" 1
8238         touch ${testdir}/${tfile} || "touch failed"
8239         check_stats $SINGLEMDS "open" 1
8240         check_stats $SINGLEMDS "close" 1
8241         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8242         check_stats $SINGLEMDS "mknod" 1
8243         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8244         check_stats $SINGLEMDS "unlink" 1
8245         rm -f ${testdir}/${tfile} || error "file remove failed"
8246         check_stats $SINGLEMDS "unlink" 2
8247
8248         # remove working dir and check mdt stats again.
8249         rmdir ${testdir} || error "rmdir failed"
8250         check_stats $SINGLEMDS "rmdir" 1
8251
8252         local testdir1=$DIR/${tdir}/stats_testdir1
8253         mkdir -p ${testdir}
8254         mkdir -p ${testdir1}
8255         touch ${testdir1}/test1
8256         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8257         check_stats $SINGLEMDS "crossdir_rename" 1
8258
8259         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8260         check_stats $SINGLEMDS "samedir_rename" 1
8261
8262         rm -rf $DIR/${tdir}
8263 }
8264 run_test 133a "Verifying MDT stats ========================================"
8265
8266 test_133b() {
8267         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8268         remote_ost_nodsh && skip "remote OST with nodsh" && return
8269         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8270         local testdir=$DIR/${tdir}/stats_testdir
8271         mkdir -p ${testdir} || error "mkdir failed"
8272         touch ${testdir}/${tfile} || "touch failed"
8273         cancel_lru_locks mdc
8274
8275         # clear stats.
8276         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8277         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8278
8279         # extra mdt stats verification.
8280         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8281         check_stats $SINGLEMDS "setattr" 1
8282         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8283         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8284         then            # LU-1740
8285                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8286                 check_stats $SINGLEMDS "getattr" 1
8287         fi
8288         $LFS df || error "lfs failed"
8289         check_stats $SINGLEMDS "statfs" 1
8290
8291         rm -rf $DIR/${tdir}
8292 }
8293 run_test 133b "Verifying extra MDT stats =================================="
8294
8295 test_133c() {
8296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8297         remote_ost_nodsh && skip "remote OST with nodsh" && return
8298         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8299         local testdir=$DIR/${tdir}/stats_testdir
8300         test_mkdir -p ${testdir} || error "mkdir failed"
8301
8302         # verify obdfilter stats.
8303         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8304         sync
8305         cancel_lru_locks osc
8306         wait_delete_completed
8307
8308         # clear stats.
8309         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8310         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8311
8312         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
8313         sync
8314         cancel_lru_locks osc
8315         check_stats ost "write" 1
8316
8317         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
8318         check_stats ost "read" 1
8319
8320         > ${testdir}/${tfile} || error "truncate failed"
8321         check_stats ost "punch" 1
8322
8323         rm -f ${testdir}/${tfile} || error "file remove failed"
8324         wait_delete_completed
8325         check_stats ost "destroy" 1
8326
8327         rm -rf $DIR/${tdir}
8328 }
8329 run_test 133c "Verifying OST stats ========================================"
8330
8331 order_2() {
8332     local value=$1
8333     local orig=$value
8334     local order=1
8335
8336     while [ $value -ge 2 ]; do
8337         order=$((order*2))
8338         value=$((value/2))
8339     done
8340
8341     if [ $orig -gt $order ]; then
8342         order=$((order*2))
8343     fi
8344     echo $order
8345 }
8346
8347 size_in_KMGT() {
8348     local value=$1
8349     local size=('K' 'M' 'G' 'T');
8350     local i=0
8351     local size_string=$value
8352
8353     while [ $value -ge 1024 ]; do
8354         if [ $i -gt 3 ]; then
8355             #T is the biggest unit we get here, if that is bigger,
8356             #just return XXXT
8357             size_string=${value}T
8358             break
8359         fi
8360         value=$((value >> 10))
8361         if [ $value -lt 1024 ]; then
8362             size_string=${value}${size[$i]}
8363             break
8364         fi
8365         i=$((i + 1))
8366     done
8367
8368     echo $size_string
8369 }
8370
8371 get_rename_size() {
8372     local size=$1
8373     local context=${2:-.}
8374     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
8375                 grep -A1 $context |
8376                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
8377     echo $sample
8378 }
8379
8380 test_133d() {
8381         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8382         remote_ost_nodsh && skip "remote OST with nodsh" && return
8383         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8384         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8385         { skip "MDS doesn't support rename stats"; return; }
8386
8387         local testdir1=$DIR/${tdir}/stats_testdir1
8388         local testdir2=$DIR/${tdir}/stats_testdir2
8389
8390         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8391
8392         mkdir -p ${testdir1} || error "mkdir failed"
8393         mkdir -p ${testdir2} || error "mkdir failed"
8394
8395         createmany -o $testdir1/test 512 || error "createmany failed"
8396
8397         # check samedir rename size
8398         mv ${testdir1}/test0 ${testdir1}/test_0
8399
8400         local testdir1_size=$(ls -l $DIR/${tdir} |
8401                 awk '/stats_testdir1/ {print $5}')
8402         local testdir2_size=$(ls -l $DIR/${tdir} |
8403                 awk '/stats_testdir2/ {print $5}')
8404
8405         testdir1_size=$(order_2 $testdir1_size)
8406         testdir2_size=$(order_2 $testdir2_size)
8407
8408         testdir1_size=$(size_in_KMGT $testdir1_size)
8409         testdir2_size=$(size_in_KMGT $testdir2_size)
8410
8411         echo "source rename dir size: ${testdir1_size}"
8412         echo "target rename dir size: ${testdir2_size}"
8413
8414         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
8415         eval $cmd || error "$cmd failed"
8416         local samedir=$($cmd | grep 'same_dir')
8417         local same_sample=$(get_rename_size $testdir1_size)
8418         [ -z "$samedir" ] && error "samedir_rename_size count error"
8419         [ "$same_sample" -eq 1 ] || error "samedir_rename_size error $same_sample"
8420         echo "Check same dir rename stats success"
8421
8422         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8423
8424         # check crossdir rename size
8425         mv ${testdir1}/test_0 ${testdir2}/test_0
8426
8427         testdir1_size=$(ls -l $DIR/${tdir} |
8428                 awk '/stats_testdir1/ {print $5}')
8429         testdir2_size=$(ls -l $DIR/${tdir} |
8430                 awk '/stats_testdir2/ {print $5}')
8431
8432         testdir1_size=$(order_2 $testdir1_size)
8433         testdir2_size=$(order_2 $testdir2_size)
8434
8435         testdir1_size=$(size_in_KMGT $testdir1_size)
8436         testdir2_size=$(size_in_KMGT $testdir2_size)
8437
8438         echo "source rename dir size: ${testdir1_size}"
8439         echo "target rename dir size: ${testdir2_size}"
8440
8441         eval $cmd || error "$cmd failed"
8442         local crossdir=$($cmd | grep 'crossdir')
8443         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
8444         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
8445         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
8446         [ "$src_sample" -eq 1 ] || error "crossdir_rename_size error $src_sample"
8447         [ "$tgt_sample" -eq 1 ] || error "crossdir_rename_size error $tgt_sample"
8448         echo "Check cross dir rename stats success"
8449         rm -rf $DIR/${tdir}
8450 }
8451 run_test 133d "Verifying rename_stats ========================================"
8452
8453 test_133e() {
8454         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8455         local testdir=$DIR/${tdir}/stats_testdir
8456         local ctr f0 f1 bs=32768 count=42 sum
8457
8458         remote_ost_nodsh && skip "remote OST with nodsh" && return
8459         mkdir -p ${testdir} || error "mkdir failed"
8460
8461         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8462
8463         for ctr in {write,read}_bytes; do
8464                 sync
8465                 cancel_lru_locks osc
8466
8467                 do_facet ost1 $LCTL set_param -n \
8468                         "obdfilter.*.exports.clear=clear"
8469
8470                 if [ $ctr = write_bytes ]; then
8471                         f0=/dev/zero
8472                         f1=${testdir}/${tfile}
8473                 else
8474                         f0=${testdir}/${tfile}
8475                         f1=/dev/null
8476                 fi
8477
8478                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
8479                         error "dd failed"
8480                 sync
8481                 cancel_lru_locks osc
8482
8483                 sum=$(do_facet ost1 $LCTL get_param \
8484                                 "obdfilter.*.exports.*.stats" | \
8485                           awk -v ctr=$ctr '\
8486                                 BEGIN { sum = 0 }
8487                                 $1 == ctr { sum += $7 }
8488                                 END { print sum }')
8489
8490                 if ((sum != bs * count)); then
8491                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
8492                 fi
8493         done
8494
8495         rm -rf $DIR/${tdir}
8496 }
8497 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
8498
8499 test_133f() {
8500         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
8501         local facet
8502
8503         # First without trusting modes.
8504         find $proc_dirs \
8505                 -exec cat '{}' \; &> /dev/null
8506
8507         # Second verifying readability.
8508         find $proc_dirs \
8509                 -type f \
8510                 -readable \
8511                 -exec cat '{}' \; > /dev/null ||
8512                         error "proc file read failed"
8513
8514         for facet in $SINGLEMDS ost1; do
8515                 do_facet $facet find $proc_dirs \
8516                         -not -name req_history \
8517                         -exec cat '{}' \\\; &> /dev/null
8518
8519             do_facet $facet     find $proc_dirs \
8520                         -not -name req_history \
8521                         -type f \
8522                         -readable \
8523                         -exec cat '{}' \\\; > /dev/null ||
8524                                 error "proc file read failed"
8525         done
8526 }
8527 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
8528
8529 test_140() { #bug-17379
8530         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8531         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
8532         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
8533         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
8534
8535         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
8536         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
8537         local i=0
8538         while i=`expr $i + 1`; do
8539                 test_mkdir -p $i || error "Creating dir $i"
8540                 cd $i || error "Changing to $i"
8541                 ln -s ../stat stat || error "Creating stat symlink"
8542                 # Read the symlink until ELOOP present,
8543                 # not LBUGing the system is considered success,
8544                 # we didn't overrun the stack.
8545                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
8546                 [ $ret -ne 0 ] && {
8547                         if [ $ret -eq 40 ]; then
8548                                 break  # -ELOOP
8549                         else
8550                                 error "Open stat symlink"
8551                                 return
8552                         fi
8553                 }
8554         done
8555         i=`expr $i - 1`
8556         echo "The symlink depth = $i"
8557         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
8558                                         error "Invalid symlink depth"
8559
8560         # Test recursive symlink
8561         ln -s symlink_self symlink_self
8562         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
8563         echo "open symlink_self returns $ret"
8564         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
8565 }
8566 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
8567
8568 test_150() {
8569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8570         local TF="$TMP/$tfile"
8571
8572         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
8573         cp $TF $DIR/$tfile
8574         cancel_lru_locks osc
8575         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
8576         remount_client $MOUNT
8577         df -P $MOUNT
8578         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
8579
8580         $TRUNCATE $TF 6000
8581         $TRUNCATE $DIR/$tfile 6000
8582         cancel_lru_locks osc
8583         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
8584
8585         echo "12345" >>$TF
8586         echo "12345" >>$DIR/$tfile
8587         cancel_lru_locks osc
8588         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
8589
8590         echo "12345" >>$TF
8591         echo "12345" >>$DIR/$tfile
8592         cancel_lru_locks osc
8593         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
8594
8595         rm -f $TF
8596         true
8597 }
8598 run_test 150 "truncate/append tests"
8599
8600 function roc_hit() {
8601         local list=$(comma_list $(osts_nodes))
8602         #debug temp debug for LU-2902: lets see what values we get back
8603         echo $(get_osd_param $list '' stats) 1>&2
8604         echo $(get_osd_param $list '' stats |
8605                awk '/'cache_hit'/ {sum+=$2} END {print sum}')
8606 }
8607
8608 function set_cache() {
8609         local on=1
8610
8611         if [ "$2" == "off" ]; then
8612                 on=0;
8613         fi
8614         local list=$(comma_list $(osts_nodes))
8615         set_osd_param $list '' $1_cache_enable $on
8616
8617         cancel_lru_locks osc
8618 }
8619
8620 test_151() {
8621         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8622         remote_ost_nodsh && skip "remote OST with nodsh" && return
8623
8624         local CPAGES=3
8625         local list=$(comma_list $(osts_nodes))
8626
8627         # check whether obdfilter is cache capable at all
8628         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
8629                 echo "not cache-capable obdfilter"
8630                 return 0
8631         fi
8632
8633         # check cache is enabled on all obdfilters
8634         if get_osd_param $list '' read_cache_enable | grep 0; then
8635                 echo "oss cache is disabled"
8636                 return 0
8637         fi
8638
8639         set_osd_param $list '' writethrough_cache_enable 1
8640
8641         # check write cache is enabled on all obdfilters
8642         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
8643                 echo "oss write cache is NOT enabled"
8644                 return 0
8645         fi
8646
8647         #define OBD_FAIL_OBD_NO_LRU  0x609
8648         do_nodes $list $LCTL set_param fail_loc=0x609
8649
8650         # pages should be in the case right after write
8651         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
8652                 error "dd failed"
8653
8654         local BEFORE=$(roc_hit)
8655         cancel_lru_locks osc
8656         cat $DIR/$tfile >/dev/null
8657         local AFTER=$(roc_hit)
8658
8659         do_nodes $list $LCTL set_param fail_loc=0
8660
8661         if ! let "AFTER - BEFORE == CPAGES"; then
8662                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
8663         fi
8664
8665         # the following read invalidates the cache
8666         cancel_lru_locks osc
8667         set_osd_param $list '' read_cache_enable 0
8668         cat $DIR/$tfile >/dev/null
8669
8670         # now data shouldn't be found in the cache
8671         BEFORE=$(roc_hit)
8672         cancel_lru_locks osc
8673         cat $DIR/$tfile >/dev/null
8674         AFTER=$(roc_hit)
8675         if let "AFTER - BEFORE != 0"; then
8676                 error "IN CACHE: before: $BEFORE, after: $AFTER"
8677         fi
8678
8679         set_osd_param $list '' read_cache_enable 1
8680         rm -f $DIR/$tfile
8681 }
8682 run_test 151 "test cache on oss and controls ==============================="
8683
8684 test_152() {
8685         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8686         local TF="$TMP/$tfile"
8687
8688         # simulate ENOMEM during write
8689 #define OBD_FAIL_OST_NOMEM      0x226
8690         lctl set_param fail_loc=0x80000226
8691         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
8692         cp $TF $DIR/$tfile
8693         sync || error "sync failed"
8694         lctl set_param fail_loc=0
8695
8696         # discard client's cache
8697         cancel_lru_locks osc
8698
8699         # simulate ENOMEM during read
8700         lctl set_param fail_loc=0x80000226
8701         cmp $TF $DIR/$tfile || error "cmp failed"
8702         lctl set_param fail_loc=0
8703
8704         rm -f $TF
8705 }
8706 run_test 152 "test read/write with enomem ============================"
8707
8708 test_153() {
8709         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
8710 }
8711 run_test 153 "test if fdatasync does not crash ======================="
8712
8713 dot_lustre_fid_permission_check() {
8714         local fid=$1
8715         local ffid=$MOUNT/.lustre/fid/$fid
8716         local test_dir=$2
8717
8718         echo "stat fid $fid"
8719         stat $ffid > /dev/null || error "stat $ffid failed."
8720         echo "touch fid $fid"
8721         touch $ffid || error "touch $ffid failed."
8722         echo "write to fid $fid"
8723         cat /etc/hosts > $ffid || error "write $ffid failed."
8724         echo "read fid $fid"
8725         diff /etc/hosts $ffid || error "read $ffid failed."
8726         echo "append write to fid $fid"
8727         cat /etc/hosts >> $ffid || error "append write $ffid failed."
8728         echo "rename fid $fid"
8729         mv $ffid $test_dir/$tfile.1 &&
8730                 error "rename $ffid to $tfile.1 should fail."
8731         touch $test_dir/$tfile.1
8732         mv $test_dir/$tfile.1 $ffid &&
8733                 error "rename $tfile.1 to $ffid should fail."
8734         rm -f $test_dir/$tfile.1
8735         echo "truncate fid $fid"
8736         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
8737         echo "link fid $fid"
8738         ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
8739         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
8740                 echo "setfacl fid $fid"
8741                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
8742                 echo "getfacl fid $fid"
8743                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
8744         fi
8745         echo "unlink fid $fid"
8746         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
8747         echo "mknod fid $fid"
8748         mknod $ffid c 1 3 && error "mknod $ffid should fail."
8749
8750         fid=[0xf00000400:0x1:0x0]
8751         ffid=$MOUNT/.lustre/fid/$fid
8752
8753         echo "stat non-exist fid $fid"
8754         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
8755         echo "write to non-exist fid $fid"
8756         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
8757         echo "link new fid $fid"
8758         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
8759
8760         mkdir -p $test_dir/$tdir
8761         touch $test_dir/$tdir/$tfile
8762         fid=$($LFS path2fid $test_dir/$tdir)
8763         rc=$?
8764         [ $rc -ne 0 ] &&
8765                 error "error: could not get fid for $test_dir/$dir/$tfile."
8766
8767         ffid=$MOUNT/.lustre/fid/$fid
8768
8769         echo "ls $fid"
8770         ls $ffid > /dev/null || error "ls $ffid failed."
8771         echo "touch $fid/$tfile.1"
8772         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
8773
8774         echo "touch $MOUNT/.lustre/fid/$tfile"
8775         touch $MOUNT/.lustre/fid/$tfile && \
8776                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
8777
8778         echo "setxattr to $MOUNT/.lustre/fid"
8779         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
8780
8781         echo "listxattr for $MOUNT/.lustre/fid"
8782         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
8783
8784         echo "delxattr from $MOUNT/.lustre/fid"
8785         setfattr -x trusted.name1 $MOUNT/.lustre/fid
8786
8787         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
8788         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
8789                 error "touch invalid fid should fail."
8790
8791         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
8792         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
8793                 error "touch non-normal fid should fail."
8794
8795         echo "rename $tdir to $MOUNT/.lustre/fid"
8796         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
8797                 error "rename to $MOUNT/.lustre/fid should fail."
8798
8799         local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
8800         local new_obf_mode=777
8801
8802         echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
8803         chmod $new_obf_mode $DIR/.lustre/fid ||
8804                 error "chmod $new_obf_mode $DIR/.lustre/fid failed"
8805
8806         local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
8807         [ $obf_mode -eq $new_obf_mode ] ||
8808                 error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
8809
8810         echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
8811         chmod $old_obf_mode $DIR/.lustre/fid ||
8812                 error "chmod $old_obf_mode $DIR/.lustre/fid failed"
8813
8814         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
8815         fid=$($LFS path2fid $test_dir/$tfile-2)
8816         echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
8817         cp /etc/passwd $MOUNT/.lustre/fid/$fid &&
8818                 error "create lov data thru .lustre should fail."
8819         echo "cp /etc/passwd $test_dir/$tfile-2"
8820         cp /etc/passwd $test_dir/$tfile-2 ||
8821                 error "copy to $test_dir/$tfile-2 failed."
8822         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
8823         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
8824                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
8825
8826         rm -rf $test_dir/tfile.lnk
8827         rm -rf $test_dir/$tfile-2
8828 }
8829
8830 test_154a() {
8831         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8832         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
8833                 { skip "Need MDS version at least 2.2.51"; return 0; }
8834
8835         cp /etc/hosts $DIR/$tfile
8836
8837         fid=$($LFS path2fid $DIR/$tfile)
8838         rc=$?
8839         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
8840
8841         dot_lustre_fid_permission_check "$fid" $DIR ||
8842                 error "dot lustre permission check $fid failed"
8843
8844         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
8845
8846         touch $MOUNT/.lustre/file &&
8847                 error "creation is not allowed under .lustre"
8848
8849         mkdir $MOUNT/.lustre/dir &&
8850                 error "mkdir is not allowed under .lustre"
8851
8852         rm -rf $DIR/$tfile
8853 }
8854 run_test 154a "Open-by-FID"
8855
8856 test_154b() {
8857         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8858         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
8859                 { skip "Need MDS version at least 2.2.51"; return 0; }
8860
8861         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
8862
8863         local remote_dir=$DIR/$tdir/remote_dir
8864         local MDTIDX=1
8865         local rc=0
8866
8867         mkdir -p $DIR/$tdir
8868         $LFS mkdir -i $MDTIDX $remote_dir ||
8869                 error "create remote directory failed"
8870
8871         cp /etc/hosts $remote_dir/$tfile
8872
8873         fid=$($LFS path2fid $remote_dir/$tfile)
8874         rc=$?
8875         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
8876
8877         dot_lustre_fid_permission_check "$fid" $remote_dir ||
8878                 error "dot lustre permission check $fid failed"
8879         rm -rf $DIR/$tdir
8880 }
8881 run_test 154b "Open-by-FID for remote directory"
8882
8883 test_155_small_load() {
8884     local temp=$TMP/$tfile
8885     local file=$DIR/$tfile
8886
8887     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
8888         error "dd of=$temp bs=6096 count=1 failed"
8889     cp $temp $file
8890     cancel_lru_locks osc
8891     cmp $temp $file || error "$temp $file differ"
8892
8893     $TRUNCATE $temp 6000
8894     $TRUNCATE $file 6000
8895     cmp $temp $file || error "$temp $file differ (truncate1)"
8896
8897     echo "12345" >>$temp
8898     echo "12345" >>$file
8899     cmp $temp $file || error "$temp $file differ (append1)"
8900
8901     echo "12345" >>$temp
8902     echo "12345" >>$file
8903     cmp $temp $file || error "$temp $file differ (append2)"
8904
8905     rm -f $temp $file
8906     true
8907 }
8908
8909 test_155_big_load() {
8910     remote_ost_nodsh && skip "remote OST with nodsh" && return
8911     local temp=$TMP/$tfile
8912     local file=$DIR/$tfile
8913
8914     free_min_max
8915     local cache_size=$(do_facet ost$((MAXI+1)) \
8916         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
8917     local large_file_size=$((cache_size * 2))
8918
8919     echo "OSS cache size: $cache_size KB"
8920     echo "Large file size: $large_file_size KB"
8921
8922     [ $MAXV -le $large_file_size ] && \
8923         skip_env "max available OST size needs > $large_file_size KB" && \
8924         return 0
8925
8926     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
8927
8928     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
8929         error "dd of=$temp bs=$large_file_size count=1k failed"
8930     cp $temp $file
8931     ls -lh $temp $file
8932     cancel_lru_locks osc
8933     cmp $temp $file || error "$temp $file differ"
8934
8935     rm -f $temp $file
8936     true
8937 }
8938
8939 test_155a() {
8940         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8941         set_cache read on
8942         set_cache writethrough on
8943         test_155_small_load
8944 }
8945 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
8946
8947 test_155b() {
8948         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8949         set_cache read on
8950         set_cache writethrough off
8951         test_155_small_load
8952 }
8953 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
8954
8955 test_155c() {
8956         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8957         set_cache read off
8958         set_cache writethrough on
8959         test_155_small_load
8960 }
8961 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
8962
8963 test_155d() {
8964         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8965         set_cache read off
8966         set_cache writethrough off
8967         test_155_small_load
8968 }
8969 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
8970
8971 test_155e() {
8972         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8973         set_cache read on
8974         set_cache writethrough on
8975         test_155_big_load
8976 }
8977 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
8978
8979 test_155f() {
8980         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8981         set_cache read on
8982         set_cache writethrough off
8983         test_155_big_load
8984 }
8985 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
8986
8987 test_155g() {
8988         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8989         set_cache read off
8990         set_cache writethrough on
8991         test_155_big_load
8992 }
8993 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
8994
8995 test_155h() {
8996         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8997         set_cache read off
8998         set_cache writethrough off
8999         test_155_big_load
9000 }
9001 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9002
9003 test_156() {
9004         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9005         local CPAGES=3
9006         local BEFORE
9007         local AFTER
9008         local file="$DIR/$tfile"
9009
9010         [ "$(facet_fstype ost1)" = "zfs" ] &&
9011                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9012                 return
9013
9014     log "Turn on read and write cache"
9015     set_cache read on
9016     set_cache writethrough on
9017
9018     log "Write data and read it back."
9019     log "Read should be satisfied from the cache."
9020     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9021     BEFORE=`roc_hit`
9022     cancel_lru_locks osc
9023     cat $file >/dev/null
9024     AFTER=`roc_hit`
9025     if ! let "AFTER - BEFORE == CPAGES"; then
9026         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9027     else
9028         log "cache hits:: before: $BEFORE, after: $AFTER"
9029     fi
9030
9031     log "Read again; it should be satisfied from the cache."
9032     BEFORE=$AFTER
9033     cancel_lru_locks osc
9034     cat $file >/dev/null
9035     AFTER=`roc_hit`
9036     if ! let "AFTER - BEFORE == CPAGES"; then
9037         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9038     else
9039         log "cache hits:: before: $BEFORE, after: $AFTER"
9040     fi
9041
9042
9043     log "Turn off the read cache and turn on the write cache"
9044     set_cache read off
9045     set_cache writethrough on
9046
9047     log "Read again; it should be satisfied from the cache."
9048     BEFORE=`roc_hit`
9049     cancel_lru_locks osc
9050     cat $file >/dev/null
9051     AFTER=`roc_hit`
9052     if ! let "AFTER - BEFORE == CPAGES"; then
9053         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9054     else
9055         log "cache hits:: before: $BEFORE, after: $AFTER"
9056     fi
9057
9058     log "Read again; it should not be satisfied from the cache."
9059     BEFORE=$AFTER
9060     cancel_lru_locks osc
9061     cat $file >/dev/null
9062     AFTER=`roc_hit`
9063     if ! let "AFTER - BEFORE == 0"; then
9064         error "IN CACHE: before: $BEFORE, after: $AFTER"
9065     else
9066         log "cache hits:: before: $BEFORE, after: $AFTER"
9067     fi
9068
9069     log "Write data and read it back."
9070     log "Read should be satisfied from the cache."
9071     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9072     BEFORE=`roc_hit`
9073     cancel_lru_locks osc
9074     cat $file >/dev/null
9075     AFTER=`roc_hit`
9076     if ! let "AFTER - BEFORE == CPAGES"; then
9077         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9078     else
9079         log "cache hits:: before: $BEFORE, after: $AFTER"
9080     fi
9081
9082     log "Read again; it should not be satisfied from the cache."
9083     BEFORE=$AFTER
9084     cancel_lru_locks osc
9085     cat $file >/dev/null
9086     AFTER=`roc_hit`
9087     if ! let "AFTER - BEFORE == 0"; then
9088         error "IN CACHE: before: $BEFORE, after: $AFTER"
9089     else
9090         log "cache hits:: before: $BEFORE, after: $AFTER"
9091     fi
9092
9093
9094     log "Turn off read and write cache"
9095     set_cache read off
9096     set_cache writethrough off
9097
9098     log "Write data and read it back"
9099     log "It should not be satisfied from the cache."
9100     rm -f $file
9101     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9102     cancel_lru_locks osc
9103     BEFORE=`roc_hit`
9104     cat $file >/dev/null
9105     AFTER=`roc_hit`
9106     if ! let "AFTER - BEFORE == 0"; then
9107         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9108     else
9109         log "cache hits:: before: $BEFORE, after: $AFTER"
9110     fi
9111
9112
9113     log "Turn on the read cache and turn off the write cache"
9114     set_cache read on
9115     set_cache writethrough off
9116
9117     log "Write data and read it back"
9118     log "It should not be satisfied from the cache."
9119     rm -f $file
9120     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9121     BEFORE=`roc_hit`
9122     cancel_lru_locks osc
9123     cat $file >/dev/null
9124     AFTER=`roc_hit`
9125     if ! let "AFTER - BEFORE == 0"; then
9126         error_ignore 20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9127     else
9128         log "cache hits:: before: $BEFORE, after: $AFTER"
9129     fi
9130
9131     log "Read again; it should be satisfied from the cache."
9132     BEFORE=`roc_hit`
9133     cancel_lru_locks osc
9134     cat $file >/dev/null
9135     AFTER=`roc_hit`
9136     if ! let "AFTER - BEFORE == CPAGES"; then
9137         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9138     else
9139         log "cache hits:: before: $BEFORE, after: $AFTER"
9140     fi
9141
9142     rm -f $file
9143 }
9144 run_test 156 "Verification of tunables ============================"
9145
9146 #Changelogs
9147 err17935 () {
9148     if [ $MDSCOUNT -gt 1 ]; then
9149         error_ignore 17935 $*
9150     else
9151         error $*
9152     fi
9153 }
9154
9155 changelog_chmask()
9156 {
9157     MASK=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_mask |\
9158            grep -c $1)
9159
9160     if [ $MASK -eq 1 ]; then
9161         do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="-$1"
9162     else
9163         do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="+$1"
9164     fi
9165 }
9166
9167 test_160() {
9168         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9169     remote_mds_nodsh && skip "remote MDS with nodsh" && return
9170     [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9171         { skip "Need MDS version at least 2.2.0"; return; }
9172     USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9173     echo "Registered as changelog user $USER"
9174     do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \
9175         grep -q $USER || error "User $USER not found in changelog_users"
9176
9177     # change something
9178     test_mkdir -p $DIR/$tdir/pics/2008/zachy
9179     touch $DIR/$tdir/pics/2008/zachy/timestamp
9180     cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
9181     mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
9182     ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
9183     ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
9184     rm $DIR/$tdir/pics/desktop.jpg
9185
9186     $LFS changelog $MDT0 | tail -5
9187
9188     echo "verifying changelog mask"
9189     changelog_chmask "MKDIR"
9190     changelog_chmask "CLOSE"
9191
9192     test_mkdir -p $DIR/$tdir/pics/zach/sofia
9193     echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9194
9195     changelog_chmask "MKDIR"
9196     changelog_chmask "CLOSE"
9197
9198     test_mkdir -p $DIR/$tdir/pics/2008/sofia
9199     echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9200
9201     $LFS changelog $MDT0
9202     MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
9203     CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
9204     [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
9205     [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
9206
9207     # verify contents
9208     echo "verifying target fid"
9209     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
9210         tail -1 | awk '{print $6}')
9211     fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
9212     [ "$fidc" == "t=$fidf" ] || \
9213         err17935 "fid in changelog $fidc != file fid $fidf"
9214     echo "verifying parent fid"
9215     fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
9216         tail -1 | awk '{print $7}')
9217     fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
9218     [ "$fidc" == "p=$fidf" ] || \
9219         err17935 "pfid in changelog $fidc != dir fid $fidf"
9220
9221     USER_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \
9222         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
9223     $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
9224     USER_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \
9225         mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
9226     echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
9227     [ $USER_REC2 == $(($USER_REC1 + 5)) ] || \
9228         err17935 "user index should be $(($USER_REC1 + 5)); is $USER_REC2"
9229
9230     MIN_REC=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_users | \
9231         awk 'min == "" || $2 < min {min = $2}; END {print min}')
9232     FIRST_REC=$($LFS changelog $MDT0 | head -1 | awk '{print $1}')
9233     echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
9234     [ $FIRST_REC == $(($MIN_REC + 1)) ] || \
9235         err17935 "first index should be $(($MIN_REC + 1)); is $FIRST_REC"
9236
9237     echo "verifying user deregister"
9238     do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9239     do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \
9240         grep -q $USER && error "User $USER still found in changelog_users"
9241
9242     USERS=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
9243         mdd.$MDT0.changelog_users | wc -l) - 2 ))
9244     if [ $USERS -eq 0 ]; then
9245         LAST_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \
9246             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
9247         touch $DIR/$tdir/chloe
9248         LAST_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \
9249             mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
9250         echo "verify changelogs are off if we were the only user: $LAST_REC1 == $LAST_REC2"
9251         [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
9252     else
9253         echo "$USERS other changelog users; can't verify off"
9254     fi
9255 }
9256 run_test 160 "changelog sanity"
9257
9258 test_161a() {
9259         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9260     test_mkdir -p $DIR/$tdir
9261     cp /etc/hosts $DIR/$tdir/$tfile
9262     test_mkdir $DIR/$tdir/foo1
9263     test_mkdir $DIR/$tdir/foo2
9264     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
9265     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
9266     ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
9267     ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
9268         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
9269         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9270                 $LFS fid2path $DIR $FID
9271                 err17935 "bad link ea"
9272         fi
9273     # middle
9274     rm $DIR/$tdir/foo2/zachary
9275     # last
9276     rm $DIR/$tdir/foo2/thor
9277     # first
9278     rm $DIR/$tdir/$tfile
9279     # rename
9280     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
9281     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
9282         then
9283         $LFS fid2path $DIR $FID
9284         err17935 "bad link rename"
9285     fi
9286     rm $DIR/$tdir/foo2/maggie
9287
9288     # overflow the EA
9289     local longname=filename_avg_len_is_thirty_two_
9290     createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
9291         error "failed to hardlink many files"
9292     links=$($LFS fid2path $DIR $FID | wc -l)
9293     echo -n "${links}/1000 links in link EA"
9294     [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
9295     unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
9296         error "failed to unlink many hardlinks"
9297 }
9298 run_test 161a "link ea sanity"
9299
9300 test_161b() {
9301         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9302         [ $MDSCOUNT -lt 2 ] &&
9303                 skip "skipping remote directory test" && return
9304         local MDTIDX=1
9305         local remote_dir=$DIR/$tdir/remote_dir
9306
9307         mkdir -p $DIR/$tdir
9308         $LFS mkdir -i $MDTIDX $remote_dir ||
9309                 error "create remote directory failed"
9310
9311         cp /etc/hosts $remote_dir/$tfile
9312         mkdir -p $remote_dir/foo1
9313         mkdir -p $remote_dir/foo2
9314         ln $remote_dir/$tfile $remote_dir/foo1/sofia
9315         ln $remote_dir/$tfile $remote_dir/foo2/zachary
9316         ln $remote_dir/$tfile $remote_dir/foo1/luna
9317         ln $remote_dir/$tfile $remote_dir/foo2/thor
9318
9319         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
9320                      tr -d ']')
9321         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9322                 $LFS fid2path $DIR $FID
9323                 err17935 "bad link ea"
9324         fi
9325         # middle
9326         rm $remote_dir/foo2/zachary
9327         # last
9328         rm $remote_dir/foo2/thor
9329         # first
9330         rm $remote_dir/$tfile
9331         # rename
9332         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
9333         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
9334         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
9335                 $LFS fid2path $DIR $FID
9336                 err17935 "bad link rename"
9337         fi
9338         rm $remote_dir/foo2/maggie
9339
9340         # overflow the EA
9341         local longname=filename_avg_len_is_thirty_two_
9342         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
9343                 error "failed to hardlink many files"
9344         links=$($LFS fid2path $DIR $FID | wc -l)
9345         echo -n "${links}/1000 links in link EA"
9346         [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
9347         unlinkmany $remote_dir/foo2/$longname 1000 ||
9348         error "failed to unlink many hardlinks"
9349 }
9350 run_test 161b "link ea sanity under remote directory"
9351
9352 check_path() {
9353     local expected=$1
9354     shift
9355     local fid=$2
9356
9357     local path=$(${LFS} fid2path $*)
9358     RC=$?
9359
9360     if [ $RC -ne 0 ]; then
9361         err17935 "path looked up of $expected failed. Error $RC"
9362         return $RC
9363     elif [ "${path}" != "${expected}" ]; then
9364         err17935 "path looked up \"${path}\" instead of \"${expected}\""
9365         return 2
9366     fi
9367     echo "fid $fid resolves to path $path (expected $expected)"
9368 }
9369
9370 test_162() {
9371         # Make changes to filesystem
9372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9373         test_mkdir -p $DIR/$tdir/d2
9374         touch $DIR/$tdir/d2/$tfile
9375         touch $DIR/$tdir/d2/x1
9376         touch $DIR/$tdir/d2/x2
9377         test_mkdir -p $DIR/$tdir/d2/a/b/c
9378         test_mkdir -p $DIR/$tdir/d2/p/q/r
9379         # regular file
9380         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
9381         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
9382
9383         # softlink
9384         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
9385         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
9386         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
9387
9388         # softlink to wrong file
9389         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
9390         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
9391         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
9392
9393         # hardlink
9394         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
9395         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
9396         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
9397         # fid2path dir/fsname should both work
9398         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
9399         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
9400
9401         # hardlink count: check that there are 2 links
9402         # Doesnt work with CMD yet: 17935
9403         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
9404                 err17935 "expected 2 links"
9405
9406         # hardlink indexing: remove the first link
9407         rm $DIR/$tdir/d2/p/q/r/hlink
9408         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
9409
9410         return 0
9411 }
9412 run_test 162 "path lookup sanity"
9413
9414 test_163() {
9415         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9416         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9417         copytool --test $FSNAME || { skip "copytool not runnable: $?" && return; }
9418         copytool $FSNAME &
9419         sleep 1
9420         local uuid=$($LCTL get_param -n mdc.${FSNAME}-MDT0000-mdc-*.uuid)
9421         # this proc file is temporary and linux-only
9422         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT0000.mdccomm=$uuid ||\
9423          error "kernel->userspace send failed"
9424         kill -INT $!
9425 }
9426 run_test 163 "kernel <-> userspace comms"
9427
9428 test_169() {
9429         # do directio so as not to populate the page cache
9430         log "creating a 10 Mb file"
9431         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
9432         log "starting reads"
9433         dd if=$DIR/$tfile of=/dev/null bs=4096 &
9434         log "truncating the file"
9435         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
9436         log "killing dd"
9437         kill %+ || true # reads might have finished
9438         echo "wait until dd is finished"
9439         wait
9440         log "removing the temporary file"
9441         rm -rf $DIR/$tfile || error "tmp file removal failed"
9442 }
9443 run_test 169 "parallel read and truncate should not deadlock"
9444
9445 test_170() {
9446         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9447         $LCTL clear     # bug 18514
9448         $LCTL debug_daemon start $TMP/${tfile}_log_good
9449         touch $DIR/$tfile
9450         $LCTL debug_daemon stop
9451         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
9452                error "sed failed to read log_good"
9453
9454         $LCTL debug_daemon start $TMP/${tfile}_log_good
9455         rm -rf $DIR/$tfile
9456         $LCTL debug_daemon stop
9457
9458         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
9459                error "lctl df log_bad failed"
9460
9461         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
9462         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
9463
9464         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
9465         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
9466
9467         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
9468                 error "bad_line good_line1 good_line2 are empty"
9469
9470         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
9471         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
9472         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
9473
9474         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
9475         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
9476         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
9477
9478         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
9479                 error "bad_line_new good_line_new are empty"
9480
9481         local expected_good=$((good_line1 + good_line2*2))
9482
9483         rm -f $TMP/${tfile}*
9484         # LU-231, short malformed line may not be counted into bad lines
9485         if [ $bad_line -ne $bad_line_new ] &&
9486                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
9487                 error "expected $bad_line bad lines, but got $bad_line_new"
9488                 return 1
9489         fi
9490
9491         if [ $expected_good -ne $good_line_new ]; then
9492                 error "expected $expected_good good lines, but got $good_line_new"
9493                 return 2
9494         fi
9495         true
9496 }
9497 run_test 170 "test lctl df to handle corrupted log ====================="
9498
9499 test_171() { # bug20592
9500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9501 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
9502         $LCTL set_param fail_loc=0x50e
9503         $LCTL set_param fail_val=3000
9504         multiop_bg_pause $DIR/$tfile O_s || true
9505         local MULTIPID=$!
9506         kill -USR1 $MULTIPID
9507         # cause log dump
9508         sleep 3
9509         wait $MULTIPID
9510         if dmesg | grep "recursive fault"; then
9511                 error "caught a recursive fault"
9512         fi
9513         $LCTL set_param fail_loc=0
9514         true
9515 }
9516 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
9517
9518 # it would be good to share it with obdfilter-survey/libecho code
9519 setup_obdecho_osc () {
9520         local rc=0
9521         local ost_nid=$1
9522         local obdfilter_name=$2
9523         echo "Creating new osc for $obdfilter_name on $ost_nid"
9524         # make sure we can find loopback nid
9525         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
9526
9527         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
9528                            ${obdfilter_name}_osc_UUID || rc=2; }
9529         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
9530                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
9531         return $rc
9532 }
9533
9534 cleanup_obdecho_osc () {
9535         local obdfilter_name=$1
9536         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
9537         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
9538         return 0
9539 }
9540
9541 obdecho_create_test() {
9542         local OBD=$1
9543         local node=$2
9544         local rc=0
9545         local id
9546         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
9547         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
9548                            rc=2; }
9549         if [ $rc -eq 0 ]; then
9550             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
9551             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
9552         fi
9553         echo "New object id is $id"
9554         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec test_brw 10 w v 64 $id" ||
9555                            rc=4; }
9556         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
9557                                         "cleanup" || rc=5; }
9558         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
9559                                         "detach" || rc=6; }
9560         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
9561         return $rc
9562 }
9563
9564 test_180a() {
9565         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9566         remote_ost_nodsh && skip "remote OST with nodsh" && return
9567         local rc=0
9568         local rmmod_local=0
9569
9570         if ! module_loaded obdecho; then
9571             load_module obdecho/obdecho
9572             rmmod_local=1
9573         fi
9574
9575         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
9576         local host=$(lctl get_param -n osc.$osc.import |
9577                              awk '/current_connection:/ {print $2}' )
9578         local target=$(lctl get_param -n osc.$osc.import |
9579                              awk '/target:/ {print $2}' )
9580         target=${target%_UUID}
9581
9582         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
9583         [ $rc -eq 0 ] && { obdecho_create_test ${target}_osc client || rc=2; }
9584         [[ -n $target ]] && cleanup_obdecho_osc $target
9585         [ $rmmod_local -eq 1 ] && rmmod obdecho
9586         return $rc
9587 }
9588 run_test 180a "test obdecho on osc"
9589
9590 test_180b() {
9591         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9592         remote_ost_nodsh && skip "remote OST with nodsh" && return
9593         local rc=0
9594         local rmmod_remote=0
9595
9596         do_facet ost1 "lsmod | grep -q obdecho || "                      \
9597                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
9598                       "modprobe obdecho; }" && rmmod_remote=1
9599         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
9600         [[ -n $target ]] && { obdecho_create_test $target ost1 || rc=1; }
9601         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
9602         return $rc
9603 }
9604 run_test 180b "test obdecho directly on obdfilter"
9605
9606 test_181() { # bug 22177
9607         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
9608         # create enough files to index the directory
9609         createmany -o $DIR/$tdir/foobar 4000
9610         # print attributes for debug purpose
9611         lsattr -d .
9612         # open dir
9613         multiop_bg_pause $DIR/$tdir D_Sc || return 1
9614         MULTIPID=$!
9615         # remove the files & current working dir
9616         unlinkmany $DIR/$tdir/foobar 4000
9617         rmdir $DIR/$tdir
9618         kill -USR1 $MULTIPID
9619         wait $MULTIPID
9620         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
9621         return 0
9622 }
9623 run_test 181 "Test open-unlinked dir ========================"
9624
9625 test_182() {
9626         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9627         # disable MDC RPC lock wouldn't crash client
9628         local fcount=1000
9629         local tcount=4
9630
9631         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
9632 #define OBD_FAIL_MDC_RPCS_SEM           0x804
9633         $LCTL set_param fail_loc=0x804
9634
9635         for (( i=0; i < $tcount; i++ )) ; do
9636                 mkdir $DIR/$tdir/$i
9637                 createmany -o $DIR/$tdir/$i/f- $fcount &
9638         done
9639         wait
9640
9641         for (( i=0; i < $tcount; i++ )) ; do
9642                 unlinkmany $DIR/$tdir/$i/f- $fcount &
9643         done
9644         wait
9645
9646         rm -rf $DIR/$tdir
9647
9648         $LCTL set_param fail_loc=0
9649 }
9650 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
9651
9652 test_183() { # LU-2275
9653         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9654         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
9655         echo aaa > $DIR/$tdir/$tfile
9656
9657 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
9658         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
9659
9660         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
9661         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
9662
9663         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
9664
9665         # Flush negative dentry cache
9666         touch $DIR/$tdir/$tfile
9667
9668         # We are not checking for any leaked references here, they'll
9669         # become evident next time we do cleanup with module unload.
9670         rm -rf $DIR/$tdir
9671 }
9672 run_test 183 "No crash or request leak in case of strange dispositions ========"
9673
9674 # test suite 184 is for LU-2016, LU-2017
9675 test_184a() {
9676         check_swap_layouts_support && return 0
9677
9678         dir0=$DIR/$tdir/$testnum
9679         test_mkdir -p $dir0 || error "creating dir $dir0"
9680         ref1=/etc/passwd
9681         ref2=/etc/group
9682         file1=$dir0/f1
9683         file2=$dir0/f2
9684         $SETSTRIPE -c1 $file1
9685         cp $ref1 $file1
9686         $SETSTRIPE -c2 $file2
9687         cp $ref2 $file2
9688         gen1=$($GETSTRIPE -g $file1)
9689         gen2=$($GETSTRIPE -g $file2)
9690
9691         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
9692         gen=$($GETSTRIPE -g $file1)
9693         [[ $gen1 != $gen ]] ||
9694                 "Layout generation on $file1 does not change"
9695         gen=$($GETSTRIPE -g $file2)
9696         [[ $gen2 != $gen ]] ||
9697                 "Layout generation on $file2 does not change"
9698
9699         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
9700         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
9701 }
9702 run_test 184a "Basic layout swap"
9703
9704 test_184b() {
9705         check_swap_layouts_support && return 0
9706
9707         dir0=$DIR/$tdir/$testnum
9708         mkdir -p $dir0 || error "creating dir $dir0"
9709         file1=$dir0/f1
9710         file2=$dir0/f2
9711         file3=$dir0/f3
9712         dir1=$dir0/d1
9713         dir2=$dir0/d2
9714         mkdir $dir1 $dir2
9715         $SETSTRIPE -c1 $file1
9716         $SETSTRIPE -c2 $file2
9717         $SETSTRIPE -c1 $file3
9718         chown $RUNAS_ID $file3
9719         gen1=$($GETSTRIPE -g $file1)
9720         gen2=$($GETSTRIPE -g $file2)
9721
9722         $LFS swap_layouts $dir1 $dir2 &&
9723                 error "swap of directories layouts should fail"
9724         $LFS swap_layouts $dir1 $file1 &&
9725                 error "swap of directory and file layouts should fail"
9726         $RUNAS $LFS swap_layouts $file1 $file2 &&
9727                 error "swap of file we cannot write should fail"
9728         $LFS swap_layouts $file1 $file3 &&
9729                 error "swap of file with different owner should fail"
9730         /bin/true # to clear error code
9731 }
9732 run_test 184b "Forbidden layout swap (will generate errors)"
9733
9734 test_184c() {
9735         check_swap_layouts_support && return 0
9736
9737         local dir0=$DIR/$tdir/$testnum
9738         mkdir -p $dir0 || error "creating dir $dir0"
9739
9740         local ref1=$dir0/ref1
9741         local ref2=$dir0/ref2
9742         local file1=$dir0/file1
9743         local file2=$dir0/file2
9744         # create a file large enough for the concurent test
9745         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
9746         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
9747         echo "ref file size: ref1(`stat -c %s $ref1`), ref2(`stat -c %s $ref2`)"
9748
9749         cp $ref2 $file2
9750         dd if=$ref1 of=$file1 bs=16k &
9751         local DD_PID=$!
9752
9753         # Make sure dd starts to copy file
9754         while [ ! -f $file1 ]; do sleep 0.1; done
9755
9756         $LFS swap_layouts $file1 $file2
9757         local rc=$?
9758         wait $DD_PID
9759         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
9760         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
9761
9762         # how many bytes copied before swapping layout
9763         local copied=`stat -c %s $file2`
9764         local remaining=`stat -c %s $ref1`
9765         remaining=$((remaining - copied))
9766         echo "Copied $copied bytes before swapping layout..."
9767
9768         cmp -n $copied $file1 $ref2 | grep differ &&
9769                 error "Content mismatch [0, $copied) of ref2 and file1"
9770         cmp -n $copied $file2 $ref1 ||
9771                 error "Content mismatch [0, $copied) of ref1 and file2"
9772         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
9773                 error "Content mismatch [$copied, EOF) of ref1 and file1"
9774
9775         # clean up
9776         rm -f $ref1 $ref2 $file1 $file2
9777 }
9778 run_test 184c "Concurrent write and layout swap"
9779
9780 test_184d() {
9781         check_swap_layouts_support && return 0
9782
9783         local file1=$DIR/$tdir/$tfile-1
9784         local file2=$DIR/$tdir/$tfile-2
9785         local file3=$DIR/$tdir/$tfile-3
9786         local lovea1
9787         local lovea2
9788
9789         mkdir -p $DIR/$tdir
9790         touch $file1 || error "create $file1 failed"
9791         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
9792                 error "create $file2 failed"
9793         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
9794                 error "create $file3 failed"
9795         lovea1=$($LFS getstripe $file1 | sed 1d)
9796
9797         $LFS swap_layouts $file2 $file3 ||
9798                 error "swap $file2 $file3 layouts failed"
9799         $LFS swap_layouts $file1 $file2 ||
9800                 error "swap $file1 $file2 layouts failed"
9801
9802         lovea2=$($LFS getstripe $file2 | sed 1d)
9803         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
9804
9805         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
9806         [ -z $lovea1 ] || error "$file1 shouldn't have lovea"
9807 }
9808 run_test 184d "allow stripeless layouts swap"
9809
9810
9811 test_185() { # LU-2441
9812         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
9813         touch $DIR/$tdir/spoo
9814         local mtime1=$(stat -c "%Y" $DIR/$tdir)
9815         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
9816                 error "cannot create/write a volatile file"
9817         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
9818                 error "FID is still valid after close"
9819
9820         multiop_bg_pause $DIR/$tdir vVw4096_c
9821         local multi_pid=$!
9822
9823         local OLD_IFS=$IFS
9824         IFS=":"
9825         local fidv=($fid)
9826         IFS=$OLD_IFS
9827         # assume that the next FID for this client is sequential, since stdout
9828         # is unfortunately eaten by multiop_bg_pause
9829         local n=$((${fidv[1]} + 1))
9830         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
9831         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
9832                 error "FID is missing before close"
9833         kill -USR1 $multi_pid
9834         # 1 second delay, so if mtime change we will see it
9835         sleep 1
9836         local mtime2=$(stat -c "%Y" $DIR/$tdir)
9837         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
9838 }
9839 run_test 185 "Volatile file support"
9840
9841 # OST pools tests
9842 check_file_in_pool()
9843 {
9844         local file=$1
9845         local pool=$2
9846         local tlist="$3"
9847         local res=$($GETSTRIPE $file | grep 0x | cut -f2)
9848         for i in $res
9849         do
9850                 for t in $tlist ; do
9851                         [ "$i" -eq "$t" ] && continue 2
9852                 done
9853
9854                 echo "pool list: $tlist"
9855                 echo "striping: $res"
9856                 error_noexit "$file not allocated in $pool"
9857                 return 1
9858         done
9859         return 0
9860 }
9861
9862 pool_add() {
9863         echo "Creating new pool"
9864         local pool=$1
9865
9866         create_pool $FSNAME.$pool ||
9867                 { error_noexit "No pool created, result code $?"; return 1; }
9868         [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
9869                 { error_noexit "$pool not in lfs pool_list"; return 2; }
9870 }
9871
9872 pool_add_targets() {
9873         echo "Adding targets to pool"
9874         local pool=$1
9875         local first=$2
9876         local last=$3
9877         local step=${4:-1}
9878
9879         local list=$(seq $first $step $last)
9880
9881         local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
9882         do_facet mgs $LCTL pool_add \
9883                         $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
9884         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
9885                         | sort -u | tr '\n' ' ' " "$t" || { 
9886                 error_noexit "Add to pool failed"
9887                 return 1
9888         }
9889         local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
9890         local addcount=$(((last - first) / step + 1))
9891         [ $lfscount -eq $addcount ] || {
9892                 error_noexit "lfs pool_list bad ost count" \
9893                                                 "$lfscount != $addcount"
9894                 return 2
9895         }
9896 }
9897
9898 pool_set_dir() {
9899         local pool=$1
9900         local tdir=$2
9901         echo "Setting pool on directory $tdir"
9902
9903         $SETSTRIPE -c 2 -p $pool $tdir && return 0
9904
9905         error_noexit "Cannot set pool $pool to $tdir"
9906         return 1
9907 }
9908
9909 pool_check_dir() {
9910         local pool=$1
9911         local tdir=$2
9912         echo "Checking pool on directory $tdir"
9913
9914         local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
9915         [ "$res" = "$pool" ] && return 0
9916
9917         error_noexit "Pool on '$tdir' is '$res', not '$pool'"
9918         return 1
9919 }
9920
9921 pool_dir_rel_path() {
9922         echo "Testing relative path works well"
9923         local pool=$1
9924         local tdir=$2
9925         local root=$3
9926
9927         mkdir -p $root/$tdir/$tdir
9928         cd $root/$tdir
9929         pool_set_dir $pool $tdir          || return 1
9930         pool_set_dir $pool ./$tdir        || return 2
9931         pool_set_dir $pool ../$tdir       || return 3
9932         pool_set_dir $pool ../$tdir/$tdir || return 4
9933         rm -rf $tdir; cd - > /dev/null
9934 }
9935
9936 pool_alloc_files() {
9937         echo "Checking files allocation from directory pool"
9938         local pool=$1
9939         local tdir=$2
9940         local count=$3
9941         local tlist="$4"
9942
9943         local failed=0
9944         for i in $(seq -w 1 $count)
9945         do
9946                 local file=$tdir/file-$i
9947                 touch $file
9948                 check_file_in_pool $file $pool "$tlist" || \
9949                         failed=$((failed + 1))
9950         done
9951         [ "$failed" = 0 ] && return 0
9952
9953         error_noexit "$failed files not allocated in $pool"
9954         return 1
9955 }
9956
9957 pool_create_files() {
9958         echo "Creating files in pool"
9959         local pool=$1
9960         local tdir=$2
9961         local count=$3
9962         local tlist="$4"
9963
9964         mkdir -p $tdir
9965         local failed=0
9966         for i in $(seq -w 1 $count)
9967         do
9968                 local file=$tdir/spoo-$i
9969                 $SETSTRIPE -p $pool $file
9970                 check_file_in_pool $file $pool "$tlist" || \
9971                         failed=$((failed + 1))
9972         done
9973         [ "$failed" = 0 ] && return 0
9974
9975         error_noexit "$failed files not allocated in $pool"
9976         return 1
9977 }
9978
9979 pool_lfs_df() {
9980         echo "Checking 'lfs df' output"
9981         local pool=$1
9982
9983         local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
9984                         tr '\n' ' ')
9985         local res=$($LFS df --pool $FSNAME.$pool |
9986                         awk '{print $1}' |
9987                         grep "$FSNAME-OST" |
9988                         tr '\n' ' ')
9989         [ "$res" = "$t" ] && return 0
9990
9991         error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
9992         return 1
9993 }
9994
9995 pool_file_rel_path() {
9996         echo "Creating files in a pool with relative pathname"
9997         local pool=$1
9998         local tdir=$2
9999
10000         mkdir -p $tdir ||
10001                 { error_noexit "unable to create $tdir"; return 1 ; }
10002         local file="/..$tdir/$tfile-1"
10003         $SETSTRIPE -p $pool $file ||
10004                 { error_noexit "unable to create $file" ; return 2 ; }
10005
10006         cd $tdir
10007         $SETSTRIPE -p $pool $tfile-2 || {
10008                 error_noexit "unable to create $tfile-2 in $tdir"
10009                 return 3
10010         }
10011 }
10012
10013 pool_remove_first_target() {
10014         echo "Removing first target from a pool"
10015         local pool=$1
10016
10017         local pname="lov.$FSNAME-*.pools.$pool"
10018         local t=$($LCTL get_param -n $pname | head -1)
10019         do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10020         wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
10021                 error_noexit "$t not removed from $FSNAME.$pool"
10022                 return 1
10023         }
10024 }
10025
10026 pool_remove_all_targets() {
10027         echo "Removing all targets from pool"
10028         local pool=$1
10029         local file=$2
10030         local pname="lov.$FSNAME-*.pools.$pool"
10031         for t in $($LCTL get_param -n $pname | sort -u)
10032         do
10033                 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10034         done
10035         wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
10036                 error_noexit "Pool $FSNAME.$pool cannot be drained"
10037                 return 1
10038         }
10039         # striping on an empty/nonexistant pool should fall back 
10040         # to "pool of everything"
10041         touch $file || {
10042                 error_noexit "failed to use fallback striping for empty pool"
10043                 return 2
10044         }
10045         # setstripe on an empty pool should fail
10046         $SETSTRIPE -p $pool $file 2>/dev/null && {
10047                 error_noexit "expected failure when creating file" \
10048                                                         "with empty pool"
10049                 return 3
10050         }
10051         return 0
10052 }
10053
10054 pool_remove() {
10055         echo "Destroying pool"
10056         local pool=$1
10057         local file=$2
10058
10059         do_facet mgs $LCTL pool_destroy $FSNAME.$pool
10060
10061         sleep 2
10062         # striping on an empty/nonexistant pool should fall back 
10063         # to "pool of everything"
10064         touch $file || {
10065                 error_noexit "failed to use fallback striping for missing pool"
10066                 return 1
10067         }
10068         # setstripe on an empty pool should fail
10069         $SETSTRIPE -p $pool $file 2>/dev/null && {
10070                 error_noexit "expected failure when creating file" \
10071                                                         "with missing pool"
10072                 return 2
10073         }
10074
10075         # get param should return err once pool is gone
10076         if wait_update $HOSTNAME "lctl get_param -n \
10077                 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
10078         then
10079                 remove_pool_from_list $FSNAME.$pool
10080                 return 0
10081         fi
10082         error_noexit "Pool $FSNAME.$pool is not destroyed"
10083         return 3
10084 }
10085
10086 test_200() {
10087         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10088         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
10089
10090         local POOL=${POOL:-cea1}
10091         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
10092         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
10093         # Pool OST targets
10094         local first_ost=0
10095         local last_ost=$(($OSTCOUNT - 1))
10096         local ost_step=2
10097         local ost_list=$(seq $first_ost $ost_step $last_ost)
10098         local ost_range="$first_ost $last_ost $ost_step"
10099         local test_path=$POOL_ROOT/$POOL_DIR_NAME
10100         local file_dir=$POOL_ROOT/file_tst
10101
10102         local rc=0
10103         while : ; do
10104                 # former test_200a test_200b
10105                 pool_add $POOL                          || { rc=$? ; break; }
10106                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
10107                 # former test_200c test_200d
10108                 mkdir -p $test_path
10109                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
10110                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
10111                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
10112                                                         || { rc=$? ; break; }
10113                 # former test_200e test_200f
10114                 local files=$((OSTCOUNT*3))
10115                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
10116                                                         || { rc=$? ; break; }
10117                 pool_create_files $POOL $file_dir $files "$ost_list" \
10118                                                         || { rc=$? ; break; }
10119                 # former test_200g test_200h
10120                 pool_lfs_df $POOL                       || { rc=$? ; break; }
10121                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
10122
10123                 # former test_201a test_201b test_201c
10124                 pool_remove_first_target $POOL          || { rc=$? ; break; }
10125
10126                 local f=$test_path/$tfile
10127                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
10128                 pool_remove $POOL $f                    || { rc=$? ; break; }
10129                 break
10130         done
10131
10132         cleanup_pools
10133         return $rc
10134 }
10135 run_test 200 "OST pools"
10136
10137 # usage: default_attr <count | size | offset>
10138 default_attr() {
10139         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
10140 }
10141
10142 # usage: check_default_stripe_attr
10143 check_default_stripe_attr() {
10144         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
10145         case $1 in
10146         --stripe-count|--count)
10147                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
10148         --stripe-size|--size)
10149                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
10150         --stripe-index|--index)
10151                 EXPECTED=-1;;
10152         *)
10153                 error "unknown getstripe attr '$1'"
10154         esac
10155
10156         [ $ACTUAL != $EXPECTED ] &&
10157                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
10158 }
10159
10160 test_204a() {
10161         test_mkdir -p $DIR/$tdir
10162         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
10163
10164         check_default_stripe_attr --stripe-count
10165         check_default_stripe_attr --stripe-size
10166         check_default_stripe_attr --stripe-index
10167
10168         return 0
10169 }
10170 run_test 204a "Print default stripe attributes ================="
10171
10172 test_204b() {
10173         test_mkdir -p $DIR/$tdir
10174         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10175
10176         check_default_stripe_attr --stripe-size
10177         check_default_stripe_attr --stripe-index
10178
10179         return 0
10180 }
10181 run_test 204b "Print default stripe size and offset  ==========="
10182
10183 test_204c() {
10184         test_mkdir -p $DIR/$tdir
10185         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10186
10187         check_default_stripe_attr --stripe-count
10188         check_default_stripe_attr --stripe-index
10189
10190         return 0
10191 }
10192 run_test 204c "Print default stripe count and offset ==========="
10193
10194 test_204d() {
10195         test_mkdir -p $DIR/$tdir
10196         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10197
10198         check_default_stripe_attr --stripe-count
10199         check_default_stripe_attr --stripe-size
10200
10201         return 0
10202 }
10203 run_test 204d "Print default stripe count and size ============="
10204
10205 test_204e() {
10206         test_mkdir -p $DIR/$tdir
10207         $SETSTRIPE -d $DIR/$tdir
10208
10209         check_default_stripe_attr --stripe-count --raw
10210         check_default_stripe_attr --stripe-size --raw
10211         check_default_stripe_attr --stripe-index --raw
10212
10213         return 0
10214 }
10215 run_test 204e "Print raw stripe attributes ================="
10216
10217 test_204f() {
10218         test_mkdir -p $DIR/$tdir
10219         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10220
10221         check_default_stripe_attr --stripe-size --raw
10222         check_default_stripe_attr --stripe-index --raw
10223
10224         return 0
10225 }
10226 run_test 204f "Print raw stripe size and offset  ==========="
10227
10228 test_204g() {
10229         test_mkdir -p $DIR/$tdir
10230         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10231
10232         check_default_stripe_attr --stripe-count --raw
10233         check_default_stripe_attr --stripe-index --raw
10234
10235         return 0
10236 }
10237 run_test 204g "Print raw stripe count and offset ==========="
10238
10239 test_204h() {
10240         test_mkdir -p $DIR/$tdir
10241         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10242
10243         check_default_stripe_attr --stripe-count --raw
10244         check_default_stripe_attr --stripe-size --raw
10245
10246         return 0
10247 }
10248 run_test 204h "Print raw stripe count and size ============="
10249
10250 # Figure out which job scheduler is being used, if any,
10251 # or use a fake one
10252 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
10253         JOBENV=SLURM_JOB_ID
10254 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
10255         JOBENV=LSB_JOBID
10256 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
10257         JOBENV=PBS_JOBID
10258 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
10259         JOBENV=LOADL_STEP_ID
10260 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
10261         JOBENV=JOB_ID
10262 else
10263         JOBENV=FAKE_JOBID
10264 fi
10265
10266 verify_jobstats() {
10267         local cmd=$1
10268         local target=$2
10269
10270         # clear old jobstats
10271         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
10272         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
10273
10274         # use a new JobID for this test, or we might see an old one
10275         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
10276
10277         JOBVAL=${!JOBENV}
10278         log "Test: $cmd"
10279         log "Using JobID environment variable $JOBENV=$JOBVAL"
10280
10281         if [ $JOBENV = "FAKE_JOBID" ]; then
10282                 FAKE_JOBID=$JOBVAL $cmd
10283         else
10284                 $cmd
10285         fi
10286
10287         if [ "$target" = "mdt" -o "$target" = "both" ]; then
10288                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
10289                 do_facet $FACET lctl get_param mdt.*.job_stats |
10290                         grep $JOBVAL || error "No job stats found on MDT $FACET"
10291         fi
10292         if [ "$target" = "ost" -o "$target" = "both" ]; then
10293                 FACET=ost1
10294                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
10295                         grep $JOBVAL || error "No job stats found on OST $FACET"
10296         fi
10297 }
10298
10299 jobstats_set() {
10300         trap 0
10301         NEW_JOBENV=${1:-$OLD_JOBENV}
10302         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
10303         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
10304 }
10305
10306 test_205() { # Job stats
10307         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10308         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
10309                 skip "Server doesn't support jobstats" && return 0
10310
10311         local cmd
10312         OLD_JOBENV=`$LCTL get_param -n jobid_var`
10313         if [ $OLD_JOBENV != $JOBENV ]; then
10314                 jobstats_set $JOBENV
10315                 trap jobstats_set EXIT
10316         fi
10317
10318         # mkdir
10319         cmd="mkdir $DIR/$tfile"
10320         verify_jobstats "$cmd" "mdt"
10321         # rmdir
10322         cmd="rm -fr $DIR/$tfile"
10323         verify_jobstats "$cmd" "mdt"
10324         # mknod
10325         cmd="mknod $DIR/$tfile c 1 3"
10326         verify_jobstats "$cmd" "mdt"
10327         # unlink
10328         cmd="rm -f $DIR/$tfile"
10329         verify_jobstats "$cmd" "mdt"
10330         # open & close
10331         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
10332         verify_jobstats "$cmd" "mdt"
10333         # setattr
10334         cmd="touch $DIR/$tfile"
10335         verify_jobstats "$cmd" "both"
10336         # write
10337         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
10338         verify_jobstats "$cmd" "ost"
10339         # read
10340         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
10341         verify_jobstats "$cmd" "ost"
10342         # truncate
10343         cmd="$TRUNCATE $DIR/$tfile 0"
10344         verify_jobstats "$cmd" "both"
10345         # rename
10346         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
10347         verify_jobstats "$cmd" "mdt"
10348
10349         # cleanup
10350         rm -f $DIR/jobstats_test_rename
10351
10352         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
10353 }
10354 run_test 205 "Verify job stats"
10355
10356 # LU-1480, LU-1773 and LU-1657
10357 test_206() {
10358         mkdir -p $DIR/$tdir
10359         lfs setstripe -c -1 $DIR/$tdir
10360 #define OBD_FAIL_LOV_INIT 0x1403
10361         $LCTL set_param fail_loc=0xa0001403
10362         $LCTL set_param fail_val=1
10363         touch $DIR/$tdir/$tfile || true
10364 }
10365 run_test 206 "fail lov_init_raid0() doesn't lbug"
10366
10367 test_207a() {
10368         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
10369         local fsz=`stat -c %s $DIR/$tfile`
10370         cancel_lru_locks mdc
10371
10372         # do not return layout in getattr intent
10373 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
10374         $LCTL set_param fail_loc=0x170
10375         local sz=`stat -c %s $DIR/$tfile`
10376
10377         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
10378
10379         rm -rf $DIR/$tfile
10380 }
10381 run_test 207a "can refresh layout at glimpse"
10382
10383 test_207b() {
10384         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
10385         local cksum=`md5sum $DIR/$tfile`
10386         local fsz=`stat -c %s $DIR/$tfile`
10387         cancel_lru_locks mdc
10388         cancel_lru_locks osc
10389
10390         # do not return layout in getattr intent
10391 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
10392         $LCTL set_param fail_loc=0x171
10393
10394         # it will refresh layout after the file is opened but before read issues
10395         echo checksum is "$cksum"
10396         echo "$cksum" |md5sum -c --quiet || error "file differs"
10397
10398         rm -rf $DIR/$tfile
10399 }
10400 run_test 207b "can refresh layout at open"
10401
10402 test_212() {
10403         size=`date +%s`
10404         size=$((size % 8192 + 1))
10405         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
10406         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
10407         rm -f $DIR/f212 $DIR/f212.xyz
10408 }
10409 run_test 212 "Sendfile test ============================================"
10410
10411 test_213() {
10412         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
10413         cancel_lru_locks osc
10414         lctl set_param fail_loc=0x8000040f
10415         # generate a read lock
10416         cat $DIR/$tfile > /dev/null
10417         # write to the file, it will try to cancel the above read lock.
10418         cat /etc/hosts >> $DIR/$tfile
10419 }
10420 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
10421
10422 test_214() { # for bug 20133
10423         test_mkdir -p $DIR/d214p/d214c
10424         for (( i=0; i < 340; i++ )) ; do
10425                 touch $DIR/d214p/d214c/a$i
10426         done
10427
10428         ls -l $DIR/d214p || error "ls -l $DIR/d214p failed"
10429         mv $DIR/d214p/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
10430         ls $DIR/d214c || error "ls $DIR/d214c failed"
10431         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
10432 }
10433 run_test 214 "hash-indexed directory test - bug 20133"
10434
10435 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
10436 create_lnet_proc_files() {
10437         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
10438         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
10439
10440         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
10441         rm -f "$TMP/lnet_$1.sys_tmp"
10442 }
10443
10444 # counterpart of create_lnet_proc_files
10445 remove_lnet_proc_files() {
10446         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
10447 }
10448
10449 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
10450 # 3rd arg as regexp for body
10451 check_lnet_proc_stats() {
10452         local l=$(cat "$TMP/lnet_$1" |wc -l)
10453         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
10454
10455         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
10456 }
10457
10458 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
10459 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
10460 # optional and can be regexp for 2nd line (lnet.routes case)
10461 check_lnet_proc_entry() {
10462         local blp=2            # blp stands for 'position of 1st line of body'
10463         [ "$5" = "" ] || blp=3 # lnet.routes case
10464
10465         local l=$(cat "$TMP/lnet_$1" |wc -l)
10466         # subtracting one from $blp because the body can be empty
10467         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
10468
10469         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
10470                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
10471
10472         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
10473                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
10474
10475         # bail out if any unexpected line happened
10476         sed -n "$blp~1 p" "$TMP/lnet_$1" |grep -Ev "$3"
10477         [ "$?" != 0 ] || error "$2 misformatted"
10478 }
10479
10480 test_215() { # for bugs 18102, 21079, 21517
10481         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10482         local N='(0|[1-9][0-9]*)'       # non-negative numeric
10483         local P='[1-9][0-9]*'           # positive numeric
10484         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
10485         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
10486         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
10487         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
10488
10489         local L1 # regexp for 1st line
10490         local L2 # regexp for 2nd line (optional)
10491         local BR # regexp for the rest (body)
10492
10493         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
10494         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
10495         create_lnet_proc_files "stats"
10496         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
10497         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
10498         remove_lnet_proc_files "stats"
10499
10500         # /proc/sys/lnet/routes should look like this:
10501         # Routing disabled/enabled
10502         # net hops state router
10503         # where net is a string like tcp0, hops >= 0, state is up/down,
10504         # router is a string like 192.168.1.1@tcp2
10505         L1="^Routing (disabled|enabled)$"
10506         L2="^net +hops +state +router$"
10507         BR="^$NET +$N +(up|down) +$NID$"
10508         create_lnet_proc_files "routes"
10509         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
10510         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
10511         remove_lnet_proc_files "routes"
10512
10513         # /proc/sys/lnet/routers should look like this:
10514         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
10515         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
10516         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
10517         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
10518         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
10519         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
10520         create_lnet_proc_files "routers"
10521         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
10522         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
10523         remove_lnet_proc_files "routers"
10524
10525         # /proc/sys/lnet/peers should look like this:
10526         # nid refs state last max rtr min tx min queue
10527         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
10528         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
10529         # numeric (0 or >0 or <0), queue >= 0.
10530         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
10531         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
10532         create_lnet_proc_files "peers"
10533         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
10534         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
10535         remove_lnet_proc_files "peers"
10536
10537         # /proc/sys/lnet/buffers  should look like this:
10538         # pages count credits min
10539         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
10540         L1="^pages +count +credits +min$"
10541         BR="^ +$N +$N +$I +$I$"
10542         create_lnet_proc_files "buffers"
10543         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
10544         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
10545         remove_lnet_proc_files "buffers"
10546
10547         # /proc/sys/lnet/nis should look like this:
10548         # nid status alive refs peer rtr max tx min
10549         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
10550         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
10551         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
10552         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
10553         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
10554         create_lnet_proc_files "nis"
10555         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
10556         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
10557         remove_lnet_proc_files "nis"
10558
10559         # can we successfully write to /proc/sys/lnet/stats?
10560         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
10561         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
10562 }
10563 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
10564
10565 test_216() { # bug 20317
10566         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10567         remote_ost_nodsh && skip "remote OST with nodsh" && return
10568
10569         local node
10570         local facets=$(get_facets OST)
10571         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10572
10573         save_lustre_params client "osc.*.contention_seconds" > $p
10574         save_lustre_params $facets \
10575                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
10576         save_lustre_params $facets \
10577                 "ldlm.namespaces.filter-*.contended_locks" >> $p
10578         save_lustre_params $facets \
10579                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
10580         clear_osc_stats
10581
10582         # agressive lockless i/o settings
10583         for node in $(osts_nodes); do
10584                 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'
10585         done
10586         lctl set_param -n osc.*.contention_seconds 60
10587
10588         $DIRECTIO write $DIR/$tfile 0 10 4096
10589         $CHECKSTAT -s 40960 $DIR/$tfile
10590
10591         # disable lockless i/o
10592         for node in $(osts_nodes); do
10593                 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'
10594         done
10595         lctl set_param -n osc.*.contention_seconds 0
10596         clear_osc_stats
10597
10598         dd if=/dev/zero of=$DIR/$tfile count=0
10599         $CHECKSTAT -s 0 $DIR/$tfile
10600
10601         restore_lustre_params <$p
10602         rm -f $p
10603         rm $DIR/$tfile
10604 }
10605 run_test 216 "check lockless direct write works and updates file size and kms correctly"
10606
10607 test_217() { # bug 22430
10608         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10609         local node
10610         local nid
10611
10612         for node in $(nodes_list); do
10613                 nid=$(host_nids_address $node $NETTYPE)
10614                 if [[ $nid = *-* ]] ; then
10615                         echo "lctl ping $nid@$NETTYPE"
10616                         lctl ping $nid@$NETTYPE
10617                 else
10618                         echo "skipping $node (no hyphen detected)"
10619                 fi
10620         done
10621 }
10622 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
10623
10624 test_218() {
10625        # do directio so as not to populate the page cache
10626        log "creating a 10 Mb file"
10627        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10628        log "starting reads"
10629        dd if=$DIR/$tfile of=/dev/null bs=4096 &
10630        log "truncating the file"
10631        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10632        log "killing dd"
10633        kill %+ || true # reads might have finished
10634        echo "wait until dd is finished"
10635        wait
10636        log "removing the temporary file"
10637        rm -rf $DIR/$tfile || error "tmp file removal failed"
10638 }
10639 run_test 218 "parallel read and truncate should not deadlock ======================="
10640
10641 test_219() {
10642         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10643         # write one partial page
10644         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
10645         # set no grant so vvp_io_commit_write will do sync write
10646         $LCTL set_param fail_loc=0x411
10647         # write a full page at the end of file
10648         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
10649
10650         $LCTL set_param fail_loc=0
10651         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
10652         $LCTL set_param fail_loc=0x411
10653         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
10654 }
10655 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
10656
10657 test_220() { #LU-325
10658         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10659         remote_ost_nodsh && skip "remote OST with nodsh" && return
10660         local OSTIDX=0
10661
10662         test_mkdir -p $DIR/$tdir
10663         local OST=$(lfs osts | grep ${OSTIDX}": " | \
10664                 awk '{print $2}' | sed -e 's/_UUID$//')
10665
10666         # on the mdt's osc
10667         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
10668         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
10669                         osc.$mdtosc_proc1.prealloc_last_id)
10670         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
10671                         osc.$mdtosc_proc1.prealloc_next_id)
10672
10673         $LFS df -i
10674
10675         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
10676         #define OBD_FAIL_OST_ENOINO              0x229
10677         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
10678         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
10679         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
10680
10681         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
10682
10683         MDSOBJS=$((last_id - next_id))
10684         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
10685
10686         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
10687         echo "OST still has $count kbytes free"
10688
10689         echo "create $MDSOBJS files @next_id..."
10690         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
10691
10692         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
10693                         osc.$mdtosc_proc1.prealloc_last_id)
10694         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
10695                         osc.$mdtosc_proc1.prealloc_next_id)
10696
10697         echo "after creation, last_id=$last_id2, next_id=$next_id2"
10698         $LFS df -i
10699
10700         echo "cleanup..."
10701
10702         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
10703         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
10704
10705         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
10706         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
10707         echo "unlink $MDSOBJS files @$next_id..."
10708         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
10709 }
10710 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
10711
10712 test_221() {
10713         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10714         dd if=`which date` of=$MOUNT/date oflag=sync
10715         chmod +x $MOUNT/date
10716
10717         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
10718         $LCTL set_param fail_loc=0x80001401
10719
10720         $MOUNT/date > /dev/null
10721         rm -f $MOUNT/date
10722 }
10723 run_test 221 "make sure fault and truncate race to not cause OOM"
10724
10725 test_222a () {
10726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10727        rm -rf $DIR/$tdir
10728        test_mkdir -p $DIR/$tdir
10729        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
10730        createmany -o $DIR/$tdir/$tfile 10
10731        cancel_lru_locks mdc
10732        cancel_lru_locks osc
10733        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
10734        $LCTL set_param fail_loc=0x31a
10735        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
10736        $LCTL set_param fail_loc=0
10737        rm -r $DIR/$tdir
10738 }
10739 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
10740
10741 test_222b () {
10742         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10743        rm -rf $DIR/$tdir
10744        test_mkdir -p $DIR/$tdir
10745        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
10746        createmany -o $DIR/$tdir/$tfile 10
10747        cancel_lru_locks mdc
10748        cancel_lru_locks osc
10749        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
10750        $LCTL set_param fail_loc=0x31a
10751        rm -r $DIR/$tdir || "AGL for rmdir failed"
10752        $LCTL set_param fail_loc=0
10753 }
10754 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
10755
10756 test_223 () {
10757         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10758        rm -rf $DIR/$tdir
10759        test_mkdir -p $DIR/$tdir
10760        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
10761        createmany -o $DIR/$tdir/$tfile 10
10762        cancel_lru_locks mdc
10763        cancel_lru_locks osc
10764        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
10765        $LCTL set_param fail_loc=0x31b
10766        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
10767        $LCTL set_param fail_loc=0
10768        rm -r $DIR/$tdir
10769 }
10770 run_test 223 "osc reenqueue if without AGL lock granted ======================="
10771
10772 test_224a() { # LU-1039, MRP-303
10773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10774         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
10775         $LCTL set_param fail_loc=0x508
10776         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
10777         $LCTL set_param fail_loc=0
10778         df $DIR
10779 }
10780 run_test 224a "Don't panic on bulk IO failure"
10781
10782 test_224b() { # LU-1039, MRP-303
10783         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10784         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
10785         cancel_lru_locks osc
10786         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
10787         $LCTL set_param fail_loc=0x515
10788         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
10789         $LCTL set_param fail_loc=0
10790         df $DIR
10791 }
10792 run_test 224b "Don't panic on bulk IO failure"
10793
10794 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
10795 test_225a () {
10796         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10797         if [ -z ${MDSSURVEY} ]; then
10798               skip_env "mds-survey not found" && return
10799         fi
10800
10801         [ $MDSCOUNT -ge 2 ] &&
10802                 skip "skipping now for more than one MDT" && return
10803
10804        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
10805             { skip "Need MDS version at least 2.2.51"; return; }
10806
10807        local mds=$(facet_host $SINGLEMDS)
10808        local target=$(do_nodes $mds 'lctl dl' | \
10809                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
10810
10811        local cmd1="file_count=1000 thrhi=4"
10812        local cmd2="dir_count=2 layer=mdd stripe_count=0"
10813        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
10814        local cmd="$cmd1 $cmd2 $cmd3"
10815
10816        rm -f ${TMP}/mds_survey*
10817        echo + $cmd
10818        eval $cmd || error "mds-survey with zero-stripe failed"
10819        cat ${TMP}/mds_survey*
10820        rm -f ${TMP}/mds_survey*
10821 }
10822 run_test 225a "Metadata survey sanity with zero-stripe"
10823
10824 test_225b () {
10825         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10826
10827         if [ -z ${MDSSURVEY} ]; then
10828               skip_env "mds-survey not found" && return
10829         fi
10830         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
10831             { skip "Need MDS version at least 2.2.51"; return; }
10832
10833         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
10834               skip_env "Need to mount OST to test" && return
10835         fi
10836
10837         [ $MDSCOUNT -ge 2 ] &&
10838                 skip "skipping now for more than one MDT" && return
10839        local mds=$(facet_host $SINGLEMDS)
10840        local target=$(do_nodes $mds 'lctl dl' | \
10841                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
10842
10843        local cmd1="file_count=1000 thrhi=4"
10844        local cmd2="dir_count=2 layer=mdd stripe_count=1"
10845        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
10846        local cmd="$cmd1 $cmd2 $cmd3"
10847
10848        rm -f ${TMP}/mds_survey*
10849        echo + $cmd
10850        eval $cmd || error "mds-survey with stripe_count failed"
10851        cat ${TMP}/mds_survey*
10852        rm -f ${TMP}/mds_survey*
10853 }
10854 run_test 225b "Metadata survey sanity with stripe_count = 1"
10855
10856 mcreate_path2fid () {
10857         local mode=$1
10858         local major=$2
10859         local minor=$3
10860         local name=$4
10861         local desc=$5
10862         local path=$DIR/$tdir/$name
10863         local fid
10864         local rc
10865         local fid_path
10866
10867         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
10868                 error "cannot create $desc"
10869
10870         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
10871         rc=$?
10872         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
10873
10874         fid_path=$($LFS fid2path $MOUNT $fid)
10875         rc=$?
10876         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
10877
10878         [ "$path" == "$fid_path" ] ||
10879                 error "fid2path returned $fid_path, expected $path"
10880
10881         echo "pass with $path and $fid"
10882 }
10883
10884 test_226a () {
10885         rm -rf $DIR/$tdir
10886         mkdir -p $DIR/$tdir
10887
10888         mcreate_path2fid 0010666 0 0 fifo "FIFO"
10889         mcreate_path2fid 0020666 1 3 null "character special file (null)"
10890         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
10891         mcreate_path2fid 0040666 0 0 dir "directory"
10892         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
10893         mcreate_path2fid 0100666 0 0 file "regular file"
10894         mcreate_path2fid 0120666 0 0 link "symbolic link"
10895         mcreate_path2fid 0140666 0 0 sock "socket"
10896 }
10897 run_test 226a "call path2fid and fid2path on files of all type"
10898
10899 test_226b () {
10900         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10901         rm -rf $DIR/$tdir
10902         local MDTIDX=1
10903
10904         mkdir -p $DIR/$tdir
10905         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
10906                 error "create remote directory failed"
10907         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
10908         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
10909                                 "character special file (null)"
10910         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
10911                                 "character special file (no device)"
10912         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
10913         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
10914                                 "block special file (loop)"
10915         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
10916         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
10917         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
10918 }
10919 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
10920
10921 # LU-1299 Executing or running ldd on a truncated executable does not
10922 # cause an out-of-memory condition.
10923 test_227() {
10924         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10925         dd if=`which date` of=$MOUNT/date bs=1k count=1
10926         chmod +x $MOUNT/date
10927
10928         $MOUNT/date > /dev/null
10929         ldd $MOUNT/date > /dev/null
10930         rm -f $MOUNT/date
10931 }
10932 run_test 227 "running truncated executable does not cause OOM"
10933
10934 # LU-1512 try to reuse idle OI blocks
10935 test_228a() {
10936         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10937         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
10938                 skip "non-ldiskfs backend" && return
10939
10940         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10941         local myDIR=$DIR/$tdir
10942
10943         mkdir -p $myDIR
10944         #define OBD_FAIL_SEQ_EXHAUST             0x1002
10945         $LCTL set_param fail_loc=0x80001002
10946         createmany -o $myDIR/t- 10000
10947         $LCTL set_param fail_loc=0
10948         # The guard is current the largest FID holder
10949         touch $myDIR/guard
10950         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
10951                     tr -d '[')
10952         local IDX=$(($SEQ % 64))
10953
10954         do_facet $SINGLEMDS sync
10955         # Make sure journal flushed.
10956         sleep 6
10957         local blk1=$(do_facet $SINGLEMDS \
10958                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
10959                      grep Blockcount | awk '{print $4}')
10960
10961         # Remove old files, some OI blocks will become idle.
10962         unlinkmany $myDIR/t- 10000
10963         # Create new files, idle OI blocks should be reused.
10964         createmany -o $myDIR/t- 2000
10965         do_facet $SINGLEMDS sync
10966         # Make sure journal flushed.
10967         sleep 6
10968         local blk2=$(do_facet $SINGLEMDS \
10969                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
10970                      grep Blockcount | awk '{print $4}')
10971
10972         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
10973 }
10974 run_test 228a "try to reuse idle OI blocks"
10975
10976 test_228b() {
10977         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10978         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
10979                 skip "non-ldiskfs backend" && return
10980
10981         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10982         local myDIR=$DIR/$tdir
10983
10984         mkdir -p $myDIR
10985         #define OBD_FAIL_SEQ_EXHAUST             0x1002
10986         $LCTL set_param fail_loc=0x80001002
10987         createmany -o $myDIR/t- 10000
10988         $LCTL set_param fail_loc=0
10989         # The guard is current the largest FID holder
10990         touch $myDIR/guard
10991         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
10992                     tr -d '[')
10993         local IDX=$(($SEQ % 64))
10994
10995         do_facet $SINGLEMDS sync
10996         # Make sure journal flushed.
10997         sleep 6
10998         local blk1=$(do_facet $SINGLEMDS \
10999                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11000                      grep Blockcount | awk '{print $4}')
11001
11002         # Remove old files, some OI blocks will become idle.
11003         unlinkmany $myDIR/t- 10000
11004
11005         # stop the MDT
11006         stop $SINGLEMDS || error "Fail to stop MDT."
11007         # remount the MDT
11008         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11009
11010         df $MOUNT || error "Fail to df."
11011         # Create new files, idle OI blocks should be reused.
11012         createmany -o $myDIR/t- 2000
11013         do_facet $SINGLEMDS sync
11014         # Make sure journal flushed.
11015         sleep 6
11016         local blk2=$(do_facet $SINGLEMDS \
11017                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11018                      grep Blockcount | awk '{print $4}')
11019
11020         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11021 }
11022 run_test 228b "idle OI blocks can be reused after MDT restart"
11023
11024 #LU-1881
11025 test_228c() {
11026         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11027         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11028                 skip "non-ldiskfs backend" && return
11029
11030         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11031         local myDIR=$DIR/$tdir
11032
11033         mkdir -p $myDIR
11034         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11035         $LCTL set_param fail_loc=0x80001002
11036         # 20000 files can guarantee there are index nodes in the OI file
11037         createmany -o $myDIR/t- 20000
11038         $LCTL set_param fail_loc=0
11039         # The guard is current the largest FID holder
11040         touch $myDIR/guard
11041         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11042                     tr -d '[')
11043         local IDX=$(($SEQ % 64))
11044
11045         do_facet $SINGLEMDS sync
11046         # Make sure journal flushed.
11047         sleep 6
11048         local blk1=$(do_facet $SINGLEMDS \
11049                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11050                      grep Blockcount | awk '{print $4}')
11051
11052         # Remove old files, some OI blocks will become idle.
11053         unlinkmany $myDIR/t- 20000
11054         rm -f $myDIR/guard
11055         # The OI file should become empty now
11056
11057         # Create new files, idle OI blocks should be reused.
11058         createmany -o $myDIR/t- 2000
11059         do_facet $SINGLEMDS sync
11060         # Make sure journal flushed.
11061         sleep 6
11062         local blk2=$(do_facet $SINGLEMDS \
11063                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11064                      grep Blockcount | awk '{print $4}')
11065
11066         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11067 }
11068 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
11069
11070 test_230a() {
11071         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11072         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11073         local MDTIDX=1
11074
11075         mkdir -p $DIR/$tdir/test_230_local
11076         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
11077         [ $mdt_idx -ne 0 ] &&
11078                 error "create local directory on wrong MDT $mdt_idx"
11079
11080         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
11081                         error "create remote directory failed"
11082         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
11083         [ $mdt_idx -ne $MDTIDX ] &&
11084                 error "create remote directory on wrong MDT $mdt_idx"
11085
11086         createmany -o $DIR/$tdir/test_230/t- 10 ||
11087                 error "create files on remote directory failed"
11088         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
11089         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
11090         rm -r $DIR/$tdir || error "unlink remote directory failed"
11091 }
11092 run_test 230a "Create remote directory and files under the remote directory"
11093
11094 test_230b() {
11095         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11096         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11097         local MDTIDX=1
11098         local remote_dir=$DIR/$tdir/remote_dir
11099         local rc=0
11100
11101         mkdir -p $DIR/$tdir
11102         $LFS mkdir -i $MDTIDX $remote_dir ||
11103                 error "create remote directory failed"
11104
11105         $LFS mkdir -i 0 $remote_dir/new_dir &&
11106                 error "nested remote directory create succeed!"
11107
11108         do_facet mds$((MDTIDX + 1)) lctl set_param mdt.*.enable_remote_dir=1
11109         $LFS mkdir -i 0 $remote_dir/new_dir || rc=$?
11110         do_facet mds$((MDTIDX + 1)) lctl set_param mdt.*.enable_remote_dir=0
11111
11112         [ $rc -ne 0 ] &&
11113            error "create remote directory failed after set enable_remote_dir"
11114
11115         rm -rf $remote_dir || error "first unlink remote directory failed"
11116
11117         $RUNAS -G$RUNAS_GID $LFS mkdir -i $MDTIDX $DIR/$tfile &&
11118                                                         error "chown worked"
11119
11120         do_facet mds$MDTIDX lctl set_param \
11121                                 mdt.*.enable_remote_dir_gid=$RUNAS_GID
11122         $LFS mkdir -i $MDTIDX $remote_dir || rc=$?
11123         do_facet mds$MDTIDX lctl set_param mdt.*.enable_remote_dir_gid=0
11124
11125         [ $rc -ne 0 ] &&
11126            error "create remote dir failed after set enable_remote_dir_gid"
11127
11128         rm -r $DIR/$tdir || error "second unlink remote directory failed"
11129 }
11130 run_test 230b "nested remote directory should be failed"
11131
11132 test_231a()
11133 {
11134         # For simplicity this test assumes that max_pages_per_rpc
11135         # is the same across all OSCs
11136         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -1)
11137         local bulk_size=$((max_pages * 4096))
11138
11139         mkdir -p $DIR/$tdir
11140
11141         # clear the OSC stats
11142         $LCTL set_param osc.*.stats=0 &>/dev/null
11143
11144         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
11145         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
11146                 oflag=direct &>/dev/null || error "dd failed"
11147
11148         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
11149         if [ x$nrpcs != "x1" ]; then
11150                 error "found $nrpc ost_write RPCs, not 1 as expected"
11151         fi
11152
11153         # Drop the OSC cache, otherwise we will read from it
11154         cancel_lru_locks osc
11155
11156         # clear the OSC stats
11157         $LCTL set_param osc.*.stats=0 &>/dev/null
11158
11159         # Client reads $bulk_size.
11160         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
11161                 iflag=direct &>/dev/null || error "dd failed"
11162
11163         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
11164         if [ x$nrpcs != "x1" ]; then
11165                 error "found $nrpc ost_read RPCs, not 1 as expected"
11166         fi
11167 }
11168 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
11169
11170 test_231b() {
11171         mkdir -p $DIR/$tdir
11172         local i
11173         for i in {0..1023}; do
11174                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
11175                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
11176                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
11177         done
11178         sync
11179 }
11180 run_test 231b "must not assert on fully utilized OST request buffer"
11181
11182 test_232() {
11183         mkdir -p $DIR/$tdir
11184         #define OBD_FAIL_LDLM_OST_LVB            0x31c
11185         $LCTL set_param fail_loc=0x31c
11186
11187         # ignore dd failure
11188         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
11189
11190         $LCTL set_param fail_loc=0
11191         umount_client $MOUNT || error "umount failed"
11192         mount_client $MOUNT || error "mount failed"
11193 }
11194 run_test 232 "failed lock should not block umount"
11195
11196 test_233() {
11197         local fid=$($LFS path2fid $MOUNT)
11198         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
11199                 error "cannot access $MOUNT using its FID '$fid'"
11200 }
11201 run_test 233 "checking that OBF of the FS root succeeds"
11202
11203 #
11204 # tests that do cleanup/setup should be run at the end
11205 #
11206
11207 test_900() {
11208         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11209         local ls
11210         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
11211         $LCTL set_param fail_loc=0x903
11212         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
11213         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
11214                 echo "clear" > $ls
11215         done
11216         FAIL_ON_ERROR=true cleanup
11217         FAIL_ON_ERROR=true setup
11218 }
11219 run_test 900 "umount should not race with any mgc requeue thread"
11220
11221 complete $SECONDS
11222 check_and_cleanup_lustre
11223 if [ "$I_MOUNTED" != "yes" ]; then
11224         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
11225 fi
11226 exit_status