Whamcloud - gitweb
LU-10041 tests: sanity/51 to cleanup properly
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 8; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: LU-9693 LU-6493 LU-9693 3561 5188
12 ALWAYS_EXCEPT="                42a    42b      42c     45   68b $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # skipped tests: LU-8411 LU-9096 LU-9054
16 ALWAYS_EXCEPT="  407     253     312 $ALWAYS_EXCEPT"
17
18 # Check Grants after these tests
19 GRANT_CHECK_LIST="$GRANT_CHECK_LIST 42a 42b 42c 42d 42e 63a 63b 64a 64b 64c"
20
21 is_sles11()                                             # LU-4341
22 {
23         if [ -r /etc/SuSE-release ]
24         then
25                 local vers=$(grep VERSION /etc/SuSE-release | awk '{print $3}')
26                 local patchlev=$(grep PATCHLEVEL /etc/SuSE-release |
27                         awk '{ print $3 }')
28                 if [ $vers -eq 11 ] && [ $patchlev -ge 3 ]; then
29                         return 0
30                 fi
31         fi
32         return 1
33 }
34
35 if is_sles11; then                                      # LU-4341
36         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 170"
37 fi
38
39 SRCDIR=$(cd $(dirname $0); echo $PWD)
40 export PATH=$PATH:/sbin
41
42 TMP=${TMP:-/tmp}
43
44 CC=${CC:-cc}
45 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
46 CREATETEST=${CREATETEST:-createtest}
47 LFS=${LFS:-lfs}
48 LFIND=${LFIND:-"$LFS find"}
49 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
50 LCTL=${LCTL:-lctl}
51 OPENFILE=${OPENFILE:-openfile}
52 OPENUNLINK=${OPENUNLINK:-openunlink}
53 export MULTIOP=${MULTIOP:-multiop}
54 READS=${READS:-"reads"}
55 MUNLINK=${MUNLINK:-munlink}
56 SOCKETSERVER=${SOCKETSERVER:-socketserver}
57 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
58 MEMHOG=${MEMHOG:-memhog}
59 DIRECTIO=${DIRECTIO:-directio}
60 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
61 STRIPES_PER_OBJ=-1
62 CHECK_GRANT=${CHECK_GRANT:-"yes"}
63 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
64 export PARALLEL=${PARALLEL:-"no"}
65
66 export NAME=${NAME:-local}
67
68 SAVE_PWD=$PWD
69
70 CLEANUP=${CLEANUP:-:}
71 SETUP=${SETUP:-:}
72 TRACE=${TRACE:-""}
73 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
74 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
75 . $LUSTRE/tests/test-framework.sh
76 init_test_env $@
77 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
78 init_logging
79
80 #                                  5          12          (min)"
81 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 300o"
82
83 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
84         # bug number for skipped test: LU-4536 LU-1957
85         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180"
86         #                                               13    (min)"
87         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
88 fi
89
90 FAIL_ON_ERROR=false
91
92 cleanup() {
93         echo -n "cln.."
94         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
95         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
96 }
97 setup() {
98         echo -n "mnt.."
99         load_modules
100         setupall || exit 10
101         echo "done"
102 }
103
104 check_swap_layouts_support()
105 {
106         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
107                 { skip "Does not support layout lock."; return 0; }
108         return 1
109 }
110
111 check_and_setup_lustre
112 DIR=${DIR:-$MOUNT}
113 assert_DIR
114
115 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
116         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
117 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
118
119 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
120 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
121 rm -rf $DIR/[Rdfs][0-9]*
122
123 # $RUNAS_ID may get set incorrectly somewhere else
124 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
125
126 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
127
128 build_test_filter
129
130 if [ "${ONLY}" = "MOUNT" ] ; then
131         echo "Lustre is up, please go on"
132         exit
133 fi
134
135 echo "preparing for tests involving mounts"
136 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
137 touch $EXT2_DEV
138 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
139 echo # add a newline after mke2fs.
140
141 umask 077
142
143 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
144 lctl set_param debug=-1 2> /dev/null || true
145 test_0a() {
146         touch $DIR/$tfile
147         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
148         rm $DIR/$tfile
149         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
150 }
151 run_test 0a "touch; rm ====================="
152
153 test_0b() {
154         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
155         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
156 }
157 run_test 0b "chmod 0755 $DIR ============================="
158
159 test_0c() {
160         $LCTL get_param mdc.*.import | grep "state: FULL" ||
161                 error "import not FULL"
162         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
163                 error "bad target"
164 }
165 run_test 0c "check import proc ============================="
166
167 test_1() {
168         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
169         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
170         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
171         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
172         rmdir $DIR/$tdir/d2
173         rmdir $DIR/$tdir
174         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
175 }
176 run_test 1 "mkdir; remkdir; rmdir =============================="
177
178 test_2() {
179         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
180         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
181         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
182         rm -r $DIR/$tdir
183         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
184 }
185 run_test 2 "mkdir; touch; rmdir; check file ===================="
186
187 test_3() {
188         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
189         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
190         touch $DIR/$tdir/$tfile
191         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
192         rm -r $DIR/$tdir
193         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
194 }
195 run_test 3 "mkdir; touch; rmdir; check dir ====================="
196
197 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
198 test_4() {
199         local MDTIDX=1
200
201         test_mkdir $DIR/$tdir ||
202                 error "Create remote directory failed"
203
204         touch $DIR/$tdir/$tfile ||
205                 error "Create file under remote directory failed"
206
207         rmdir $DIR/$tdir &&
208                 error "Expect error removing in-use dir $DIR/$tdir"
209
210         test -d $DIR/$tdir || error "Remote directory disappeared"
211
212         rm -rf $DIR/$tdir || error "remove remote dir error"
213 }
214 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
215
216 test_5() {
217         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
218         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
219         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
220         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
221         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
222 }
223 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
224
225 test_6a() {
226         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
227         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
228         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
229                 error "$tfile does not have perm 0666 or UID $UID"
230         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
231         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
232                 error "$tfile should be 0666 and owned by UID $UID"
233 }
234 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
235
236 test_6c() {
237         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
238         touch $DIR/$tfile
239         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
240         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
241                 error "$tfile should be owned by UID $RUNAS_ID"
242         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
243         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
244                 error "$tfile should be owned by UID $RUNAS_ID"
245 }
246 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
247
248 test_6e() {
249         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
250         touch $DIR/$tfile
251         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
252         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
253                 error "$tfile should be owned by GID $UID"
254         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
255         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
256                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
257 }
258 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
259
260 test_6g() {
261         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
262         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
263         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
264         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
265         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
266         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
267         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
268                 error "$tdir/d/subdir should be GID $RUNAS_GID"
269         if [[ $MDSCOUNT -gt 1 ]]; then
270                 # check remote dir sgid inherite
271                 $LFS mkdir -i 0 $DIR/$tdir.local ||
272                         error "mkdir $tdir.local failed"
273                 chmod g+s $DIR/$tdir.local ||
274                         error "chmod $tdir.local failed"
275                 chgrp $RUNAS_GID $DIR/$tdir.local ||
276                         error "chgrp $tdir.local failed"
277                 $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
278                         error "mkdir $tdir.remote failed"
279                 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
280                         error "$tdir.remote should be owned by $UID.$RUNAS_ID"
281                 $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
282                         error "$tdir.remote should be mode 02755"
283         fi
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                 test_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         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
388 }
389 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
390
391 test_16() {
392         test_mkdir $DIR/$tdir
393         touch $DIR/$tdir/$tfile
394         rm -rf $DIR/$tdir/$tfile
395         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
396 }
397 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
398
399 test_17a() {
400         test_mkdir -p $DIR/$tdir
401         touch $DIR/$tdir/$tfile
402         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
403         ls -l $DIR/$tdir
404         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
405                 error "$tdir/l-exist not a symlink"
406         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
407                 error "$tdir/l-exist not referencing a file"
408         rm -f $DIR/$tdir/l-exist
409         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
410 }
411 run_test 17a "symlinks: create, remove (real) =================="
412
413 test_17b() {
414         test_mkdir -p $DIR/$tdir
415         ln -s no-such-file $DIR/$tdir/l-dangle
416         ls -l $DIR/$tdir
417         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
418                 error "$tdir/l-dangle not referencing no-such-file"
419         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
420                 error "$tdir/l-dangle not referencing non-existent file"
421         rm -f $DIR/$tdir/l-dangle
422         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
423 }
424 run_test 17b "symlinks: create, remove (dangling) =============="
425
426 test_17c() { # bug 3440 - don't save failed open RPC for replay
427         test_mkdir -p $DIR/$tdir
428         ln -s foo $DIR/$tdir/$tfile
429         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
430 }
431 run_test 17c "symlinks: open dangling (should return error) ===="
432
433 test_17d() {
434         test_mkdir -p $DIR/$tdir
435         ln -s foo $DIR/$tdir/$tfile
436         touch $DIR/$tdir/$tfile || error "creating to new symlink"
437 }
438 run_test 17d "symlinks: create dangling ========================"
439
440 test_17e() {
441         test_mkdir -p $DIR/$tdir
442         local foo=$DIR/$tdir/$tfile
443         ln -s $foo $foo || error "create symlink failed"
444         ls -l $foo || error "ls -l failed"
445         ls $foo && error "ls not failed" || true
446 }
447 run_test 17e "symlinks: create recursive symlink (should return error) ===="
448
449 test_17f() {
450         test_mkdir -p $DIR/$tdir
451         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
452         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
453         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
454         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
455         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
456         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890/aaaaaaaaaa/bbbbbbbbbb/cccccccccc/dddddddddd/eeeeeeeeee/ffffffffff/ $DIR/$tdir/666
457         ls -l  $DIR/$tdir
458 }
459 run_test 17f "symlinks: long and very long symlink name ========================"
460
461 # str_repeat(S, N) generate a string that is string S repeated N times
462 str_repeat() {
463         local s=$1
464         local n=$2
465         local ret=''
466         while [ $((n -= 1)) -ge 0 ]; do
467                 ret=$ret$s
468         done
469         echo $ret
470 }
471
472 # Long symlinks and LU-2241
473 test_17g() {
474         test_mkdir -p $DIR/$tdir
475         local TESTS="59 60 61 4094 4095"
476
477         # Fix for inode size boundary in 2.1.4
478         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
479                 TESTS="4094 4095"
480
481         # Patch not applied to 2.2 or 2.3 branches
482         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
483         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
484                 TESTS="4094 4095"
485
486         # skip long symlink name for rhel6.5.
487         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
488         grep -q '6.5' /etc/redhat-release &>/dev/null &&
489                 TESTS="59 60 61 4062 4063"
490
491         for i in $TESTS; do
492                 local SYMNAME=$(str_repeat 'x' $i)
493                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
494                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
495         done
496 }
497 run_test 17g "symlinks: really long symlink name and inode boundaries"
498
499 test_17h() { #bug 17378
500         remote_mds_nodsh && skip "remote MDS with nodsh" && return
501         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
502         local mdt_idx
503         test_mkdir -p $DIR/$tdir
504         if [[ $MDSCOUNT -gt 1 ]]; then
505                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
506         else
507                 mdt_idx=0
508         fi
509         $SETSTRIPE -c -1 $DIR/$tdir
510 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
511         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
512         touch $DIR/$tdir/$tfile || true
513 }
514 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
515
516 test_17i() { #bug 20018
517         remote_mds_nodsh && skip "remote MDS with nodsh" && return
518         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
519         test_mkdir -c1 $DIR/$tdir
520         local foo=$DIR/$tdir/$tfile
521         local mdt_idx
522         if [[ $MDSCOUNT -gt 1 ]]; then
523                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
524         else
525                 mdt_idx=0
526         fi
527         ln -s $foo $foo || error "create symlink failed"
528 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
529         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
530         ls -l $foo && error "error not detected"
531         return 0
532 }
533 run_test 17i "don't panic on short symlink"
534
535 test_17k() { #bug 22301
536         [[ -z "$(which rsync 2>/dev/null)" ]] &&
537                 skip "no rsync command" && return 0
538         rsync --help | grep -q xattr ||
539                 skip_env "$(rsync --version | head -n1) does not support xattrs"
540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
541         test_mkdir -p $DIR/$tdir
542         test_mkdir -p $DIR/$tdir.new
543         touch $DIR/$tdir/$tfile
544         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
545         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
546                 error "rsync failed with xattrs enabled"
547 }
548 run_test 17k "symlinks: rsync with xattrs enabled ========================="
549
550 test_17l() { # LU-279
551         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
552                 skip "no getfattr command" && return 0
553         test_mkdir -p $DIR/$tdir
554         touch $DIR/$tdir/$tfile
555         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
556         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
557                 # -h to not follow symlinks. -m '' to list all the xattrs.
558                 # grep to remove first line: '# file: $path'.
559                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
560                 do
561                         lgetxattr_size_check $path $xattr ||
562                                 error "lgetxattr_size_check $path $xattr failed"
563                 done
564         done
565 }
566 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
567
568 # LU-1540
569 test_17m() {
570         local short_sym="0123456789"
571         local WDIR=$DIR/${tdir}m
572         local i
573
574         remote_mds_nodsh && skip "remote MDS with nodsh" && return
575         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
576         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
577                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
578
579         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
580                 skip "ldiskfs only test" && return 0
581
582         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
583
584         test_mkdir -p $WDIR
585         long_sym=$short_sym
586         # create a long symlink file
587         for ((i = 0; i < 4; ++i)); do
588                 long_sym=${long_sym}${long_sym}
589         done
590
591         echo "create 512 short and long symlink files under $WDIR"
592         for ((i = 0; i < 256; ++i)); do
593                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
594                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
595         done
596
597         echo "erase them"
598         rm -f $WDIR/*
599         sync
600         wait_delete_completed
601
602         echo "recreate the 512 symlink files with a shorter string"
603         for ((i = 0; i < 512; ++i)); do
604                 # rewrite the symlink file with a shorter string
605                 ln -sf ${long_sym} $WDIR/long-$i || error "long_sym failed"
606                 ln -sf ${short_sym} $WDIR/short-$i || error "short_sym failed"
607         done
608
609         local mds_index=$(($($LFS getstripe -M $WDIR) + 1))
610         local devname=$(mdsdevname $mds_index)
611
612         echo "stop and checking mds${mds_index}:"
613         # e2fsck should not return error
614         stop mds${mds_index}
615         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
616         rc=$?
617
618         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
619         df $MOUNT > /dev/null 2>&1
620         [ $rc -eq 0 ] ||
621                 error "e2fsck detected error for short/long symlink: rc=$rc"
622 }
623 run_test 17m "run e2fsck against MDT which contains short/long symlink"
624
625 check_fs_consistency_17n() {
626         local mdt_index
627         local rc=0
628
629         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
630         # so it only check MDT1/MDT2 instead of all of MDTs.
631         for mdt_index in 1 2; do
632                 local devname=$(mdsdevname $mdt_index)
633                 # e2fsck should not return error
634                 stop mds${mdt_index}
635                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
636                         rc=$((rc + $?))
637
638                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
639                         error "mount mds$mdt_index failed"
640                 df $MOUNT > /dev/null 2>&1
641         done
642         return $rc
643 }
644
645 test_17n() {
646         local i
647
648         remote_mds_nodsh && skip "remote MDS with nodsh" && return
649         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
650         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
651                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
652
653         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
654                 skip "ldiskfs only test" && return 0
655
656         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
657
658         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
659
660         test_mkdir $DIR/$tdir
661         for ((i=0; i<10; i++)); do
662                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
663                         error "create remote dir error $i"
664                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
665                         error "create files under remote dir failed $i"
666         done
667
668         check_fs_consistency_17n ||
669                 error "e2fsck report error after create files under remote dir"
670
671         for ((i = 0; i < 10; i++)); do
672                 rm -rf $DIR/$tdir/remote_dir_${i} ||
673                         error "destroy remote dir error $i"
674         done
675
676         check_fs_consistency_17n ||
677                 error "e2fsck report error after unlink files under remote dir"
678
679         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
680                 skip "lustre < 2.4.50 does not support migrate mv " && return
681
682         for ((i = 0; i < 10; i++)); do
683                 mkdir -p $DIR/$tdir/remote_dir_${i}
684                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
685                         error "create files under remote dir failed $i"
686                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
687                         error "migrate remote dir error $i"
688         done
689         check_fs_consistency_17n || error "e2fsck report error after migration"
690
691         for ((i = 0; i < 10; i++)); do
692                 rm -rf $DIR/$tdir/remote_dir_${i} ||
693                         error "destroy remote dir error $i"
694         done
695
696         check_fs_consistency_17n || error "e2fsck report error after unlink"
697 }
698 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
699
700 test_17o() {
701         remote_mds_nodsh && skip "remote MDS with nodsh" && return
702         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
703                 skip "Need MDS version at least 2.3.64" && return
704
705         local WDIR=$DIR/${tdir}o
706         local mdt_index
707         local rc=0
708
709         test_mkdir -p $WDIR
710         touch $WDIR/$tfile
711         mdt_index=$($LFS getstripe -M $WDIR/$tfile)
712         mdt_index=$((mdt_index+1))
713
714         cancel_lru_locks mdc
715         #fail mds will wait the failover finish then set
716         #following fail_loc to avoid interfer the recovery process.
717         fail mds${mdt_index}
718
719         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
720         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
721         ls -l $WDIR/$tfile && rc=1
722         do_facet mds${mdt_index} lctl set_param fail_loc=0
723         [[ $rc -ne 0 ]] && error "stat file should fail"
724         true
725 }
726 run_test 17o "stat file with incompat LMA feature"
727
728 test_18() {
729         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
730         ls $DIR || error "Failed to ls $DIR: $?"
731 }
732 run_test 18 "touch .../f ; ls ... =============================="
733
734 test_19a() {
735         touch $DIR/$tfile
736         ls -l $DIR
737         rm $DIR/$tfile
738         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
739 }
740 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
741
742 test_19b() {
743         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
744 }
745 run_test 19b "ls -l .../f19 (should return error) =============="
746
747 test_19c() {
748         [ $RUNAS_ID -eq $UID ] &&
749                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
750         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
751 }
752 run_test 19c "$RUNAS touch .../f19 (should return error) =="
753
754 test_19d() {
755         cat $DIR/f19 && error || true
756 }
757 run_test 19d "cat .../f19 (should return error) =============="
758
759 test_20() {
760         touch $DIR/$tfile
761         rm $DIR/$tfile
762         touch $DIR/$tfile
763         rm $DIR/$tfile
764         touch $DIR/$tfile
765         rm $DIR/$tfile
766         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
767 }
768 run_test 20 "touch .../f ; ls -l ... ==========================="
769
770 test_21() {
771         test_mkdir -p $DIR/$tdir
772         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
773         ln -s dangle $DIR/$tdir/link
774         echo foo >> $DIR/$tdir/link
775         cat $DIR/$tdir/dangle
776         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
777         $CHECKSTAT -f -t file $DIR/$tdir/link ||
778                 error "$tdir/link not linked to a file"
779 }
780 run_test 21 "write to dangling link ============================"
781
782 test_22() {
783         WDIR=$DIR/$tdir
784         test_mkdir -p $DIR/$tdir
785         chown $RUNAS_ID:$RUNAS_GID $WDIR
786         (cd $WDIR || error "cd $WDIR failed";
787         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
788         $RUNAS tar xf -)
789         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
790         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
791         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
792 }
793 run_test 22 "unpack tar archive as non-root user ==============="
794
795 # was test_23
796 test_23a() {
797         test_mkdir -p $DIR/$tdir
798         local file=$DIR/$tdir/$tfile
799
800         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
801         openfile -f O_CREAT:O_EXCL $file &&
802                 error "$file recreate succeeded" || true
803 }
804 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
805
806 test_23b() { # bug 18988
807         test_mkdir -p $DIR/$tdir
808         local file=$DIR/$tdir/$tfile
809
810         rm -f $file
811         echo foo > $file || error "write filed"
812         echo bar >> $file || error "append filed"
813         $CHECKSTAT -s 8 $file || error "wrong size"
814         rm $file
815 }
816 run_test 23b "O_APPEND check =========================="
817
818 # rename sanity
819 test_24a() {
820         echo '-- same directory rename'
821         test_mkdir $DIR/$tdir
822         touch $DIR/$tdir/$tfile.1
823         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
824         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
825 }
826 run_test 24a "rename file to non-existent target"
827
828 test_24b() {
829         test_mkdir $DIR/$tdir
830         touch $DIR/$tdir/$tfile.{1,2}
831         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
832         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
833         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
834 }
835 run_test 24b "rename file to existing target"
836
837 test_24c() {
838         test_mkdir $DIR/$tdir
839         test_mkdir $DIR/$tdir/d$testnum.1
840         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
841         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
842         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
843 }
844 run_test 24c "rename directory to non-existent target"
845
846 test_24d() {
847         test_mkdir -c1 $DIR/$tdir
848         test_mkdir -c1 $DIR/$tdir/d$testnum.1
849         test_mkdir -c1 $DIR/$tdir/d$testnum.2
850         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
851         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
852         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
853 }
854 run_test 24d "rename directory to existing target"
855
856 test_24e() {
857         echo '-- cross directory renames --'
858         test_mkdir $DIR/R5a
859         test_mkdir $DIR/R5b
860         touch $DIR/R5a/f
861         mv $DIR/R5a/f $DIR/R5b/g
862         $CHECKSTAT -a $DIR/R5a/f || error
863         $CHECKSTAT -t file $DIR/R5b/g || error
864 }
865 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
866
867 test_24f() {
868         test_mkdir $DIR/R6a
869         test_mkdir $DIR/R6b
870         touch $DIR/R6a/f $DIR/R6b/g
871         mv $DIR/R6a/f $DIR/R6b/g
872         $CHECKSTAT -a $DIR/R6a/f || error
873         $CHECKSTAT -t file $DIR/R6b/g || error
874 }
875 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
876
877 test_24g() {
878         test_mkdir $DIR/R7a
879         test_mkdir $DIR/R7b
880         test_mkdir $DIR/R7a/d
881         mv $DIR/R7a/d $DIR/R7b/e
882         $CHECKSTAT -a $DIR/R7a/d || error
883         $CHECKSTAT -t dir $DIR/R7b/e || error
884 }
885 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
886
887 test_24h() {
888         test_mkdir -c1 $DIR/R8a
889         test_mkdir -c1 $DIR/R8b
890         test_mkdir -c1 $DIR/R8a/d
891         test_mkdir -c1 $DIR/R8b/e
892         mrename $DIR/R8a/d $DIR/R8b/e
893         $CHECKSTAT -a $DIR/R8a/d || error
894         $CHECKSTAT -t dir $DIR/R8b/e || error
895 }
896 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
897
898 test_24i() {
899         echo "-- rename error cases"
900         test_mkdir $DIR/R9
901         test_mkdir $DIR/R9/a
902         touch $DIR/R9/f
903         mrename $DIR/R9/f $DIR/R9/a
904         $CHECKSTAT -t file $DIR/R9/f || error
905         $CHECKSTAT -t dir  $DIR/R9/a || error
906         $CHECKSTAT -a $DIR/R9/a/f || error
907 }
908 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
909
910 test_24j() {
911         test_mkdir $DIR/R10
912         mrename $DIR/R10/f $DIR/R10/g
913         $CHECKSTAT -t dir $DIR/R10 || error
914         $CHECKSTAT -a $DIR/R10/f || error
915         $CHECKSTAT -a $DIR/R10/g || error
916 }
917 run_test 24j "source does not exist ============================"
918
919 test_24k() {
920         test_mkdir $DIR/R11a
921         test_mkdir $DIR/R11a/d
922         touch $DIR/R11a/f
923         mv $DIR/R11a/f $DIR/R11a/d
924         $CHECKSTAT -a $DIR/R11a/f || error
925         $CHECKSTAT -t file $DIR/R11a/d/f || error
926 }
927 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
928
929 # bug 2429 - rename foo foo foo creates invalid file
930 test_24l() {
931         f="$DIR/f24l"
932         $MULTIOP $f OcNs || error
933 }
934 run_test 24l "Renaming a file to itself ========================"
935
936 test_24m() {
937         f="$DIR/f24m"
938         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
939         # on ext3 this does not remove either the source or target files
940         # though the "expected" operation would be to remove the source
941         $CHECKSTAT -t file ${f} || error "${f} missing"
942         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
943 }
944 run_test 24m "Renaming a file to a hard link to itself ========="
945
946 test_24n() {
947     f="$DIR/f24n"
948     # this stats the old file after it was renamed, so it should fail
949     touch ${f}
950     $CHECKSTAT ${f}
951     mv ${f} ${f}.rename
952     $CHECKSTAT ${f}.rename
953     $CHECKSTAT -a ${f}
954 }
955 run_test 24n "Statting the old file after renaming (Posix rename 2)"
956
957 test_24o() {
958         test_mkdir -p $DIR/d24o
959         rename_many -s random -v -n 10 $DIR/d24o
960 }
961 run_test 24o "rename of files during htree split ==============="
962
963 test_24p() {
964         test_mkdir $DIR/R12a
965         test_mkdir $DIR/R12b
966         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
967         mrename $DIR/R12a $DIR/R12b
968         $CHECKSTAT -a $DIR/R12a || error
969         $CHECKSTAT -t dir $DIR/R12b || error
970         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
971         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
972 }
973 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
974
975 cleanup_multiop_pause() {
976         trap 0
977         kill -USR1 $MULTIPID
978 }
979
980 test_24q() {
981         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
982         test_mkdir $DIR/R13a
983         test_mkdir $DIR/R13b
984         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
985         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
986         MULTIPID=$!
987
988         trap cleanup_multiop_pause EXIT
989         mrename $DIR/R13a $DIR/R13b
990         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
991         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
992         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
993         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
994         cleanup_multiop_pause
995         wait $MULTIPID || error "multiop close failed"
996 }
997 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
998
999 test_24r() { #bug 3789
1000         test_mkdir $DIR/R14a
1001         test_mkdir $DIR/R14a/b
1002         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1003         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1004         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1005 }
1006 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1007
1008 test_24s() {
1009         test_mkdir $DIR/R15a
1010         test_mkdir $DIR/R15a/b
1011         test_mkdir $DIR/R15a/b/c
1012         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1013         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1014         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1015 }
1016 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1017 test_24t() {
1018         test_mkdir $DIR/R16a
1019         test_mkdir $DIR/R16a/b
1020         test_mkdir $DIR/R16a/b/c
1021         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1022         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1023         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1024 }
1025 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1026
1027 test_24u() { # bug12192
1028         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1029         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1030 }
1031 run_test 24u "create stripe file"
1032
1033 page_size() {
1034         local size
1035         size=$(getconf PAGE_SIZE 2>/dev/null)
1036         echo -n ${size:-4096}
1037 }
1038
1039 simple_cleanup_common() {
1040         local rc=0
1041         trap 0
1042         [ -z "$DIR" -o -z "$tdir" ] && return 0
1043
1044         local start=$SECONDS
1045         rm -rf $DIR/$tdir
1046         rc=$?
1047         wait_delete_completed
1048         echo "cleanup time $((SECONDS - start))"
1049         return $rc
1050 }
1051
1052 max_pages_per_rpc() {
1053         local mdtname="$(printf "MDT%04x" ${1:-0})"
1054         $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
1055 }
1056
1057 test_24v() {
1058         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1059         local nrfiles=${COUNT:-100000}
1060         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1061         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && nrfiles=${COUNT:-10000}
1062
1063         local fname="$DIR/$tdir/$tfile"
1064         test_mkdir "$(dirname $fname)"
1065         # assume MDT0000 has the fewest inodes
1066         local stripes=$($LFS getdirstripe -c $(dirname $fname))
1067         local free_inodes=$(($(mdt_free_inodes 0) * stripes))
1068         [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
1069
1070         trap simple_cleanup_common EXIT
1071
1072         createmany -m "$fname" $nrfiles
1073
1074         cancel_lru_locks mdc
1075         lctl set_param mdc.*.stats clear
1076
1077         # was previously test_24D: LU-6101
1078         # readdir() returns correct number of entries after cursor reload
1079         local num_ls=$(ls $DIR/$tdir | wc -l)
1080         local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
1081         local num_all=$(ls -a $DIR/$tdir | wc -l)
1082         if [ $num_ls -ne $nrfiles -o $num_uniq -ne $nrfiles -o \
1083              $num_all -ne $((nrfiles + 2)) ]; then
1084                 error "Expected $nrfiles files, got $num_ls " \
1085                         "($num_uniq unique $num_all .&..)"
1086         fi
1087         # LU-5 large readdir
1088         # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
1089         #               N bytes for name (len($nrfiles) rounded to 8 bytes) +
1090         #               8 bytes for luda_type (4 bytes rounded to 8 bytes)
1091         # take into account of overhead in lu_dirpage header and end mark in
1092         # each page, plus one in rpc_num calculation.
1093         local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
1094         local page_entries=$((($(page_size) - 24) / dirent_size))
1095         local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
1096         local rpc_pages=$(max_pages_per_rpc $mdt_idx)
1097         local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
1098         local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
1099         echo "readpages: $mds_readpage rpc_max: $rpc_max"
1100         (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
1101                 error "large readdir doesn't take effect: " \
1102                       "$mds_readpage should be about $rpc_max"
1103
1104         simple_cleanup_common
1105 }
1106 run_test 24v "list large directory (test hash collision, b=17560)"
1107
1108 test_24w() { # bug21506
1109         SZ1=234852
1110         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1111         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1112         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1113         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1114         [[ "$SZ1" -eq "$SZ2" ]] ||
1115                 error "Error reading at the end of the file $tfile"
1116 }
1117 run_test 24w "Reading a file larger than 4Gb"
1118
1119 test_24x() {
1120         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1121
1122         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1123                 skip "Need MDS version at least 2.7.56" && return
1124
1125         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1126         local MDTIDX=1
1127         local remote_dir=$DIR/$tdir/remote_dir
1128
1129         test_mkdir -p $DIR/$tdir
1130         $LFS mkdir -i $MDTIDX $remote_dir ||
1131                 error "create remote directory failed"
1132
1133         test_mkdir -p $DIR/$tdir/src_dir
1134         touch $DIR/$tdir/src_file
1135         test_mkdir -p $remote_dir/tgt_dir
1136         touch $remote_dir/tgt_file
1137
1138         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1139                 error "rename dir cross MDT failed!"
1140
1141         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1142                 error "rename file cross MDT failed!"
1143
1144         touch $DIR/$tdir/ln_file
1145         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1146                 error "ln file cross MDT failed"
1147
1148         rm -rf $DIR/$tdir || error "Can not delete directories"
1149 }
1150 run_test 24x "cross MDT rename/link"
1151
1152 test_24y() {
1153         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1154         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1155         local MDTIDX=1
1156         local remote_dir=$DIR/$tdir/remote_dir
1157
1158         test_mkdir -p $DIR/$tdir
1159         $LFS mkdir -i $MDTIDX $remote_dir ||
1160                    error "create remote directory failed"
1161
1162         test_mkdir -p $remote_dir/src_dir
1163         touch $remote_dir/src_file
1164         test_mkdir -p $remote_dir/tgt_dir
1165         touch $remote_dir/tgt_file
1166
1167         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1168                 error "rename subdir in the same remote dir failed!"
1169
1170         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1171                 error "rename files in the same remote dir failed!"
1172
1173         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1174                 error "link files in the same remote dir failed!"
1175
1176         rm -rf $DIR/$tdir || error "Can not delete directories"
1177 }
1178 run_test 24y "rename/link on the same dir should succeed"
1179
1180 test_24A() { # LU-3182
1181         local NFILES=5000
1182
1183         rm -rf $DIR/$tdir
1184         test_mkdir -p $DIR/$tdir
1185         trap simple_cleanup_common EXIT
1186         createmany -m $DIR/$tdir/$tfile $NFILES
1187         local t=$(ls $DIR/$tdir | wc -l)
1188         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1189         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1190         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1191                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1192         fi
1193
1194         simple_cleanup_common || error "Can not delete directories"
1195 }
1196 run_test 24A "readdir() returns correct number of entries."
1197
1198 test_24B() { # LU-4805
1199         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1200         local count
1201
1202         test_mkdir $DIR/$tdir
1203         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1204                 error "create striped dir failed"
1205
1206         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1207         [ $count -eq 2 ] || error "Expected 2, got $count"
1208
1209         touch $DIR/$tdir/striped_dir/a
1210
1211         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1212         [ $count -eq 3 ] || error "Expected 3, got $count"
1213
1214         touch $DIR/$tdir/striped_dir/.f
1215
1216         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1217         [ $count -eq 4 ] || error "Expected 4, got $count"
1218
1219         rm -rf $DIR/$tdir || error "Can not delete directories"
1220 }
1221 run_test 24B "readdir for striped dir return correct number of entries"
1222
1223 test_24C() {
1224         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1225
1226         mkdir $DIR/$tdir
1227         mkdir $DIR/$tdir/d0
1228         mkdir $DIR/$tdir/d1
1229
1230         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1231                 error "create striped dir failed"
1232
1233         cd $DIR/$tdir/d0/striped_dir
1234
1235         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1236         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1237         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1238
1239         [ "$d0_ino" = "$parent_ino" ] ||
1240                 error ".. wrong, expect $d0_ino, get $parent_ino"
1241
1242         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1243                 error "mv striped dir failed"
1244
1245         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1246
1247         [ "$d1_ino" = "$parent_ino" ] ||
1248                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1249 }
1250 run_test 24C "check .. in striped dir"
1251
1252 test_24E() {
1253         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1254         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1255
1256         mkdir -p $DIR/$tdir
1257         mkdir $DIR/$tdir/src_dir
1258         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1259                 error "create remote source failed"
1260
1261         touch $DIR/$tdir/src_dir/src_child/a
1262
1263         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1264                 error "create remote target dir failed"
1265
1266         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1267                 error "create remote target child failed"
1268
1269         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1270                 error "rename dir cross MDT failed!"
1271
1272         find $DIR/$tdir
1273
1274         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1275                 error "src_child still exists after rename"
1276
1277         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1278                 error "missing file(a) after rename"
1279
1280         rm -rf $DIR/$tdir || error "Can not delete directories"
1281 }
1282 run_test 24E "cross MDT rename/link"
1283
1284 test_25a() {
1285         echo '== symlink sanity ============================================='
1286
1287         test_mkdir $DIR/d25
1288         ln -s d25 $DIR/s25
1289         touch $DIR/s25/foo || error
1290 }
1291 run_test 25a "create file in symlinked directory ==============="
1292
1293 test_25b() {
1294         [ ! -d $DIR/d25 ] && test_25a
1295         $CHECKSTAT -t file $DIR/s25/foo || error
1296 }
1297 run_test 25b "lookup file in symlinked directory ==============="
1298
1299 test_26a() {
1300         test_mkdir $DIR/d26
1301         test_mkdir $DIR/d26/d26-2
1302         ln -s d26/d26-2 $DIR/s26
1303         touch $DIR/s26/foo || error
1304 }
1305 run_test 26a "multiple component symlink ======================="
1306
1307 test_26b() {
1308         test_mkdir -p $DIR/d26b/d26-2
1309         ln -s d26b/d26-2/foo $DIR/s26-2
1310         touch $DIR/s26-2 || error
1311 }
1312 run_test 26b "multiple component symlink at end of lookup ======"
1313
1314 test_26c() {
1315         test_mkdir $DIR/d26.2
1316         touch $DIR/d26.2/foo
1317         ln -s d26.2 $DIR/s26.2-1
1318         ln -s s26.2-1 $DIR/s26.2-2
1319         ln -s s26.2-2 $DIR/s26.2-3
1320         chmod 0666 $DIR/s26.2-3/foo
1321 }
1322 run_test 26c "chain of symlinks ================================"
1323
1324 # recursive symlinks (bug 439)
1325 test_26d() {
1326         ln -s d26-3/foo $DIR/d26-3
1327 }
1328 run_test 26d "create multiple component recursive symlink ======"
1329
1330 test_26e() {
1331         [ ! -h $DIR/d26-3 ] && test_26d
1332         rm $DIR/d26-3
1333 }
1334 run_test 26e "unlink multiple component recursive symlink ======"
1335
1336 # recursive symlinks (bug 7022)
1337 test_26f() {
1338         test_mkdir -p $DIR/$tdir
1339         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1340         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1341         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1342         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1343         cd $tfile                || error "cd $tfile failed"
1344         ln -s .. dotdot          || error "ln dotdot failed"
1345         ln -s dotdot/lndir lndir || error "ln lndir failed"
1346         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1347         output=`ls $tfile/$tfile/lndir/bar1`
1348         [ "$output" = bar1 ] && error "unexpected output"
1349         rm -r $tfile             || error "rm $tfile failed"
1350         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1351 }
1352 run_test 26f "rm -r of a directory which has recursive symlink"
1353
1354 test_27a() {
1355         test_mkdir -p $DIR/d27 || error "mkdir failed"
1356         $LFS getstripe $DIR/d27
1357         $LFS setstripe -c 1 $DIR/d27/f0 || error "setstripe failed"
1358         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1359         cp /etc/hosts $DIR/d27/f0 || error
1360 }
1361 run_test 27a "one stripe file"
1362
1363 test_27b() {
1364         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1365         test_mkdir -p $DIR/d27
1366         $LFS setstripe -c 2 $DIR/d27/f01 || error "setstripe failed"
1367         $LFS getstripe -c $DIR/d27/f01
1368         [ $($LFS getstripe -c $DIR/d27/f01) -eq 2 ] ||
1369                 error "two-stripe file doesn't have two stripes"
1370
1371         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1372 }
1373 run_test 27b "create and write to two stripe file"
1374
1375 test_27d() {
1376         test_mkdir -p $DIR/d27
1377         $LFS setstripe -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1378         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1379         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1380 }
1381 run_test 27d "create file with default settings"
1382
1383 test_27e() {
1384         # LU-5839 adds check for existed layout before setting it
1385         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1386                 skip "Need MDS version at least 2.7.56" && return
1387         test_mkdir -p $DIR/d27
1388         $LFS setstripe -c 2 $DIR/d27/f12 || error "setstripe failed"
1389         $LFS setstripe -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1390         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1391 }
1392 run_test 27e "setstripe existing file (should return error)"
1393
1394 test_27f() {
1395         test_mkdir $DIR/$tdir
1396         $LFS setstripe -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1397                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1398         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1399                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1400         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1401         $LFS getstripe $DIR/$tdir/$tfile || error "$LFS getstripe failed"
1402 }
1403 run_test 27f "setstripe with bad stripe size (should return error)"
1404
1405 test_27g() {
1406         test_mkdir -p $DIR/d27
1407         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1408         $LFS getstripe $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1409                 error "$DIR/d27/fnone has object"
1410 }
1411 run_test 27g "$LFS getstripe with no objects"
1412
1413 test_27i() {
1414         test_mkdir $DIR/$tdir
1415         touch $DIR/$tdir/$tfile || error "touch failed"
1416         [[ $($LFS getstripe -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1417                 error "missing objects"
1418 }
1419 run_test 27i "$LFS getstripe with some objects"
1420
1421 test_27j() {
1422         test_mkdir -p $DIR/d27
1423         $LFS setstripe -i $OSTCOUNT $DIR/d27/f27j &&
1424                 error "setstripe failed" || true
1425 }
1426 run_test 27j "setstripe with bad stripe offset (should return error)"
1427
1428 test_27k() { # bug 2844
1429         test_mkdir -p $DIR/d27
1430         FILE=$DIR/d27/f27k
1431         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1432         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1433         $LFS setstripe -S 67108864 $FILE || error "setstripe failed"
1434         BLKSIZE=$(stat $FILE | awk '/IO Block:/ { print $7 }')
1435         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1436         dd if=/dev/zero of=$FILE bs=4k count=1
1437         BLKSIZE=$(stat $FILE | awk '/IO Block:/ { print $7 }')
1438         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1439 }
1440 run_test 27k "limit i_blksize for broken user apps"
1441
1442 test_27l() {
1443         test_mkdir -p $DIR/d27
1444         mcreate $DIR/f27l || error "creating file"
1445         $RUNAS $SETSTRIPE -c 1 $DIR/f27l &&
1446                 error "setstripe should have failed" || true
1447 }
1448 run_test 27l "check setstripe permissions (should return error)"
1449
1450 test_27m() {
1451         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1452
1453         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1454                    head -n1)
1455         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1456                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1457                 return
1458         fi
1459         trap simple_cleanup_common EXIT
1460         test_mkdir -p $DIR/$tdir
1461         $LFS setstripe -i 0 -c 1 $DIR/$tdir/f27m_1
1462         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1463                 error "dd should fill OST0"
1464         i=2
1465         while $LFS setstripe -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1466                 i=$((i + 1))
1467                 [ $i -gt 256 ] && break
1468         done
1469         i=$((i + 1))
1470         touch $DIR/$tdir/f27m_$i
1471         [ $($LFS getstripe $DIR/$tdir/f27m_$i | grep -A 10 obdidx |
1472             awk '{print $1}' | grep -w "0") ] &&
1473                 error "OST0 was full but new created file still use it"
1474         i=$((i + 1))
1475         touch $DIR/$tdir/f27m_$i
1476         [ $($LFS getstripe $DIR/$tdir/f27m_$i | grep -A 10 obdidx |
1477             awk '{print $1}'| grep -w "0") ] &&
1478                 error "OST0 was full but new created file still use it"
1479         simple_cleanup_common
1480 }
1481 run_test 27m "create file while OST0 was full"
1482
1483 sleep_maxage() {
1484         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
1485                       head -n 1 | awk '{print $1 * 2}')
1486         sleep $DELAY
1487 }
1488
1489 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1490 # if the OST isn't full anymore.
1491 reset_enospc() {
1492         local OSTIDX=${1:-""}
1493
1494         local list=$(comma_list $(osts_nodes))
1495         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1496
1497         do_nodes $list lctl set_param fail_loc=0
1498         sync    # initiate all OST_DESTROYs from MDS to OST
1499         sleep_maxage
1500 }
1501
1502 exhaust_precreations() {
1503         local OSTIDX=$1
1504         local FAILLOC=$2
1505         local FAILIDX=${3:-$OSTIDX}
1506         local ofacet=ost$((OSTIDX + 1))
1507
1508         test_mkdir -p -c1 $DIR/$tdir
1509         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1510         local mfacet=mds$((mdtidx + 1))
1511         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1512
1513         local OST=$(ostname_from_index $OSTIDX)
1514
1515         # on the mdt's osc
1516         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1517         local last_id=$(do_facet $mfacet lctl get_param -n \
1518                         osc.$mdtosc_proc1.prealloc_last_id)
1519         local next_id=$(do_facet $mfacet lctl get_param -n \
1520                         osc.$mdtosc_proc1.prealloc_next_id)
1521
1522         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1523         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1524
1525         test_mkdir -p $DIR/$tdir/${OST}
1526         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1527 #define OBD_FAIL_OST_ENOSPC              0x215
1528         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1529         echo "Creating to objid $last_id on ost $OST..."
1530         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1531         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1532         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1533         sleep_maxage
1534 }
1535
1536 exhaust_all_precreations() {
1537         local i
1538         for (( i=0; i < OSTCOUNT; i++ )) ; do
1539                 exhaust_precreations $i $1 -1
1540         done
1541 }
1542
1543 test_27n() {
1544         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1546         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1547         remote_ost_nodsh && skip "remote OST with nodsh" && return
1548
1549         reset_enospc
1550         rm -f $DIR/$tdir/$tfile
1551         exhaust_precreations 0 0x80000215
1552         $LFS setstripe -c -1 $DIR/$tdir
1553         touch $DIR/$tdir/$tfile || error
1554         $LFS getstripe $DIR/$tdir/$tfile
1555         reset_enospc
1556 }
1557 run_test 27n "create file with some full OSTs"
1558
1559 test_27o() {
1560         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1561         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1562         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1563         remote_ost_nodsh && skip "remote OST with nodsh" && return
1564
1565         reset_enospc
1566         rm -f $DIR/$tdir/$tfile
1567         exhaust_all_precreations 0x215
1568
1569         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1570
1571         reset_enospc
1572         rm -rf $DIR/$tdir/*
1573 }
1574 run_test 27o "create file with all full OSTs (should error)"
1575
1576 test_27p() {
1577         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1578         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1579         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1580         remote_ost_nodsh && skip "remote OST with nodsh" && return
1581
1582         reset_enospc
1583         rm -f $DIR/$tdir/$tfile
1584         test_mkdir -p $DIR/$tdir
1585
1586         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1587         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1588         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1589
1590         exhaust_precreations 0 0x80000215
1591         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1592         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1593         $LFS getstripe $DIR/$tdir/$tfile
1594
1595         reset_enospc
1596 }
1597 run_test 27p "append to a truncated file with some full OSTs"
1598
1599 test_27q() {
1600         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1601         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1602         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1603         remote_ost_nodsh && skip "remote OST with nodsh" && return
1604
1605         reset_enospc
1606         rm -f $DIR/$tdir/$tfile
1607
1608         test_mkdir -p $DIR/$tdir
1609         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1610         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||
1611                 error "truncate $DIR/$tdir/$tfile failed"
1612         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1613
1614         exhaust_all_precreations 0x215
1615
1616         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1617         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1618
1619         reset_enospc
1620 }
1621 run_test 27q "append to truncated file with all OSTs full (should error)"
1622
1623 test_27r() {
1624         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1625         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1626         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1627         remote_ost_nodsh && skip "remote OST with nodsh" && return
1628
1629         reset_enospc
1630         rm -f $DIR/$tdir/$tfile
1631         exhaust_precreations 0 0x80000215
1632
1633         $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile # && error
1634
1635         reset_enospc
1636 }
1637 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1638
1639 test_27s() { # bug 10725
1640         test_mkdir -p $DIR/$tdir
1641         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1642         local stripe_count=0
1643         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1644         $LFS setstripe -S $stripe_size -c $stripe_count $DIR/$tdir &&
1645                 error "stripe width >= 2^32 succeeded" || true
1646
1647 }
1648 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1649
1650 test_27t() { # bug 10864
1651         WDIR=$(pwd)
1652         WLFS=$(which lfs)
1653         cd $DIR
1654         touch $tfile
1655         $WLFS getstripe $tfile
1656         cd $WDIR
1657 }
1658 run_test 27t "check that utils parse path correctly"
1659
1660 test_27u() { # bug 4900
1661         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1662         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1663         local index
1664         local list=$(comma_list $(mdts_nodes))
1665
1666 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1667         do_nodes $list $LCTL set_param fail_loc=0x139
1668         test_mkdir -p $DIR/$tdir
1669         trap simple_cleanup_common EXIT
1670         createmany -o $DIR/$tdir/t- 1000
1671         do_nodes $list $LCTL set_param fail_loc=0
1672
1673         TLOG=$TMP/$tfile.getstripe
1674         $LFS getstripe $DIR/$tdir > $TLOG
1675         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1676         unlinkmany $DIR/$tdir/t- 1000
1677         trap 0
1678         [[ $OBJS -gt 0 ]] &&
1679                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1680 }
1681 run_test 27u "skip object creation on OSC w/o objects"
1682
1683 test_27v() { # bug 4900
1684         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1685         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1686         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1687         remote_ost_nodsh && skip "remote OST with nodsh" && return
1688
1689         exhaust_all_precreations 0x215
1690         reset_enospc
1691
1692         test_mkdir $DIR/$tdir
1693         $LFS setstripe -c 1 $DIR/$tdir         # 1 stripe / file
1694
1695         touch $DIR/$tdir/$tfile
1696         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1697         # all except ost1
1698         for (( i=1; i < OSTCOUNT; i++ )); do
1699                 do_facet ost$i lctl set_param fail_loc=0x705
1700         done
1701         local START=`date +%s`
1702         createmany -o $DIR/$tdir/$tfile 32
1703
1704         local FINISH=`date +%s`
1705         local TIMEOUT=`lctl get_param -n timeout`
1706         local PROCESS=$((FINISH - START))
1707         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1708                error "$FINISH - $START >= $TIMEOUT / 2"
1709         sleep $((TIMEOUT / 2 - PROCESS))
1710         reset_enospc
1711 }
1712 run_test 27v "skip object creation on slow OST"
1713
1714 test_27w() { # bug 10997
1715         test_mkdir $DIR/$tdir || error "mkdir failed"
1716         $LFS setstripe -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1717         [ $($LFS getstripe -S $DIR/$tdir/f0) -ne 65536 ] &&
1718                 error "stripe size $size != 65536" || true
1719         [ $($LFS getstripe -d $DIR/$tdir | grep -c "stripe_count") -eq 0 ] &&
1720                 error "$LFS getstripe -d $DIR/$tdir no 'stripe_count'" || true
1721 }
1722 run_test 27w "check $LFS setstripe -S and getstrip -d options"
1723
1724 test_27wa() {
1725         [[ $OSTCOUNT -lt 2 ]] &&
1726                 skip_env "skipping multiple stripe count/offset test" && return
1727
1728         test_mkdir $DIR/$tdir || error "mkdir failed"
1729         for i in $(seq 1 $OSTCOUNT); do
1730                 offset=$((i - 1))
1731                 $LFS setstripe -c $i -i $offset $DIR/$tdir/f$i ||
1732                         error "setstripe -c $i -i $offset failed"
1733                 count=$($LFS getstripe -c $DIR/$tdir/f$i)
1734                 index=$($LFS getstripe -i $DIR/$tdir/f$i)
1735                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1736                 [ $index -ne $offset ] &&
1737                         error "stripe offset $index != $offset" || true
1738         done
1739 }
1740 run_test 27wa "check $LFS setstripe -c -i options"
1741
1742 test_27x() {
1743         remote_ost_nodsh && skip "remote OST with nodsh" && return
1744         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1745         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1746         OFFSET=$(($OSTCOUNT - 1))
1747         OSTIDX=0
1748         local OST=$(ostname_from_index $OSTIDX)
1749
1750         test_mkdir -p $DIR/$tdir
1751         $LFS setstripe -c 1 $DIR/$tdir  # 1 stripe per file
1752         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1753         sleep_maxage
1754         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1755         for i in $(seq 0 $OFFSET); do
1756                 [ $($LFS getstripe $DIR/$tdir/$tfile$i | grep -A 10 obdidx |
1757                         awk '{print $1}' | grep -w "$OSTIDX") ] &&
1758                 error "OST0 was degraded but new created file still use it"
1759         done
1760         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1761 }
1762 run_test 27x "create files while OST0 is degraded"
1763
1764 test_27y() {
1765         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1766         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1767         remote_ost_nodsh && skip "remote OST with nodsh" && return
1768         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1769
1770         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1771         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1772                 osc.$mdtosc.prealloc_last_id)
1773         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1774                 osc.$mdtosc.prealloc_next_id)
1775         local fcount=$((last_id - next_id))
1776         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1777         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1778
1779         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1780                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1781         local OST_DEACTIVE_IDX=-1
1782         local OSC
1783         local OSTIDX
1784         local OST
1785
1786         for OSC in $MDS_OSCS; do
1787                 OST=$(osc_to_ost $OSC)
1788                 OSTIDX=$(index_from_ostuuid $OST)
1789                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1790                         OST_DEACTIVE_IDX=$OSTIDX
1791                 fi
1792                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1793                         echo $OSC "is Deactivated:"
1794                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1795                 fi
1796         done
1797
1798         OSTIDX=$(index_from_ostuuid $OST)
1799         test_mkdir -p $DIR/$tdir
1800         $LFS setstripe -c 1 $DIR/$tdir      # 1 stripe / file
1801
1802         for OSC in $MDS_OSCS; do
1803                 OST=$(osc_to_ost $OSC)
1804                 OSTIDX=$(index_from_ostuuid $OST)
1805                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1806                         echo $OST "is degraded:"
1807                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1808                                                 obdfilter.$OST.degraded=1
1809                 fi
1810         done
1811
1812         sleep_maxage
1813         createmany -o $DIR/$tdir/$tfile $fcount
1814
1815         for OSC in $MDS_OSCS; do
1816                 OST=$(osc_to_ost $OSC)
1817                 OSTIDX=$(index_from_ostuuid $OST)
1818                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1819                         echo $OST "is recovered from degraded:"
1820                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1821                                                 obdfilter.$OST.degraded=0
1822                 else
1823                         do_facet $SINGLEMDS lctl --device %$OSC activate
1824                 fi
1825         done
1826
1827         # all osp devices get activated, hence -1 stripe count restored
1828         local stripecnt=0
1829
1830         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1831         # devices get activated.
1832         sleep_maxage
1833         $LFS setstripe -c -1 $DIR/$tfile
1834         stripecnt=$($LFS getstripe -c $DIR/$tfile)
1835         rm -f $DIR/$tfile
1836         [ $stripecnt -ne $OSTCOUNT ] &&
1837                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1838         return 0
1839 }
1840 run_test 27y "create files while OST0 is degraded and the rest inactive"
1841
1842 check_seq_oid()
1843 {
1844         log "check file $1"
1845
1846         lmm_count=$($GETSTRIPE -c $1)
1847         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1848         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1849
1850         local old_ifs="$IFS"
1851         IFS=$'[:]'
1852         fid=($($LFS path2fid $1))
1853         IFS="$old_ifs"
1854
1855         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1856         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1857
1858         # compare lmm_seq and lu_fid->f_seq
1859         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1860         # compare lmm_object_id and lu_fid->oid
1861         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1862
1863         # check the trusted.fid attribute of the OST objects of the file
1864         local have_obdidx=false
1865         local stripe_nr=0
1866         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1867                 # skip lines up to and including "obdidx"
1868                 [ -z "$obdidx" ] && break
1869                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1870                 $have_obdidx || continue
1871
1872                 local ost=$((obdidx + 1))
1873                 local dev=$(ostdevname $ost)
1874                 local oid_hex
1875
1876                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1877
1878                 seq=$(echo $seq | sed -e "s/^0x//g")
1879                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1880                         oid_hex=$(echo $oid)
1881                 else
1882                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1883                 fi
1884                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1885
1886                 local ff=""
1887                 #
1888                 # Don't unmount/remount the OSTs if we don't need to do that.
1889                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1890                 # update too, until that use mount/ll_decode_filter_fid/mount.
1891                 # Re-enable when debugfs will understand new filter_fid.
1892                 #
1893                 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
1894                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1895                                 $dev 2>/dev/null" | grep "parent=")
1896                 fi
1897                 if [ -z "$ff" ]; then
1898                         stop ost$ost
1899                         mount_fstype ost$ost
1900                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1901                                 $(facet_mntpt ost$ost)/$obj_file)
1902                         unmount_fstype ost$ost
1903                         start ost$ost $dev $OST_MOUNT_OPTS
1904                         clients_up
1905                 fi
1906
1907                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1908
1909                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1910
1911                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1912                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1913                 #
1914                 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
1915                 #       stripe_size=1048576 component_id=1 component_start=0 \
1916                 #       component_end=33554432
1917                 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
1918                 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
1919                 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
1920                 local ff_pstripe
1921                 if grep -q 'stripe=' <<<$ff; then
1922                         ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
1923                 else
1924                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1925                         # into f_ver in this case.  See comment on ff_parent.
1926                         ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
1927                 fi
1928
1929                 if grep -q 'stripe_count=' <<<$ff; then
1930                         local ff_scnt=$(sed -e 's/.*stripe_count=//' \
1931                                             -e 's/ .*//' <<<$ff)
1932                         [ $lmm_count = $ff_scnt ] ||
1933                                 error "FF stripe count $lmm_count != $ff_scnt"
1934                 fi
1935                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1936                 [ $ff_pseq = $lmm_seq ] ||
1937                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1938                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1939                 [ $ff_poid = $lmm_oid ] ||
1940                         error "FF parent OID $ff_poid != $lmm_oid"
1941                 (($ff_pstripe == $stripe_nr)) ||
1942                         error "FF stripe $ff_pstripe != $stripe_nr"
1943
1944                 stripe_nr=$((stripe_nr + 1))
1945         done
1946 }
1947
1948 test_27z() {
1949         remote_ost_nodsh && skip "remote OST with nodsh" && return
1950         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1951         test_mkdir -p $DIR/$tdir
1952
1953         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1954                 { error "setstripe -c -1 failed"; return 1; }
1955         # We need to send a write to every object to get parent FID info set.
1956         # This _should_ also work for setattr, but does not currently.
1957         # touch $DIR/$tdir/$tfile-1 ||
1958         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1959                 { error "dd $tfile-1 failed"; return 2; }
1960         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1961                 { error "setstripe -c -1 failed"; return 3; }
1962         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1963                 { error "dd $tfile-2 failed"; return 4; }
1964
1965         # make sure write RPCs have been sent to OSTs
1966         sync; sleep 5; sync
1967
1968         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1969         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1970 }
1971 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1972
1973 test_27A() { # b=19102
1974         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1975         local restore_size=$($GETSTRIPE -S $MOUNT)
1976         local restore_count=$($GETSTRIPE -c $MOUNT)
1977         local restore_offset=$($GETSTRIPE -i $MOUNT)
1978         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1979         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1980                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1981         local default_size=$($GETSTRIPE -S $MOUNT)
1982         local default_offset=$($GETSTRIPE -i $MOUNT)
1983         local dsize=$((1024 * 1024))
1984         [ $default_size -eq $dsize ] ||
1985                 error "stripe size $default_size != $dsize"
1986         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1987         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1988 }
1989 run_test 27A "check filesystem-wide default LOV EA values"
1990
1991 test_27B() { # LU-2523
1992         test_mkdir -p $DIR/$tdir
1993         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1994         touch $DIR/$tdir/f0
1995         # open f1 with O_LOV_DELAY_CREATE
1996         # rename f0 onto f1
1997         # call setstripe ioctl on open file descriptor for f1
1998         # close
1999         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
2000                 $DIR/$tdir/f0
2001
2002         rm -f $DIR/$tdir/f1
2003         # open f1 with O_LOV_DELAY_CREATE
2004         # unlink f1
2005         # call setstripe ioctl on open file descriptor for f1
2006         # close
2007         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
2008
2009         # Allow multiop to fail in imitation of NFS's busted semantics.
2010         true
2011 }
2012 run_test 27B "call setstripe on open unlinked file/rename victim"
2013
2014 test_27C() { #LU-2871
2015         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
2016
2017         declare -a ost_idx
2018         local index
2019         local found
2020         local i
2021         local j
2022
2023         test_mkdir -p $DIR/$tdir
2024         cd $DIR/$tdir
2025         for i in $(seq 0 $((OSTCOUNT - 1))); do
2026                 # set stripe across all OSTs starting from OST$i
2027                 $SETSTRIPE -i $i -c -1 $tfile$i
2028                 # get striping information
2029                 ost_idx=($($GETSTRIPE $tfile$i |
2030                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2031                 echo ${ost_idx[@]}
2032
2033                 # check the layout
2034                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2035                         error "${#ost_idx[@]} != $OSTCOUNT"
2036
2037                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2038                         found=0
2039                         for j in $(echo ${ost_idx[@]}); do
2040                                 if [ $index -eq $j ]; then
2041                                         found=1
2042                                         break
2043                                 fi
2044                         done
2045                         [ $found = 1 ] ||
2046                                 error "Can not find $index in ${ost_idx[@]}"
2047                 done
2048         done
2049 }
2050 run_test 27C "check full striping across all OSTs"
2051
2052 test_27D() {
2053         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2054         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
2055         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2056         local POOL=${POOL:-testpool}
2057         local first_ost=0
2058         local last_ost=$(($OSTCOUNT - 1))
2059         local ost_step=1
2060         local ost_list=$(seq $first_ost $ost_step $last_ost)
2061         local ost_range="$first_ost $last_ost $ost_step"
2062
2063         test_mkdir -p $DIR/$tdir
2064         pool_add $POOL || error "pool_add failed"
2065         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2066
2067         local skip27D
2068         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ] &&
2069                 skip27D += "-s 29"
2070         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.55) ] &&
2071                 skip27D += "-s 30,31"
2072         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
2073                 error "llapi_layout_test failed"
2074
2075         destroy_test_pools || error "destroy test pools failed"
2076 }
2077 run_test 27D "validate llapi_layout API"
2078
2079 # Verify that default_easize is increased from its initial value after
2080 # accessing a widely striped file.
2081 test_27E() {
2082         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2083         [ $(lustre_version_code client) -lt $(version_code 2.5.57) ] &&
2084                 skip "client does not have LU-3338 fix" && return
2085
2086         # 72 bytes is the minimum space required to store striping
2087         # information for a file striped across one OST:
2088         # (sizeof(struct lov_user_md_v3) +
2089         #  sizeof(struct lov_user_ost_data_v1))
2090         local min_easize=72
2091         $LCTL set_param -n llite.*.default_easize $min_easize ||
2092                 error "lctl set_param failed"
2093         local easize=$($LCTL get_param -n llite.*.default_easize)
2094
2095         [ $easize -eq $min_easize ] ||
2096                 error "failed to set default_easize"
2097
2098         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2099                 error "setstripe failed"
2100         cat $DIR/$tfile
2101         rm $DIR/$tfile
2102
2103         easize=$($LCTL get_param -n llite.*.default_easize)
2104
2105         [ $easize -gt $min_easize ] ||
2106                 error "default_easize not updated"
2107 }
2108 run_test 27E "check that default extended attribute size properly increases"
2109
2110 test_27F() { # LU-5346/LU-7975
2111         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2112         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.51) ]] &&
2113                 skip "Need MDS version at least 2.8.51" && return
2114         remote_ost_nodsh && skip "remote OST with nodsh" && return
2115
2116         test_mkdir -p $DIR/$tdir
2117         rm -f $DIR/$tdir/f0
2118         $SETSTRIPE -c 2 $DIR/$tdir
2119
2120         # stop all OSTs to reproduce situation for LU-7975 ticket
2121         for num in $(seq $OSTCOUNT); do
2122                 stop ost$num
2123         done
2124
2125         # open/create f0 with O_LOV_DELAY_CREATE
2126         # truncate f0 to a non-0 size
2127         # close
2128         multiop $DIR/$tdir/f0 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T1050000c
2129
2130         $CHECKSTAT -s 1050000 $DIR/$tdir/f0 || error "checkstat failed"
2131         # open/write it again to force delayed layout creation
2132         cat /etc/hosts > $DIR/$tdir/f0 &
2133         catpid=$!
2134
2135         # restart OSTs
2136         for num in $(seq $OSTCOUNT); do
2137                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
2138                         error "ost$num failed to start"
2139         done
2140
2141         wait $catpid || error "cat failed"
2142
2143         cmp /etc/hosts $DIR/$tdir/f0 || error "cmp failed"
2144         [[ $($GETSTRIPE -c $DIR/$tdir/f0) == 2 ]] || error "wrong stripecount"
2145
2146 }
2147 run_test 27F "Client resend delayed layout creation with non-zero size"
2148
2149 # createtest also checks that device nodes are created and
2150 # then visible correctly (#2091)
2151 test_28() { # bug 2091
2152         test_mkdir $DIR/d28
2153         $CREATETEST $DIR/d28/ct || error
2154 }
2155 run_test 28 "create/mknod/mkdir with bad file types ============"
2156
2157 test_29() {
2158         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
2159         sync; sleep 1; sync # flush out any dirty pages from previous tests
2160         cancel_lru_locks
2161         test_mkdir $DIR/d29
2162         touch $DIR/d29/foo
2163         log 'first d29'
2164         ls -l $DIR/d29
2165
2166         declare -i LOCKCOUNTORIG=0
2167         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2168                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2169         done
2170         [ $LOCKCOUNTORIG -eq 0 ] && error "No mdc lock count" && return 1
2171
2172         declare -i LOCKUNUSEDCOUNTORIG=0
2173         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2174                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2175         done
2176
2177         log 'second d29'
2178         ls -l $DIR/d29
2179         log 'done'
2180
2181         declare -i LOCKCOUNTCURRENT=0
2182         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2183                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2184         done
2185
2186         declare -i LOCKUNUSEDCOUNTCURRENT=0
2187         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2188                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2189         done
2190
2191         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2192                 $LCTL set_param -n ldlm.dump_namespaces ""
2193                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2194                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2195                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2196                 return 2
2197         fi
2198         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2199                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2200                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2201                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2202                 return 3
2203         fi
2204 }
2205 run_test 29 "IT_GETATTR regression  ============================"
2206
2207 test_30a() { # was test_30
2208         cp $(which ls) $DIR || cp /bin/ls $DIR
2209         $DIR/ls / || error
2210         rm $DIR/ls
2211 }
2212 run_test 30a "execute binary from Lustre (execve) =============="
2213
2214 test_30b() {
2215         cp `which ls` $DIR || cp /bin/ls $DIR
2216         chmod go+rx $DIR/ls
2217         $RUNAS $DIR/ls / || error
2218         rm $DIR/ls
2219 }
2220 run_test 30b "execute binary from Lustre as non-root ==========="
2221
2222 test_30c() { # b=22376
2223         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2224         cp `which ls` $DIR || cp /bin/ls $DIR
2225         chmod a-rw $DIR/ls
2226         cancel_lru_locks mdc
2227         cancel_lru_locks osc
2228         $RUNAS $DIR/ls / || error
2229         rm -f $DIR/ls
2230 }
2231 run_test 30c "execute binary from Lustre without read perms ===="
2232
2233 test_31a() {
2234         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2235         $CHECKSTAT -a $DIR/f31 || error
2236 }
2237 run_test 31a "open-unlink file =================================="
2238
2239 test_31b() {
2240         touch $DIR/f31 || error
2241         ln $DIR/f31 $DIR/f31b || error
2242         $MULTIOP $DIR/f31b Ouc || error
2243         $CHECKSTAT -t file $DIR/f31 || error
2244 }
2245 run_test 31b "unlink file with multiple links while open ======="
2246
2247 test_31c() {
2248         touch $DIR/f31 || error
2249         ln $DIR/f31 $DIR/f31c || error
2250         multiop_bg_pause $DIR/f31 O_uc || return 1
2251         MULTIPID=$!
2252         $MULTIOP $DIR/f31c Ouc
2253         kill -USR1 $MULTIPID
2254         wait $MULTIPID
2255 }
2256 run_test 31c "open-unlink file with multiple links ============="
2257
2258 test_31d() {
2259         opendirunlink $DIR/d31d $DIR/d31d || error
2260         $CHECKSTAT -a $DIR/d31d || error
2261 }
2262 run_test 31d "remove of open directory ========================="
2263
2264 test_31e() { # bug 2904
2265         openfilleddirunlink $DIR/d31e || error
2266 }
2267 run_test 31e "remove of open non-empty directory ==============="
2268
2269 test_31f() { # bug 4554
2270         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2271         set -vx
2272         test_mkdir $DIR/d31f
2273         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2274         cp /etc/hosts $DIR/d31f
2275         ls -l $DIR/d31f
2276         $GETSTRIPE $DIR/d31f/hosts
2277         multiop_bg_pause $DIR/d31f D_c || return 1
2278         MULTIPID=$!
2279
2280         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2281         test_mkdir $DIR/d31f
2282         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2283         cp /etc/hosts $DIR/d31f
2284         ls -l $DIR/d31f
2285         $GETSTRIPE $DIR/d31f/hosts
2286         multiop_bg_pause $DIR/d31f D_c || return 1
2287         MULTIPID2=$!
2288
2289         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2290         wait $MULTIPID || error "first opendir $MULTIPID failed"
2291
2292         sleep 6
2293
2294         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2295         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2296         set +vx
2297 }
2298 run_test 31f "remove of open directory with open-unlink file ==="
2299
2300 test_31g() {
2301         echo "-- cross directory link --"
2302         test_mkdir -c1 $DIR/${tdir}ga
2303         test_mkdir -c1 $DIR/${tdir}gb
2304         touch $DIR/${tdir}ga/f
2305         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2306         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2307         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2308         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2309         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2310 }
2311 run_test 31g "cross directory link==============="
2312
2313 test_31h() {
2314         echo "-- cross directory link --"
2315         test_mkdir -c1 $DIR/${tdir}
2316         test_mkdir -c1 $DIR/${tdir}/dir
2317         touch $DIR/${tdir}/f
2318         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2319         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2320         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2321         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2322         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2323 }
2324 run_test 31h "cross directory link under child==============="
2325
2326 test_31i() {
2327         echo "-- cross directory link --"
2328         test_mkdir -c1 $DIR/$tdir
2329         test_mkdir -c1 $DIR/$tdir/dir
2330         touch $DIR/$tdir/dir/f
2331         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2332         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2333         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2334         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2335         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2336 }
2337 run_test 31i "cross directory link under parent==============="
2338
2339 test_31j() {
2340         test_mkdir -c1 -p $DIR/$tdir
2341         test_mkdir -c1 -p $DIR/$tdir/dir1
2342         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2343         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2344         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2345         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2346         return 0
2347 }
2348 run_test 31j "link for directory==============="
2349
2350 test_31k() {
2351         test_mkdir -c1 -p $DIR/$tdir
2352         touch $DIR/$tdir/s
2353         touch $DIR/$tdir/exist
2354         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2355         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2356         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2357         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2358         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2359         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2360         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2361         return 0
2362 }
2363 run_test 31k "link to file: the same, non-existing, dir==============="
2364
2365 test_31m() {
2366         mkdir $DIR/d31m
2367         touch $DIR/d31m/s
2368         mkdir $DIR/d31m2
2369         touch $DIR/d31m2/exist
2370         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2371         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2372         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2373         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2374         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2375         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2376         return 0
2377 }
2378 run_test 31m "link to file: the same, non-existing, dir==============="
2379
2380 test_31n() {
2381         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2382         nlink=$(stat --format=%h $DIR/$tfile)
2383         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2384         local fd=$(free_fd)
2385         local cmd="exec $fd<$DIR/$tfile"
2386         eval $cmd
2387         cmd="exec $fd<&-"
2388         trap "eval $cmd" EXIT
2389         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2390         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2391         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2392         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2393         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2394         eval $cmd
2395 }
2396 run_test 31n "check link count of unlinked file"
2397
2398 link_one() {
2399         local TEMPNAME=$(mktemp $1_XXXXXX)
2400         mlink $TEMPNAME $1 2> /dev/null &&
2401                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2402         munlink $TEMPNAME
2403 }
2404
2405 test_31o() { # LU-2901
2406         test_mkdir -p $DIR/$tdir
2407         for LOOP in $(seq 100); do
2408                 rm -f $DIR/$tdir/$tfile*
2409                 for THREAD in $(seq 8); do
2410                         link_one $DIR/$tdir/$tfile.$LOOP &
2411                 done
2412                 wait
2413                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2414                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2415                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2416                         break || true
2417         done
2418 }
2419 run_test 31o "duplicate hard links with same filename"
2420
2421 test_31p() {
2422         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2423
2424         test_mkdir $DIR/$tdir
2425         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2426         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2427
2428         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2429                 error "open unlink test1 failed"
2430         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2431                 error "open unlink test2 failed"
2432
2433         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2434                 error "test1 still exists"
2435         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2436                 error "test2 still exists"
2437 }
2438 run_test 31p "remove of open striped directory"
2439
2440 cleanup_test32_mount() {
2441         local rc=0
2442         trap 0
2443         local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$//p')
2444         $UMOUNT $DIR/$tdir/ext2-mountpoint || rc=$?
2445         losetup -d $loopdev || true
2446         rm -rf $DIR/$tdir
2447         return $rc
2448 }
2449
2450 test_32a() {
2451         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2452         echo "== more mountpoints and symlinks ================="
2453         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2454         trap cleanup_test32_mount EXIT
2455         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2456         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2457         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2458         cleanup_test32_mount
2459 }
2460 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2461
2462 test_32b() {
2463         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2464         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2465         trap cleanup_test32_mount EXIT
2466         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2467         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2468         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2469         cleanup_test32_mount
2470 }
2471 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2472
2473 test_32c() {
2474         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2475         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2476         trap cleanup_test32_mount EXIT
2477         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2478         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2479         test_mkdir -p $DIR/$tdir/d2/test_dir
2480         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2481         cleanup_test32_mount
2482 }
2483 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2484
2485 test_32d() {
2486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2487         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2488         trap cleanup_test32_mount EXIT
2489         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2490         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2491         test_mkdir -p $DIR/$tdir/d2/test_dir
2492         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2493         cleanup_test32_mount
2494 }
2495 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2496
2497 test_32e() {
2498         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2499         test_mkdir -p $DIR/d32e/tmp
2500         TMP_DIR=$DIR/d32e/tmp
2501         ln -s $DIR/d32e $TMP_DIR/symlink11
2502         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2503         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2504         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2505 }
2506 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2507
2508 test_32f() {
2509         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2510         test_mkdir -p $DIR/d32f/tmp
2511         TMP_DIR=$DIR/d32f/tmp
2512         ln -s $DIR/d32f $TMP_DIR/symlink11
2513         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2514         ls $DIR/d32f/tmp/symlink11  || error
2515         ls $DIR/d32f/symlink01 || error
2516 }
2517 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2518
2519 test_32g() {
2520         TMP_DIR=$DIR/$tdir/tmp
2521         test_mkdir -p $DIR/$tdir/tmp
2522         test_mkdir $DIR/${tdir}2
2523         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2524         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2525         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2526         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2527         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2528         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2529 }
2530 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2531
2532 test_32h() {
2533         rm -fr $DIR/$tdir $DIR/${tdir}2
2534         TMP_DIR=$DIR/$tdir/tmp
2535         test_mkdir -p $DIR/$tdir/tmp
2536         test_mkdir $DIR/${tdir}2
2537         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2538         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2539         ls $TMP_DIR/symlink12 || error
2540         ls $DIR/$tdir/symlink02  || error
2541 }
2542 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2543
2544 test_32i() {
2545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2546         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2547         trap cleanup_test32_mount EXIT
2548         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2549         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2550         touch $DIR/$tdir/test_file
2551         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2552         cleanup_test32_mount
2553 }
2554 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2555
2556 test_32j() {
2557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2558         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2559         trap cleanup_test32_mount EXIT
2560         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2561         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2562         touch $DIR/$tdir/test_file
2563         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2564         cleanup_test32_mount
2565 }
2566 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2567
2568 test_32k() {
2569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2570         rm -fr $DIR/$tdir
2571         trap cleanup_test32_mount EXIT
2572         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2573         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2574         test_mkdir -p $DIR/$tdir/d2
2575         touch $DIR/$tdir/d2/test_file || error
2576         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2577         cleanup_test32_mount
2578 }
2579 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2580
2581 test_32l() {
2582         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2583         rm -fr $DIR/$tdir
2584         trap cleanup_test32_mount EXIT
2585         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2586         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2587         test_mkdir -p $DIR/$tdir/d2
2588         touch $DIR/$tdir/d2/test_file
2589         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2590         cleanup_test32_mount
2591 }
2592 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2593
2594 test_32m() {
2595         rm -fr $DIR/d32m
2596         test_mkdir -p $DIR/d32m/tmp
2597         TMP_DIR=$DIR/d32m/tmp
2598         ln -s $DIR $TMP_DIR/symlink11
2599         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2600         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2601         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2602 }
2603 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2604
2605 test_32n() {
2606         rm -fr $DIR/d32n
2607         test_mkdir -p $DIR/d32n/tmp
2608         TMP_DIR=$DIR/d32n/tmp
2609         ln -s $DIR $TMP_DIR/symlink11
2610         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2611         ls -l $DIR/d32n/tmp/symlink11  || error
2612         ls -l $DIR/d32n/symlink01 || error
2613 }
2614 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2615
2616 test_32o() {
2617         touch $DIR/$tfile
2618         test_mkdir -p $DIR/d32o/tmp
2619         TMP_DIR=$DIR/d32o/tmp
2620         ln -s $DIR/$tfile $TMP_DIR/symlink12
2621         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2622         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2623         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2624         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2625         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2626 }
2627 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2628
2629 test_32p() {
2630         log 32p_1
2631         rm -fr $DIR/d32p
2632         log 32p_2
2633         rm -f $DIR/$tfile
2634         log 32p_3
2635         touch $DIR/$tfile
2636         log 32p_4
2637         test_mkdir -p $DIR/d32p/tmp
2638         log 32p_5
2639         TMP_DIR=$DIR/d32p/tmp
2640         log 32p_6
2641         ln -s $DIR/$tfile $TMP_DIR/symlink12
2642         log 32p_7
2643         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2644         log 32p_8
2645         cat $DIR/d32p/tmp/symlink12 || error
2646         log 32p_9
2647         cat $DIR/d32p/symlink02 || error
2648         log 32p_10
2649 }
2650 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2651
2652 test_32q() {
2653         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2654         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2655         trap cleanup_test32_mount EXIT
2656         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2657         touch $DIR/$tdir/ext2-mountpoint/under_the_mount
2658         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2659         ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
2660         cleanup_test32_mount
2661 }
2662 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2663
2664 test_32r() {
2665         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2666         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2667         trap cleanup_test32_mount EXIT
2668         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2669         touch $DIR/$tdir/ext2-mountpoint/under_the_mount
2670         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2671         ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
2672         cleanup_test32_mount
2673 }
2674 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2675
2676 test_33aa() {
2677         rm -f $DIR/$tfile
2678         touch $DIR/$tfile
2679         chmod 444 $DIR/$tfile
2680         chown $RUNAS_ID $DIR/$tfile
2681         log 33_1
2682         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2683         log 33_2
2684 }
2685 run_test 33aa "write file with mode 444 (should return error) ===="
2686
2687 test_33a() {
2688         rm -fr $DIR/d33
2689         test_mkdir -p $DIR/d33
2690         chown $RUNAS_ID $DIR/d33
2691         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2692         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2693                 error "open RDWR" || true
2694 }
2695 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2696
2697 test_33b() {
2698         rm -fr $DIR/d33
2699         test_mkdir -p $DIR/d33
2700         chown $RUNAS_ID $DIR/d33
2701         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2702 }
2703 run_test 33b "test open file with malformed flags (No panic)"
2704
2705 test_33c() {
2706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2707         local ostnum
2708         local ostname
2709         local write_bytes
2710         local all_zeros
2711
2712         remote_ost_nodsh && skip "remote OST with nodsh" && return
2713         all_zeros=:
2714         rm -fr $DIR/d33
2715         test_mkdir -p $DIR/d33
2716         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2717
2718         sync
2719         for ostnum in $(seq $OSTCOUNT); do
2720                 # test-framework's OST numbering is one-based, while Lustre's
2721                 # is zero-based
2722                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2723                 # Parsing llobdstat's output sucks; we could grep the /proc
2724                 # path, but that's likely to not be as portable as using the
2725                 # llobdstat utility.  So we parse lctl output instead.
2726                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2727                         obdfilter/$ostname/stats |
2728                         awk '/^write_bytes/ {print $7}' )
2729                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2730                 if (( ${write_bytes:-0} > 0 ))
2731                 then
2732                         all_zeros=false
2733                         break;
2734                 fi
2735         done
2736
2737         $all_zeros || return 0
2738
2739         # Write four bytes
2740         echo foo > $DIR/d33/bar
2741         # Really write them
2742         sync
2743
2744         # Total up write_bytes after writing.  We'd better find non-zeros.
2745         for ostnum in $(seq $OSTCOUNT); do
2746                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2747                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2748                         obdfilter/$ostname/stats |
2749                         awk '/^write_bytes/ {print $7}' )
2750                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2751                 if (( ${write_bytes:-0} > 0 ))
2752                 then
2753                         all_zeros=false
2754                         break;
2755                 fi
2756         done
2757
2758         if $all_zeros
2759         then
2760                 for ostnum in $(seq $OSTCOUNT); do
2761                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2762                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2763                         do_facet ost$ostnum lctl get_param -n \
2764                                 obdfilter/$ostname/stats
2765                 done
2766                 error "OST not keeping write_bytes stats (b22312)"
2767         fi
2768 }
2769 run_test 33c "test llobdstat and write_bytes"
2770
2771 test_33d() {
2772         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2774         local MDTIDX=1
2775         local remote_dir=$DIR/$tdir/remote_dir
2776
2777         test_mkdir -p $DIR/$tdir
2778         $LFS mkdir -i $MDTIDX $remote_dir ||
2779                 error "create remote directory failed"
2780
2781         touch $remote_dir/$tfile
2782         chmod 444 $remote_dir/$tfile
2783         chown $RUNAS_ID $remote_dir/$tfile
2784
2785         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2786
2787         chown $RUNAS_ID $remote_dir
2788         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2789                                         error "create" || true
2790         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2791                                     error "open RDWR" || true
2792         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2793 }
2794 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2795
2796 test_33e() {
2797         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2798
2799         mkdir $DIR/$tdir
2800
2801         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2802         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2803         mkdir $DIR/$tdir/local_dir
2804
2805         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2806         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2807         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2808
2809         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2810                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2811
2812         rmdir $DIR/$tdir/* || error "rmdir failed"
2813
2814         umask 777
2815         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2816         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2817         mkdir $DIR/$tdir/local_dir
2818
2819         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2820         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2821         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2822
2823         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2824                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2825
2826         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2827
2828         umask 000
2829         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2830         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2831         mkdir $DIR/$tdir/local_dir
2832
2833         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2834         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2835         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2836
2837         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2838                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2839 }
2840 run_test 33e "mkdir and striped directory should have same mode"
2841
2842 cleanup_33f() {
2843         trap 0
2844         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2845 }
2846
2847 test_33f() {
2848         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2849         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2850
2851         mkdir $DIR/$tdir
2852         chmod go+rwx $DIR/$tdir
2853         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2854         trap cleanup_33f EXIT
2855
2856         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2857                 error "cannot create striped directory"
2858
2859         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2860                 error "cannot create files in striped directory"
2861
2862         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2863                 error "cannot remove files in striped directory"
2864
2865         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2866                 error "cannot remove striped directory"
2867
2868         cleanup_33f
2869 }
2870 run_test 33f "nonroot user can create, access, and remove a striped directory"
2871
2872 test_33g() {
2873         mkdir -p $DIR/$tdir/dir2
2874
2875         local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
2876         echo $err
2877         [[ $err =~ "exists" ]] || error "Not exists error"
2878 }
2879 run_test 33g "nonroot user create already existing root created file"
2880
2881 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2882 test_34a() {
2883         rm -f $DIR/f34
2884         $MCREATE $DIR/f34 || error
2885         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2886         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2887         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2888         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2889 }
2890 run_test 34a "truncate file that has not been opened ==========="
2891
2892 test_34b() {
2893         [ ! -f $DIR/f34 ] && test_34a
2894         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2895         $OPENFILE -f O_RDONLY $DIR/f34
2896         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2897         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2898 }
2899 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2900
2901 test_34c() {
2902         [ ! -f $DIR/f34 ] && test_34a
2903         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2904         $OPENFILE -f O_RDWR $DIR/f34
2905         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2906         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2907 }
2908 run_test 34c "O_RDWR opening file-with-size works =============="
2909
2910 test_34d() {
2911         [ ! -f $DIR/f34 ] && test_34a
2912         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2913         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2914         rm $DIR/f34
2915 }
2916 run_test 34d "write to sparse file ============================="
2917
2918 test_34e() {
2919         rm -f $DIR/f34e
2920         $MCREATE $DIR/f34e || error
2921         $TRUNCATE $DIR/f34e 1000 || error
2922         $CHECKSTAT -s 1000 $DIR/f34e || error
2923         $OPENFILE -f O_RDWR $DIR/f34e
2924         $CHECKSTAT -s 1000 $DIR/f34e || error
2925 }
2926 run_test 34e "create objects, some with size and some without =="
2927
2928 test_34f() { # bug 6242, 6243
2929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2930         SIZE34F=48000
2931         rm -f $DIR/f34f
2932         $MCREATE $DIR/f34f || error
2933         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2934         dd if=$DIR/f34f of=$TMP/f34f
2935         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2936         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2937         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2938         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2939         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2940 }
2941 run_test 34f "read from a file with no objects until EOF ======="
2942
2943 test_34g() {
2944         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2945         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2946         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2947         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2948         cancel_lru_locks osc
2949         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2950                 error "wrong size after lock cancel"
2951
2952         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2953         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2954                 error "expanding truncate failed"
2955         cancel_lru_locks osc
2956         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2957                 error "wrong expanded size after lock cancel"
2958 }
2959 run_test 34g "truncate long file ==============================="
2960
2961 test_34h() {
2962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2963         local gid=10
2964         local sz=1000
2965
2966         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2967         sync # Flush the cache so that multiop below does not block on cache
2968              # flush when getting the group lock
2969         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2970         MULTIPID=$!
2971
2972         # Since just timed wait is not good enough, let's do a sync write
2973         # that way we are sure enough time for a roundtrip + processing
2974         # passed + 2 seconds of extra margin.
2975         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2976         rm $DIR/${tfile}-1
2977         sleep 2
2978
2979         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2980                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2981                 kill -9 $MULTIPID
2982         fi
2983         wait $MULTIPID
2984         local nsz=`stat -c %s $DIR/$tfile`
2985         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2986 }
2987 run_test 34h "ftruncate file under grouplock should not block"
2988
2989 test_35a() {
2990         cp /bin/sh $DIR/f35a
2991         chmod 444 $DIR/f35a
2992         chown $RUNAS_ID $DIR/f35a
2993         $RUNAS $DIR/f35a && error || true
2994         rm $DIR/f35a
2995 }
2996 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2997
2998 test_36a() {
2999         rm -f $DIR/f36
3000         utime $DIR/f36 || error
3001 }
3002 run_test 36a "MDS utime check (mknod, utime) ==================="
3003
3004 test_36b() {
3005         echo "" > $DIR/f36
3006         utime $DIR/f36 || error
3007 }
3008 run_test 36b "OST utime check (open, utime) ===================="
3009
3010 test_36c() {
3011         rm -f $DIR/d36/f36
3012         test_mkdir $DIR/d36
3013         chown $RUNAS_ID $DIR/d36
3014         $RUNAS utime $DIR/d36/f36 || error
3015 }
3016 run_test 36c "non-root MDS utime check (mknod, utime) =========="
3017
3018 test_36d() {
3019         [ ! -d $DIR/d36 ] && test_36c
3020         echo "" > $DIR/d36/f36
3021         $RUNAS utime $DIR/d36/f36 || error
3022 }
3023 run_test 36d "non-root OST utime check (open, utime) ==========="
3024
3025 test_36e() {
3026         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3027         test_mkdir -p $DIR/$tdir
3028         touch $DIR/$tdir/$tfile
3029         $RUNAS utime $DIR/$tdir/$tfile && \
3030                 error "utime worked, expected failure" || true
3031 }
3032 run_test 36e "utime on non-owned file (should return error) ===="
3033
3034 subr_36fh() {
3035         local fl="$1"
3036         local LANG_SAVE=$LANG
3037         local LC_LANG_SAVE=$LC_LANG
3038         export LANG=C LC_LANG=C # for date language
3039
3040         DATESTR="Dec 20  2000"
3041         test_mkdir -p $DIR/$tdir
3042         lctl set_param fail_loc=$fl
3043         date; date +%s
3044         cp /etc/hosts $DIR/$tdir/$tfile
3045         sync & # write RPC generated with "current" inode timestamp, but delayed
3046         sleep 1
3047         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
3048         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
3049         cancel_lru_locks osc
3050         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
3051         date; date +%s
3052         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
3053                 echo "BEFORE: $LS_BEFORE" && \
3054                 echo "AFTER : $LS_AFTER" && \
3055                 echo "WANT  : $DATESTR" && \
3056                 error "$DIR/$tdir/$tfile timestamps changed" || true
3057
3058         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
3059 }
3060
3061 test_36f() {
3062         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3063         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3064         subr_36fh "0x80000214"
3065 }
3066 run_test 36f "utime on file racing with OST BRW write =========="
3067
3068 test_36g() {
3069         remote_ost_nodsh && skip "remote OST with nodsh" && return
3070         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3071         local fmd_max_age
3072         local fmd_before
3073         local fmd_after
3074
3075         test_mkdir -p $DIR/$tdir
3076         fmd_max_age=$(do_facet ost1 \
3077                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
3078                 head -n 1")
3079
3080         fmd_before=$(do_facet ost1 \
3081                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3082         touch $DIR/$tdir/$tfile
3083         sleep $((fmd_max_age + 12))
3084         fmd_after=$(do_facet ost1 \
3085                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3086
3087         echo "fmd_before: $fmd_before"
3088         echo "fmd_after: $fmd_after"
3089         [[ $fmd_after -gt $fmd_before ]] &&
3090                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
3091                 error "fmd didn't expire after ping" || true
3092 }
3093 run_test 36g "filter mod data cache expiry ====================="
3094
3095 test_36h() {
3096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3097         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3098         subr_36fh "0x80000227"
3099 }
3100 run_test 36h "utime on file racing with OST BRW write =========="
3101
3102 test_36i() {
3103         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3104
3105         test_mkdir $DIR/$tdir
3106         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3107
3108         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3109         local new_mtime=$((mtime + 200))
3110
3111         #change Modify time of striped dir
3112         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3113                         error "change mtime failed"
3114
3115         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3116
3117         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3118 }
3119 run_test 36i "change mtime on striped directory"
3120
3121 # test_37 - duplicate with tests 32q 32r
3122
3123 test_38() {
3124         local file=$DIR/$tfile
3125         touch $file
3126         openfile -f O_DIRECTORY $file
3127         local RC=$?
3128         local ENOTDIR=20
3129         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3130         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3131 }
3132 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3133
3134 test_39a() { # was test_39
3135         touch $DIR/$tfile
3136         touch $DIR/${tfile}2
3137 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3138 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3139 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3140         sleep 2
3141         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3142         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3143                 echo "mtime"
3144                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3145                 echo "atime"
3146                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3147                 echo "ctime"
3148                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3149                 error "O_TRUNC didn't change timestamps"
3150         fi
3151 }
3152 run_test 39a "mtime changed on create ==========================="
3153
3154 test_39b() {
3155         test_mkdir -p -c1 $DIR/$tdir
3156         cp -p /etc/passwd $DIR/$tdir/fopen
3157         cp -p /etc/passwd $DIR/$tdir/flink
3158         cp -p /etc/passwd $DIR/$tdir/funlink
3159         cp -p /etc/passwd $DIR/$tdir/frename
3160         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3161
3162         sleep 1
3163         echo "aaaaaa" >> $DIR/$tdir/fopen
3164         echo "aaaaaa" >> $DIR/$tdir/flink
3165         echo "aaaaaa" >> $DIR/$tdir/funlink
3166         echo "aaaaaa" >> $DIR/$tdir/frename
3167
3168         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3169         local link_new=`stat -c %Y $DIR/$tdir/flink`
3170         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3171         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3172
3173         cat $DIR/$tdir/fopen > /dev/null
3174         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3175         rm -f $DIR/$tdir/funlink2
3176         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3177
3178         for (( i=0; i < 2; i++ )) ; do
3179                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3180                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3181                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3182                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3183
3184                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3185                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3186                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3187                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3188
3189                 cancel_lru_locks osc
3190                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3191         done
3192 }
3193 run_test 39b "mtime change on open, link, unlink, rename  ======"
3194
3195 # this should be set to past
3196 TEST_39_MTIME=`date -d "1 year ago" +%s`
3197
3198 # bug 11063
3199 test_39c() {
3200         touch $DIR1/$tfile
3201         sleep 2
3202         local mtime0=`stat -c %Y $DIR1/$tfile`
3203
3204         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3205         local mtime1=`stat -c %Y $DIR1/$tfile`
3206         [ "$mtime1" = $TEST_39_MTIME ] || \
3207                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3208
3209         local d1=`date +%s`
3210         echo hello >> $DIR1/$tfile
3211         local d2=`date +%s`
3212         local mtime2=`stat -c %Y $DIR1/$tfile`
3213         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3214                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3215
3216         mv $DIR1/$tfile $DIR1/$tfile-1
3217
3218         for (( i=0; i < 2; i++ )) ; do
3219                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3220                 [ "$mtime2" = "$mtime3" ] || \
3221                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3222
3223                 cancel_lru_locks osc
3224                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3225         done
3226 }
3227 run_test 39c "mtime change on rename ==========================="
3228
3229 # bug 21114
3230 test_39d() {
3231         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3232         touch $DIR1/$tfile
3233
3234         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3235
3236         for (( i=0; i < 2; i++ )) ; do
3237                 local mtime=`stat -c %Y $DIR1/$tfile`
3238                 [ $mtime = $TEST_39_MTIME ] || \
3239                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3240
3241                 cancel_lru_locks osc
3242                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3243         done
3244 }
3245 run_test 39d "create, utime, stat =============================="
3246
3247 # bug 21114
3248 test_39e() {
3249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3250         touch $DIR1/$tfile
3251         local mtime1=`stat -c %Y $DIR1/$tfile`
3252
3253         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3254
3255         for (( i=0; i < 2; i++ )) ; do
3256                 local mtime2=`stat -c %Y $DIR1/$tfile`
3257                 [ $mtime2 = $TEST_39_MTIME ] || \
3258                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3259
3260                 cancel_lru_locks osc
3261                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3262         done
3263 }
3264 run_test 39e "create, stat, utime, stat ========================"
3265
3266 # bug 21114
3267 test_39f() {
3268         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3269         touch $DIR1/$tfile
3270         mtime1=`stat -c %Y $DIR1/$tfile`
3271
3272         sleep 2
3273         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3274
3275         for (( i=0; i < 2; i++ )) ; do
3276                 local mtime2=`stat -c %Y $DIR1/$tfile`
3277                 [ $mtime2 = $TEST_39_MTIME ] || \
3278                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3279
3280                 cancel_lru_locks osc
3281                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3282         done
3283 }
3284 run_test 39f "create, stat, sleep, utime, stat ================="
3285
3286 # bug 11063
3287 test_39g() {
3288         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3289         echo hello >> $DIR1/$tfile
3290         local mtime1=`stat -c %Y $DIR1/$tfile`
3291
3292         sleep 2
3293         chmod o+r $DIR1/$tfile
3294
3295         for (( i=0; i < 2; i++ )) ; do
3296                 local mtime2=`stat -c %Y $DIR1/$tfile`
3297                 [ "$mtime1" = "$mtime2" ] || \
3298                         error "lost mtime: $mtime2, should be $mtime1"
3299
3300                 cancel_lru_locks osc
3301                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3302         done
3303 }
3304 run_test 39g "write, chmod, stat ==============================="
3305
3306 # bug 11063
3307 test_39h() {
3308         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3309         touch $DIR1/$tfile
3310         sleep 1
3311
3312         local d1=`date`
3313         echo hello >> $DIR1/$tfile
3314         local mtime1=`stat -c %Y $DIR1/$tfile`
3315
3316         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3317         local d2=`date`
3318         if [ "$d1" != "$d2" ]; then
3319                 echo "write and touch not within one second"
3320         else
3321                 for (( i=0; i < 2; i++ )) ; do
3322                         local mtime2=`stat -c %Y $DIR1/$tfile`
3323                         [ "$mtime2" = $TEST_39_MTIME ] || \
3324                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3325
3326                         cancel_lru_locks osc
3327                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3328                 done
3329         fi
3330 }
3331 run_test 39h "write, utime within one second, stat ============="
3332
3333 test_39i() {
3334         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3335         touch $DIR1/$tfile
3336         sleep 1
3337
3338         echo hello >> $DIR1/$tfile
3339         local mtime1=`stat -c %Y $DIR1/$tfile`
3340
3341         mv $DIR1/$tfile $DIR1/$tfile-1
3342
3343         for (( i=0; i < 2; i++ )) ; do
3344                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3345
3346                 [ "$mtime1" = "$mtime2" ] || \
3347                         error "lost mtime: $mtime2, should be $mtime1"
3348
3349                 cancel_lru_locks osc
3350                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3351         done
3352 }
3353 run_test 39i "write, rename, stat =============================="
3354
3355 test_39j() {
3356         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3357         start_full_debug_logging
3358         touch $DIR1/$tfile
3359         sleep 1
3360
3361         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3362         lctl set_param fail_loc=0x80000412
3363         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3364                 error "multiop failed"
3365         local multipid=$!
3366         local mtime1=`stat -c %Y $DIR1/$tfile`
3367
3368         mv $DIR1/$tfile $DIR1/$tfile-1
3369
3370         kill -USR1 $multipid
3371         wait $multipid || error "multiop close failed"
3372
3373         for (( i=0; i < 2; i++ )) ; do
3374                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3375                 [ "$mtime1" = "$mtime2" ] ||
3376                         error "mtime is lost on close: $mtime2, " \
3377                               "should be $mtime1"
3378
3379                 cancel_lru_locks osc
3380                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3381         done
3382         lctl set_param fail_loc=0
3383         stop_full_debug_logging
3384 }
3385 run_test 39j "write, rename, close, stat ======================="
3386
3387 test_39k() {
3388         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3389         touch $DIR1/$tfile
3390         sleep 1
3391
3392         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3393         local multipid=$!
3394         local mtime1=`stat -c %Y $DIR1/$tfile`
3395
3396         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3397
3398         kill -USR1 $multipid
3399         wait $multipid || error "multiop close failed"
3400
3401         for (( i=0; i < 2; i++ )) ; do
3402                 local mtime2=`stat -c %Y $DIR1/$tfile`
3403
3404                 [ "$mtime2" = $TEST_39_MTIME ] || \
3405                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3406
3407                 cancel_lru_locks osc
3408                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3409         done
3410 }
3411 run_test 39k "write, utime, close, stat ========================"
3412
3413 # this should be set to future
3414 TEST_39_ATIME=`date -d "1 year" +%s`
3415
3416 test_39l() {
3417         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3418         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3419         local atime_diff=$(do_facet $SINGLEMDS \
3420                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3421         rm -rf $DIR/$tdir
3422         mkdir -p $DIR/$tdir
3423
3424         # test setting directory atime to future
3425         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3426         local atime=$(stat -c %X $DIR/$tdir)
3427         [ "$atime" = $TEST_39_ATIME ] ||
3428                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3429
3430         # test setting directory atime from future to now
3431         local now=$(date +%s)
3432         touch -a -d @$now $DIR/$tdir
3433
3434         atime=$(stat -c %X $DIR/$tdir)
3435         [ "$atime" -eq "$now"  ] ||
3436                 error "atime is not updated from future: $atime, $now"
3437
3438         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3439         sleep 3
3440
3441         # test setting directory atime when now > dir atime + atime_diff
3442         local d1=$(date +%s)
3443         ls $DIR/$tdir
3444         local d2=$(date +%s)
3445         cancel_lru_locks mdc
3446         atime=$(stat -c %X $DIR/$tdir)
3447         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3448                 error "atime is not updated  : $atime, should be $d2"
3449
3450         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3451         sleep 3
3452
3453         # test not setting directory atime when now < dir atime + atime_diff
3454         ls $DIR/$tdir
3455         cancel_lru_locks mdc
3456         atime=$(stat -c %X $DIR/$tdir)
3457         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3458                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3459
3460         do_facet $SINGLEMDS \
3461                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3462 }
3463 run_test 39l "directory atime update ==========================="
3464
3465 test_39m() {
3466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3467         touch $DIR1/$tfile
3468         sleep 2
3469         local far_past_mtime=$(date -d "May 29 1953" +%s)
3470         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3471
3472         touch -m -d @$far_past_mtime $DIR1/$tfile
3473         touch -a -d @$far_past_atime $DIR1/$tfile
3474
3475         for (( i=0; i < 2; i++ )) ; do
3476                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3477                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3478                         error "atime or mtime set incorrectly"
3479
3480                 cancel_lru_locks osc
3481                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3482         done
3483 }
3484 run_test 39m "test atime and mtime before 1970"
3485
3486 test_39n() { # LU-3832
3487         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3488         local atime_diff=$(do_facet $SINGLEMDS \
3489                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3490         local atime0
3491         local atime1
3492         local atime2
3493
3494         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3495
3496         rm -rf $DIR/$tfile
3497         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3498         atime0=$(stat -c %X $DIR/$tfile)
3499
3500         sleep 5
3501         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3502         atime1=$(stat -c %X $DIR/$tfile)
3503
3504         sleep 5
3505         cancel_lru_locks mdc
3506         cancel_lru_locks osc
3507         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3508         atime2=$(stat -c %X $DIR/$tfile)
3509
3510         do_facet $SINGLEMDS \
3511                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3512
3513         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3514         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3515 }
3516 run_test 39n "check that O_NOATIME is honored"
3517
3518 test_39o() {
3519         TESTDIR=$DIR/$tdir/$tfile
3520         [ -e $TESTDIR ] && rm -rf $TESTDIR
3521         mkdir -p $TESTDIR
3522         cd $TESTDIR
3523         links1=2
3524         ls
3525         mkdir a b
3526         ls
3527         links2=$(stat -c %h .)
3528         [ $(($links1 + 2)) != $links2 ] &&
3529                 error "wrong links count $(($links1 + 2)) != $links2"
3530         rmdir b
3531         links3=$(stat -c %h .)
3532         [ $(($links1 + 1)) != $links3 ] &&
3533                 error "wrong links count $links1 != $links3"
3534         return 0
3535 }
3536 run_test 39o "directory cached attributes updated after create ========"
3537
3538 test_39p() {
3539         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3540         local MDTIDX=1
3541         TESTDIR=$DIR/$tdir/$tfile
3542         [ -e $TESTDIR ] && rm -rf $TESTDIR
3543         test_mkdir -p $TESTDIR
3544         cd $TESTDIR
3545         links1=2
3546         ls
3547         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3548         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3549         ls
3550         links2=$(stat -c %h .)
3551         [ $(($links1 + 2)) != $links2 ] &&
3552                 error "wrong links count $(($links1 + 2)) != $links2"
3553         rmdir remote_dir2
3554         links3=$(stat -c %h .)
3555         [ $(($links1 + 1)) != $links3 ] &&
3556                 error "wrong links count $links1 != $links3"
3557         return 0
3558 }
3559 run_test 39p "remote directory cached attributes updated after create ========"
3560
3561
3562 test_39q() { # LU-8041
3563         local testdir=$DIR/$tdir
3564         mkdir -p $testdir
3565         multiop_bg_pause $testdir D_c || error "multiop failed"
3566         local multipid=$!
3567         cancel_lru_locks mdc
3568         kill -USR1 $multipid
3569         local atime=$(stat -c %X $testdir)
3570         [ "$atime" -ne 0 ] || error "atime is zero"
3571 }
3572 run_test 39q "close won't zero out atime"
3573
3574 test_40() {
3575         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3576         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3577                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3578         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3579                 error "$tfile is not 4096 bytes in size"
3580 }
3581 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3582
3583 test_41() {
3584         # bug 1553
3585         small_write $DIR/f41 18
3586 }
3587 run_test 41 "test small file write + fstat ====================="
3588
3589 count_ost_writes() {
3590         lctl get_param -n osc.*.stats |
3591                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3592                         END { printf("%0.0f", writes) }'
3593 }
3594
3595 # decent default
3596 WRITEBACK_SAVE=500
3597 DIRTY_RATIO_SAVE=40
3598 MAX_DIRTY_RATIO=50
3599 BG_DIRTY_RATIO_SAVE=10
3600 MAX_BG_DIRTY_RATIO=25
3601
3602 start_writeback() {
3603         trap 0
3604         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3605         # dirty_ratio, dirty_background_ratio
3606         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3607                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3608                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3609                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3610         else
3611                 # if file not here, we are a 2.4 kernel
3612                 kill -CONT `pidof kupdated`
3613         fi
3614 }
3615
3616 stop_writeback() {
3617         # setup the trap first, so someone cannot exit the test at the
3618         # exact wrong time and mess up a machine
3619         trap start_writeback EXIT
3620         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3621         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3622                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3623                 sysctl -w vm.dirty_writeback_centisecs=0
3624                 sysctl -w vm.dirty_writeback_centisecs=0
3625                 # save and increase /proc/sys/vm/dirty_ratio
3626                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3627                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3628                 # save and increase /proc/sys/vm/dirty_background_ratio
3629                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3630                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3631         else
3632                 # if file not here, we are a 2.4 kernel
3633                 kill -STOP `pidof kupdated`
3634         fi
3635 }
3636
3637 # ensure that all stripes have some grant before we test client-side cache
3638 setup_test42() {
3639         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3640                 dd if=/dev/zero of=$i bs=4k count=1
3641                 rm $i
3642         done
3643 }
3644
3645 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3646 # file truncation, and file removal.
3647 test_42a() {
3648         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3649         setup_test42
3650         cancel_lru_locks osc
3651         stop_writeback
3652         sync; sleep 1; sync # just to be safe
3653         BEFOREWRITES=`count_ost_writes`
3654         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3655         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3656         AFTERWRITES=`count_ost_writes`
3657         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3658                 error "$BEFOREWRITES < $AFTERWRITES"
3659         start_writeback
3660 }
3661 run_test 42a "ensure that we don't flush on close"
3662
3663 test_42b() {
3664         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3665         setup_test42
3666         cancel_lru_locks osc
3667         stop_writeback
3668         sync
3669         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3670         BEFOREWRITES=$(count_ost_writes)
3671         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3672         AFTERWRITES=$(count_ost_writes)
3673         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3674                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3675         fi
3676         BEFOREWRITES=$(count_ost_writes)
3677         sync || error "sync: $?"
3678         AFTERWRITES=$(count_ost_writes)
3679         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3680                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3681         fi
3682         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3683         start_writeback
3684         return 0
3685 }
3686 run_test 42b "test destroy of file with cached dirty data ======"
3687
3688 # if these tests just want to test the effect of truncation,
3689 # they have to be very careful.  consider:
3690 # - the first open gets a {0,EOF}PR lock
3691 # - the first write conflicts and gets a {0, count-1}PW
3692 # - the rest of the writes are under {count,EOF}PW
3693 # - the open for truncate tries to match a {0,EOF}PR
3694 #   for the filesize and cancels the PWs.
3695 # any number of fixes (don't get {0,EOF} on open, match
3696 # composite locks, do smarter file size management) fix
3697 # this, but for now we want these tests to verify that
3698 # the cancellation with truncate intent works, so we
3699 # start the file with a full-file pw lock to match against
3700 # until the truncate.
3701 trunc_test() {
3702         test=$1
3703         file=$DIR/$test
3704         offset=$2
3705         cancel_lru_locks osc
3706         stop_writeback
3707         # prime the file with 0,EOF PW to match
3708         touch $file
3709         $TRUNCATE $file 0
3710         sync; sync
3711         # now the real test..
3712         dd if=/dev/zero of=$file bs=1024 count=100
3713         BEFOREWRITES=`count_ost_writes`
3714         $TRUNCATE $file $offset
3715         cancel_lru_locks osc
3716         AFTERWRITES=`count_ost_writes`
3717         start_writeback
3718 }
3719
3720 test_42c() {
3721         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3722         trunc_test 42c 1024
3723         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3724             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3725         rm $file
3726 }
3727 run_test 42c "test partial truncate of file with cached dirty data"
3728
3729 test_42d() {
3730         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3731         trunc_test 42d 0
3732         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3733             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3734         rm $file
3735 }
3736 run_test 42d "test complete truncate of file with cached dirty data"
3737
3738 test_42e() { # bug22074
3739         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3740         local TDIR=$DIR/${tdir}e
3741         local pagesz=$(page_size)
3742         local pages=16 # hardcoded 16 pages, don't change it.
3743         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3744         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3745         local max_dirty_mb
3746         local warmup_files
3747
3748         test_mkdir -p $DIR/${tdir}e
3749         $SETSTRIPE -c 1 $TDIR
3750         createmany -o $TDIR/f $files
3751
3752         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3753
3754         # we assume that with $OSTCOUNT files, at least one of them will
3755         # be allocated on OST0.
3756         warmup_files=$((OSTCOUNT * max_dirty_mb))
3757         createmany -o $TDIR/w $warmup_files
3758
3759         # write a large amount of data into one file and sync, to get good
3760         # avail_grant number from OST.
3761         for ((i=0; i<$warmup_files; i++)); do
3762                 idx=$($GETSTRIPE -i $TDIR/w$i)
3763                 [ $idx -ne 0 ] && continue
3764                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3765                 break
3766         done
3767         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3768         sync
3769         $LCTL get_param $proc_osc0/cur_dirty_bytes
3770         $LCTL get_param $proc_osc0/cur_grant_bytes
3771
3772         # create as much dirty pages as we can while not to trigger the actual
3773         # RPCs directly. but depends on the env, VFS may trigger flush during this
3774         # period, hopefully we are good.
3775         for ((i=0; i<$warmup_files; i++)); do
3776                 idx=$($GETSTRIPE -i $TDIR/w$i)
3777                 [ $idx -ne 0 ] && continue
3778                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3779         done
3780         $LCTL get_param $proc_osc0/cur_dirty_bytes
3781         $LCTL get_param $proc_osc0/cur_grant_bytes
3782
3783         # perform the real test
3784         $LCTL set_param $proc_osc0/rpc_stats 0
3785         for ((;i<$files; i++)); do
3786                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3787                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3788         done
3789         sync
3790         $LCTL get_param $proc_osc0/rpc_stats
3791
3792         local percent=0
3793         local have_ppr=false
3794         $LCTL get_param $proc_osc0/rpc_stats |
3795                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3796                         # skip lines until we are at the RPC histogram data
3797                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3798                         $have_ppr || continue
3799
3800                         # we only want the percent stat for < 16 pages
3801                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3802
3803                         percent=$((percent + WPCT))
3804                         if [[ $percent -gt 15 ]]; then
3805                                 error "less than 16-pages write RPCs" \
3806                                       "$percent% > 15%"
3807                                 break
3808                         fi
3809                 done
3810         rm -rf $TDIR
3811 }
3812 run_test 42e "verify sub-RPC writes are not done synchronously"
3813
3814 test_43A() { # was test_43
3815         test_mkdir -p $DIR/$tdir
3816         cp -p /bin/ls $DIR/$tdir/$tfile
3817         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3818         pid=$!
3819         # give multiop a chance to open
3820         sleep 1
3821
3822         $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
3823         kill -USR1 $pid
3824 }
3825 run_test 43A "execution of file opened for write should return -ETXTBSY"
3826
3827 test_43a() {
3828         test_mkdir $DIR/$tdir
3829         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3830                 cp -p multiop $DIR/$tdir/multiop
3831         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3832                 error "multiop open $TMP/$tfile.junk failed"
3833         MULTIOP_PID=$!
3834         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3835         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3836         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3837 }
3838 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3839
3840 test_43b() {
3841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3842         test_mkdir $DIR/$tdir
3843         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3844                 cp -p multiop $DIR/$tdir/multiop
3845         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3846                 error "multiop open $TMP/$tfile.junk failed"
3847         MULTIOP_PID=$!
3848         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3849         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3850         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3851 }
3852 run_test 43b "truncate of file being executed should return -ETXTBSY"
3853
3854 test_43c() {
3855         local testdir="$DIR/$tdir"
3856         test_mkdir $testdir
3857         cp $SHELL $testdir/
3858         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |
3859                 ( cd $testdir && md5sum -c )
3860 }
3861 run_test 43c "md5sum of copy into lustre"
3862
3863 test_44A() { # was test_44
3864         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
3865         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3866         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3867 }
3868 run_test 44A "zero length read from a sparse stripe"
3869
3870 test_44a() {
3871         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3872                 awk '{ print $2 }')
3873         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3874         [[ $nstripe -gt $OSTCOUNT ]] &&
3875             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3876             return
3877         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3878                 awk '{ print $2 }')
3879         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3880                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3881                         awk '{ print $2 }')
3882         fi
3883
3884         OFFSETS="0 $((stride/2)) $((stride-1))"
3885         for offset in $OFFSETS; do
3886                 for i in $(seq 0 $((nstripe-1))); do
3887                         local GLOBALOFFSETS=""
3888                         # size in Bytes
3889                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3890                         local myfn=$DIR/d44a-$size
3891                         echo "--------writing $myfn at $size"
3892                         ll_sparseness_write $myfn $size ||
3893                                 error "ll_sparseness_write"
3894                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3895                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3896                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3897
3898                         for j in $(seq 0 $((nstripe-1))); do
3899                                 # size in Bytes
3900                                 size=$((((j + $nstripe )*$stride + $offset)))
3901                                 ll_sparseness_write $myfn $size ||
3902                                         error "ll_sparseness_write"
3903                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3904                         done
3905                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3906                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3907                         rm -f $myfn
3908                 done
3909         done
3910 }
3911 run_test 44a "test sparse pwrite ==============================="
3912
3913 dirty_osc_total() {
3914         tot=0
3915         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3916                 tot=$(($tot + $d))
3917         done
3918         echo $tot
3919 }
3920 do_dirty_record() {
3921         before=`dirty_osc_total`
3922         echo executing "\"$*\""
3923         eval $*
3924         after=`dirty_osc_total`
3925         echo before $before, after $after
3926 }
3927 test_45() {
3928         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3929         f="$DIR/f45"
3930         # Obtain grants from OST if it supports it
3931         echo blah > ${f}_grant
3932         stop_writeback
3933         sync
3934         do_dirty_record "echo blah > $f"
3935         [[ $before -eq $after ]] && error "write wasn't cached"
3936         do_dirty_record "> $f"
3937         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3938         do_dirty_record "echo blah > $f"
3939         [[ $before -eq $after ]] && error "write wasn't cached"
3940         do_dirty_record "sync"
3941         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3942         do_dirty_record "echo blah > $f"
3943         [[ $before -eq $after ]] && error "write wasn't cached"
3944         do_dirty_record "cancel_lru_locks osc"
3945         [[ $before -gt $after ]] ||
3946                 error "lock cancellation didn't lower dirty count"
3947         start_writeback
3948 }
3949 run_test 45 "osc io page accounting ============================"
3950
3951 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3952 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3953 # objects offset and an assert hit when an rpc was built with 1023's mapped
3954 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3955 test_46() {
3956         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3957         f="$DIR/f46"
3958         stop_writeback
3959         sync
3960         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3961         sync
3962         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3963         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3964         sync
3965         start_writeback
3966 }
3967 run_test 46 "dirtying a previously written page ================"
3968
3969 # test_47 is removed "Device nodes check" is moved to test_28
3970
3971 test_48a() { # bug 2399
3972         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3973         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3974                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3975                 return
3976         test_mkdir $DIR/$tdir
3977         cd $DIR/$tdir
3978         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3979         test_mkdir $DIR/$tdir || error "recreate directory failed"
3980         touch foo || error "'touch foo' failed after recreating cwd"
3981         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
3982         touch .foo || error "'touch .foo' failed after recreating cwd"
3983         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
3984         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3985         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3986         cd . || error "'cd .' failed after recreating cwd"
3987         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3988         rmdir . && error "'rmdir .' worked after recreating cwd"
3989         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3990         cd .. || error "'cd ..' failed after recreating cwd"
3991 }
3992 run_test 48a "Access renamed working dir (should return errors)="
3993
3994 test_48b() { # bug 2399
3995         rm -rf $DIR/$tdir
3996         test_mkdir $DIR/$tdir
3997         cd $DIR/$tdir
3998         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3999         touch foo && error "'touch foo' worked after removing cwd"
4000         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
4001         touch .foo && error "'touch .foo' worked after removing cwd"
4002         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
4003         ls . > /dev/null && error "'ls .' worked after removing cwd"
4004         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4005         test_mkdir . && error "'mkdir .' worked after removing cwd"
4006         rmdir . && error "'rmdir .' worked after removing cwd"
4007         ln -s . foo && error "'ln -s .' worked after removing cwd"
4008         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
4009 }
4010 run_test 48b "Access removed working dir (should return errors)="
4011
4012 test_48c() { # bug 2350
4013         #lctl set_param debug=-1
4014         #set -vx
4015         rm -rf $DIR/$tdir
4016         test_mkdir -p $DIR/$tdir/dir
4017         cd $DIR/$tdir/dir
4018         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4019         $TRACE touch foo && error "touch foo worked after removing cwd"
4020         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
4021         touch .foo && error "touch .foo worked after removing cwd"
4022         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
4023         $TRACE ls . && error "'ls .' worked after removing cwd"
4024         $TRACE ls .. || error "'ls ..' failed after removing cwd"
4025         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
4026         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
4027         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
4028         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
4029 }
4030 run_test 48c "Access removed working subdir (should return errors)"
4031
4032 test_48d() { # bug 2350
4033         #lctl set_param debug=-1
4034         #set -vx
4035         rm -rf $DIR/$tdir
4036         test_mkdir -p $DIR/$tdir/dir
4037         cd $DIR/$tdir/dir
4038         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4039         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4040         $TRACE touch foo && error "'touch foo' worked after removing parent"
4041         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
4042         touch .foo && error "'touch .foo' worked after removing parent"
4043         test_mkdir .foo && error "mkdir .foo worked after removing parent"
4044         $TRACE ls . && error "'ls .' worked after removing parent"
4045         $TRACE ls .. && error "'ls ..' worked after removing parent"
4046         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
4047         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
4048         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
4049         true
4050 }
4051 run_test 48d "Access removed parent subdir (should return errors)"
4052
4053 test_48e() { # bug 4134
4054         #lctl set_param debug=-1
4055         #set -vx
4056         rm -rf $DIR/$tdir
4057         test_mkdir -p $DIR/$tdir/dir
4058         cd $DIR/$tdir/dir
4059         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4060         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4061         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
4062         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
4063         # On a buggy kernel addition of "touch foo" after cd .. will
4064         # produce kernel oops in lookup_hash_it
4065         touch ../foo && error "'cd ..' worked after recreate parent"
4066         cd $DIR
4067         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
4068 }
4069 run_test 48e "Access to recreated parent subdir (should return errors)"
4070
4071 test_49() { # LU-1030
4072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4073         remote_ost_nodsh && skip "remote OST with nodsh" && return
4074         # get ost1 size - lustre-OST0000
4075         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
4076                 awk '{ print $4 }')
4077         # write 800M at maximum
4078         [[ $ost1_size -lt 2 ]] && ost1_size=2
4079         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
4080
4081         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
4082         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
4083         local dd_pid=$!
4084
4085         # change max_pages_per_rpc while writing the file
4086         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
4087         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
4088         # loop until dd process exits
4089         while ps ax -opid | grep -wq $dd_pid; do
4090                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
4091                 sleep $((RANDOM % 5 + 1))
4092         done
4093         # restore original max_pages_per_rpc
4094         $LCTL set_param $osc1_mppc=$orig_mppc
4095         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
4096 }
4097 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4098
4099 test_50() {
4100         # bug 1485
4101         test_mkdir $DIR/$tdir
4102         cd $DIR/$tdir
4103         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4104 }
4105 run_test 50 "special situations: /proc symlinks  ==============="
4106
4107 test_51a() {    # was test_51
4108         # bug 1516 - create an empty entry right after ".." then split dir
4109         test_mkdir -c1 $DIR/$tdir
4110         touch $DIR/$tdir/foo
4111         $MCREATE $DIR/$tdir/bar
4112         rm $DIR/$tdir/foo
4113         createmany -m $DIR/$tdir/longfile 201
4114         FNUM=202
4115         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4116                 $MCREATE $DIR/$tdir/longfile$FNUM
4117                 FNUM=$(($FNUM + 1))
4118                 echo -n "+"
4119         done
4120         echo
4121         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4122 }
4123 run_test 51a "special situations: split htree with empty entry =="
4124
4125 cleanup_print_lfs_df () {
4126         trap 0
4127         $LFS df
4128         $LFS df -i
4129 }
4130
4131 test_51b() {
4132         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4133         local dir=$DIR/$tdir
4134
4135         local nrdirs=$((65536 + 100))
4136
4137         # cleanup the directory
4138         rm -fr $dir
4139
4140         test_mkdir -p -c1 $dir
4141
4142         $LFS df
4143         $LFS df -i
4144         local mdtidx=$(printf "%04x" $($LFS getstripe -M $dir))
4145         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4146         [[ $numfree -lt $nrdirs ]] &&
4147                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4148                 return
4149
4150         # need to check free space for the directories as well
4151         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4152         numfree=$(( blkfree / $(fs_inode_ksize) ))
4153         [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)" &&
4154                 return
4155
4156         trap cleanup_print_lfs_df EXIT
4157
4158         # create files
4159         createmany -d $dir/d $nrdirs || {
4160                 unlinkmany $dir/d $nrdirs
4161                 error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
4162         }
4163
4164         # really created :
4165         nrdirs=$(ls -U $dir | wc -l)
4166
4167         # unlink all but 100 subdirectories, then check it still works
4168         local left=100
4169         local delete=$((nrdirs - left))
4170
4171         $LFS df
4172         $LFS df -i
4173
4174         # for ldiskfs the nlink count should be 1, but this is OSD specific
4175         # and so this is listed for informational purposes only
4176         echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
4177         unlinkmany -d $dir/d $delete ||
4178                 error "unlink of first $delete subdirs failed"
4179
4180         echo "nlink between: $(stat -c %h $dir)"
4181         local found=$(ls -U $dir | wc -l)
4182         [ $found -ne $left ] &&
4183                 error "can't find subdirs: found only $found, expected $left"
4184
4185         unlinkmany -d $dir/d $delete $left ||
4186                 error "unlink of second $left subdirs failed"
4187         # regardless of whether the backing filesystem tracks nlink accurately
4188         # or not, the nlink count shouldn't be more than "." and ".." here
4189         local after=$(stat -c %h $dir)
4190         [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
4191                 echo "nlink after: $after"
4192
4193         cleanup_print_lfs_df
4194 }
4195 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
4196
4197 test_51d() {
4198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4199         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
4200         test_mkdir -p $DIR/$tdir
4201         createmany -o $DIR/$tdir/t- 1000
4202         $GETSTRIPE $DIR/$tdir > $TMP/$tfile
4203         for N in $(seq 0 $((OSTCOUNT - 1))); do
4204                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4205                         END { printf("%0.0f", objs) }' $TMP/$tfile)
4206                 OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
4207                         '($1 == '$N') { objs += 1 } \
4208                         END { printf("%0.0f", objs) }')
4209                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4210         done
4211         unlinkmany $DIR/$tdir/t- 1000
4212
4213         NLAST=0
4214         for N in $(seq 1 $((OSTCOUNT - 1))); do
4215                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4216                         error "OST $N has less objects vs OST $NLAST" \
4217                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4218                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4219                         error "OST $N has less objects vs OST $NLAST" \
4220                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4221
4222                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4223                         error "OST $N has less #0 objects vs OST $NLAST" \
4224                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4225                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4226                         error "OST $N has less #0 objects vs OST $NLAST" \
4227                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4228                 NLAST=$N
4229         done
4230         rm -f $TMP/$tfile
4231 }
4232 run_test 51d "check object distribution"
4233
4234 test_51e() {
4235         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4236                 skip "ldiskfs only test"
4237                 return
4238         fi
4239
4240         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4241         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4242
4243         touch $DIR/$tdir/d0/foo
4244         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4245                 error "file exceed 65000 nlink limit!"
4246         unlinkmany $DIR/$tdir/d0/f- 65001
4247         return 0
4248 }
4249 run_test 51e "check file nlink limit"
4250
4251 test_51f() {
4252         test_mkdir $DIR/$tdir
4253
4254         local max=100000
4255         local ulimit_old=$(ulimit -n)
4256         local spare=20 # number of spare fd's for scripts/libraries, etc.
4257         local mdt=$(lfs getstripe -M $DIR/$tdir)
4258         local numfree=$(lfs df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
4259
4260         echo "MDT$mdt numfree=$numfree, max=$max"
4261         [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
4262         if [ $((numfree + spare)) -gt $ulimit_old ]; then
4263                 while ! ulimit -n $((numfree + spare)); do
4264                         numfree=$((numfree * 3 / 4))
4265                 done
4266                 echo "changed ulimit from $ulimit_old to $((numfree + spare))"
4267         else
4268                 echo "left ulimit at $ulimit_old"
4269         fi
4270
4271         createmany -o -k -t 120 $DIR/$tdir/f $numfree || {
4272                 unlinkmany $DIR/$tdir/f $numfree
4273                 error "create+open $numfree files in $DIR/$tdir failed"
4274         }
4275         ulimit -n $ulimit_old
4276
4277         # if createmany exits at 120s there will be fewer than $numfree files
4278         unlinkmany $DIR/$tdir/f $numfree || true
4279 }
4280 run_test 51f "check many open files limit"
4281
4282 test_52a() {
4283         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4284         test_mkdir -p $DIR/$tdir
4285         touch $DIR/$tdir/foo
4286         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4287         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4288         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4289         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4290         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4291                                         error "link worked"
4292         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4293         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4294         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4295                                                      error "lsattr"
4296         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4297         cp -r $DIR/$tdir $TMP/
4298         rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
4299 }
4300 run_test 52a "append-only flag test (should return errors)"
4301
4302 test_52b() {
4303         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4304         test_mkdir -p $DIR/$tdir
4305         touch $DIR/$tdir/foo
4306         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4307         cat test > $DIR/$tdir/foo && error "cat test worked"
4308         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4309         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4310         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4311                                         error "link worked"
4312         echo foo >> $DIR/$tdir/foo && error "echo worked"
4313         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4314         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4315         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4316         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4317                                                         error "lsattr"
4318         chattr -i $DIR/$tdir/foo || error "chattr failed"
4319
4320         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4321 }
4322 run_test 52b "immutable flag test (should return errors) ======="
4323
4324 test_53() {
4325         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4326         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4327         remote_ost_nodsh && skip "remote OST with nodsh" && return
4328
4329         local param
4330         local param_seq
4331         local ostname
4332         local mds_last
4333         local mds_last_seq
4334         local ost_last
4335         local ost_last_seq
4336         local ost_last_id
4337         local ostnum
4338         local node
4339         local found=false
4340         local support_last_seq=true
4341
4342         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4343                 support_last_seq=false
4344
4345         # only test MDT0000
4346         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4347         local value
4348         for value in $(do_facet $SINGLEMDS \
4349                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4350                 param=$(echo ${value[0]} | cut -d "=" -f1)
4351                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4352
4353                 if $support_last_seq; then
4354                         param_seq=$(echo $param |
4355                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4356                         mds_last_seq=$(do_facet $SINGLEMDS \
4357                                        $LCTL get_param -n $param_seq)
4358                 fi
4359                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4360
4361                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4362                 node=$(facet_active_host ost$((ostnum+1)))
4363                 param="obdfilter.$ostname.last_id"
4364                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4365                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4366                         ost_last_id=$ost_last
4367
4368                         if $support_last_seq; then
4369                                 ost_last_id=$(echo $ost_last |
4370                                               awk -F':' '{print $2}' |
4371                                               sed -e "s/^0x//g")
4372                                 ost_last_seq=$(echo $ost_last |
4373                                                awk -F':' '{print $1}')
4374                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4375                         fi
4376
4377                         if [[ $ost_last_id != $mds_last ]]; then
4378                                 error "$ost_last_id != $mds_last"
4379                         else
4380                                 found=true
4381                                 break
4382                         fi
4383                 done
4384         done
4385         $found || error "can not match last_seq/last_id for $mdtosc"
4386         return 0
4387 }
4388 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4389
4390 test_54a() {
4391         perl -MSocket -e ';' || { skip "no Socket perl module installed" && return; }
4392
4393         $SOCKETSERVER $DIR/socket ||
4394                 error "$SOCKETSERVER $DIR/socket failed: $?"
4395         $SOCKETCLIENT $DIR/socket ||
4396                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4397         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4398 }
4399 run_test 54a "unix domain socket test =========================="
4400
4401 test_54b() {
4402         f="$DIR/f54b"
4403         mknod $f c 1 3
4404         chmod 0666 $f
4405         dd if=/dev/zero of=$f bs=$(page_size) count=1
4406 }
4407 run_test 54b "char device works in lustre ======================"
4408
4409 find_loop_dev() {
4410         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4411         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4412         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4413
4414         for i in $(seq 3 7); do
4415                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4416                 LOOPDEV=$LOOPBASE$i
4417                 LOOPNUM=$i
4418                 break
4419         done
4420 }
4421
4422 cleanup_54c() {
4423         local rc=0
4424         loopdev="$DIR/loop54c"
4425
4426         trap 0
4427         $UMOUNT $DIR/$tdir || rc=$?
4428         losetup -d $loopdev || true
4429         losetup -d $LOOPDEV || true
4430         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4431         return $rc
4432 }
4433
4434 test_54c() {
4435         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4436         loopdev="$DIR/loop54c"
4437
4438         find_loop_dev
4439         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4440         trap cleanup_54c EXIT
4441         mknod $loopdev b 7 $LOOPNUM
4442         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4443         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4444         losetup $loopdev $DIR/$tfile ||
4445                 error "can't set up $loopdev for $DIR/$tfile"
4446         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4447         test_mkdir -p $DIR/$tdir
4448         mount -t ext2 $loopdev $DIR/$tdir ||
4449                 error "error mounting $loopdev on $DIR/$tdir"
4450         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4451                 error "dd write"
4452         df $DIR/$tdir
4453         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4454                 error "dd read"
4455         cleanup_54c
4456 }
4457 run_test 54c "block device works in lustre ====================="
4458
4459 test_54d() {
4460         f="$DIR/f54d"
4461         string="aaaaaa"
4462         mknod $f p
4463         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4464 }
4465 run_test 54d "fifo device works in lustre ======================"
4466
4467 test_54e() {
4468         f="$DIR/f54e"
4469         string="aaaaaa"
4470         cp -aL /dev/console $f
4471         echo $string > $f || error "echo $string to $f failed"
4472 }
4473 run_test 54e "console/tty device works in lustre ======================"
4474
4475 #The test_55 used to be iopen test and it was removed by bz#24037.
4476 #run_test 55 "check iopen_connect_dentry() ======================"
4477
4478 test_56a() {    # was test_56
4479         rm -rf $DIR/$tdir
4480         $SETSTRIPE -d $DIR
4481         test_mkdir -p $DIR/$tdir/dir
4482         NUMFILES=3
4483         NUMFILESx2=$(($NUMFILES * 2))
4484         for i in $(seq 1 $NUMFILES); do
4485                 touch $DIR/$tdir/file$i
4486                 touch $DIR/$tdir/dir/file$i
4487         done
4488
4489         # test lfs getstripe with --recursive
4490         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4491         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4492                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4493         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4494         [[ $FILENUM -eq $NUMFILES ]] ||
4495                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4496         echo "$GETSTRIPE --recursive passed."
4497
4498         # test lfs getstripe with file instead of dir
4499         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4500         [[ $FILENUM -eq 1 ]] ||
4501                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4502         echo "$GETSTRIPE file1 passed."
4503
4504         #test lfs getstripe with --verbose
4505         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4506                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4507                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4508         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4509                 error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4510
4511         #test lfs getstripe with -v prints lmm_fid
4512         [[ $($GETSTRIPE -v $DIR/$tdir | grep -c lmm_fid) -eq $NUMFILES ]] ||
4513                 error "$GETSTRIPE -v $DIR/$tdir: want $NUMFILES lmm_fid: lines"
4514         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_fid) -eq 0 ]] ||
4515                 error "$GETSTRIPE $DIR/$tdir: showed lmm_fid"
4516         echo "$GETSTRIPE --verbose passed."
4517
4518         #check for FID information
4519         local fid1=$($GETSTRIPE --fid $DIR/$tdir/file1)
4520         local fid2=$($GETSTRIPE --verbose $DIR/$tdir/file1 |
4521                        awk '/lmm_fid: / { print $2 }')
4522         local fid3=$($LFS path2fid $DIR/$tdir/file1)
4523         [ "$fid1" != "$fid2" ] &&
4524                 error "getstripe --fid $fid1 != getstripe --verbose $fid2"
4525         [ "$fid1" != "$fid3" ] &&
4526                 error "getstripe --fid $fid1 != lfs path2fid $fid3"
4527         echo "$GETSTRIPE --fid passed."
4528
4529         #test lfs getstripe with --obd
4530         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4531                 grep -q "unknown obduuid" ||
4532                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4533
4534         [[ $OSTCOUNT -lt 2 ]] &&
4535                 skip_env "skipping other $GETSTRIPE --obd test" && return
4536
4537         OSTIDX=1
4538         OBDUUID=$(ostuuid_from_index $OSTIDX)
4539         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4540         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4541         [[ $FOUND -eq $FILENUM ]] ||
4542                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4543         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4544                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4545                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4546                 error "$GETSTRIPE --obd: should not show file on other obd"
4547         echo "$GETSTRIPE --obd passed"
4548 }
4549 run_test 56a "check $GETSTRIPE"
4550
4551 test_56b() {
4552         test_mkdir $DIR/$tdir
4553         NUMDIRS=3
4554         for i in $(seq 1 $NUMDIRS); do
4555                 test_mkdir $DIR/$tdir/dir$i
4556         done
4557
4558         # test lfs getdirstripe default mode is non-recursion, which is
4559         # different from lfs getstripe
4560         dircnt=$($LFS getdirstripe $DIR/$tdir | grep -c lmv_stripe_count)
4561         [[ $dircnt -eq 1 ]] ||
4562                 error "$LFS getdirstripe: found $dircnt, not 1"
4563         dircnt=$($LFS getdirstripe --recursive $DIR/$tdir |
4564                 grep -c lmv_stripe_count)
4565         [[ $dircnt -eq $((NUMDIRS + 1)) ]] ||
4566                 error "$LFS getdirstripe --recursive: found $dircnt, \
4567                         not $((NUMDIRS + 1))"
4568 }
4569 run_test 56b "check $LFS getdirstripe"
4570
4571 test_56c() {
4572         local ost_idx=0
4573         local ost_name=$(ostname_from_index $ost_idx)
4574
4575         local old_status=$(ost_dev_status $ost_idx)
4576         [[ -z "$old_status" ]] ||
4577                 { skip_env "OST $ost_name is in $old_status status"; return 0; }
4578
4579         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
4580         sleep_maxage
4581
4582         local new_status=$(ost_dev_status $ost_idx)
4583         [[ "$new_status" = "D" ]] ||
4584                 error "OST $ost_name is in status of '$new_status', not 'D'"
4585
4586         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
4587         sleep_maxage
4588
4589         new_status=$(ost_dev_status $ost_idx)
4590         [[ -z "$new_status" ]] ||
4591                 error "OST $ost_name is in status of '$new_status', not ''"
4592 }
4593 run_test 56c "check 'lfs df' showing device status"
4594
4595 NUMFILES=3
4596 NUMDIRS=3
4597 setup_56() {
4598         local LOCAL_NUMFILES="$1"
4599         local LOCAL_NUMDIRS="$2"
4600         local MKDIR_PARAMS="$3"
4601         local DIR_STRIPE_PARAMS="$4"
4602
4603         if [ ! -d "$TDIR" ] ; then
4604                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4605                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4606                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4607                         touch $TDIR/file$i
4608                 done
4609                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4610                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4611                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4612                                 touch $TDIR/dir$i/file$j
4613                         done
4614                 done
4615         fi
4616 }
4617
4618 setup_56_special() {
4619         LOCAL_NUMFILES=$1
4620         LOCAL_NUMDIRS=$2
4621         setup_56 $1 $2
4622         if [ ! -e "$TDIR/loop1b" ] ; then
4623                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4624                         mknod $TDIR/loop${i}b b 7 $i
4625                         mknod $TDIR/null${i}c c 1 3
4626                         ln -s $TDIR/file1 $TDIR/link${i}l
4627                 done
4628                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4629                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4630                         mknod $TDIR/dir$i/null${i}c c 1 3
4631                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4632                 done
4633         fi
4634 }
4635
4636 test_56g() {
4637         $SETSTRIPE -d $DIR
4638
4639         TDIR=$DIR/${tdir}g
4640         setup_56 $NUMFILES $NUMDIRS
4641
4642         EXPECTED=$(($NUMDIRS + 2))
4643         # test lfs find with -name
4644         for i in $(seq 1 $NUMFILES) ; do
4645                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4646                 [ $NUMS -eq $EXPECTED ] ||
4647                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4648                               "found $NUMS, expected $EXPECTED"
4649         done
4650 }
4651 run_test 56g "check lfs find -name ============================="
4652
4653 test_56h() {
4654         $SETSTRIPE -d $DIR
4655
4656         TDIR=$DIR/${tdir}g
4657         setup_56 $NUMFILES $NUMDIRS
4658
4659         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4660         # test lfs find with ! -name
4661         for i in $(seq 1 $NUMFILES) ; do
4662                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4663                 [ $NUMS -eq $EXPECTED ] ||
4664                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4665                               "found $NUMS, expected $EXPECTED"
4666         done
4667 }
4668 run_test 56h "check lfs find ! -name ============================="
4669
4670 test_56i() {
4671        tdir=${tdir}i
4672        test_mkdir -p $DIR/$tdir
4673        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4674        CMD="$LFIND -ost $UUID $DIR/$tdir"
4675        OUT=$($CMD)
4676        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4677 }
4678 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4679
4680 test_56j() {
4681         TDIR=$DIR/${tdir}g
4682         setup_56_special $NUMFILES $NUMDIRS
4683
4684         EXPECTED=$((NUMDIRS + 1))
4685         CMD="$LFIND -type d $TDIR"
4686         NUMS=$($CMD | wc -l)
4687         [ $NUMS -eq $EXPECTED ] ||
4688                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4689 }
4690 run_test 56j "check lfs find -type d ============================="
4691
4692 test_56k() {
4693         TDIR=$DIR/${tdir}g
4694         setup_56_special $NUMFILES $NUMDIRS
4695
4696         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4697         CMD="$LFIND -type f $TDIR"
4698         NUMS=$($CMD | wc -l)
4699         [ $NUMS -eq $EXPECTED ] ||
4700                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4701 }
4702 run_test 56k "check lfs find -type f ============================="
4703
4704 test_56l() {
4705         TDIR=$DIR/${tdir}g
4706         setup_56_special $NUMFILES $NUMDIRS
4707
4708         EXPECTED=$((NUMDIRS + NUMFILES))
4709         CMD="$LFIND -type b $TDIR"
4710         NUMS=$($CMD | wc -l)
4711         [ $NUMS -eq $EXPECTED ] ||
4712                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4713 }
4714 run_test 56l "check lfs find -type b ============================="
4715
4716 test_56m() {
4717         TDIR=$DIR/${tdir}g
4718         setup_56_special $NUMFILES $NUMDIRS
4719
4720         EXPECTED=$((NUMDIRS + NUMFILES))
4721         CMD="$LFIND -type c $TDIR"
4722         NUMS=$($CMD | wc -l)
4723         [ $NUMS -eq $EXPECTED ] ||
4724                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4725 }
4726 run_test 56m "check lfs find -type c ============================="
4727
4728 test_56n() {
4729         TDIR=$DIR/${tdir}g
4730         setup_56_special $NUMFILES $NUMDIRS
4731
4732         EXPECTED=$((NUMDIRS + NUMFILES))
4733         CMD="$LFIND -type l $TDIR"
4734         NUMS=$($CMD | wc -l)
4735         [ $NUMS -eq $EXPECTED ] ||
4736                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4737 }
4738 run_test 56n "check lfs find -type l ============================="
4739
4740 test_56o() {
4741         TDIR=$DIR/${tdir}o
4742         setup_56 $NUMFILES $NUMDIRS
4743         utime $TDIR/file1 > /dev/null || error "utime (1)"
4744         utime $TDIR/file2 > /dev/null || error "utime (2)"
4745         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4746         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4747         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4748         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4749
4750         EXPECTED=4
4751         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4752         [ $NUMS -eq $EXPECTED ] || \
4753                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4754
4755         EXPECTED=12
4756         CMD="$LFIND -mtime 0 $TDIR"
4757         NUMS=$($CMD | wc -l)
4758         [ $NUMS -eq $EXPECTED ] ||
4759                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4760 }
4761 run_test 56o "check lfs find -mtime for old files =========================="
4762
4763 test_56p() {
4764         [ $RUNAS_ID -eq $UID ] &&
4765                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4766
4767         TDIR=$DIR/${tdir}p
4768         setup_56 $NUMFILES $NUMDIRS
4769
4770         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4771         EXPECTED=$NUMFILES
4772         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4773         NUMS=$($CMD | wc -l)
4774         [ $NUMS -eq $EXPECTED ] || \
4775                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4776
4777         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4778         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4779         NUMS=$($CMD | wc -l)
4780         [ $NUMS -eq $EXPECTED ] || \
4781                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4782 }
4783 run_test 56p "check lfs find -uid and ! -uid ==============================="
4784
4785 test_56q() {
4786         [ $RUNAS_ID -eq $UID ] &&
4787                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4788
4789         TDIR=$DIR/${tdir}q
4790         setup_56 $NUMFILES $NUMDIRS
4791
4792         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4793
4794         EXPECTED=$NUMFILES
4795         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4796         NUMS=$($CMD | wc -l)
4797         [ $NUMS -eq $EXPECTED ] ||
4798                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4799
4800         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4801         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4802         NUMS=$($CMD | wc -l)
4803         [ $NUMS -eq $EXPECTED ] ||
4804                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4805 }
4806 run_test 56q "check lfs find -gid and ! -gid ==============================="
4807
4808 test_56r() {
4809         TDIR=$DIR/${tdir}r
4810         setup_56 $NUMFILES $NUMDIRS
4811
4812         EXPECTED=12
4813         CMD="$LFIND -size 0 -type f $TDIR"
4814         NUMS=$($CMD | wc -l)
4815         [ $NUMS -eq $EXPECTED ] ||
4816                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4817         EXPECTED=0
4818         CMD="$LFIND ! -size 0 -type f $TDIR"
4819         NUMS=$($CMD | wc -l)
4820         [ $NUMS -eq $EXPECTED ] ||
4821                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4822         echo "test" > $TDIR/$tfile
4823         echo "test2" > $TDIR/$tfile.2 && sync
4824         EXPECTED=1
4825         CMD="$LFIND -size 5 -type f $TDIR"
4826         NUMS=$($CMD | wc -l)
4827         [ $NUMS -eq $EXPECTED ] ||
4828                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4829         EXPECTED=1
4830         CMD="$LFIND -size +5 -type f $TDIR"
4831         NUMS=$($CMD | wc -l)
4832         [ $NUMS -eq $EXPECTED ] ||
4833                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4834         EXPECTED=2
4835         CMD="$LFIND -size +0 -type f $TDIR"
4836         NUMS=$($CMD | wc -l)
4837         [ $NUMS -eq $EXPECTED ] ||
4838                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4839         EXPECTED=2
4840         CMD="$LFIND ! -size -5 -type f $TDIR"
4841         NUMS=$($CMD | wc -l)
4842         [ $NUMS -eq $EXPECTED ] ||
4843                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4844         EXPECTED=12
4845         CMD="$LFIND -size -5 -type f $TDIR"
4846         NUMS=$($CMD | wc -l)
4847         [ $NUMS -eq $EXPECTED ] ||
4848                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4849 }
4850 run_test 56r "check lfs find -size works =========================="
4851
4852 test_56s() { # LU-611
4853         TDIR=$DIR/${tdir}s
4854
4855         #LU-9369
4856         setup_56 0 $NUMDIRS
4857         for i in $(seq 1 $NUMDIRS); do
4858                 $SETSTRIPE -c $((OSTCOUNT + 1)) $TDIR/dir$i/$tfile
4859         done
4860         EXPECTED=$NUMDIRS
4861         CMD="$LFIND -c $OSTCOUNT $TDIR"
4862         NUMS=$($CMD | wc -l)
4863         [ $NUMS -eq $EXPECTED ] || {
4864                 $GETSTRIPE -R $TDIR
4865                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4866         }
4867         rm -rf $TDIR
4868
4869         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4870         if [[ $OSTCOUNT -gt 1 ]]; then
4871                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4872                 ONESTRIPE=4
4873                 EXTRA=4
4874         else
4875                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4876                 EXTRA=0
4877         fi
4878
4879         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4880         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4881         NUMS=$($CMD | wc -l)
4882         [ $NUMS -eq $EXPECTED ] || {
4883                 $GETSTRIPE -R $TDIR
4884                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4885         }
4886
4887         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4888         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4889         NUMS=$($CMD | wc -l)
4890         [ $NUMS -eq $EXPECTED ] || {
4891                 $GETSTRIPE -R $TDIR
4892                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4893         }
4894
4895         EXPECTED=$ONESTRIPE
4896         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4897         NUMS=$($CMD | wc -l)
4898         [ $NUMS -eq $EXPECTED ] || {
4899                 $GETSTRIPE -R $TDIR
4900                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4901         }
4902
4903         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4904         NUMS=$($CMD | wc -l)
4905         [ $NUMS -eq $EXPECTED ] || {
4906                 $GETSTRIPE -R $TDIR
4907                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4908         }
4909
4910         EXPECTED=0
4911         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4912         NUMS=$($CMD | wc -l)
4913         [ $NUMS -eq $EXPECTED ] || {
4914                 $GETSTRIPE -R $TDIR
4915                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4916         }
4917 }
4918 run_test 56s "check lfs find -stripe-count works"
4919
4920 test_56t() { # LU-611
4921         TDIR=$DIR/${tdir}t
4922
4923         #LU-9369
4924         setup_56 0 $NUMDIRS
4925         for i in $(seq 1 $NUMDIRS); do
4926                 $SETSTRIPE -S 4M $TDIR/dir$i/$tfile
4927         done
4928         EXPECTED=$NUMDIRS
4929         CMD="$LFIND -S 4M $TDIR"
4930         NUMS=$($CMD | wc -l)
4931         [ $NUMS -eq $EXPECTED ] || {
4932                 $GETSTRIPE -R $TDIR
4933                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4934         }
4935         rm -rf $TDIR
4936
4937         setup_56 $NUMFILES $NUMDIRS "--stripe-size 512k"
4938
4939         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4940
4941         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4942         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4943         NUMS=$($CMD | wc -l)
4944         [ $NUMS -eq $EXPECTED ] ||
4945                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4946
4947         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4948         NUMS=$($CMD | wc -l)
4949         [ $NUMS -eq $EXPECTED ] ||
4950                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4951
4952         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4953         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4954         NUMS=$($CMD | wc -l)
4955         [ $NUMS -eq $EXPECTED ] ||
4956                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4957
4958         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4959         NUMS=$($CMD | wc -l)
4960         [ $NUMS -eq $EXPECTED ] ||
4961                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4962
4963         EXPECTED=4
4964         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4965         NUMS=$($CMD | wc -l)
4966         [ $NUMS -eq $EXPECTED ] ||
4967                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4968
4969         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4970         NUMS=$($CMD | wc -l)
4971         [ $NUMS -eq $EXPECTED ] ||
4972                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4973
4974         EXPECTED=0
4975         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4976         NUMS=$($CMD | wc -l)
4977         [ $NUMS -eq $EXPECTED ] ||
4978                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4979 }
4980 run_test 56t "check lfs find -stripe-size works"
4981
4982 test_56u() { # LU-611
4983         TDIR=$DIR/${tdir}u
4984         setup_56 $NUMFILES $NUMDIRS "-i 0"
4985
4986         if [[ $OSTCOUNT -gt 1 ]]; then
4987                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4988                 ONESTRIPE=4
4989         else
4990                 ONESTRIPE=0
4991         fi
4992
4993         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4994         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4995         NUMS=$($CMD | wc -l)
4996         [ $NUMS -eq $EXPECTED ] ||
4997                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4998
4999         EXPECTED=$ONESTRIPE
5000         CMD="$LFIND -stripe-index 1 -type f $TDIR"
5001         NUMS=$($CMD | wc -l)
5002         [ $NUMS -eq $EXPECTED ] ||
5003                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5004
5005         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
5006         NUMS=$($CMD | wc -l)
5007         [ $NUMS -eq $EXPECTED ] ||
5008                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5009
5010         EXPECTED=0
5011         # This should produce an error and not return any files
5012         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
5013         NUMS=$($CMD 2>/dev/null | wc -l)
5014         [ $NUMS -eq $EXPECTED ] ||
5015                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5016
5017         if [[ $OSTCOUNT -gt 1 ]]; then
5018                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
5019                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
5020                 NUMS=$($CMD | wc -l)
5021                 [ $NUMS -eq $EXPECTED ] ||
5022                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5023         fi
5024 }
5025 run_test 56u "check lfs find -stripe-index works"
5026
5027 test_56v() {
5028     local MDT_IDX=0
5029
5030     TDIR=$DIR/${tdir}v
5031     rm -rf $TDIR
5032     setup_56 $NUMFILES $NUMDIRS
5033
5034     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
5035     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
5036
5037     for file in $($LFIND -mdt $UUID $TDIR); do
5038         file_mdt_idx=$($GETSTRIPE -M $file)
5039         [ $file_mdt_idx -eq $MDT_IDX ] ||
5040             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
5041     done
5042 }
5043 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
5044
5045 test_56w() {
5046         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5047         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5048         TDIR=$DIR/${tdir}w
5049
5050     rm -rf $TDIR || error "remove $TDIR failed"
5051     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
5052
5053     local stripe_size
5054     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
5055         error "$GETSTRIPE -S -d $TDIR failed"
5056     stripe_size=${stripe_size%% *}
5057
5058     local file_size=$((stripe_size * OSTCOUNT))
5059     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
5060     local required_space=$((file_num * file_size))
5061
5062     local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
5063                         head -n1)
5064     [[ $free_space -le $((required_space / 1024)) ]] &&
5065         skip_env "need at least $required_space bytes free space," \
5066                  "have $free_space kbytes" && return
5067
5068     local dd_bs=65536
5069     local dd_count=$((file_size / dd_bs))
5070
5071     # write data into the files
5072     local i
5073     local j
5074     local file
5075     for i in $(seq 1 $NUMFILES); do
5076         file=$TDIR/file$i
5077         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
5078             error "write data into $file failed"
5079     done
5080     for i in $(seq 1 $NUMDIRS); do
5081         for j in $(seq 1 $NUMFILES); do
5082             file=$TDIR/dir$i/file$j
5083             yes | dd bs=$dd_bs count=$dd_count of=$file \
5084                 >/dev/null 2>&1 ||
5085                 error "write data into $file failed"
5086         done
5087     done
5088
5089     local expected=-1
5090     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
5091
5092     # lfs_migrate file
5093     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
5094     echo "$cmd"
5095     eval $cmd || error "$cmd failed"
5096
5097     check_stripe_count $TDIR/file1 $expected
5098
5099         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
5100         then
5101                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
5102                 # OST 1 if it is on OST 0. This file is small enough to
5103                 # be on only one stripe.
5104                 file=$TDIR/migr_1_ost
5105                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
5106                         error "write data into $file failed"
5107                 local obdidx=$($LFS getstripe -i $file)
5108                 local oldmd5=$(md5sum $file)
5109                 local newobdidx=0
5110                 [[ $obdidx -eq 0 ]] && newobdidx=1
5111                 cmd="$LFS migrate -i $newobdidx $file"
5112                 echo $cmd
5113                 eval $cmd || error "$cmd failed"
5114                 local realobdix=$($LFS getstripe -i $file)
5115                 local newmd5=$(md5sum $file)
5116                 [[ $newobdidx -ne $realobdix ]] &&
5117                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
5118                 [[ "$oldmd5" != "$newmd5" ]] &&
5119                         error "md5sum differ: $oldmd5, $newmd5"
5120         fi
5121
5122     # lfs_migrate dir
5123     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
5124     echo "$cmd"
5125     eval $cmd || error "$cmd failed"
5126
5127     for j in $(seq 1 $NUMFILES); do
5128         check_stripe_count $TDIR/dir1/file$j $expected
5129     done
5130
5131     # lfs_migrate works with lfs find
5132     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
5133          $LFS_MIGRATE -y -c $expected"
5134     echo "$cmd"
5135     eval $cmd || error "$cmd failed"
5136
5137     for i in $(seq 2 $NUMFILES); do
5138         check_stripe_count $TDIR/file$i $expected
5139     done
5140     for i in $(seq 2 $NUMDIRS); do
5141         for j in $(seq 1 $NUMFILES); do
5142             check_stripe_count $TDIR/dir$i/file$j $expected
5143         done
5144     done
5145 }
5146 run_test 56w "check lfs_migrate -c stripe_count works"
5147
5148 test_56x() {
5149         check_swap_layouts_support && return 0
5150         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5151
5152         local dir0=$DIR/$tdir/$testnum
5153         test_mkdir -p $dir0 || error "creating dir $dir0"
5154
5155         local ref1=/etc/passwd
5156         local file1=$dir0/file1
5157
5158         $SETSTRIPE -c 2 $file1
5159         cp $ref1 $file1
5160         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
5161         stripe=$($GETSTRIPE -c $file1)
5162         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5163         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5164
5165         # clean up
5166         rm -f $file1
5167 }
5168 run_test 56x "lfs migration support"
5169
5170 test_56xa() {
5171         check_swap_layouts_support && return 0
5172         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5173
5174         local dir0=$DIR/$tdir/$testnum
5175         test_mkdir -p $dir0 || error "creating dir $dir0"
5176
5177         local ref1=/etc/passwd
5178         local file1=$dir0/file1
5179
5180         $SETSTRIPE -c 2 $file1
5181         cp $ref1 $file1
5182         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
5183         local stripe=$($GETSTRIPE -c $file1)
5184         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5185         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5186
5187         # clean up
5188         rm -f $file1
5189 }
5190 run_test 56xa "lfs migration --block support"
5191
5192 test_56y() {
5193         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
5194                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
5195                 return
5196
5197         local res=""
5198         local dir0=$DIR/$tdir/$testnum
5199         test_mkdir -p $dir0 || error "creating dir $dir0"
5200         local f1=$dir0/file1
5201         local f2=$dir0/file2
5202
5203         touch $f1 || error "creating std file $f1"
5204         $MULTIOP $f2 H2c || error "creating released file $f2"
5205
5206         # a directory can be raid0, so ask only for files
5207         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
5208         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
5209
5210         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
5211         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
5212
5213         # only files can be released, so no need to force file search
5214         res=$($LFIND $dir0 -L released)
5215         [[ $res == $f2 ]] || error "search released: found $res != $f2"
5216
5217         res=$($LFIND $dir0 \! -L released)
5218         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
5219
5220 }
5221 run_test 56y "lfs find -L raid0|released"
5222
5223 test_56z() { # LU-4824
5224         # This checks to make sure 'lfs find' continues after errors
5225         # There are two classes of errors that should be caught:
5226         # - If multiple paths are provided, all should be searched even if one
5227         #   errors out
5228         # - If errors are encountered during the search, it should not terminate
5229         #   early
5230         local i
5231         test_mkdir $DIR/$tdir
5232         for i in d{0..9}; do
5233                 test_mkdir $DIR/$tdir/$i
5234         done
5235         touch $DIR/$tdir/d{0..9}/$tfile
5236         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5237                 error "$LFS find did not return an error"
5238         # Make a directory unsearchable. This should NOT be the last entry in
5239         # directory order.  Arbitrarily pick the 6th entry
5240         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5241         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5242         # The user should be able to see 10 directories and 9 files
5243         [ $count == 19 ] || error "$LFS find did not continue after error"
5244 }
5245 run_test 56z "lfs find should continue after an error"
5246
5247 test_56aa() { # LU-5937
5248         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5249
5250         mkdir $DIR/$tdir
5251         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5252
5253         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5254         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5255
5256         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5257 }
5258 run_test 56aa "lfs find --size under striped dir"
5259
5260 test_57a() {
5261         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5262         # note test will not do anything if MDS is not local
5263         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5264                 skip "ldiskfs only test"
5265                 return
5266         fi
5267
5268         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5269         local MNTDEV="osd*.*MDT*.mntdev"
5270         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5271         [ -z "$DEV" ] && error "can't access $MNTDEV"
5272         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5273                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5274                         error "can't access $DEV"
5275                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5276                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5277                 rm $TMP/t57a.dump
5278         done
5279 }
5280 run_test 57a "verify MDS filesystem created with large inodes =="
5281
5282 test_57b() {
5283         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5284         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5285                 skip "ldiskfs only test"
5286                 return
5287         fi
5288
5289         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5290         local dir=$DIR/$tdir
5291
5292         local FILECOUNT=100
5293         local FILE1=$dir/f1
5294         local FILEN=$dir/f$FILECOUNT
5295
5296         rm -rf $dir || error "removing $dir"
5297         test_mkdir -p -c1 $dir || error "creating $dir"
5298         local mdtidx=$($LFS getstripe -M $dir)
5299         local mdtname=MDT$(printf %04x $mdtidx)
5300         local facet=mds$((mdtidx + 1))
5301
5302         echo "mcreating $FILECOUNT files"
5303         createmany -m $dir/f 1 $FILECOUNT || \
5304                 error "creating files in $dir"
5305
5306         # verify that files do not have EAs yet
5307         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5308         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5309
5310         sync
5311         sleep 1
5312         df $dir  #make sure we get new statfs data
5313         local MDSFREE=$(do_facet $facet \
5314                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5315         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5316         echo "opening files to create objects/EAs"
5317         local FILE
5318         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5319                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5320         done
5321
5322         # verify that files have EAs now
5323         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5324         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5325
5326         sleep 1  #make sure we get new statfs data
5327         df $dir
5328         local MDSFREE2=$(do_facet $facet \
5329                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5330         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5331         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5332                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5333                         error "MDC before $MDCFREE != after $MDCFREE2"
5334                 else
5335                         echo "MDC before $MDCFREE != after $MDCFREE2"
5336                         echo "unable to confirm if MDS has large inodes"
5337                 fi
5338         fi
5339         rm -rf $dir
5340 }
5341 run_test 57b "default LOV EAs are stored inside large inodes ==="
5342
5343 test_58() {
5344         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5345         [ -z "$(which wiretest 2>/dev/null)" ] &&
5346                         skip_env "could not find wiretest" && return
5347         wiretest
5348 }
5349 run_test 58 "verify cross-platform wire constants =============="
5350
5351 test_59() {
5352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5353         echo "touch 130 files"
5354         createmany -o $DIR/f59- 130
5355         echo "rm 130 files"
5356         unlinkmany $DIR/f59- 130
5357         sync
5358         # wait for commitment of removal
5359         wait_delete_completed
5360 }
5361 run_test 59 "verify cancellation of llog records async ========="
5362
5363 TEST60_HEAD="test_60 run $RANDOM"
5364 test_60a() {
5365         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5366         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5367         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5368                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5369                         skip_env "missing subtest run-llog.sh" && return
5370
5371         log "$TEST60_HEAD - from kernel mode"
5372         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5373         do_facet mgs sh run-llog.sh
5374         do_facet mgs $LCTL dk > $TMP/$tfile
5375
5376         # LU-6388: test llog_reader
5377         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5378         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5379         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5380                         skip_env "missing llog_reader" && return
5381         local fstype=$(facet_fstype mgs)
5382         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5383                 skip_env "Only for ldiskfs or zfs type mgs" && return
5384
5385         local mntpt=$(facet_mntpt mgs)
5386         local mgsdev=$(mgsdevname 1)
5387         local fid_list
5388         local fid
5389         local rec_list
5390         local rec
5391         local rec_type
5392         local obj_file
5393         local path
5394         local seq
5395         local oid
5396         local pass=true
5397
5398         #get fid and record list
5399         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5400                 tail -n 4))
5401         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5402                 tail -n 4))
5403         #remount mgs as ldiskfs or zfs type
5404         stop mgs || error "stop mgs failed"
5405         mount_fstype mgs || error "remount mgs failed"
5406         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5407                 fid=${fid_list[i]}
5408                 rec=${rec_list[i]}
5409                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5410                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5411                 oid=$((16#$oid))
5412
5413                 case $fstype in
5414                         ldiskfs )
5415                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5416                         zfs )
5417                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5418                 esac
5419                 echo "obj_file is $obj_file"
5420                 do_facet mgs $llog_reader $obj_file
5421
5422                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5423                         awk '{ print $3 }' | sed -e "s/^type=//g")
5424                 if [ $rec_type != $rec ]; then
5425                         echo "FAILED test_60a wrong record type $rec_type," \
5426                               "should be $rec"
5427                         pass=false
5428                         break
5429                 fi
5430
5431                 #check obj path if record type is LLOG_LOGID_MAGIC
5432                 if [ "$rec" == "1064553b" ]; then
5433                         path=$(do_facet mgs $llog_reader $obj_file |
5434                                 grep "path=" | awk '{ print $NF }' |
5435                                 sed -e "s/^path=//g")
5436                         if [ $obj_file != $mntpt/$path ]; then
5437                                 echo "FAILED test_60a wrong obj path" \
5438                                       "$montpt/$path, should be $obj_file"
5439                                 pass=false
5440                                 break
5441                         fi
5442                 fi
5443         done
5444         rm -f $TMP/$tfile
5445         #restart mgs before "error", otherwise it will block the next test
5446         stop mgs || error "stop mgs failed"
5447         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5448         $pass || error "test failed, see FAILED test_60a messages for specifics"
5449 }
5450 run_test 60a "llog_test run from kernel module and test llog_reader"
5451
5452 test_60aa() {
5453         # test old logid format
5454         if [ $(lustre_version_code mgs) -le $(version_code 3.1.53) ]; then
5455                 do_facet mgs $LCTL dl | grep MGS
5456                 do_facet mgs "$LCTL --device %MGS llog_print \\\\\\\$$FSNAME-client" ||
5457                         error "old llog_print failed"
5458         fi
5459
5460         # test new logid format
5461         if [ $(lustre_version_code mgs) -ge $(version_code 2.9.53) ]; then
5462                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
5463                         error "new llog_print failed"
5464         fi
5465 }
5466 run_test 60aa "llog_print works with FIDs and simple names"
5467
5468 test_60b() { # bug 6411
5469         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5470         dmesg > $DIR/$tfile
5471         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
5472                                 /llog.test/ {
5473                                         if (marker)
5474                                                 from_marker++
5475                                         from_begin++
5476                                 }
5477                                 END {
5478                                         if (marker)
5479                                                 print from_marker
5480                                         else
5481                                                 print from_begin
5482                                 }")
5483         [[ $LLOG_COUNT -gt 100 ]] &&
5484                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5485 }
5486 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5487
5488 test_60c() {
5489         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5490         echo "create 5000 files"
5491         createmany -o $DIR/f60c- 5000
5492 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5493         lctl set_param fail_loc=0x80000137
5494         unlinkmany $DIR/f60c- 5000
5495         lctl set_param fail_loc=0
5496 }
5497 run_test 60c "unlink file when mds full"
5498
5499 test_60d() {
5500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5501         SAVEPRINTK=$(lctl get_param -n printk)
5502
5503         # verify "lctl mark" is even working"
5504         MESSAGE="test message ID $RANDOM $$"
5505         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5506         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5507
5508         lctl set_param printk=0 || error "set lnet.printk failed"
5509         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5510         MESSAGE="new test message ID $RANDOM $$"
5511         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5512         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5513         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5514
5515         lctl set_param -n printk="$SAVEPRINTK"
5516 }
5517 run_test 60d "test printk console message masking"
5518
5519 test_60e() {
5520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5521         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5522         touch $DIR/$tfile
5523 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5524         do_facet mds1 lctl set_param fail_loc=0x15b
5525         rm $DIR/$tfile
5526 }
5527 run_test 60e "no space while new llog is being created"
5528
5529 test_61() {
5530         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5531         f="$DIR/f61"
5532         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5533         cancel_lru_locks osc
5534         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5535         sync
5536 }
5537 run_test 61 "mmap() writes don't make sync hang ================"
5538
5539 # bug 2330 - insufficient obd_match error checking causes LBUG
5540 test_62() {
5541         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5542         f="$DIR/f62"
5543         echo foo > $f
5544         cancel_lru_locks osc
5545         lctl set_param fail_loc=0x405
5546         cat $f && error "cat succeeded, expect -EIO"
5547         lctl set_param fail_loc=0
5548 }
5549 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5550 # match every page all of the time.
5551 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5552
5553 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5554 # Though this test is irrelevant anymore, it helped to reveal some
5555 # other grant bugs (LU-4482), let's keep it.
5556 test_63a() {   # was test_63
5557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5558         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5559         for i in `seq 10` ; do
5560                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5561                 sleep 5
5562                 kill $!
5563                 sleep 1
5564         done
5565
5566         rm -f $DIR/f63 || true
5567 }
5568 run_test 63a "Verify oig_wait interruption does not crash ======="
5569
5570 # bug 2248 - async write errors didn't return to application on sync
5571 # bug 3677 - async write errors left page locked
5572 test_63b() {
5573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5574         debugsave
5575         lctl set_param debug=-1
5576
5577         # ensure we have a grant to do async writes
5578         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5579         rm $DIR/$tfile
5580
5581         sync    # sync lest earlier test intercept the fail_loc
5582
5583         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5584         lctl set_param fail_loc=0x80000406
5585         $MULTIOP $DIR/$tfile Owy && \
5586                 error "sync didn't return ENOMEM"
5587         sync; sleep 2; sync     # do a real sync this time to flush page
5588         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5589                 error "locked page left in cache after async error" || true
5590         debugrestore
5591 }
5592 run_test 63b "async write errors should be returned to fsync ==="
5593
5594 test_64a () {
5595         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5596         df $DIR
5597         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5598 }
5599 run_test 64a "verify filter grant calculations (in kernel) ====="
5600
5601 test_64b () {
5602         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5603         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5604 }
5605 run_test 64b "check out-of-space detection on client ==========="
5606
5607 test_64c() {
5608         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5609 }
5610 run_test 64c "verify grant shrink ========================------"
5611
5612 # bug 1414 - set/get directories' stripe info
5613 test_65a() {
5614         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5615         test_mkdir -p $DIR/$tdir
5616         touch $DIR/$tdir/f1
5617         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5618 }
5619 run_test 65a "directory with no stripe info ===================="
5620
5621 test_65b() {
5622         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5623         test_mkdir -p $DIR/$tdir
5624         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5625
5626         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5627                                                 error "setstripe"
5628         touch $DIR/$tdir/f2
5629         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5630 }
5631 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
5632
5633 test_65c() {
5634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5635         if [[ $OSTCOUNT -gt 1 ]]; then
5636                 test_mkdir -p $DIR/$tdir
5637                 local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5638
5639                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5640                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5641                 touch $DIR/$tdir/f3
5642                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5643         fi
5644 }
5645 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
5646
5647 test_65d() {
5648         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5649         test_mkdir -p $DIR/$tdir
5650         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
5651         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5652
5653         if [[ $STRIPECOUNT -le 0 ]]; then
5654                 sc=1
5655         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5656 #LOV_MAX_STRIPE_COUNT is 2000
5657                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5658         else
5659                 sc=$(($STRIPECOUNT - 1))
5660         fi
5661         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5662         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5663         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5664                 error "lverify failed"
5665 }
5666 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
5667
5668 test_65e() {
5669         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5670         test_mkdir -p $DIR/$tdir
5671
5672         $SETSTRIPE $DIR/$tdir || error "setstripe"
5673         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5674                                         error "no stripe info failed"
5675         touch $DIR/$tdir/f6
5676         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5677 }
5678 run_test 65e "directory setstripe defaults ======================="
5679
5680 test_65f() {
5681         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5682         test_mkdir -p $DIR/${tdir}f
5683         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5684 }
5685 run_test 65f "dir setstripe permission (should return error) ==="
5686
5687 test_65g() {
5688         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5689         test_mkdir -p $DIR/$tdir
5690         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5691
5692         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5693                                                         error "setstripe"
5694         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5695         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5696                 error "delete default stripe failed"
5697 }
5698 run_test 65g "directory setstripe -d ==========================="
5699
5700 test_65h() {
5701         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5702         test_mkdir -p $DIR/$tdir
5703         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5704
5705         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5706                                                         error "setstripe"
5707         test_mkdir -p $DIR/$tdir/dd1
5708         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5709                 error "stripe info inherit failed"
5710 }
5711 run_test 65h "directory stripe info inherit ===================="
5712
5713 test_65i() { # bug6367
5714         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5715         $SETSTRIPE -S 65536 -c -1 $MOUNT
5716 }
5717 run_test 65i "set non-default striping on root directory (bug 6367)="
5718
5719 test_65ia() { # bug12836
5720         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5721         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5722 }
5723 run_test 65ia "getstripe on -1 default directory striping"
5724
5725 test_65ib() { # bug12836
5726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5727         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5728 }
5729 run_test 65ib "getstripe -v on -1 default directory striping"
5730
5731 test_65ic() { # bug12836
5732         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5733         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5734 }
5735 run_test 65ic "new find on -1 default directory striping"
5736
5737 test_65j() { # bug6367
5738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5739         sync; sleep 1
5740         # if we aren't already remounting for each test, do so for this test
5741         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5742                 cleanup || error "failed to unmount"
5743                 setup
5744         fi
5745         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5746 }
5747 run_test 65j "set default striping on root directory (bug 6367)="
5748
5749 test_65k() { # bug11679
5750         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5751         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5752         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5753
5754         local disable_precreate=true
5755         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.8.54) ] &&
5756                 disable_precreate=false
5757
5758         echo "Check OST status: "
5759         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
5760                 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
5761
5762         for OSC in $MDS_OSCS; do
5763                 echo $OSC "is active"
5764                 do_facet $SINGLEMDS lctl --device %$OSC activate
5765         done
5766
5767         for INACTIVE_OSC in $MDS_OSCS; do
5768                 local ost=$(osc_to_ost $INACTIVE_OSC)
5769                 local ostnum=$(do_facet $SINGLEMDS lctl get_param -n \
5770                                lov.*md*.target_obd |
5771                                awk -F: /$ost/'{ print $1 }' | head -n 1)
5772
5773                 mkdir -p $DIR/$tdir
5774                 $SETSTRIPE -i $ostnum -c 1 $DIR/$tdir
5775                 createmany -o $DIR/$tdir/$tfile.$ostnum. 1000
5776
5777                 echo "Deactivate: " $INACTIVE_OSC
5778                 do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5779
5780                 local count=$(do_facet $SINGLEMDS "lctl get_param -n \
5781                               osp.$ost*MDT0000.create_count")
5782                 local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
5783                                   osp.$ost*MDT0000.max_create_count")
5784                 $disable_precreate &&
5785                         do_facet $SINGLEMDS "lctl set_param -n \
5786                                 osp.$ost*MDT0000.max_create_count=0"
5787
5788                 for idx in $(seq 0 $((OSTCOUNT - 1))); do
5789                         [ -f $DIR/$tdir/$idx ] && continue
5790                         echo "$SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx"
5791                         $SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx ||
5792                                 error "setstripe $idx should succeed"
5793                         rm -f $DIR/$tdir/$idx || error "rm $idx failed"
5794                 done
5795                 unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
5796                 rmdir $DIR/$tdir
5797
5798                 do_facet $SINGLEMDS "lctl set_param -n \
5799                         osp.$ost*MDT0000.max_create_count=$max_count"
5800                 do_facet $SINGLEMDS "lctl set_param -n \
5801                         osp.$ost*MDT0000.create_count=$count"
5802                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5803                 echo $INACTIVE_OSC "is Activate"
5804
5805                 wait_osc_import_state mds ost$ostnum FULL
5806         done
5807 }
5808 run_test 65k "validate manual striping works properly with deactivated OSCs"
5809
5810 test_65l() { # bug 12836
5811         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5812         test_mkdir -p $DIR/$tdir/test_dir
5813         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5814         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5815 }
5816 run_test 65l "lfs find on -1 stripe dir ========================"
5817
5818 test_65m() {
5819         $RUNAS $SETSTRIPE -c 2 $MOUNT && error "setstripe should fail"
5820         true
5821 }
5822 run_test 65m "normal user can't set filesystem default stripe"
5823
5824 # bug 2543 - update blocks count on client
5825 test_66() {
5826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5827         COUNT=${COUNT:-8}
5828         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5829         sync; sync_all_data; sync; sync_all_data
5830         cancel_lru_locks osc
5831         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5832         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5833 }
5834 run_test 66 "update inode blocks count on client ==============="
5835
5836 meminfo() {
5837         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5838 }
5839
5840 swap_used() {
5841         swapon -s | awk '($1 == "'$1'") { print $4 }'
5842 }
5843
5844 # bug5265, obdfilter oa2dentry return -ENOENT
5845 # #define OBD_FAIL_SRV_ENOENT 0x217
5846 test_69() {
5847         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5848         remote_ost_nodsh && skip "remote OST with nodsh" && return
5849
5850         f="$DIR/$tfile"
5851         $SETSTRIPE -c 1 -i 0 $f
5852
5853         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5854
5855         do_facet ost1 lctl set_param fail_loc=0x217
5856         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5857         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5858
5859         do_facet ost1 lctl set_param fail_loc=0
5860         $DIRECTIO write $f 0 2 || error "write error"
5861
5862         cancel_lru_locks osc
5863         $DIRECTIO read $f 0 1 || error "read error"
5864
5865         do_facet ost1 lctl set_param fail_loc=0x217
5866         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5867
5868         do_facet ost1 lctl set_param fail_loc=0
5869         rm -f $f
5870 }
5871 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5872
5873 test_71() {
5874         test_mkdir -p $DIR/$tdir
5875         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
5876         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5877 }
5878 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5879
5880 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5881         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5882         [ "$RUNAS_ID" = "$UID" ] &&
5883                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5884
5885         # Check that testing environment is properly set up. Skip if not
5886         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5887                 skip_env "User $RUNAS_ID does not exist - skipping"
5888                 return 0
5889         }
5890         touch $DIR/$tfile
5891         chmod 777 $DIR/$tfile
5892         chmod ug+s $DIR/$tfile
5893         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5894                 error "$RUNAS dd $DIR/$tfile failed"
5895         # See if we are still setuid/sgid
5896         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5897                 error "S/gid is not dropped on write"
5898         # Now test that MDS is updated too
5899         cancel_lru_locks mdc
5900         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5901                 error "S/gid is not dropped on MDS"
5902         rm -f $DIR/$tfile
5903 }
5904 run_test 72a "Test that remove suid works properly (bug5695) ===="
5905
5906 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5907         local perm
5908
5909         [ "$RUNAS_ID" = "$UID" ] && \
5910                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5911         [ "$RUNAS_ID" -eq 0 ] && \
5912                 skip_env "RUNAS_ID = 0 -- skipping" && return
5913
5914         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5915         # Check that testing environment is properly set up. Skip if not
5916         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5917                 skip_env "User $RUNAS_ID does not exist - skipping"
5918                 return 0
5919         }
5920         touch $DIR/${tfile}-f{g,u}
5921         test_mkdir $DIR/${tfile}-dg
5922         test_mkdir $DIR/${tfile}-du
5923         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5924         chmod g+s $DIR/${tfile}-{f,d}g
5925         chmod u+s $DIR/${tfile}-{f,d}u
5926         for perm in 777 2777 4777; do
5927                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5928                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5929                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5930                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5931         done
5932         true
5933 }
5934 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5935
5936 # bug 3462 - multiple simultaneous MDC requests
5937 test_73() {
5938         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5939         test_mkdir $DIR/d73-1
5940         test_mkdir $DIR/d73-2
5941         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5942         pid1=$!
5943
5944         lctl set_param fail_loc=0x80000129
5945         $MULTIOP $DIR/d73-1/f73-2 Oc &
5946         sleep 1
5947         lctl set_param fail_loc=0
5948
5949         $MULTIOP $DIR/d73-2/f73-3 Oc &
5950         pid3=$!
5951
5952         kill -USR1 $pid1
5953         wait $pid1 || return 1
5954
5955         sleep 25
5956
5957         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5958         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5959         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5960
5961         rm -rf $DIR/d73-*
5962 }
5963 run_test 73 "multiple MDC requests (should not deadlock)"
5964
5965 test_74a() { # bug 6149, 6184
5966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5967         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5968         #
5969         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5970         # will spin in a tight reconnection loop
5971         touch $DIR/f74a
5972         $LCTL set_param fail_loc=0x8000030e
5973         # get any lock that won't be difficult - lookup works.
5974         ls $DIR/f74a
5975         $LCTL set_param fail_loc=0
5976         rm -f $DIR/f74a
5977         true
5978 }
5979 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5980
5981 test_74b() { # bug 13310
5982         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5983         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5984         #
5985         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5986         # will spin in a tight reconnection loop
5987         $LCTL set_param fail_loc=0x8000030e
5988         # get a "difficult" lock
5989         touch $DIR/f74b
5990         $LCTL set_param fail_loc=0
5991         rm -f $DIR/f74b
5992         true
5993 }
5994 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5995
5996 test_74c() {
5997         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5998         #define OBD_FAIL_LDLM_NEW_LOCK
5999         $LCTL set_param fail_loc=0x319
6000         touch $DIR/$tfile && error "touch successful"
6001         $LCTL set_param fail_loc=0
6002         true
6003 }
6004 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
6005
6006 num_inodes() {
6007         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
6008 }
6009
6010 test_76() { # Now for bug 20433, added originally in bug 1443
6011         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6012         local CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
6013         cancel_lru_locks osc
6014         BEFORE_INODES=$(num_inodes)
6015         echo "before inodes: $BEFORE_INODES"
6016         local COUNT=1000
6017         [ "$SLOW" = "no" ] && COUNT=100
6018         for i in $(seq $COUNT); do
6019                 touch $DIR/$tfile
6020                 rm -f $DIR/$tfile
6021         done
6022         cancel_lru_locks osc
6023         AFTER_INODES=$(num_inodes)
6024         echo "after inodes: $AFTER_INODES"
6025         local wait=0
6026         while [[ $((AFTER_INODES-1*${CPUS:-1})) -gt $BEFORE_INODES ]]; do
6027                 sleep 2
6028                 AFTER_INODES=$(num_inodes)
6029                 wait=$((wait+2))
6030                 echo "wait $wait seconds inodes: $AFTER_INODES"
6031                 if [ $wait -gt 30 ]; then
6032                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
6033                 fi
6034         done
6035 }
6036 run_test 76 "confirm clients recycle inodes properly ===="
6037
6038
6039 export ORIG_CSUM=""
6040 set_checksums()
6041 {
6042         # Note: in sptlrpc modes which enable its own bulk checksum, the
6043         # original crc32_le bulk checksum will be automatically disabled,
6044         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
6045         # will be checked by sptlrpc code against sptlrpc bulk checksum.
6046         # In this case set_checksums() will not be no-op, because sptlrpc
6047         # bulk checksum will be enabled all through the test.
6048
6049         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
6050         lctl set_param -n osc.*.checksums $1
6051         return 0
6052 }
6053
6054 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
6055                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
6056 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
6057 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
6058 set_checksum_type()
6059 {
6060         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
6061         log "set checksum type to $1"
6062         return 0
6063 }
6064 F77_TMP=$TMP/f77-temp
6065 F77SZ=8
6066 setup_f77() {
6067         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
6068                 error "error writing to $F77_TMP"
6069 }
6070
6071 test_77a() { # bug 10889
6072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6073         $GSS && skip "could not run with gss" && return
6074         [ ! -f $F77_TMP ] && setup_f77
6075         set_checksums 1
6076         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
6077         set_checksums 0
6078         rm -f $DIR/$tfile
6079 }
6080 run_test 77a "normal checksum read/write operation"
6081
6082 test_77b() { # bug 10889
6083         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6084         $GSS && skip "could not run with gss" && return
6085         [ ! -f $F77_TMP ] && setup_f77
6086         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6087         $LCTL set_param fail_loc=0x80000409
6088         set_checksums 1
6089
6090         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6091                 error "dd error: $?"
6092         $LCTL set_param fail_loc=0
6093
6094         for algo in $CKSUM_TYPES; do
6095                 cancel_lru_locks osc
6096                 set_checksum_type $algo
6097                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6098                 $LCTL set_param fail_loc=0x80000408
6099                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6100                 $LCTL set_param fail_loc=0
6101         done
6102         set_checksums 0
6103         set_checksum_type $ORIG_CSUM_TYPE
6104         rm -f $DIR/$tfile
6105 }
6106 run_test 77b "checksum error on client write, read"
6107
6108 cleanup_77c() {
6109         trap 0
6110         set_checksums 0
6111         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
6112         $check_ost &&
6113                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
6114         [ -n $osc_file_prefix ] && rm -f ${osc_file_prefix}*
6115         $check_ost && [ -n $ost_file_prefix ] &&
6116                 do_facet ost1 rm -f ${ost_file_prefix}\*
6117 }
6118
6119 test_77c() {
6120         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6121         $GSS && skip "could not run with gss" && return
6122
6123         local bad1
6124         local osc_file_prefix
6125         local osc_file
6126         local check_ost=false
6127         local ost_file_prefix
6128         local ost_file
6129         local orig_cksum
6130         local dump_cksum
6131         local fid
6132
6133         # ensure corruption will occur on first OSS/OST
6134         $LFS setstripe -i 0 $DIR/$tfile
6135
6136         [ ! -f $F77_TMP ] && setup_f77
6137         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6138                 error "dd write error: $?"
6139         fid=$($LFS path2fid $DIR/$tfile)
6140
6141         if [ $(lustre_version_code ost1) -ge $(version_code 2.9.57) ]
6142         then
6143                 check_ost=true
6144                 ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
6145                 ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
6146         else
6147                 echo "OSS do not support bulk pages dump upon error"
6148         fi
6149
6150         osc_file_prefix=$($LCTL get_param -n debug_path)
6151         osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
6152
6153         trap cleanup_77c EXIT
6154
6155         set_checksums 1
6156         # enable bulk pages dump upon error on Client
6157         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
6158         # enable bulk pages dump upon error on OSS
6159         $check_ost &&
6160                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
6161
6162         # flush Client cache to allow next read to reach OSS
6163         cancel_lru_locks osc
6164
6165         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
6166         $LCTL set_param fail_loc=0x80000408
6167         dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
6168         $LCTL set_param fail_loc=0
6169
6170         rm -f $DIR/$tfile
6171
6172         # check cksum dump on Client
6173         osc_file=$(ls ${osc_file_prefix}*)
6174         [ -n "$osc_file" ] || error "no checksum dump file on Client"
6175         # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
6176         bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
6177         [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
6178         orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
6179                      cksum)
6180         dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
6181         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6182                 error "dump content does not match on Client"
6183
6184         $check_ost || skip "No need to check cksum dump on OSS"
6185
6186         # check cksum dump on OSS
6187         ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
6188         [ -n "$ost_file" ] || error "no checksum dump file on OSS"
6189         orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
6190         dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
6191         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6192                 error "dump content does not match on OSS"
6193
6194         cleanup_77c
6195 }
6196 run_test 77c "checksum error on client read with debug"
6197
6198 test_77d() { # bug 10889
6199         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6200         $GSS && skip "could not run with gss" && return
6201         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6202         $LCTL set_param fail_loc=0x80000409
6203         set_checksums 1
6204         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6205                 error "direct write: rc=$?"
6206         $LCTL set_param fail_loc=0
6207         set_checksums 0
6208
6209         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6210         $LCTL set_param fail_loc=0x80000408
6211         set_checksums 1
6212         cancel_lru_locks osc
6213         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6214                 error "direct read: rc=$?"
6215         $LCTL set_param fail_loc=0
6216         set_checksums 0
6217 }
6218 run_test 77d "checksum error on OST direct write, read"
6219
6220 test_77f() { # bug 10889
6221         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6222         $GSS && skip "could not run with gss" && return
6223         set_checksums 1
6224         for algo in $CKSUM_TYPES; do
6225                 cancel_lru_locks osc
6226                 set_checksum_type $algo
6227                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6228                 $LCTL set_param fail_loc=0x409
6229                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
6230                         error "direct write succeeded"
6231                 $LCTL set_param fail_loc=0
6232         done
6233         set_checksum_type $ORIG_CSUM_TYPE
6234         set_checksums 0
6235 }
6236 run_test 77f "repeat checksum error on write (expect error)"
6237
6238 test_77g() { # bug 10889
6239         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6240         $GSS && skip "could not run with gss" && return
6241         remote_ost_nodsh && skip "remote OST with nodsh" && return
6242
6243         [ ! -f $F77_TMP ] && setup_f77
6244
6245         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
6246         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
6247         do_facet ost1 lctl set_param fail_loc=0x8000021a
6248         set_checksums 1
6249         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
6250                 error "write error: rc=$?"
6251         do_facet ost1 lctl set_param fail_loc=0
6252         set_checksums 0
6253
6254         cancel_lru_locks osc
6255         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
6256         do_facet ost1 lctl set_param fail_loc=0x8000021b
6257         set_checksums 1
6258         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6259         do_facet ost1 lctl set_param fail_loc=0
6260         set_checksums 0
6261 }
6262 run_test 77g "checksum error on OST write, read"
6263
6264 test_77j() { # bug 13805
6265         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6266         $GSS && skip "could not run with gss" && return
6267         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6268         lctl set_param fail_loc=0x40c
6269         remount_client $MOUNT
6270         lctl set_param fail_loc=0
6271         # wait async osc connect to finish and reflect updated state value
6272         local i
6273         for (( i=0; i < OSTCOUNT; i++ )) ; do
6274                 wait_osc_import_state client ost$((i+1)) FULL
6275         done
6276
6277         for VALUE in $(lctl get_param osc.*osc-[^mM]*.checksum_type); do
6278                 PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
6279                 algo=$(lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g')
6280                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6281         done
6282         remount_client $MOUNT
6283 }
6284 run_test 77j "client only supporting ADLER32"
6285
6286 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6287 rm -f $F77_TMP
6288 unset F77_TMP
6289
6290 cleanup_test_78() {
6291         trap 0
6292         rm -f $DIR/$tfile
6293 }
6294
6295 test_78() { # bug 10901
6296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6297         remote_ost || { skip_env "local OST" && return; }
6298
6299         NSEQ=5
6300         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6301         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6302         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6303         echo "MemTotal: $MEMTOTAL"
6304
6305         # reserve 256MB of memory for the kernel and other running processes,
6306         # and then take 1/2 of the remaining memory for the read/write buffers.
6307         if [ $MEMTOTAL -gt 512 ] ;then
6308                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6309         else
6310                 # for those poor memory-starved high-end clusters...
6311                 MEMTOTAL=$((MEMTOTAL / 2))
6312         fi
6313         echo "Mem to use for directio: $MEMTOTAL"
6314
6315         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6316         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6317         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6318         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6319                 head -n1)
6320         echo "Smallest OST: $SMALLESTOST"
6321         [[ $SMALLESTOST -lt 10240 ]] &&
6322                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6323
6324         trap cleanup_test_78 EXIT
6325
6326         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6327                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6328
6329         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6330         echo "File size: $F78SIZE"
6331         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6332         for i in $(seq 1 $NSEQ); do
6333                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6334                 echo directIO rdwr round $i of $NSEQ
6335                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6336         done
6337
6338         cleanup_test_78
6339 }
6340 run_test 78 "handle large O_DIRECT writes correctly ============"
6341
6342 test_79() { # bug 12743
6343         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6344         wait_delete_completed
6345
6346         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6347         BKFREE=$(calc_osc_kbytes kbytesfree)
6348         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6349
6350         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6351         DFTOTAL=`echo $STRING | cut -d, -f1`
6352         DFUSED=`echo $STRING  | cut -d, -f2`
6353         DFAVAIL=`echo $STRING | cut -d, -f3`
6354         DFFREE=$(($DFTOTAL - $DFUSED))
6355
6356         ALLOWANCE=$((64 * $OSTCOUNT))
6357
6358         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6359            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6360                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6361         fi
6362         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6363            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6364                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6365         fi
6366         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6367            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6368                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6369         fi
6370 }
6371 run_test 79 "df report consistency check ======================="
6372
6373 test_80() { # bug 10718
6374         remote_ost_nodsh && skip "remote OST with nodsh" && return
6375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6376         # relax strong synchronous semantics for slow backends like ZFS
6377         local soc="obdfilter.*.sync_on_lock_cancel"
6378         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6379         local hosts=
6380         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6381                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6382                           facet_active_host $host; done | sort -u)
6383                 do_nodes $hosts lctl set_param $soc=never
6384         fi
6385
6386         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6387         sync; sleep 1; sync
6388         local BEFORE=`date +%s`
6389         cancel_lru_locks osc
6390         local AFTER=`date +%s`
6391         local DIFF=$((AFTER-BEFORE))
6392         if [ $DIFF -gt 1 ] ; then
6393                 error "elapsed for 1M@1T = $DIFF"
6394         fi
6395
6396         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6397
6398         rm -f $DIR/$tfile
6399 }
6400 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6401
6402 test_81a() { # LU-456
6403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6404         remote_ost_nodsh && skip "remote OST with nodsh" && return
6405         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6406         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6407         do_facet ost1 lctl set_param fail_loc=0x80000228
6408
6409         # write should trigger a retry and success
6410         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6411         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6412         RC=$?
6413         if [ $RC -ne 0 ] ; then
6414                 error "write should success, but failed for $RC"
6415         fi
6416 }
6417 run_test 81a "OST should retry write when get -ENOSPC ==============="
6418
6419 test_81b() { # LU-456
6420         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6421         remote_ost_nodsh && skip "remote OST with nodsh" && return
6422         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6423         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6424         do_facet ost1 lctl set_param fail_loc=0x228
6425
6426         # write should retry several times and return -ENOSPC finally
6427         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6428         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6429         RC=$?
6430         ENOSPC=28
6431         if [ $RC -ne $ENOSPC ] ; then
6432                 error "dd should fail for -ENOSPC, but succeed."
6433         fi
6434 }
6435 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6436
6437 test_82() { # LU-1031
6438         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6439         local gid1=14091995
6440         local gid2=16022000
6441
6442         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6443         local MULTIPID1=$!
6444         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6445         local MULTIPID2=$!
6446         kill -USR1 $MULTIPID2
6447         sleep 2
6448         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6449                 error "First grouplock does not block second one"
6450         else
6451                 echo "Second grouplock blocks first one"
6452         fi
6453         kill -USR1 $MULTIPID1
6454         wait $MULTIPID1
6455         wait $MULTIPID2
6456 }
6457 run_test 82 "Basic grouplock test ==============================="
6458
6459 test_83() {
6460         local sfile="/boot/System.map-$(uname -r)"
6461         # define OBD_FAIL_LLITE_PTASK_IO_FAIL 0x140d
6462         $LCTL set_param fail_loc=0x140d
6463         cp $sfile $DIR/$tfile || error "write failed"
6464         diff -c $sfile $DIR/$tfile || error "files are different"
6465         $LCTL set_param fail_loc=0
6466         rm -f $DIR/$tfile
6467 }
6468 run_test 83 "Short write in ptask ==============================="
6469
6470 test_99a() {
6471         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6472                 return
6473         test_mkdir -p $DIR/d99cvsroot
6474         chown $RUNAS_ID $DIR/d99cvsroot
6475         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6476         cd $TMP
6477
6478         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6479         cd $oldPWD
6480 }
6481 run_test 99a "cvs init ========================================="
6482
6483 test_99b() {
6484         [ -z "$(which cvs 2>/dev/null)" ] &&
6485                 skip_env "could not find cvs" && return
6486         [ ! -d $DIR/d99cvsroot ] && test_99a
6487         cd /etc/init.d
6488         # some versions of cvs import exit(1) when asked to import links or
6489         # files they can't read.  ignore those files.
6490         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6491                         ! -perm /4 -printf '-I %f\n')
6492         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6493                 d99reposname vtag rtag
6494 }
6495 run_test 99b "cvs import ======================================="
6496
6497 test_99c() {
6498         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6499         [ ! -d $DIR/d99cvsroot ] && test_99b
6500         cd $DIR
6501         test_mkdir -p $DIR/d99reposname
6502         chown $RUNAS_ID $DIR/d99reposname
6503         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6504 }
6505 run_test 99c "cvs checkout ====================================="
6506
6507 test_99d() {
6508         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6509         [ ! -d $DIR/d99cvsroot ] && test_99c
6510         cd $DIR/d99reposname
6511         $RUNAS touch foo99
6512         $RUNAS cvs add -m 'addmsg' foo99
6513 }
6514 run_test 99d "cvs add =========================================="
6515
6516 test_99e() {
6517         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6518         [ ! -d $DIR/d99cvsroot ] && test_99c
6519         cd $DIR/d99reposname
6520         $RUNAS cvs update
6521 }
6522 run_test 99e "cvs update ======================================="
6523
6524 test_99f() {
6525         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6526         [ ! -d $DIR/d99cvsroot ] && test_99d
6527         cd $DIR/d99reposname
6528         $RUNAS cvs commit -m 'nomsg' foo99
6529     rm -fr $DIR/d99cvsroot
6530 }
6531 run_test 99f "cvs commit ======================================="
6532
6533 test_100() {
6534         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6535         [[ "$NETTYPE" =~ tcp ]] ||
6536                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" &&
6537                         return ; }
6538
6539         remote_ost_nodsh && skip "remote OST with nodsh" && return
6540         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6541         remote_servers ||
6542                 { skip "useless for local single node setup" && return; }
6543
6544         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6545                 [ "$PROT" != "tcp" ] && continue
6546                 RPORT=$(echo $REMOTE | cut -d: -f2)
6547                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6548
6549                 rc=0
6550                 LPORT=`echo $LOCAL | cut -d: -f2`
6551                 if [ $LPORT -ge 1024 ]; then
6552                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6553                         netstat -tna
6554                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6555                 fi
6556         done
6557         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6558 }
6559 run_test 100 "check local port using privileged port ==========="
6560
6561 function get_named_value()
6562 {
6563     local tag
6564
6565     tag=$1
6566     while read ;do
6567         line=$REPLY
6568         case $line in
6569         $tag*)
6570             echo $line | sed "s/^$tag[ ]*//"
6571             break
6572             ;;
6573         esac
6574     done
6575 }
6576
6577 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6578                    awk '/^max_cached_mb/ { print $2 }')
6579
6580 cleanup_101a() {
6581         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6582         trap 0
6583 }
6584
6585 test_101a() {
6586         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6587         [ $MDSCOUNT -ge 2 ] && skip "needs < 2 MDTs" && return #LU-4322
6588         local s
6589         local discard
6590         local nreads=10000
6591         local cache_limit=32
6592
6593         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6594         trap cleanup_101a EXIT
6595         $LCTL set_param -n llite.*.read_ahead_stats 0
6596         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6597
6598         #
6599         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6600         #
6601         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6602         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6603
6604         discard=0
6605         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6606                 get_named_value 'read but discarded' | cut -d" " -f1); do
6607                         discard=$(($discard + $s))
6608         done
6609         cleanup_101a
6610
6611         if [[ $(($discard * 10)) -gt $nreads ]]; then
6612                 $LCTL get_param osc.*-osc*.rpc_stats
6613                 $LCTL get_param llite.*.read_ahead_stats
6614                 error "too many ($discard) discarded pages"
6615         fi
6616         rm -f $DIR/$tfile || true
6617 }
6618 run_test 101a "check read-ahead for random reads ================"
6619
6620 setup_test101bc() {
6621         test_mkdir -p $DIR/$tdir
6622         local STRIPE_SIZE=$1
6623         local FILE_LENGTH=$2
6624         STRIPE_OFFSET=0
6625
6626         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6627
6628         local list=$(comma_list $(osts_nodes))
6629         set_osd_param $list '' read_cache_enable 0
6630         set_osd_param $list '' writethrough_cache_enable 0
6631
6632         trap cleanup_test101bc EXIT
6633         # prepare the read-ahead file
6634         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6635
6636         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6637                                 count=$FILE_SIZE_MB 2> /dev/null
6638
6639 }
6640
6641 cleanup_test101bc() {
6642         trap 0
6643         rm -rf $DIR/$tdir
6644         rm -f $DIR/$tfile
6645
6646         local list=$(comma_list $(osts_nodes))
6647         set_osd_param $list '' read_cache_enable 1
6648         set_osd_param $list '' writethrough_cache_enable 1
6649 }
6650
6651 calc_total() {
6652         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6653 }
6654
6655 ra_check_101() {
6656         local READ_SIZE=$1
6657         local STRIPE_SIZE=$2
6658         local FILE_LENGTH=$3
6659         local RA_INC=1048576
6660         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6661         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6662                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6663         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6664                         get_named_value 'read but discarded' |
6665                         cut -d" " -f1 | calc_total)
6666         if [[ $DISCARD -gt $discard_limit ]]; then
6667                 $LCTL get_param llite.*.read_ahead_stats
6668                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6669         else
6670                 echo "Read-ahead success for size ${READ_SIZE}"
6671         fi
6672 }
6673
6674 test_101b() {
6675         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6676         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
6677         local STRIPE_SIZE=1048576
6678         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6679         if [ $SLOW == "yes" ]; then
6680                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6681         else
6682                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6683         fi
6684
6685         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6686
6687         # prepare the read-ahead file
6688         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6689         cancel_lru_locks osc
6690         for BIDX in 2 4 8 16 32 64 128 256
6691         do
6692                 local BSIZE=$((BIDX*4096))
6693                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6694                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6695                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6696                 $LCTL set_param -n llite.*.read_ahead_stats 0
6697                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6698                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6699                 cancel_lru_locks osc
6700                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6701         done
6702         cleanup_test101bc
6703         true
6704 }
6705 run_test 101b "check stride-io mode read-ahead ================="
6706
6707 test_101c() {
6708         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6709         local STRIPE_SIZE=1048576
6710         local FILE_LENGTH=$((STRIPE_SIZE*100))
6711         local nreads=10000
6712         local osc_rpc_stats
6713
6714         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6715
6716         cancel_lru_locks osc
6717         $LCTL set_param osc.*.rpc_stats 0
6718         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6719         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6720                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6721                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6722                 local size
6723
6724                 if [ $lines -le 20 ]; then
6725                         continue
6726                 fi
6727                 for size in 1 2 4 8; do
6728                         local rpc=$(echo "$stats" |
6729                                     awk '($1 == "'$size':") {print $2; exit; }')
6730                         [ $rpc != 0 ] &&
6731                                 error "Small $((size*4))k read IO $rpc !"
6732                 done
6733                 echo "$osc_rpc_stats check passed!"
6734         done
6735         cleanup_test101bc
6736         true
6737 }
6738 run_test 101c "check stripe_size aligned read-ahead ================="
6739
6740 set_read_ahead() {
6741         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6742         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6743 }
6744
6745 test_101d() {
6746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6747         local file=$DIR/$tfile
6748         local sz_MB=${FILESIZE_101d:-500}
6749         local ra_MB=${READAHEAD_MB:-40}
6750
6751         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6752         [ $free_MB -lt $sz_MB ] &&
6753                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6754
6755         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6756         $SETSTRIPE -c -1 $file || error "setstripe failed"
6757
6758         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6759         echo Cancel LRU locks on lustre client to flush the client cache
6760         cancel_lru_locks osc
6761
6762         echo Disable read-ahead
6763         local old_READAHEAD=$(set_read_ahead 0)
6764
6765         echo Reading the test file $file with read-ahead disabled
6766         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6767
6768         echo Cancel LRU locks on lustre client to flush the client cache
6769         cancel_lru_locks osc
6770         echo Enable read-ahead with ${ra_MB}MB
6771         set_read_ahead $ra_MB
6772
6773         echo Reading the test file $file with read-ahead enabled
6774         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6775
6776         echo "read-ahead disabled time read $raOFF"
6777         echo "read-ahead enabled  time read $raON"
6778
6779         set_read_ahead $old_READAHEAD
6780         rm -f $file
6781         wait_delete_completed
6782
6783         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6784                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6785 }
6786 run_test 101d "file read with and without read-ahead enabled"
6787
6788 test_101e() {
6789         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6790         local file=$DIR/$tfile
6791         local size_KB=500  #KB
6792         local count=100
6793         local bsize=1024
6794
6795         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6796         local need_KB=$((count * size_KB))
6797         [[ $free_KB -le $need_KB ]] &&
6798                 skip_env "Need free space $need_KB, have $free_KB" && return
6799
6800         echo "Creating $count ${size_KB}K test files"
6801         for ((i = 0; i < $count; i++)); do
6802                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6803         done
6804
6805         echo "Cancel LRU locks on lustre client to flush the client cache"
6806         cancel_lru_locks osc
6807
6808         echo "Reset readahead stats"
6809         $LCTL set_param -n llite.*.read_ahead_stats 0
6810
6811         for ((i = 0; i < $count; i++)); do
6812                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6813         done
6814
6815         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6816                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6817
6818         for ((i = 0; i < $count; i++)); do
6819                 rm -rf $file.$i 2>/dev/null
6820         done
6821
6822         #10000 means 20% reads are missing in readahead
6823         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6824 }
6825 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6826
6827 test_101f() {
6828         which iozone || { skip "no iozone installed" && return; }
6829
6830         local old_debug=$($LCTL get_param debug)
6831         old_debug=${old_debug#*=}
6832         $LCTL set_param debug="reada mmap"
6833
6834         # create a test file
6835         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
6836
6837         echo Cancel LRU locks on lustre client to flush the client cache
6838         cancel_lru_locks osc
6839
6840         echo Reset readahead stats
6841         $LCTL set_param -n llite.*.read_ahead_stats 0
6842
6843         echo mmap read the file with small block size
6844         iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
6845                 > /dev/null 2>&1
6846
6847         echo checking missing pages
6848         $LCTL get_param llite.*.read_ahead_stats
6849         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6850                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
6851
6852         $LCTL set_param debug="$old_debug"
6853         [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
6854         rm -f $DIR/$tfile
6855 }
6856 run_test 101f "check mmap read performance"
6857
6858 test_101g_brw_size_test() {
6859         local mb=$1
6860         local pages=$((mb * 1048576 / $(page_size)))
6861
6862         $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
6863                 { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
6864         for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
6865                 [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
6866                         return 2
6867         done
6868
6869         $LCTL set_param -n osc.*.rpc_stats=0
6870
6871         # 10 RPCs should be enough for the test
6872         local count=10
6873         dd if=/dev/zero of=$DIR/$tfile bs=${mb}M count=$count ||
6874                 { error "dd write ${mb} MB blocks failed"; return 3; }
6875         cancel_lru_locks osc
6876         dd of=/dev/null if=$DIR/$tfile bs=${mb}M count=$count ||
6877                 { error "dd write ${mb} MB blocks failed"; return 4; }
6878
6879         # calculate number of full-sized read and write RPCs
6880         rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
6881                 sed -n '/pages per rpc/,/^$/p' |
6882                 awk '/'$pages':/ { reads += $2; writes += $6 }; \
6883                 END { print reads,writes }'))
6884         [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
6885                 return 5
6886         [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
6887                 return 6
6888
6889         return 0
6890 }
6891
6892 test_101g() {
6893         local rpcs
6894         local osts=$(get_facets OST)
6895         local list=$(comma_list $(osts_nodes))
6896         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
6897         local brw_size="obdfilter.*.brw_size"
6898
6899         $LFS setstripe -i 0 -c 1 $DIR/$tfile
6900
6901         local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
6902         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.52) ]; then
6903                 [ $(lustre_version_code ost1) -ge $(version_code 2.9.52) ] &&
6904                         suffix="M"
6905                 if [[ $orig_mb -lt 16 ]]; then
6906                         save_lustre_params $osts "$brw_size" > $p
6907                         do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
6908                                 error "set 16MB RPC size failed"
6909
6910                         echo "remount client to enable new RPC size"
6911                         remount_client $MOUNT || error "remount_client failed"
6912                 fi
6913
6914                 test_101g_brw_size_test 16 || error "16MB RPC test failed"
6915                 # should be able to set brw_size=12, but no rpc_stats for that
6916                 test_101g_brw_size_test 8 || error "8MB RPC test failed"
6917         fi
6918
6919         test_101g_brw_size_test 4 || error "4MB RPC test failed"
6920
6921         if [[ $orig_mb -lt 16 ]]; then
6922                 restore_lustre_params < $p
6923                 remount_client $MOUNT || error "remount_client restore failed"
6924         fi
6925
6926         rm -f $p $DIR/$tfile
6927 }
6928 run_test 101g "Big bulk(4/16 MiB) readahead"
6929
6930 setup_test102() {
6931         test_mkdir $DIR/$tdir
6932         chown $RUNAS_ID $DIR/$tdir
6933         STRIPE_SIZE=65536
6934         STRIPE_OFFSET=1
6935         STRIPE_COUNT=$OSTCOUNT
6936         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6937
6938         trap cleanup_test102 EXIT
6939         cd $DIR
6940         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6941         cd $DIR/$tdir
6942         for num in 1 2 3 4; do
6943                 for count in $(seq 1 $STRIPE_COUNT); do
6944                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6945                                 local size=`expr $STRIPE_SIZE \* $num`
6946                                 local file=file"$num-$idx-$count"
6947                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6948                         done
6949                 done
6950         done
6951
6952         cd $DIR
6953         $1 tar cf $TMP/f102.tar $tdir --xattrs
6954 }
6955
6956 cleanup_test102() {
6957         trap 0
6958         rm -f $TMP/f102.tar
6959         rm -rf $DIR/d0.sanity/d102
6960 }
6961
6962 test_102a() {
6963         local testfile=$DIR/$tfile
6964
6965         touch $testfile
6966
6967         [ "$UID" != 0 ] && skip_env "must run as root" && return
6968         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6969                 skip_env "must have user_xattr" && return
6970
6971         [ -z "$(which setfattr 2>/dev/null)" ] &&
6972                 skip_env "could not find setfattr" && return
6973
6974         echo "set/get xattr..."
6975         setfattr -n trusted.name1 -v value1 $testfile ||
6976                 error "setfattr -n trusted.name1=value1 $testfile failed"
6977         getfattr -n trusted.name1 $testfile 2> /dev/null |
6978           grep "trusted.name1=.value1" ||
6979                 error "$testfile missing trusted.name1=value1"
6980
6981         setfattr -n user.author1 -v author1 $testfile ||
6982                 error "setfattr -n user.author1=author1 $testfile failed"
6983         getfattr -n user.author1 $testfile 2> /dev/null |
6984           grep "user.author1=.author1" ||
6985                 error "$testfile missing trusted.author1=author1"
6986
6987         echo "listxattr..."
6988         setfattr -n trusted.name2 -v value2 $testfile ||
6989                 error "$testfile unable to set trusted.name2"
6990         setfattr -n trusted.name3 -v value3 $testfile ||
6991                 error "$testfile unable to set trusted.name3"
6992         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6993             grep "trusted.name" | wc -l) -eq 3 ] ||
6994                 error "$testfile missing 3 trusted.name xattrs"
6995
6996         setfattr -n user.author2 -v author2 $testfile ||
6997                 error "$testfile unable to set user.author2"
6998         setfattr -n user.author3 -v author3 $testfile ||
6999                 error "$testfile unable to set user.author3"
7000         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
7001             grep "user.author" | wc -l) -eq 3 ] ||
7002                 error "$testfile missing 3 user.author xattrs"
7003
7004         echo "remove xattr..."
7005         setfattr -x trusted.name1 $testfile ||
7006                 error "$testfile error deleting trusted.name1"
7007         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
7008                 error "$testfile did not delete trusted.name1 xattr"
7009
7010         setfattr -x user.author1 $testfile ||
7011                 error "$testfile error deleting user.author1"
7012         echo "set lustre special xattr ..."
7013         $LFS setstripe -c1 $testfile
7014         local lovea=$(getfattr -n "trusted.lov" -e hex $testfile |
7015                 awk -F "=" '/trusted.lov/ { print $2 }' )
7016         setfattr -n "trusted.lov" -v $lovea $testfile ||
7017                 error "$testfile doesn't ignore setting trusted.lov again"
7018         setfattr -n "trusted.lov" -v "invalid_value" $testfile &&
7019                 error "$testfile allow setting invalid trusted.lov"
7020         rm -f $testfile
7021 }
7022 run_test 102a "user xattr test =================================="
7023
7024 test_102b() {
7025         [ -z "$(which setfattr 2>/dev/null)" ] &&
7026                 skip_env "could not find setfattr" && return
7027
7028         # b10930: get/set/list trusted.lov xattr
7029         echo "get/set/list trusted.lov xattr ..."
7030         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7031         local testfile=$DIR/$tfile
7032         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7033                 error "setstripe failed"
7034         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
7035                 error "getstripe failed"
7036         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
7037                 error "can't get trusted.lov from $testfile"
7038
7039         local testfile2=${testfile}2
7040         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
7041                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
7042
7043         $MCREATE $testfile2
7044         setfattr -n trusted.lov -v $value $testfile2
7045         local stripe_size=$($GETSTRIPE -S $testfile2)
7046         local stripe_count=$($GETSTRIPE -c $testfile2)
7047         [[ $stripe_size -eq 65536 ]] ||
7048                 error "stripe size $stripe_size != 65536"
7049         [[ $stripe_count -eq $STRIPECOUNT ]] ||
7050                 error "stripe count $stripe_count != $STRIPECOUNT"
7051         rm -f $DIR/$tfile
7052 }
7053 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
7054
7055 test_102c() {
7056         [ -z "$(which setfattr 2>/dev/null)" ] &&
7057                 skip_env "could not find setfattr" && return
7058
7059         # b10930: get/set/list lustre.lov xattr
7060         echo "get/set/list lustre.lov xattr ..."
7061         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7062         test_mkdir $DIR/$tdir
7063         chown $RUNAS_ID $DIR/$tdir
7064         local testfile=$DIR/$tdir/$tfile
7065         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7066                 error "setstripe failed"
7067         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
7068                 error "getstripe failed"
7069         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
7070         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
7071
7072         local testfile2=${testfile}2
7073         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
7074                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
7075
7076         $RUNAS $MCREATE $testfile2
7077         $RUNAS setfattr -n lustre.lov -v $value $testfile2
7078         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
7079         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
7080         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
7081         [ $stripe_count -eq $STRIPECOUNT ] ||
7082                 error "stripe count $stripe_count != $STRIPECOUNT"
7083 }
7084 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
7085
7086 compare_stripe_info1() {
7087         local stripe_index_all_zero=true
7088
7089         for num in 1 2 3 4; do
7090                 for count in $(seq 1 $STRIPE_COUNT); do
7091                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
7092                                 local size=$((STRIPE_SIZE * num))
7093                                 local file=file"$num-$offset-$count"
7094                                 stripe_size=$($LFS getstripe -S $PWD/$file)
7095                                 [[ $stripe_size -ne $size ]] &&
7096                                     error "$file: size $stripe_size != $size"
7097                                 stripe_count=$($LFS getstripe -c $PWD/$file)
7098                                 # allow fewer stripes to be created, ORI-601
7099                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
7100                                     error "$file: count $stripe_count != $count"
7101                                 stripe_index=$($LFS getstripe -i $PWD/$file)
7102                                 [[ $stripe_index -ne 0 ]] &&
7103                                         stripe_index_all_zero=false
7104                         done
7105                 done
7106         done
7107         $stripe_index_all_zero &&
7108                 error "all files are being extracted starting from OST index 0"
7109         return 0
7110 }
7111
7112 have_xattrs_include() {
7113         tar --help | grep -q xattrs-include &&
7114                 echo --xattrs-include="lustre.*"
7115 }
7116
7117 test_102d() {
7118         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7119         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7120         local xinc=$(have_xattrs_include)
7121         setup_test102
7122         tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $xinc
7123         cd $DIR/$tdir/$tdir
7124         compare_stripe_info1
7125 }
7126 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
7127
7128 test_102f() {
7129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7130         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7131         local xinc=$(have_xattrs_include)
7132         setup_test102
7133         test_mkdir $DIR/$tdir.restore
7134         cd $DIR
7135         tar cf - --xattrs $tdir | tar xf - \
7136                 -C $DIR/$tdir.restore --xattrs $xinc
7137         cd $DIR/$tdir.restore/$tdir
7138         compare_stripe_info1
7139 }
7140 run_test 102f "tar copy files, not keep osts ==========="
7141
7142 grow_xattr() {
7143         local xsize=${1:-1024}  # in bytes
7144         local file=$DIR/$tfile
7145
7146         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
7147                 skip "must have user_xattr" && return 0
7148         [ -z "$(which setfattr 2>/dev/null)" ] &&
7149                 skip_env "could not find setfattr" && return 0
7150         [ -z "$(which getfattr 2>/dev/null)" ] &&
7151                 skip_env "could not find getfattr" && return 0
7152
7153         touch $file
7154
7155         local value="$(generate_string $xsize)"
7156
7157         local xbig=trusted.big
7158         log "save $xbig on $file"
7159         setfattr -n $xbig -v $value $file ||
7160                 error "saving $xbig on $file failed"
7161
7162         local orig=$(get_xattr_value $xbig $file)
7163         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
7164
7165         local xsml=trusted.sml
7166         log "save $xsml on $file"
7167         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
7168
7169         local new=$(get_xattr_value $xbig $file)
7170         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
7171
7172         log "grow $xsml on $file"
7173         setfattr -n $xsml -v "$value" $file ||
7174                 error "growing $xsml on $file failed"
7175
7176         new=$(get_xattr_value $xbig $file)
7177         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
7178         log "$xbig still valid after growing $xsml"
7179
7180         rm -f $file
7181 }
7182
7183 test_102h() { # bug 15777
7184         grow_xattr 1024
7185 }
7186 run_test 102h "grow xattr from inside inode to external block"
7187
7188 test_102ha() {
7189         large_xattr_enabled || { skip "large_xattr disabled" && return; }
7190         grow_xattr $(max_xattr_size)
7191 }
7192 run_test 102ha "grow xattr from inside inode to external inode"
7193
7194 test_102i() { # bug 17038
7195         [ -z "$(which getfattr 2>/dev/null)" ] &&
7196                 skip "could not find getfattr" && return
7197         touch $DIR/$tfile
7198         ln -s $DIR/$tfile $DIR/${tfile}link
7199         getfattr -n trusted.lov $DIR/$tfile ||
7200                 error "lgetxattr on $DIR/$tfile failed"
7201         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
7202                 grep -i "no such attr" ||
7203                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
7204         rm -f $DIR/$tfile $DIR/${tfile}link
7205 }
7206 run_test 102i "lgetxattr test on symbolic link ============"
7207
7208 test_102j() {
7209         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7210         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7211         local xinc=$(have_xattrs_include)
7212         setup_test102 "$RUNAS"
7213         chown $RUNAS_ID $DIR/$tdir
7214         $RUNAS tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $xinc
7215         cd $DIR/$tdir/$tdir
7216         compare_stripe_info1 "$RUNAS"
7217 }
7218 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
7219
7220 test_102k() {
7221         [ -z "$(which setfattr 2>/dev/null)" ] &&
7222                 skip "could not find setfattr" && return
7223         touch $DIR/$tfile
7224         # b22187 just check that does not crash for regular file.
7225         setfattr -n trusted.lov $DIR/$tfile
7226         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
7227         local test_kdir=$DIR/$tdir
7228         test_mkdir $test_kdir
7229         local default_size=`$GETSTRIPE -S $test_kdir`
7230         local default_count=`$GETSTRIPE -c $test_kdir`
7231         local default_offset=`$GETSTRIPE -i $test_kdir`
7232         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
7233                 error 'dir setstripe failed'
7234         setfattr -n trusted.lov $test_kdir
7235         local stripe_size=`$GETSTRIPE -S $test_kdir`
7236         local stripe_count=`$GETSTRIPE -c $test_kdir`
7237         local stripe_offset=`$GETSTRIPE -i $test_kdir`
7238         [ $stripe_size -eq $default_size ] ||
7239                 error "stripe size $stripe_size != $default_size"
7240         [ $stripe_count -eq $default_count ] ||
7241                 error "stripe count $stripe_count != $default_count"
7242         [ $stripe_offset -eq $default_offset ] ||
7243                 error "stripe offset $stripe_offset != $default_offset"
7244         rm -rf $DIR/$tfile $test_kdir
7245 }
7246 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
7247
7248 test_102l() {
7249         [ -z "$(which getfattr 2>/dev/null)" ] &&
7250                 skip "could not find getfattr" && return
7251
7252         # LU-532 trusted. xattr is invisible to non-root
7253         local testfile=$DIR/$tfile
7254
7255         touch $testfile
7256
7257         echo "listxattr as user..."
7258         chown $RUNAS_ID $testfile
7259         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
7260             grep -q "trusted" &&
7261                 error "$testfile trusted xattrs are user visible"
7262
7263         return 0;
7264 }
7265 run_test 102l "listxattr size test =================================="
7266
7267 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
7268         local path=$DIR/$tfile
7269         touch $path
7270
7271         listxattr_size_check $path || error "listattr_size_check $path failed"
7272 }
7273 run_test 102m "Ensure listxattr fails on small bufffer ========"
7274
7275 cleanup_test102
7276
7277 getxattr() { # getxattr path name
7278         # Return the base64 encoding of the value of xattr name on path.
7279         local path=$1
7280         local name=$2
7281
7282         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
7283         # file: $path
7284         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7285         #
7286         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7287
7288         getfattr --absolute-names --encoding=base64 --name=$name $path |
7289                 awk -F= -v name=$name '$1 == name {
7290                         print substr($0, index($0, "=") + 1);
7291         }'
7292 }
7293
7294 test_102n() { # LU-4101 mdt: protect internal xattrs
7295         [ -z "$(which setfattr 2>/dev/null)" ] &&
7296                 skip "could not find setfattr" && return
7297         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
7298         then
7299                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
7300                 return
7301         fi
7302
7303         local file0=$DIR/$tfile.0
7304         local file1=$DIR/$tfile.1
7305         local xattr0=$TMP/$tfile.0
7306         local xattr1=$TMP/$tfile.1
7307         local namelist="lov lma lmv link fid version som hsm"
7308         local name
7309         local value
7310
7311         rm -rf $file0 $file1 $xattr0 $xattr1
7312         touch $file0 $file1
7313
7314         # Get 'before' xattrs of $file1.
7315         getfattr --absolute-names --dump --match=- $file1 > $xattr0
7316
7317         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
7318                 namelist+=" lfsck_namespace"
7319         for name in $namelist; do
7320                 # Try to copy xattr from $file0 to $file1.
7321                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7322
7323                 setfattr --name=trusted.$name --value="$value" $file1 ||
7324                         error "setxattr 'trusted.$name' failed"
7325
7326                 # Try to set a garbage xattr.
7327                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7328
7329                 if [[ x$name == "xlov" ]]; then
7330                         setfattr --name=trusted.lov --value="$value" $file1 &&
7331                         error "setxattr invalid 'trusted.lov' success"
7332                 else
7333                         setfattr --name=trusted.$name --value="$value" $file1 ||
7334                                 error "setxattr invalid 'trusted.$name' failed"
7335                 fi
7336
7337                 # Try to remove the xattr from $file1. We don't care if this
7338                 # appears to succeed or fail, we just don't want there to be
7339                 # any changes or crashes.
7340                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7341         done
7342
7343         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
7344         then
7345                 name="lfsck_ns"
7346                 # Try to copy xattr from $file0 to $file1.
7347                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7348
7349                 setfattr --name=trusted.$name --value="$value" $file1 ||
7350                         error "setxattr 'trusted.$name' failed"
7351
7352                 # Try to set a garbage xattr.
7353                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7354
7355                 setfattr --name=trusted.$name --value="$value" $file1 ||
7356                         error "setxattr 'trusted.$name' failed"
7357
7358                 # Try to remove the xattr from $file1. We don't care if this
7359                 # appears to succeed or fail, we just don't want there to be
7360                 # any changes or crashes.
7361                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7362         fi
7363
7364         # Get 'after' xattrs of file1.
7365         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7366
7367         if ! diff $xattr0 $xattr1; then
7368                 error "before and after xattrs of '$file1' differ"
7369         fi
7370
7371         rm -rf $file0 $file1 $xattr0 $xattr1
7372
7373         return 0
7374 }
7375 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7376
7377 test_102p() { # LU-4703 setxattr did not check ownership
7378         local testfile=$DIR/$tfile
7379
7380         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7381                 skip "MDS needs to be at least 2.5.56" && return
7382
7383         touch $testfile
7384
7385         echo "setfacl as user..."
7386         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7387         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7388
7389         echo "setfattr as user..."
7390         setfacl -m "u:$RUNAS_ID:---" $testfile
7391         $RUNAS setfattr -x system.posix_acl_access $testfile
7392         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7393 }
7394 run_test 102p "check setxattr(2) correctly fails without permission"
7395
7396 test_102q() {
7397         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7398                 skip "MDS needs to be at least 2.6.92" && return
7399         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7400 }
7401 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7402
7403 test_102r() {
7404         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7405                 skip "MDS needs to be at least 2.6.93" && return
7406         touch $DIR/$tfile || error "touch"
7407         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7408         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7409         rm $DIR/$tfile || error "rm"
7410
7411         #normal directory
7412         mkdir -p $DIR/$tdir || error "mkdir"
7413         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7414         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7415         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7416                 error "$testfile error deleting user.author1"
7417         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7418                 grep "user.$(basename $tdir)" &&
7419                 error "$tdir did not delete user.$(basename $tdir)"
7420         rmdir $DIR/$tdir || error "rmdir"
7421
7422         #striped directory
7423         test_mkdir $DIR/$tdir || error "make striped dir"
7424         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7425         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7426         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7427                 error "$testfile error deleting user.author1"
7428         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7429                 grep "user.$(basename $tdir)" &&
7430                 error "$tdir did not delete user.$(basename $tdir)"
7431         rmdir $DIR/$tdir || error "rm striped dir"
7432 }
7433 run_test 102r "set EAs with empty values"
7434
7435 run_acl_subtest()
7436 {
7437     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7438     return $?
7439 }
7440
7441 test_103a() {
7442         [ "$UID" != 0 ] && skip_env "must run as root" && return
7443         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7444                 skip "must have acl enabled" && return
7445         [ -z "$(which setfacl 2>/dev/null)" ] &&
7446                 skip_env "could not find setfacl" && return
7447         $GSS && skip "could not run under gss" && return
7448         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7449
7450         gpasswd -a daemon bin                           # LU-5641
7451         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7452
7453         declare -a identity_old
7454
7455         for num in $(seq $MDSCOUNT); do
7456                 switch_identity $num true || identity_old[$num]=$?
7457         done
7458
7459         SAVE_UMASK=$(umask)
7460         umask 0022
7461         mkdir -p $DIR/$tdir
7462         cd $DIR/$tdir
7463
7464         echo "performing cp ..."
7465         run_acl_subtest cp || error "run_acl_subtest cp failed"
7466         echo "performing getfacl-noacl..."
7467         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7468         echo "performing misc..."
7469         run_acl_subtest misc || error  "misc test failed"
7470         echo "performing permissions..."
7471         run_acl_subtest permissions || error "permissions failed"
7472         # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
7473         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.8.55) -o \
7474              \( $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6) -a \
7475              $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.29) \) ]
7476         then
7477                 echo "performing permissions xattr..."
7478                 run_acl_subtest permissions_xattr ||
7479                         error "permissions_xattr failed"
7480         fi
7481         echo "performing setfacl..."
7482         run_acl_subtest setfacl || error  "setfacl test failed"
7483
7484         # inheritance test got from HP
7485         echo "performing inheritance..."
7486         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7487         chmod +x make-tree || error "chmod +x failed"
7488         run_acl_subtest inheritance || error "inheritance test failed"
7489         rm -f make-tree
7490
7491         echo "LU-974 ignore umask when acl is enabled..."
7492         run_acl_subtest 974 || error "LU-974 umask test failed"
7493         if [ $MDSCOUNT -ge 2 ]; then
7494                 run_acl_subtest 974_remote ||
7495                         error "LU-974 umask test failed under remote dir"
7496         fi
7497
7498         echo "LU-2561 newly created file is same size as directory..."
7499         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7500                 run_acl_subtest 2561 || error "LU-2561 test failed"
7501         else
7502                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7503         fi
7504
7505         run_acl_subtest 4924 || error "LU-4924 test failed"
7506
7507         cd $SAVE_PWD
7508         umask $SAVE_UMASK
7509
7510         for num in $(seq $MDSCOUNT); do
7511                 if [ "${identity_old[$num]}" = 1 ]; then
7512                         switch_identity $num false || identity_old[$num]=$?
7513                 fi
7514         done
7515 }
7516 run_test 103a "acl test ========================================="
7517
7518 test_103b() {
7519         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7520         local noacl=false
7521         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7522         local mountopts=$MDS_MOUNT_OPTS
7523
7524         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7525                 noacl=true
7526         else
7527                 # stop the MDT
7528                 stop $SINGLEMDS || error "failed to stop MDT."
7529                 # remount the MDT
7530                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7531                         MDS_MOUNT_OPTS="-o noacl"
7532                 else
7533                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7534                 fi
7535                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7536                         error "failed to start MDT."
7537                 MDS_MOUNT_OPTS=$mountopts
7538         fi
7539
7540         touch $DIR/$tfile
7541         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7542
7543         if ! $noacl; then
7544                 # stop the MDT
7545                 stop $SINGLEMDS || error "failed to stop MDT."
7546                 # remount the MDT
7547                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7548                         error "failed to start MDT."
7549         fi
7550
7551         true
7552 }
7553 run_test 103b "MDS mount option 'noacl'"
7554
7555 test_103c() {
7556         mkdir -p $DIR/$tdir
7557         cp -rp $DIR/$tdir $DIR/$tdir.bak
7558
7559         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7560                 error "$DIR/$tdir shouldn't contain default ACL"
7561         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7562                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7563         true
7564 }
7565 run_test 103c "'cp -rp' won't set empty acl"
7566
7567 test_104a() {
7568         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7569         touch $DIR/$tfile
7570         lfs df || error "lfs df failed"
7571         lfs df -ih || error "lfs df -ih failed"
7572         lfs df -h $DIR || error "lfs df -h $DIR failed"
7573         lfs df -i $DIR || error "lfs df -i $DIR failed"
7574         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7575         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7576
7577         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7578         lctl --device %$OSC deactivate
7579         lfs df || error "lfs df with deactivated OSC failed"
7580         lctl --device %$OSC activate
7581         # wait the osc back to normal
7582         wait_osc_import_state client ost FULL
7583
7584         lfs df || error "lfs df with reactivated OSC failed"
7585         rm -f $DIR/$tfile
7586 }
7587 run_test 104a "lfs df [-ih] [path] test ========================="
7588
7589 test_104b() {
7590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7591         [ $RUNAS_ID -eq $UID ] &&
7592                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7593         chmod 666 /dev/obd
7594         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7595                         grep "Permission denied" | wc -l)))
7596         if [ $denied_cnt -ne 0 ]; then
7597                 error "lfs check servers test failed"
7598         fi
7599 }
7600 run_test 104b "$RUNAS lfs check servers test ===================="
7601
7602 test_105a() {
7603         # doesn't work on 2.4 kernels
7604         touch $DIR/$tfile
7605         if $(flock_is_enabled); then
7606                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7607         else
7608                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7609         fi
7610         rm -f $DIR/$tfile
7611 }
7612 run_test 105a "flock when mounted without -o flock test ========"
7613
7614 test_105b() {
7615         touch $DIR/$tfile
7616         if $(flock_is_enabled); then
7617                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7618         else
7619                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7620         fi
7621         rm -f $DIR/$tfile
7622 }
7623 run_test 105b "fcntl when mounted without -o flock test ========"
7624
7625 test_105c() {
7626         touch $DIR/$tfile
7627         if $(flock_is_enabled); then
7628                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7629         else
7630                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7631         fi
7632         rm -f $DIR/$tfile
7633 }
7634 run_test 105c "lockf when mounted without -o flock test ========"
7635
7636 test_105d() { # bug 15924
7637         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7638         test_mkdir -p $DIR/$tdir
7639         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7640         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7641         $LCTL set_param fail_loc=0x80000315
7642         flocks_test 2 $DIR/$tdir
7643 }
7644 run_test 105d "flock race (should not freeze) ========"
7645
7646 test_105e() { # bug 22660 && 22040
7647         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7648         touch $DIR/$tfile
7649         flocks_test 3 $DIR/$tfile
7650 }
7651 run_test 105e "Two conflicting flocks from same process ======="
7652
7653 test_106() { #bug 10921
7654         test_mkdir -p $DIR/$tdir
7655         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7656         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7657 }
7658 run_test 106 "attempt exec of dir followed by chown of that dir"
7659
7660 test_107() {
7661         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7662         CDIR=`pwd`
7663         cd $DIR
7664
7665         local file=core
7666         rm -f $file
7667
7668         local save_pattern=$(sysctl -n kernel.core_pattern)
7669         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7670         sysctl -w kernel.core_pattern=$file
7671         sysctl -w kernel.core_uses_pid=0
7672
7673         ulimit -c unlimited
7674         sleep 60 &
7675         SLEEPPID=$!
7676
7677         sleep 1
7678
7679         kill -s 11 $SLEEPPID
7680         wait $SLEEPPID
7681         if [ -e $file ]; then
7682                 size=`stat -c%s $file`
7683                 [ $size -eq 0 ] && error "Fail to create core file $file"
7684         else
7685                 error "Fail to create core file $file"
7686         fi
7687         rm -f $file
7688         sysctl -w kernel.core_pattern=$save_pattern
7689         sysctl -w kernel.core_uses_pid=$save_uses_pid
7690         cd $CDIR
7691 }
7692 run_test 107 "Coredump on SIG"
7693
7694 test_110() {
7695         test_mkdir -p $DIR/$tdir
7696         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7697                 error "mkdir with 255 char failed"
7698         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7699                 error "mkdir with 256 char should fail, but did not"
7700         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7701                 error "create with 255 char failed"
7702         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7703                 error "create with 256 char should fail, but did not"
7704
7705         ls -l $DIR/$tdir
7706         rm -rf $DIR/$tdir
7707 }
7708 run_test 110 "filename length checking"
7709
7710 #
7711 # Purpose: To verify dynamic thread (OSS) creation.
7712 #
7713 test_115() {
7714         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7715         remote_ost_nodsh && skip "remote OST with nodsh" && return
7716
7717         # Lustre does not stop service threads once they are started.
7718         # Reset number of running threads to default.
7719         stopall
7720         setupall
7721
7722         local OSTIO_pre
7723         local save_params="$TMP/sanity-$TESTNAME.parameters"
7724
7725         # Get ll_ost_io count before I/O
7726         OSTIO_pre=$(do_facet ost1 \
7727                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
7728         # Exit if lustre is not running (ll_ost_io not running).
7729         [ -z "$OSTIO_pre" ] && error "no OSS threads"
7730
7731         echo "Starting with $OSTIO_pre threads"
7732         local thread_max=$((OSTIO_pre * 2))
7733         local rpc_in_flight=$((thread_max * 2))
7734         # Number of I/O Process proposed to be started.
7735         local nfiles
7736         local facets=$(get_facets OST)
7737
7738         save_lustre_params client \
7739                 "osc.*OST*.max_rpcs_in_flight" > $save_params
7740         save_lustre_params $facets \
7741                 "ost.OSS.ost_io.threads_max" >> $save_params
7742
7743         # Set in_flight to $rpc_in_flight
7744         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
7745                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
7746         nfiles=${rpc_in_flight}
7747         # Set ost thread_max to $thread_max
7748         do_facet ost1 \
7749                 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
7750
7751         # 5 Minutes should be sufficient for max number of OSS
7752         # threads(thread_max) to be created.
7753         local timeout=300
7754
7755         # Start I/O.
7756         local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
7757         mkdir -p $DIR/$tdir
7758         for i in $(seq $nfiles); do
7759                 local file=$DIR/$tdir/${tfile}-$i
7760                 $LFS setstripe -c -1 -i 0 $file
7761                 ($WTL $file $timeout)&
7762         done
7763
7764         # I/O Started - Wait for thread_started to reach thread_max or report
7765         # error if thread_started is more than thread_max.
7766         echo "Waiting for thread_started to reach thread_max"
7767         local thread_started=0
7768         local end_time=$((SECONDS + timeout))
7769
7770         while [ $SECONDS -le $end_time ] ; do
7771                 echo -n "."
7772                 # Get ost i/o thread_started count.
7773                 thread_started=$(do_facet ost1 \
7774                         "$LCTL get_param \
7775                         ost.OSS.ost_io.threads_started | cut -d= -f2")
7776                 # Break out if thread_started is equal/greater than thread_max
7777                 if [[ $thread_started -ge $thread_max ]]; then
7778                         echo ll_ost_io thread_started $thread_started, \
7779                                 equal/greater than thread_max $thread_max
7780                         break
7781                 fi
7782                 sleep 1
7783         done
7784
7785         # Cleanup - We have the numbers, Kill i/o jobs if running.
7786         jobcount=($(jobs -p))
7787         for i in $(seq 0 $((${#jobcount[@]}-1)))
7788         do
7789                 kill -9 ${jobcount[$i]}
7790                 if [ $? -ne 0 ] ; then
7791                         echo Warning: \
7792                         Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
7793                 fi
7794         done
7795
7796         # Cleanup files left by WTL binary.
7797         for i in $(seq $nfiles); do
7798                 local file=$DIR/$tdir/${tfile}-$i
7799                 rm -rf $file
7800                 if [ $? -ne 0 ] ; then
7801                         echo "Warning: Failed to delete file $file"
7802                 fi
7803         done
7804
7805         restore_lustre_params <$save_params
7806         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
7807
7808         # Error out if no new thread has started or Thread started is greater
7809         # than thread max.
7810         if [[ $thread_started -le $OSTIO_pre ||
7811                         $thread_started -gt $thread_max ]]; then
7812                 error "ll_ost_io: thread_started $thread_started" \
7813                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
7814                       "No new thread started or thread started greater " \
7815                       "than thread_max."
7816         fi
7817 }
7818 run_test 115 "verify dynamic thread creation===================="
7819
7820 free_min_max () {
7821         wait_delete_completed
7822         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7823         echo "OST kbytes available: ${AVAIL[@]}"
7824         MAXV=${AVAIL[0]}
7825         MAXI=0
7826         MINV=${AVAIL[0]}
7827         MINI=0
7828         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7829                 #echo OST $i: ${AVAIL[i]}kb
7830                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7831                         MAXV=${AVAIL[i]}
7832                         MAXI=$i
7833                 fi
7834                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7835                         MINV=${AVAIL[i]}
7836                         MINI=$i
7837                 fi
7838         done
7839         echo "Min free space: OST $MINI: $MINV"
7840         echo "Max free space: OST $MAXI: $MAXV"
7841 }
7842
7843 test_116a() { # was previously test_116()
7844         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7845         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7846
7847         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7848
7849         echo -n "Free space priority "
7850         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7851                 head -n1
7852         declare -a AVAIL
7853         free_min_max
7854
7855         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7856         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7857                 && return
7858         trap simple_cleanup_common EXIT
7859
7860
7861         # Check if we need to generate uneven OSTs
7862         test_mkdir -p $DIR/$tdir/OST${MINI}
7863         local FILL=$((MINV / 4))
7864         local DIFF=$((MAXV - MINV))
7865         local DIFF2=$((DIFF * 100 / MINV))
7866
7867         local threshold=$(do_facet $SINGLEMDS \
7868                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7869         threshold=${threshold%%%}
7870         echo -n "Check for uneven OSTs: "
7871         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7872
7873         if [[ $DIFF2 -gt $threshold ]]; then
7874                 echo "ok"
7875                 echo "Don't need to fill OST$MINI"
7876         else
7877                 # generate uneven OSTs. Write 2% over the QOS threshold value
7878                 echo "no"
7879                 DIFF=$((threshold - DIFF2 + 2))
7880                 DIFF2=$((MINV * DIFF / 100))
7881                 echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
7882                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7883                         error "setstripe failed"
7884                 DIFF=$((DIFF2 / 2048))
7885                 i=0
7886                 while [ $i -lt $DIFF ]; do
7887                         i=$((i + 1))
7888                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7889                                 bs=2M count=1 2>/dev/null
7890                         echo -n .
7891                 done
7892                 echo .
7893                 sync
7894                 sleep_maxage
7895                 free_min_max
7896         fi
7897
7898         DIFF=$((MAXV - MINV))
7899         DIFF2=$((DIFF * 100 / MINV))
7900         echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
7901         if [ $DIFF2 -gt $threshold ]; then
7902                 echo "ok"
7903         else
7904                 echo "failed - QOS mode won't be used"
7905                 skip "QOS imbalance criteria not met"
7906                 simple_cleanup_common
7907                 return
7908         fi
7909
7910         MINI1=$MINI
7911         MINV1=$MINV
7912         MAXI1=$MAXI
7913         MAXV1=$MAXV
7914
7915         # now fill using QOS
7916         $SETSTRIPE -c 1 $DIR/$tdir
7917         FILL=$((FILL / 200))
7918         if [ $FILL -gt 600 ]; then
7919                 FILL=600
7920         fi
7921         echo "writing $FILL files to QOS-assigned OSTs"
7922         i=0
7923         while [ $i -lt $FILL ]; do
7924                 i=$((i + 1))
7925                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7926                         count=1 2>/dev/null
7927                 echo -n .
7928         done
7929         echo "wrote $i 200k files"
7930         sync
7931         sleep_maxage
7932
7933         echo "Note: free space may not be updated, so measurements might be off"
7934         free_min_max
7935         DIFF2=$((MAXV - MINV))
7936         echo "free space delta: orig $DIFF final $DIFF2"
7937         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7938         DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
7939         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7940         DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
7941         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7942         if [[ $DIFF -gt 0 ]]; then
7943                 FILL=$((DIFF2 * 100 / DIFF - 100))
7944                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7945         fi
7946
7947         # Figure out which files were written where
7948         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7949                awk '/'$MINI1': / {print $2; exit}')
7950         echo $UUID
7951         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7952         echo "$MINC files created on smaller OST $MINI1"
7953         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7954                awk '/'$MAXI1': / {print $2; exit}')
7955         echo $UUID
7956         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7957         echo "$MAXC files created on larger OST $MAXI1"
7958         if [[ $MINC -gt 0 ]]; then
7959                 FILL=$((MAXC * 100 / MINC - 100))
7960                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7961         fi
7962         [[ $MAXC -gt $MINC ]] ||
7963                 error_ignore LU-9 "stripe QOS didn't balance free space"
7964         simple_cleanup_common
7965 }
7966 run_test 116a "stripe QOS: free space balance ==================="
7967
7968 test_116b() { # LU-2093
7969         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7970         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7971
7972 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7973         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7974                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7975         [ -z "$old_rr" ] && skip "no QOS" && return 0
7976         do_facet $SINGLEMDS lctl set_param \
7977                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7978         mkdir -p $DIR/$tdir
7979         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7980         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7981         do_facet $SINGLEMDS lctl set_param fail_loc=0
7982         rm -rf $DIR/$tdir
7983         do_facet $SINGLEMDS lctl set_param \
7984                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7985 }
7986 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7987
7988 test_117() # bug 10891
7989 {
7990         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7991         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7992         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7993         lctl set_param fail_loc=0x21e
7994         > $DIR/$tfile || error "truncate failed"
7995         lctl set_param fail_loc=0
7996         echo "Truncate succeeded."
7997         rm -f $DIR/$tfile
7998 }
7999 run_test 117 "verify osd extend =========="
8000
8001 NO_SLOW_RESENDCOUNT=4
8002 export OLD_RESENDCOUNT=""
8003 set_resend_count () {
8004         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
8005         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
8006         lctl set_param -n $PROC_RESENDCOUNT $1
8007         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
8008 }
8009
8010 # for reduce test_118* time (b=14842)
8011 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8012
8013 # Reset async IO behavior after error case
8014 reset_async() {
8015         FILE=$DIR/reset_async
8016
8017         # Ensure all OSCs are cleared
8018         $SETSTRIPE -c -1 $FILE
8019         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
8020         sync
8021         rm $FILE
8022 }
8023
8024 test_118a() #bug 11710
8025 {
8026         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8027         reset_async
8028
8029         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8030         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8031         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8032
8033         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8034                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8035                 return 1;
8036         fi
8037         rm -f $DIR/$tfile
8038 }
8039 run_test 118a "verify O_SYNC works =========="
8040
8041 test_118b()
8042 {
8043         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8044         remote_ost_nodsh && skip "remote OST with nodsh" && return
8045
8046         reset_async
8047
8048         #define OBD_FAIL_SRV_ENOENT 0x217
8049         set_nodes_failloc "$(osts_nodes)" 0x217
8050         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8051         RC=$?
8052         set_nodes_failloc "$(osts_nodes)" 0
8053         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8054         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8055                     grep -c writeback)
8056
8057         if [[ $RC -eq 0 ]]; then
8058                 error "Must return error due to dropped pages, rc=$RC"
8059                 return 1;
8060         fi
8061
8062         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8063                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8064                 return 1;
8065         fi
8066
8067         echo "Dirty pages not leaked on ENOENT"
8068
8069         # Due to the above error the OSC will issue all RPCs syncronously
8070         # until a subsequent RPC completes successfully without error.
8071         $MULTIOP $DIR/$tfile Ow4096yc
8072         rm -f $DIR/$tfile
8073
8074         return 0
8075 }
8076 run_test 118b "Reclaim dirty pages on fatal error =========="
8077
8078 test_118c()
8079 {
8080         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8081
8082         # for 118c, restore the original resend count, LU-1940
8083         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
8084                                 set_resend_count $OLD_RESENDCOUNT
8085         remote_ost_nodsh && skip "remote OST with nodsh" && return
8086
8087         reset_async
8088
8089         #define OBD_FAIL_OST_EROFS               0x216
8090         set_nodes_failloc "$(osts_nodes)" 0x216
8091
8092         # multiop should block due to fsync until pages are written
8093         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8094         MULTIPID=$!
8095         sleep 1
8096
8097         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8098                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8099         fi
8100
8101         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8102                     grep -c writeback)
8103         if [[ $WRITEBACK -eq 0 ]]; then
8104                 error "No page in writeback, writeback=$WRITEBACK"
8105         fi
8106
8107         set_nodes_failloc "$(osts_nodes)" 0
8108         wait $MULTIPID
8109         RC=$?
8110         if [[ $RC -ne 0 ]]; then
8111                 error "Multiop fsync failed, rc=$RC"
8112         fi
8113
8114         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8115         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8116                     grep -c writeback)
8117         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8118                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8119         fi
8120
8121         rm -f $DIR/$tfile
8122         echo "Dirty pages flushed via fsync on EROFS"
8123         return 0
8124 }
8125 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
8126
8127 # continue to use small resend count to reduce test_118* time (b=14842)
8128 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8129
8130 test_118d()
8131 {
8132         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8133         remote_ost_nodsh && skip "remote OST with nodsh" && return
8134
8135         reset_async
8136
8137         #define OBD_FAIL_OST_BRW_PAUSE_BULK
8138         set_nodes_failloc "$(osts_nodes)" 0x214
8139         # multiop should block due to fsync until pages are written
8140         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8141         MULTIPID=$!
8142         sleep 1
8143
8144         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8145                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8146         fi
8147
8148         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8149                     grep -c writeback)
8150         if [[ $WRITEBACK -eq 0 ]]; then
8151                 error "No page in writeback, writeback=$WRITEBACK"
8152         fi
8153
8154         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
8155         set_nodes_failloc "$(osts_nodes)" 0
8156
8157         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8158         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8159                     grep -c writeback)
8160         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8161                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8162         fi
8163
8164         rm -f $DIR/$tfile
8165         echo "Dirty pages gaurenteed flushed via fsync"
8166         return 0
8167 }
8168 run_test 118d "Fsync validation inject a delay of the bulk =========="
8169
8170 test_118f() {
8171         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8172         reset_async
8173
8174         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
8175         lctl set_param fail_loc=0x8000040a
8176
8177         # Should simulate EINVAL error which is fatal
8178         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8179         RC=$?
8180         if [[ $RC -eq 0 ]]; then
8181                 error "Must return error due to dropped pages, rc=$RC"
8182         fi
8183
8184         lctl set_param fail_loc=0x0
8185
8186         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8187         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8188         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8189                     grep -c writeback)
8190         if [[ $LOCKED -ne 0 ]]; then
8191                 error "Locked pages remain in cache, locked=$LOCKED"
8192         fi
8193
8194         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8195                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8196         fi
8197
8198         rm -f $DIR/$tfile
8199         echo "No pages locked after fsync"
8200
8201         reset_async
8202         return 0
8203 }
8204 run_test 118f "Simulate unrecoverable OSC side error =========="
8205
8206 test_118g() {
8207         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8208         reset_async
8209
8210         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
8211         lctl set_param fail_loc=0x406
8212
8213         # simulate local -ENOMEM
8214         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8215         RC=$?
8216
8217         lctl set_param fail_loc=0
8218         if [[ $RC -eq 0 ]]; then
8219                 error "Must return error due to dropped pages, rc=$RC"
8220         fi
8221
8222         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8223         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8224         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8225                         grep -c writeback)
8226         if [[ $LOCKED -ne 0 ]]; then
8227                 error "Locked pages remain in cache, locked=$LOCKED"
8228         fi
8229
8230         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8231                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8232         fi
8233
8234         rm -f $DIR/$tfile
8235         echo "No pages locked after fsync"
8236
8237         reset_async
8238         return 0
8239 }
8240 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
8241
8242 test_118h() {
8243         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8244         remote_ost_nodsh && skip "remote OST with nodsh" && return
8245
8246         reset_async
8247
8248         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8249         set_nodes_failloc "$(osts_nodes)" 0x20e
8250         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8251         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8252         RC=$?
8253
8254         set_nodes_failloc "$(osts_nodes)" 0
8255         if [[ $RC -eq 0 ]]; then
8256                 error "Must return error due to dropped pages, rc=$RC"
8257         fi
8258
8259         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8260         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8261         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8262                     grep -c writeback)
8263         if [[ $LOCKED -ne 0 ]]; then
8264                 error "Locked pages remain in cache, locked=$LOCKED"
8265         fi
8266
8267         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8268                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8269         fi
8270
8271         rm -f $DIR/$tfile
8272         echo "No pages locked after fsync"
8273
8274         return 0
8275 }
8276 run_test 118h "Verify timeout in handling recoverables errors  =========="
8277
8278 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8279
8280 test_118i() {
8281         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8282         remote_ost_nodsh && skip "remote OST with nodsh" && return
8283
8284         reset_async
8285
8286         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8287         set_nodes_failloc "$(osts_nodes)" 0x20e
8288
8289         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8290         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8291         PID=$!
8292         sleep 5
8293         set_nodes_failloc "$(osts_nodes)" 0
8294
8295         wait $PID
8296         RC=$?
8297         if [[ $RC -ne 0 ]]; then
8298                 error "got error, but should be not, rc=$RC"
8299         fi
8300
8301         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8302         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8303         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8304         if [[ $LOCKED -ne 0 ]]; then
8305                 error "Locked pages remain in cache, locked=$LOCKED"
8306         fi
8307
8308         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8309                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8310         fi
8311
8312         rm -f $DIR/$tfile
8313         echo "No pages locked after fsync"
8314
8315         return 0
8316 }
8317 run_test 118i "Fix error before timeout in recoverable error  =========="
8318
8319 [ "$SLOW" = "no" ] && set_resend_count 4
8320
8321 test_118j() {
8322         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8323         remote_ost_nodsh && skip "remote OST with nodsh" && return
8324
8325         reset_async
8326
8327         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
8328         set_nodes_failloc "$(osts_nodes)" 0x220
8329
8330         # return -EIO from OST
8331         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8332         RC=$?
8333         set_nodes_failloc "$(osts_nodes)" 0x0
8334         if [[ $RC -eq 0 ]]; then
8335                 error "Must return error due to dropped pages, rc=$RC"
8336         fi
8337
8338         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8339         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8340         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8341         if [[ $LOCKED -ne 0 ]]; then
8342                 error "Locked pages remain in cache, locked=$LOCKED"
8343         fi
8344
8345         # in recoverable error on OST we want resend and stay until it finished
8346         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8347                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8348         fi
8349
8350         rm -f $DIR/$tfile
8351         echo "No pages locked after fsync"
8352
8353         return 0
8354 }
8355 run_test 118j "Simulate unrecoverable OST side error =========="
8356
8357 test_118k()
8358 {
8359         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8360         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
8361
8362         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8363         set_nodes_failloc "$(osts_nodes)" 0x20e
8364         test_mkdir -p $DIR/$tdir
8365
8366         for ((i=0;i<10;i++)); do
8367                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
8368                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
8369                 SLEEPPID=$!
8370                 sleep 0.500s
8371                 kill $SLEEPPID
8372                 wait $SLEEPPID
8373         done
8374
8375         set_nodes_failloc "$(osts_nodes)" 0
8376         rm -rf $DIR/$tdir
8377 }
8378 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
8379
8380 test_118l()
8381 {
8382         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8383         # LU-646
8384         test_mkdir -p $DIR/$tdir
8385         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
8386         rm -rf $DIR/$tdir
8387 }
8388 run_test 118l "fsync dir ========="
8389
8390 test_118m() # LU-3066
8391 {
8392         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8393         test_mkdir -p $DIR/$tdir
8394         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
8395         rm -rf $DIR/$tdir
8396 }
8397 run_test 118m "fdatasync dir ========="
8398
8399 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8400
8401 test_119a() # bug 11737
8402 {
8403         BSIZE=$((512 * 1024))
8404         directio write $DIR/$tfile 0 1 $BSIZE
8405         # We ask to read two blocks, which is more than a file size.
8406         # directio will indicate an error when requested and actual
8407         # sizes aren't equeal (a normal situation in this case) and
8408         # print actual read amount.
8409         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
8410         if [ "$NOB" != "$BSIZE" ]; then
8411                 error "read $NOB bytes instead of $BSIZE"
8412         fi
8413         rm -f $DIR/$tfile
8414 }
8415 run_test 119a "Short directIO read must return actual read amount"
8416
8417 test_119b() # bug 11737
8418 {
8419         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
8420
8421         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
8422         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
8423         sync
8424         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
8425                 error "direct read failed"
8426         rm -f $DIR/$tfile
8427 }
8428 run_test 119b "Sparse directIO read must return actual read amount"
8429
8430 test_119c() # bug 13099
8431 {
8432         BSIZE=1048576
8433         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
8434         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
8435         rm -f $DIR/$tfile
8436 }
8437 run_test 119c "Testing for direct read hitting hole"
8438
8439 test_119d() # bug 15950
8440 {
8441         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8442         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
8443         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
8444         BSIZE=1048576
8445         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
8446         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
8447         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
8448         lctl set_param fail_loc=0x40d
8449         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
8450         pid_dio=$!
8451         sleep 1
8452         cat $DIR/$tfile > /dev/null &
8453         lctl set_param fail_loc=0
8454         pid_reads=$!
8455         wait $pid_dio
8456         log "the DIO writes have completed, now wait for the reads (should not block very long)"
8457         sleep 2
8458         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8459         error "the read rpcs have not completed in 2s"
8460         rm -f $DIR/$tfile
8461         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8462 }
8463 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8464
8465 test_120a() {
8466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8467         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8468         test_mkdir -p $DIR/$tdir
8469         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8470                skip "no early lock cancel on server" && return 0
8471
8472         lru_resize_disable mdc
8473         lru_resize_disable osc
8474         cancel_lru_locks mdc
8475         # asynchronous object destroy at MDT could cause bl ast to client
8476         cancel_lru_locks osc
8477
8478         stat $DIR/$tdir > /dev/null
8479         can1=$(do_facet $SINGLEMDS \
8480                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8481                awk '/ldlm_cancel/ {print $2}')
8482         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8483                awk '/ldlm_bl_callback/ {print $2}')
8484         test_mkdir -c1 $DIR/$tdir/d1
8485         can2=$(do_facet $SINGLEMDS \
8486                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8487                awk '/ldlm_cancel/ {print $2}')
8488         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8489                awk '/ldlm_bl_callback/ {print $2}')
8490         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8491         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8492         lru_resize_enable mdc
8493         lru_resize_enable osc
8494 }
8495 run_test 120a "Early Lock Cancel: mkdir test"
8496
8497 test_120b() {
8498         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8499         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8500         test_mkdir $DIR/$tdir
8501         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8502                skip "no early lock cancel on server" && return 0
8503         lru_resize_disable mdc
8504         lru_resize_disable osc
8505         cancel_lru_locks mdc
8506         stat $DIR/$tdir > /dev/null
8507         can1=$(do_facet $SINGLEMDS \
8508                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8509                awk '/ldlm_cancel/ {print $2}')
8510         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8511                awk '/ldlm_bl_callback/ {print $2}')
8512         touch $DIR/$tdir/f1
8513         can2=$(do_facet $SINGLEMDS \
8514                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8515                awk '/ldlm_cancel/ {print $2}')
8516         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8517                awk '/ldlm_bl_callback/ {print $2}')
8518         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8519         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8520         lru_resize_enable mdc
8521         lru_resize_enable osc
8522 }
8523 run_test 120b "Early Lock Cancel: create test"
8524
8525 test_120c() {
8526         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8527         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8528         test_mkdir -c1 $DIR/$tdir
8529         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8530                skip "no early lock cancel on server" && return 0
8531         lru_resize_disable mdc
8532         lru_resize_disable osc
8533         test_mkdir -p -c1 $DIR/$tdir/d1
8534         test_mkdir -p -c1 $DIR/$tdir/d2
8535         touch $DIR/$tdir/d1/f1
8536         cancel_lru_locks mdc
8537         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8538         can1=$(do_facet $SINGLEMDS \
8539                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8540                awk '/ldlm_cancel/ {print $2}')
8541         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8542                awk '/ldlm_bl_callback/ {print $2}')
8543         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8544         can2=$(do_facet $SINGLEMDS \
8545                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8546                awk '/ldlm_cancel/ {print $2}')
8547         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8548                awk '/ldlm_bl_callback/ {print $2}')
8549         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8550         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8551         lru_resize_enable mdc
8552         lru_resize_enable osc
8553 }
8554 run_test 120c "Early Lock Cancel: link test"
8555
8556 test_120d() {
8557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8558         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8559         test_mkdir -p -c1 $DIR/$tdir
8560         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8561                skip "no early lock cancel on server" && return 0
8562         lru_resize_disable mdc
8563         lru_resize_disable osc
8564         touch $DIR/$tdir
8565         cancel_lru_locks mdc
8566         stat $DIR/$tdir > /dev/null
8567         can1=$(do_facet $SINGLEMDS \
8568                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8569                awk '/ldlm_cancel/ {print $2}')
8570         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8571                awk '/ldlm_bl_callback/ {print $2}')
8572         chmod a+x $DIR/$tdir
8573         can2=$(do_facet $SINGLEMDS \
8574                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8575                awk '/ldlm_cancel/ {print $2}')
8576         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8577                awk '/ldlm_bl_callback/ {print $2}')
8578         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8579         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8580         lru_resize_enable mdc
8581         lru_resize_enable osc
8582 }
8583 run_test 120d "Early Lock Cancel: setattr test"
8584
8585 test_120e() {
8586         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8587         ! $($LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_can) &&
8588                 skip "no early lock cancel on server" && return 0
8589         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8590         local dlmtrace_set=false
8591
8592         test_mkdir -p -c1 $DIR/$tdir
8593         lru_resize_disable mdc
8594         lru_resize_disable osc
8595         ! $LCTL get_param debug | grep -q dlmtrace &&
8596                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
8597         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8598         cancel_lru_locks mdc
8599         cancel_lru_locks osc
8600         dd if=$DIR/$tdir/f1 of=/dev/null
8601         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8602         # XXX client can not do early lock cancel of OST lock
8603         # during unlink (LU-4206), so cancel osc lock now.
8604         sleep 2
8605         cancel_lru_locks osc
8606         can1=$(do_facet $SINGLEMDS \
8607                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8608                awk '/ldlm_cancel/ {print $2}')
8609         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8610                awk '/ldlm_bl_callback/ {print $2}')
8611         unlink $DIR/$tdir/f1
8612         sleep 5
8613         can2=$(do_facet $SINGLEMDS \
8614                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8615                awk '/ldlm_cancel/ {print $2}')
8616         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8617                awk '/ldlm_bl_callback/ {print $2}')
8618         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
8619                 $LCTL dk $TMP/cancel.debug.txt
8620         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
8621                 $LCTL dk $TMP/blocking.debug.txt
8622         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
8623         lru_resize_enable mdc
8624         lru_resize_enable osc
8625 }
8626 run_test 120e "Early Lock Cancel: unlink test"
8627
8628 test_120f() {
8629         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8630         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8631                skip "no early lock cancel on server" && return 0
8632         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8633         test_mkdir -p -c1 $DIR/$tdir
8634         lru_resize_disable mdc
8635         lru_resize_disable osc
8636         test_mkdir -p -c1 $DIR/$tdir/d1
8637         test_mkdir -p -c1 $DIR/$tdir/d2
8638         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8639         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8640         cancel_lru_locks mdc
8641         cancel_lru_locks osc
8642         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8643         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8644         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8645         # XXX client can not do early lock cancel of OST lock
8646         # during rename (LU-4206), so cancel osc lock now.
8647         sleep 2
8648         cancel_lru_locks osc
8649         can1=$(do_facet $SINGLEMDS \
8650                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8651                awk '/ldlm_cancel/ {print $2}')
8652         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8653                awk '/ldlm_bl_callback/ {print $2}')
8654         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8655         sleep 5
8656         can2=$(do_facet $SINGLEMDS \
8657                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8658                awk '/ldlm_cancel/ {print $2}')
8659         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8660                awk '/ldlm_bl_callback/ {print $2}')
8661         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8662         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8663         lru_resize_enable mdc
8664         lru_resize_enable osc
8665 }
8666 run_test 120f "Early Lock Cancel: rename test"
8667
8668 test_120g() {
8669         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8670         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8671                skip "no early lock cancel on server" && return 0
8672         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8673         lru_resize_disable mdc
8674         lru_resize_disable osc
8675         count=10000
8676         echo create $count files
8677         test_mkdir -p $DIR/$tdir
8678         cancel_lru_locks mdc
8679         cancel_lru_locks osc
8680         t0=`date +%s`
8681
8682         can0=$(do_facet $SINGLEMDS \
8683                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8684                awk '/ldlm_cancel/ {print $2}')
8685         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8686                awk '/ldlm_bl_callback/ {print $2}')
8687         createmany -o $DIR/$tdir/f $count
8688         sync
8689         can1=$(do_facet $SINGLEMDS \
8690                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8691                awk '/ldlm_cancel/ {print $2}')
8692         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8693                awk '/ldlm_bl_callback/ {print $2}')
8694         t1=$(date +%s)
8695         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8696         echo rm $count files
8697         rm -r $DIR/$tdir
8698         sync
8699         can2=$(do_facet $SINGLEMDS \
8700                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8701                awk '/ldlm_cancel/ {print $2}')
8702         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8703                awk '/ldlm_bl_callback/ {print $2}')
8704         t2=$(date +%s)
8705         echo total: $count removes in $((t2-t1))
8706         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8707         sleep 2
8708         # wait for commitment of removal
8709         lru_resize_enable mdc
8710         lru_resize_enable osc
8711 }
8712 run_test 120g "Early Lock Cancel: performance test"
8713
8714 test_121() { #bug #10589
8715         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8716         rm -rf $DIR/$tfile
8717         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8718 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8719         lctl set_param fail_loc=0x310
8720         cancel_lru_locks osc > /dev/null
8721         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8722         lctl set_param fail_loc=0
8723         [[ $reads -eq $writes ]] ||
8724                 error "read $reads blocks, must be $writes blocks"
8725 }
8726 run_test 121 "read cancel race ========="
8727
8728 test_123a() { # was test 123, statahead(bug 11401)
8729         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8730         SLOWOK=0
8731         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8732             log "testing on UP system. Performance may be not as good as expected."
8733                         SLOWOK=1
8734         fi
8735
8736         rm -rf $DIR/$tdir
8737         test_mkdir -p $DIR/$tdir
8738         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8739         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8740         MULT=10
8741         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8742                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8743
8744                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8745                 lctl set_param -n llite.*.statahead_max 0
8746                 lctl get_param llite.*.statahead_max
8747                 cancel_lru_locks mdc
8748                 cancel_lru_locks osc
8749                 stime=`date +%s`
8750                 time ls -l $DIR/$tdir | wc -l
8751                 etime=`date +%s`
8752                 delta=$((etime - stime))
8753                 log "ls $i files without statahead: $delta sec"
8754                 lctl set_param llite.*.statahead_max=$max
8755
8756                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8757                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8758                 cancel_lru_locks mdc
8759                 cancel_lru_locks osc
8760                 stime=`date +%s`
8761                 time ls -l $DIR/$tdir | wc -l
8762                 etime=`date +%s`
8763                 delta_sa=$((etime - stime))
8764                 log "ls $i files with statahead: $delta_sa sec"
8765                 lctl get_param -n llite.*.statahead_stats
8766                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8767
8768                 [[ $swrong -lt $ewrong ]] &&
8769                         log "statahead was stopped, maybe too many locks held!"
8770                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8771
8772                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8773                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8774                     lctl set_param -n llite.*.statahead_max 0
8775                     lctl get_param llite.*.statahead_max
8776                     cancel_lru_locks mdc
8777                     cancel_lru_locks osc
8778                     stime=`date +%s`
8779                     time ls -l $DIR/$tdir | wc -l
8780                     etime=`date +%s`
8781                     delta=$((etime - stime))
8782                     log "ls $i files again without statahead: $delta sec"
8783                     lctl set_param llite.*.statahead_max=$max
8784                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8785                         if [  $SLOWOK -eq 0 ]; then
8786                                 error "ls $i files is slower with statahead!"
8787                         else
8788                                 log "ls $i files is slower with statahead!"
8789                         fi
8790                         break
8791                     fi
8792                 fi
8793
8794                 [ $delta -gt 20 ] && break
8795                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8796                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8797         done
8798         log "ls done"
8799
8800         stime=`date +%s`
8801         rm -r $DIR/$tdir
8802         sync
8803         etime=`date +%s`
8804         delta=$((etime - stime))
8805         log "rm -r $DIR/$tdir/: $delta seconds"
8806         log "rm done"
8807         lctl get_param -n llite.*.statahead_stats
8808 }
8809 run_test 123a "verify statahead work"
8810
8811 test_123b () { # statahead(bug 15027)
8812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8813         test_mkdir -p $DIR/$tdir
8814         createmany -o $DIR/$tdir/$tfile-%d 1000
8815
8816         cancel_lru_locks mdc
8817         cancel_lru_locks osc
8818
8819 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8820         lctl set_param fail_loc=0x80000803
8821         ls -lR $DIR/$tdir > /dev/null
8822         log "ls done"
8823         lctl set_param fail_loc=0x0
8824         lctl get_param -n llite.*.statahead_stats
8825         rm -r $DIR/$tdir
8826         sync
8827
8828 }
8829 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8830
8831 test_124a() {
8832         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8833         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8834                 skip "no lru resize on server" && return 0
8835         local NR=2000
8836         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8837
8838         log "create $NR files at $DIR/$tdir"
8839         createmany -o $DIR/$tdir/f $NR ||
8840                 error "failed to create $NR files in $DIR/$tdir"
8841
8842         cancel_lru_locks mdc
8843         ls -l $DIR/$tdir > /dev/null
8844
8845         local NSDIR=""
8846         local LRU_SIZE=0
8847         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8848                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8849                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8850                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8851                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8852                         log "NSDIR=$NSDIR"
8853                         log "NS=$(basename $NSDIR)"
8854                         break
8855                 fi
8856         done
8857
8858         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8859                 skip "Not enough cached locks created!"
8860                 return 0
8861         fi
8862         log "LRU=$LRU_SIZE"
8863
8864         local SLEEP=30
8865
8866         # We know that lru resize allows one client to hold $LIMIT locks
8867         # for 10h. After that locks begin to be killed by client.
8868         local MAX_HRS=10
8869         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8870         log "LIMIT=$LIMIT"
8871         if [ $LIMIT -lt $LRU_SIZE ]; then
8872             skip "Limit is too small $LIMIT"
8873             return 0
8874         fi
8875
8876         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8877         # killing locks. Some time was spent for creating locks. This means
8878         # that up to the moment of sleep finish we must have killed some of
8879         # them (10-100 locks). This depends on how fast ther were created.
8880         # Many of them were touched in almost the same moment and thus will
8881         # be killed in groups.
8882         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8883
8884         # Use $LRU_SIZE_B here to take into account real number of locks
8885         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8886         local LRU_SIZE_B=$LRU_SIZE
8887         log "LVF=$LVF"
8888         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8889         log "OLD_LVF=$OLD_LVF"
8890         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8891
8892         # Let's make sure that we really have some margin. Client checks
8893         # cached locks every 10 sec.
8894         SLEEP=$((SLEEP+20))
8895         log "Sleep ${SLEEP} sec"
8896         local SEC=0
8897         while ((SEC<$SLEEP)); do
8898                 echo -n "..."
8899                 sleep 5
8900                 SEC=$((SEC+5))
8901                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8902                 echo -n "$LRU_SIZE"
8903         done
8904         echo ""
8905         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8906         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8907
8908         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8909                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8910                 unlinkmany $DIR/$tdir/f $NR
8911                 return
8912         }
8913
8914         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8915         log "unlink $NR files at $DIR/$tdir"
8916         unlinkmany $DIR/$tdir/f $NR
8917 }
8918 run_test 124a "lru resize ======================================="
8919
8920 get_max_pool_limit()
8921 {
8922         local limit=$($LCTL get_param \
8923                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8924         local max=0
8925         for l in $limit; do
8926                 if [[ $l -gt $max ]]; then
8927                         max=$l
8928                 fi
8929         done
8930         echo $max
8931 }
8932
8933 test_124b() {
8934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8935         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8936                 skip "no lru resize on server" && return 0
8937
8938         LIMIT=$(get_max_pool_limit)
8939
8940         NR=$(($(default_lru_size)*20))
8941         if [[ $NR -gt $LIMIT ]]; then
8942                 log "Limit lock number by $LIMIT locks"
8943                 NR=$LIMIT
8944         fi
8945
8946         IFree=$(mdsrate_inodes_available)
8947         if [ $IFree -lt $NR ]; then
8948                 log "Limit lock number by $IFree inodes"
8949                 NR=$IFree
8950         fi
8951
8952         lru_resize_disable mdc
8953         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8954                 error "failed to create $DIR/$tdir/disable_lru_resize"
8955
8956         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8957         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8958         cancel_lru_locks mdc
8959         stime=`date +%s`
8960         PID=""
8961         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8962         PID="$PID $!"
8963         sleep 2
8964         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8965         PID="$PID $!"
8966         sleep 2
8967         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8968         PID="$PID $!"
8969         wait $PID
8970         etime=`date +%s`
8971         nolruresize_delta=$((etime-stime))
8972         log "ls -la time: $nolruresize_delta seconds"
8973         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8974         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8975
8976         lru_resize_enable mdc
8977         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8978                 error "failed to create $DIR/$tdir/enable_lru_resize"
8979
8980         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8981         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8982         cancel_lru_locks mdc
8983         stime=`date +%s`
8984         PID=""
8985         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8986         PID="$PID $!"
8987         sleep 2
8988         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8989         PID="$PID $!"
8990         sleep 2
8991         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8992         PID="$PID $!"
8993         wait $PID
8994         etime=`date +%s`
8995         lruresize_delta=$((etime-stime))
8996         log "ls -la time: $lruresize_delta seconds"
8997         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8998
8999         if [ $lruresize_delta -gt $nolruresize_delta ]; then
9000                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
9001         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
9002                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
9003         else
9004                 log "lru resize performs the same with no lru resize"
9005         fi
9006         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
9007 }
9008 run_test 124b "lru resize (performance test) ======================="
9009
9010 test_124c() {
9011         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9012         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
9013                 skip "no lru resize on server" && return 0
9014
9015         # cache ununsed locks on client
9016         local nr=100
9017         cancel_lru_locks mdc
9018         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9019         createmany -o $DIR/$tdir/f $nr ||
9020                 error "failed to create $nr files in $DIR/$tdir"
9021         ls -l $DIR/$tdir > /dev/null
9022
9023         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9024         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9025         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
9026         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
9027         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
9028
9029         # set lru_max_age to 1 sec
9030         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
9031         echo "sleep $((recalc_p * 2)) seconds..."
9032         sleep $((recalc_p * 2))
9033
9034         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
9035         # restore lru_max_age
9036         $LCTL set_param -n $nsdir.lru_max_age $max_age
9037         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
9038         unlinkmany $DIR/$tdir/f $nr
9039 }
9040 run_test 124c "LRUR cancel very aged locks"
9041
9042 test_125() { # 13358
9043         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
9044         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
9045         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9046         test_mkdir -p $DIR/d125 || error "mkdir failed"
9047         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
9048         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
9049         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
9050 }
9051 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
9052
9053 test_126() { # bug 12829/13455
9054         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
9055         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
9056         $GSS && skip "must run as gss disabled" && return
9057
9058         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
9059         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
9060         rm -f $DIR/$tfile
9061         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
9062 }
9063 run_test 126 "check that the fsgid provided by the client is taken into account"
9064
9065 test_127a() { # bug 15521
9066         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9067         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
9068         $LCTL set_param osc.*.stats=0
9069         FSIZE=$((2048 * 1024))
9070         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9071         cancel_lru_locks osc
9072         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
9073
9074         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
9075         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9076                 echo "got $COUNT $NAME"
9077                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
9078                 eval $NAME=$COUNT || error "Wrong proc format"
9079
9080                 case $NAME in
9081                         read_bytes|write_bytes)
9082                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
9083                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
9084                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
9085                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
9086                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
9087                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
9088                                 error "sumsquare is too small: $SUMSQ"
9089                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
9090                                 error "sumsquare is too big: $SUMSQ"
9091                         ;;
9092                         *) ;;
9093                 esac
9094         done < $DIR/${tfile}.tmp
9095
9096         #check that we actually got some stats
9097         [ "$read_bytes" ] || error "Missing read_bytes stats"
9098         [ "$write_bytes" ] || error "Missing write_bytes stats"
9099         [ "$read_bytes" != 0 ] || error "no read done"
9100         [ "$write_bytes" != 0 ] || error "no write done"
9101 }
9102 run_test 127a "verify the client stats are sane"
9103
9104 test_127b() { # bug LU-333
9105         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9106         $LCTL set_param llite.*.stats=0
9107         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
9108         # perform 2 reads and writes so MAX is different from SUM.
9109         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9110         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9111         cancel_lru_locks osc
9112         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9113         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9114
9115         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
9116         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9117                 echo "got $COUNT $NAME"
9118                 eval $NAME=$COUNT || error "Wrong proc format"
9119
9120         case $NAME in
9121                 read_bytes)
9122                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9123                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9124                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9125                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9126                         ;;
9127                 write_bytes)
9128                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9129                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9130                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9131                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9132                         ;;
9133                         *) ;;
9134                 esac
9135         done < $TMP/${tfile}.tmp
9136
9137         #check that we actually got some stats
9138         [ "$read_bytes" ] || error "Missing read_bytes stats"
9139         [ "$write_bytes" ] || error "Missing write_bytes stats"
9140         [ "$read_bytes" != 0 ] || error "no read done"
9141         [ "$write_bytes" != 0 ] || error "no write done"
9142
9143         rm -f $TMP/${tfile}.tmp
9144 }
9145 run_test 127b "verify the llite client stats are sane"
9146
9147 test_128() { # bug 15212
9148         touch $DIR/$tfile
9149         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
9150                 find $DIR/$tfile
9151                 find $DIR/$tfile
9152         EOF
9153
9154         result=$(grep error $TMP/$tfile.log)
9155         rm -f $DIR/$tfile $TMP/$tfile.log
9156         [ -z "$result" ] ||
9157                 error "consecutive find's under interactive lfs failed"
9158 }
9159 run_test 128 "interactive lfs for 2 consecutive find's"
9160
9161 set_dir_limits () {
9162         local mntdev
9163         local canondev
9164         local node
9165
9166         local ldproc=/proc/fs/ldiskfs
9167         local facets=$(get_facets MDS)
9168
9169         for facet in ${facets//,/ }; do
9170                 canondev=$(ldiskfs_canon \
9171                            *.$(convert_facet2label $facet).mntdev $facet)
9172                 do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
9173                         ldproc=/sys/fs/ldiskfs
9174                 do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
9175                 do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
9176         done
9177 }
9178
9179 check_mds_dmesg() {
9180         local facets=$(get_facets MDS)
9181         for facet in ${facets//,/ }; do
9182                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
9183         done
9184         return 1
9185 }
9186
9187 test_129() {
9188         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.56) ]] ||
9189                 { skip "Need MDS version with at least 2.5.56"; return 0; }
9190
9191         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9192         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
9193                 skip "ldiskfs only test"
9194                 return
9195         fi
9196         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9197         local ENOSPC=28
9198         local EFBIG=27
9199         local has_warning=false
9200
9201         rm -rf $DIR/$tdir
9202         mkdir -p $DIR/$tdir
9203
9204         # block size of mds1
9205         local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
9206         set_dir_limits $maxsize $maxsize
9207         local dirsize=$(stat -c%s "$DIR/$tdir")
9208         local nfiles=0
9209         while [[ $dirsize -le $maxsize ]]; do
9210                 $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
9211                 rc=$?
9212                 if ! $has_warning; then
9213                         check_mds_dmesg '"is approaching"' && has_warning=true
9214                 fi
9215                 # check two errors:
9216                 # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
9217                 # EFBIG for previous versions included in ldiskfs series
9218                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
9219                         set_dir_limits 0 0
9220                         echo "return code $rc received as expected"
9221
9222                         createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
9223                                 error_exit "create failed w/o dir size limit"
9224
9225                         check_mds_dmesg '"has reached"' ||
9226                                 error_exit "reached message should be output"
9227
9228                         [ $has_warning -eq 0 ] &&
9229                                 error_exit "warning message should be output"
9230
9231                         dirsize=$(stat -c%s "$DIR/$tdir")
9232
9233                         [[ $dirsize -ge $maxsize ]] && return 0
9234                         error_exit "current dir size $dirsize, " \
9235                                    "previous limit $maxsize"
9236                 elif [ $rc -ne 0 ]; then
9237                         set_dir_limits 0 0
9238                         error_exit "return $rc received instead of expected " \
9239                                    "$EFBIG or $ENOSPC, files in dir $dirsize"
9240                 fi
9241                 nfiles=$((nfiles + 1))
9242                 dirsize=$(stat -c%s "$DIR/$tdir")
9243         done
9244
9245         set_dir_limits 0 0
9246         error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
9247 }
9248 run_test 129 "test directory size limit ========================"
9249
9250 OLDIFS="$IFS"
9251 cleanup_130() {
9252         trap 0
9253         IFS="$OLDIFS"
9254 }
9255
9256 test_130a() {
9257         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9258         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9259                 return
9260
9261         trap cleanup_130 EXIT RETURN
9262
9263         local fm_file=$DIR/$tfile
9264         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
9265         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
9266                 error "dd failed for $fm_file"
9267
9268         # LU-1795: test filefrag/FIEMAP once, even if unsupported
9269         filefrag -ves $fm_file
9270         RC=$?
9271         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9272                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9273         [ $RC != 0 ] && error "filefrag $fm_file failed"
9274
9275         filefrag_op=$(filefrag -ve $fm_file |
9276                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9277         lun=$($GETSTRIPE -i $fm_file)
9278
9279         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
9280         IFS=$'\n'
9281         tot_len=0
9282         for line in $filefrag_op
9283         do
9284                 frag_lun=`echo $line | cut -d: -f5`
9285                 ext_len=`echo $line | cut -d: -f4`
9286                 if (( $frag_lun != $lun )); then
9287                         cleanup_130
9288                         error "FIEMAP on 1-stripe file($fm_file) failed"
9289                         return
9290                 fi
9291                 (( tot_len += ext_len ))
9292         done
9293
9294         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
9295                 cleanup_130
9296                 error "FIEMAP on 1-stripe file($fm_file) failed;"
9297                 return
9298         fi
9299
9300         cleanup_130
9301
9302         echo "FIEMAP on single striped file succeeded"
9303 }
9304 run_test 130a "FIEMAP (1-stripe file)"
9305
9306 test_130b() {
9307         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
9308
9309         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9310         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9311                 return
9312
9313         trap cleanup_130 EXIT RETURN
9314
9315         local fm_file=$DIR/$tfile
9316         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9317                         error "setstripe on $fm_file"
9318         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9319                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9320
9321         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
9322                 error "dd failed on $fm_file"
9323
9324         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9325         filefrag_op=$(filefrag -ve $fm_file |
9326                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9327
9328         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9329                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9330
9331         IFS=$'\n'
9332         tot_len=0
9333         num_luns=1
9334         for line in $filefrag_op
9335         do
9336                 frag_lun=$(echo $line | cut -d: -f5 |
9337                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9338                 ext_len=$(echo $line | cut -d: -f4)
9339                 if (( $frag_lun != $last_lun )); then
9340                         if (( tot_len != 1024 )); then
9341                                 cleanup_130
9342                                 error "FIEMAP on $fm_file failed; returned " \
9343                                 "len $tot_len for OST $last_lun instead of 1024"
9344                                 return
9345                         else
9346                                 (( num_luns += 1 ))
9347                                 tot_len=0
9348                         fi
9349                 fi
9350                 (( tot_len += ext_len ))
9351                 last_lun=$frag_lun
9352         done
9353         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
9354                 cleanup_130
9355                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9356                         "luns or wrong len for OST $last_lun"
9357                 return
9358         fi
9359
9360         cleanup_130
9361
9362         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
9363 }
9364 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
9365
9366 test_130c() {
9367         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9368
9369         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9370         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9371                 return
9372
9373         trap cleanup_130 EXIT RETURN
9374
9375         local fm_file=$DIR/$tfile
9376         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
9377         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9378                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9379
9380         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
9381                         error "dd failed on $fm_file"
9382
9383         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9384         filefrag_op=$(filefrag -ve $fm_file |
9385                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9386
9387         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9388                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9389
9390         IFS=$'\n'
9391         tot_len=0
9392         num_luns=1
9393         for line in $filefrag_op
9394         do
9395                 frag_lun=$(echo $line | cut -d: -f5 |
9396                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9397                 ext_len=$(echo $line | cut -d: -f4)
9398                 if (( $frag_lun != $last_lun )); then
9399                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
9400                         if (( logical != 512 )); then
9401                                 cleanup_130
9402                                 error "FIEMAP on $fm_file failed; returned " \
9403                                 "logical start for lun $logical instead of 512"
9404                                 return
9405                         fi
9406                         if (( tot_len != 512 )); then
9407                                 cleanup_130
9408                                 error "FIEMAP on $fm_file failed; returned " \
9409                                 "len $tot_len for OST $last_lun instead of 1024"
9410                                 return
9411                         else
9412                                 (( num_luns += 1 ))
9413                                 tot_len=0
9414                         fi
9415                 fi
9416                 (( tot_len += ext_len ))
9417                 last_lun=$frag_lun
9418         done
9419         if (( num_luns != 2 || tot_len != 512 )); then
9420                 cleanup_130
9421                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9422                         "luns or wrong len for OST $last_lun"
9423                 return
9424         fi
9425
9426         cleanup_130
9427
9428         echo "FIEMAP on 2-stripe file with hole succeeded"
9429 }
9430 run_test 130c "FIEMAP (2-stripe file with hole)"
9431
9432 test_130d() {
9433         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
9434
9435         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9436         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9437                 return
9438
9439         trap cleanup_130 EXIT RETURN
9440
9441         local fm_file=$DIR/$tfile
9442         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9443                         error "setstripe on $fm_file"
9444         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9445                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9446
9447         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
9448         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
9449                 error "dd failed on $fm_file"
9450
9451         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9452         filefrag_op=$(filefrag -ve $fm_file |
9453                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9454
9455         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9456                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9457
9458         IFS=$'\n'
9459         tot_len=0
9460         num_luns=1
9461         for line in $filefrag_op
9462         do
9463                 frag_lun=$(echo $line | cut -d: -f5 |
9464                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9465                 ext_len=$(echo $line | cut -d: -f4)
9466                 if (( $frag_lun != $last_lun )); then
9467                         if (( tot_len != 1024 )); then
9468                                 cleanup_130
9469                                 error "FIEMAP on $fm_file failed; returned " \
9470                                 "len $tot_len for OST $last_lun instead of 1024"
9471                                 return
9472                         else
9473                                 (( num_luns += 1 ))
9474                                 tot_len=0
9475                         fi
9476                 fi
9477                 (( tot_len += ext_len ))
9478                 last_lun=$frag_lun
9479         done
9480         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
9481                 cleanup_130
9482                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9483                         "luns or wrong len for OST $last_lun"
9484                 return
9485         fi
9486
9487         cleanup_130
9488
9489         echo "FIEMAP on N-stripe file succeeded"
9490 }
9491 run_test 130d "FIEMAP (N-stripe file)"
9492
9493 test_130e() {
9494         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9495
9496         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9497         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9498
9499         trap cleanup_130 EXIT RETURN
9500
9501         local fm_file=$DIR/$tfile
9502         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9503         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9504                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9505
9506         NUM_BLKS=512
9507         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9508         for ((i = 0; i < $NUM_BLKS; i++))
9509         do
9510                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9511         done
9512
9513         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9514         filefrag_op=$(filefrag -ve $fm_file |
9515                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9516
9517         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9518                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9519
9520         IFS=$'\n'
9521         tot_len=0
9522         num_luns=1
9523         for line in $filefrag_op
9524         do
9525                 frag_lun=$(echo $line | cut -d: -f5 |
9526                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9527                 ext_len=$(echo $line | cut -d: -f4)
9528                 if (( $frag_lun != $last_lun )); then
9529                         if (( tot_len != $EXPECTED_LEN )); then
9530                                 cleanup_130
9531                                 error "FIEMAP on $fm_file failed; returned " \
9532                                 "len $tot_len for OST $last_lun instead " \
9533                                 "of $EXPECTED_LEN"
9534                                 return
9535                         else
9536                                 (( num_luns += 1 ))
9537                                 tot_len=0
9538                         fi
9539                 fi
9540                 (( tot_len += ext_len ))
9541                 last_lun=$frag_lun
9542         done
9543         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9544                 cleanup_130
9545                 error "FIEMAP on $fm_file failed; returned wrong number " \
9546                         "of luns or wrong len for OST $last_lun"
9547                 return
9548         fi
9549
9550         cleanup_130
9551
9552         echo "FIEMAP with continuation calls succeeded"
9553 }
9554 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9555
9556 # Test for writev/readv
9557 test_131a() {
9558         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
9559                 error "writev test failed"
9560         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 ||
9561                 error "readv failed"
9562         rm -f $DIR/$tfile
9563 }
9564 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9565
9566 test_131b() {
9567         local fsize=$((524288 + 1048576 + 1572864))
9568         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 &&
9569                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9570                         error "append writev test failed"
9571
9572         ((fsize += 1572864 + 1048576))
9573         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 &&
9574                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9575                         error "append writev test failed"
9576         rm -f $DIR/$tfile
9577 }
9578 run_test 131b "test append writev"
9579
9580 test_131c() {
9581         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9582         error "NOT PASS"
9583 }
9584 run_test 131c "test read/write on file w/o objects"
9585
9586 test_131d() {
9587         rwv -f $DIR/$tfile -w -n 1 1572864
9588         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9589         if [ "$NOB" != 1572864 ]; then
9590                 error "Short read filed: read $NOB bytes instead of 1572864"
9591         fi
9592         rm -f $DIR/$tfile
9593 }
9594 run_test 131d "test short read"
9595
9596 test_131e() {
9597         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9598         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9599         error "read hitting hole failed"
9600         rm -f $DIR/$tfile
9601 }
9602 run_test 131e "test read hitting hole"
9603
9604 check_stats() {
9605         local facet=$1
9606         local op=$2
9607         local want=${3:-0}
9608         local res
9609
9610         case $facet in
9611         mds*) res=$(do_facet $facet \
9612                    $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
9613                  ;;
9614         ost*) res=$(do_facet $facet \
9615                    $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
9616                  ;;
9617         *) error "Wrong facet '$facet'" ;;
9618         esac
9619         echo $res
9620         [ "$res" ] || error "The counter for $op on $facet was not incremented"
9621         # if the argument $3 is zero, it means any stat increment is ok.
9622         if [[ $want -gt 0 ]]; then
9623                 local count=$(echo $res | awk '{ print $2 }')
9624                 [[ $count -ne $want ]] &&
9625                         error "The $op counter on $facet is $count, not $want"
9626         fi
9627 }
9628
9629 test_133a() {
9630         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9631         remote_ost_nodsh && skip "remote OST with nodsh" && return
9632         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9633
9634         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9635                 { skip "MDS doesn't support rename stats"; return; }
9636         local testdir=$DIR/${tdir}/stats_testdir
9637         mkdir -p $DIR/${tdir}
9638
9639         # clear stats.
9640         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9641         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9642
9643         # verify mdt stats first.
9644         mkdir ${testdir} || error "mkdir failed"
9645         check_stats $SINGLEMDS "mkdir" 1
9646         touch ${testdir}/${tfile} || error "touch failed"
9647         check_stats $SINGLEMDS "open" 1
9648         check_stats $SINGLEMDS "close" 1
9649         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ] && {
9650                 mknod ${testdir}/${tfile}-pipe p || error "mknod failed"
9651                 check_stats $SINGLEMDS "mknod" 2
9652         }
9653         rm -f ${testdir}/${tfile}-pipe || error "pipe remove failed"
9654         check_stats $SINGLEMDS "unlink" 1
9655         rm -f ${testdir}/${tfile} || error "file remove failed"
9656         check_stats $SINGLEMDS "unlink" 2
9657
9658         # remove working dir and check mdt stats again.
9659         rmdir ${testdir} || error "rmdir failed"
9660         check_stats $SINGLEMDS "rmdir" 1
9661
9662         local testdir1=$DIR/${tdir}/stats_testdir1
9663         mkdir -p ${testdir}
9664         mkdir -p ${testdir1}
9665         touch ${testdir1}/test1
9666         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9667         check_stats $SINGLEMDS "crossdir_rename" 1
9668
9669         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9670         check_stats $SINGLEMDS "samedir_rename" 1
9671
9672         rm -rf $DIR/${tdir}
9673 }
9674 run_test 133a "Verifying MDT stats ========================================"
9675
9676 test_133b() {
9677         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9678         remote_ost_nodsh && skip "remote OST with nodsh" && return
9679         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9680         local testdir=$DIR/${tdir}/stats_testdir
9681         mkdir -p ${testdir} || error "mkdir failed"
9682         touch ${testdir}/${tfile} || error "touch failed"
9683         cancel_lru_locks mdc
9684
9685         # clear stats.
9686         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9687         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9688
9689         # extra mdt stats verification.
9690         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9691         check_stats $SINGLEMDS "setattr" 1
9692         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9693         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9694         then            # LU-1740
9695                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9696                 check_stats $SINGLEMDS "getattr" 1
9697         fi
9698         $LFS df || error "lfs failed"
9699         check_stats $SINGLEMDS "statfs" 1
9700
9701         rm -rf $DIR/${tdir}
9702 }
9703 run_test 133b "Verifying extra MDT stats =================================="
9704
9705 test_133c() {
9706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9707         remote_ost_nodsh && skip "remote OST with nodsh" && return
9708         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9709         local testdir=$DIR/${tdir}/stats_testdir
9710         test_mkdir -p ${testdir} || error "mkdir failed"
9711
9712         # verify obdfilter stats.
9713         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9714         sync
9715         cancel_lru_locks osc
9716         wait_delete_completed
9717
9718         # clear stats.
9719         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9720         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9721
9722         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9723         sync
9724         cancel_lru_locks osc
9725         check_stats ost1 "write" 1
9726
9727         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9728         check_stats ost1 "read" 1
9729
9730         > ${testdir}/${tfile} || error "truncate failed"
9731         check_stats ost1 "punch" 1
9732
9733         rm -f ${testdir}/${tfile} || error "file remove failed"
9734         wait_delete_completed
9735         check_stats ost1 "destroy" 1
9736
9737         rm -rf $DIR/${tdir}
9738 }
9739 run_test 133c "Verifying OST stats ========================================"
9740
9741 order_2() {
9742         local value=$1
9743         local orig=$value
9744         local order=1
9745
9746         while [ $value -ge 2 ]; do
9747                 order=$((order*2))
9748                 value=$((value/2))
9749         done
9750
9751         if [ $orig -gt $order ]; then
9752                 order=$((order*2))
9753         fi
9754         echo $order
9755 }
9756
9757 size_in_KMGT() {
9758     local value=$1
9759     local size=('K' 'M' 'G' 'T');
9760     local i=0
9761     local size_string=$value
9762
9763     while [ $value -ge 1024 ]; do
9764         if [ $i -gt 3 ]; then
9765             #T is the biggest unit we get here, if that is bigger,
9766             #just return XXXT
9767             size_string=${value}T
9768             break
9769         fi
9770         value=$((value >> 10))
9771         if [ $value -lt 1024 ]; then
9772             size_string=${value}${size[$i]}
9773             break
9774         fi
9775         i=$((i + 1))
9776     done
9777
9778     echo $size_string
9779 }
9780
9781 get_rename_size() {
9782     local size=$1
9783     local context=${2:-.}
9784     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9785                 grep -A1 $context |
9786                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9787     echo $sample
9788 }
9789
9790 test_133d() {
9791         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9792         remote_ost_nodsh && skip "remote OST with nodsh" && return
9793         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9794         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9795         { skip "MDS doesn't support rename stats"; return; }
9796
9797         local testdir1=$DIR/${tdir}/stats_testdir1
9798         local testdir2=$DIR/${tdir}/stats_testdir2
9799
9800         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9801
9802         mkdir -p ${testdir1} || error "mkdir failed"
9803         mkdir -p ${testdir2} || error "mkdir failed"
9804
9805         createmany -o $testdir1/test 512 || error "createmany failed"
9806
9807         # check samedir rename size
9808         mv ${testdir1}/test0 ${testdir1}/test_0
9809
9810         local testdir1_size=$(ls -l $DIR/${tdir} |
9811                 awk '/stats_testdir1/ {print $5}')
9812         local testdir2_size=$(ls -l $DIR/${tdir} |
9813                 awk '/stats_testdir2/ {print $5}')
9814
9815         testdir1_size=$(order_2 $testdir1_size)
9816         testdir2_size=$(order_2 $testdir2_size)
9817
9818         testdir1_size=$(size_in_KMGT $testdir1_size)
9819         testdir2_size=$(size_in_KMGT $testdir2_size)
9820
9821         echo "source rename dir size: ${testdir1_size}"
9822         echo "target rename dir size: ${testdir2_size}"
9823
9824         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9825         eval $cmd || error "$cmd failed"
9826         local samedir=$($cmd | grep 'same_dir')
9827         local same_sample=$(get_rename_size $testdir1_size)
9828         [ -z "$samedir" ] && error "samedir_rename_size count error"
9829         [[ $same_sample -eq 1 ]] ||
9830                 error "samedir_rename_size error $same_sample"
9831         echo "Check same dir rename stats success"
9832
9833         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9834
9835         # check crossdir rename size
9836         mv ${testdir1}/test_0 ${testdir2}/test_0
9837
9838         testdir1_size=$(ls -l $DIR/${tdir} |
9839                 awk '/stats_testdir1/ {print $5}')
9840         testdir2_size=$(ls -l $DIR/${tdir} |
9841                 awk '/stats_testdir2/ {print $5}')
9842
9843         testdir1_size=$(order_2 $testdir1_size)
9844         testdir2_size=$(order_2 $testdir2_size)
9845
9846         testdir1_size=$(size_in_KMGT $testdir1_size)
9847         testdir2_size=$(size_in_KMGT $testdir2_size)
9848
9849         echo "source rename dir size: ${testdir1_size}"
9850         echo "target rename dir size: ${testdir2_size}"
9851
9852         eval $cmd || error "$cmd failed"
9853         local crossdir=$($cmd | grep 'crossdir')
9854         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9855         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9856         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9857         [[ $src_sample -eq 1 ]] ||
9858                 error "crossdir_rename_size error $src_sample"
9859         [[ $tgt_sample -eq 1 ]] ||
9860                 error "crossdir_rename_size error $tgt_sample"
9861         echo "Check cross dir rename stats success"
9862         rm -rf $DIR/${tdir}
9863 }
9864 run_test 133d "Verifying rename_stats ========================================"
9865
9866 test_133e() {
9867         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9868         remote_ost_nodsh && skip "remote OST with nodsh" && return
9869         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9870         local testdir=$DIR/${tdir}/stats_testdir
9871         local ctr f0 f1 bs=32768 count=42 sum
9872
9873         mkdir -p ${testdir} || error "mkdir failed"
9874
9875         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9876
9877         for ctr in {write,read}_bytes; do
9878                 sync
9879                 cancel_lru_locks osc
9880
9881                 do_facet ost1 $LCTL set_param -n \
9882                         "obdfilter.*.exports.clear=clear"
9883
9884                 if [ $ctr = write_bytes ]; then
9885                         f0=/dev/zero
9886                         f1=${testdir}/${tfile}
9887                 else
9888                         f0=${testdir}/${tfile}
9889                         f1=/dev/null
9890                 fi
9891
9892                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9893                         error "dd failed"
9894                 sync
9895                 cancel_lru_locks osc
9896
9897                 sum=$(do_facet ost1 $LCTL get_param \
9898                         "obdfilter.*.exports.*.stats" |
9899                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9900                                 $1 == ctr { sum += $7 }
9901                                 END { printf("%0.0f", sum) }')
9902
9903                 if ((sum != bs * count)); then
9904                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9905                 fi
9906         done
9907
9908         rm -rf $DIR/${tdir}
9909 }
9910 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9911
9912 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
9913
9914 test_133f() {
9915         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9916         remote_ost_nodsh && skip "remote OST with nodsh" && return
9917         # First without trusting modes.
9918         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
9919         echo "proc_dirs='$proc_dirs'"
9920         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
9921         find $proc_dirs -exec cat '{}' \; &> /dev/null
9922
9923         # Second verifying readability.
9924         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
9925
9926         # eventually, this can also be replaced with "lctl get_param -R",
9927         # but not until that option is always available on the server
9928         local facet
9929         for facet in mds1 ost1; do
9930                 local facet_proc_dirs=$(do_facet $facet \
9931                                         \\\ls -d $proc_regexp 2>/dev/null)
9932                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
9933                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
9934                 do_facet $facet find $facet_proc_dirs \
9935                         ! -name req_history \
9936                         -exec cat '{}' \\\; &> /dev/null
9937
9938                 do_facet $facet find $facet_proc_dirs \
9939                         ! -name req_history \
9940                         -type f \
9941                         -exec cat '{}' \\\; &> /dev/null ||
9942                                 error "proc file read failed"
9943         done
9944 }
9945 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9946
9947 test_133g() {
9948         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9949         remote_ost_nodsh && skip "remote OST with nodsh" && return
9950         # Second verifying writability.
9951         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
9952         echo "proc_dirs='$proc_dirs'"
9953         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
9954         find $proc_dirs \
9955                 -type f \
9956                 -not -name force_lbug \
9957                 -not -name changelog_mask \
9958                 -exec badarea_io '{}' \; &> /dev/null ||
9959                 error "find $proc_dirs failed"
9960
9961         local facet
9962         for facet in mds1 ost1; do
9963                 [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
9964                         skip "Too old lustre on $facet" && continue
9965                 local facet_proc_dirs=$(do_facet $facet \
9966                                         \\\ls -d $proc_regexp 2> /dev/null)
9967                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
9968                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
9969                 do_facet $facet find $facet_proc_dirs \
9970                         -type f \
9971                         -not -name force_lbug \
9972                         -not -name changelog_mask \
9973                         -exec badarea_io '{}' \\\; &> /dev/null ||
9974                                 error "$facet find $facet_proc_dirs failed"
9975         done
9976
9977         # remount the FS in case writes/reads /proc break the FS
9978         cleanup || error "failed to unmount"
9979         setup || error "failed to setup"
9980         true
9981 }
9982 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9983
9984 test_133h() {
9985         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9986         remote_ost_nodsh && skip "remote OST with nodsh" && return
9987         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.54) ]] &&
9988                 skip "Need MDS version at least 2.9.54" && return
9989
9990         local facet
9991         for facet in client mds1 ost1; do
9992                 local facet_proc_dirs=$(do_facet $facet \
9993                                         \\\ls -d $proc_regexp 2> /dev/null)
9994                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
9995                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
9996                 # Get the list of files that are missing the terminating newline
9997                 local missing=($(do_facet $facet \
9998                         find ${facet_proc_dirs} -type f \|              \
9999                                 while read F\; do                       \
10000                                         awk -v FS='\v' -v RS='\v\v'     \
10001                                         "'END { if(NR>0 &&              \
10002                                         \\\$NF !~ /.*\\\n\$/)           \
10003                                                 print FILENAME}'"       \
10004                                         '\$F'\;                         \
10005                                 done 2>/dev/null))
10006                 [ ${#missing[*]} -eq 0 ] ||
10007                         error "files do not end with newline: ${missing[*]}"
10008         done
10009 }
10010 run_test 133h "Proc files should end with newlines"
10011
10012 test_134a() {
10013         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10014         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10015                 skip "Need MDS version at least 2.7.54" && return
10016
10017         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10018         cancel_lru_locks mdc
10019
10020         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
10021         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10022         [ $unused -eq 0 ] || error "$unused locks are not cleared"
10023
10024         local nr=1000
10025         createmany -o $DIR/$tdir/f $nr ||
10026                 error "failed to create $nr files in $DIR/$tdir"
10027         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10028
10029         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
10030         do_facet mds1 $LCTL set_param fail_loc=0x327
10031         do_facet mds1 $LCTL set_param fail_val=500
10032         touch $DIR/$tdir/m
10033
10034         echo "sleep 10 seconds ..."
10035         sleep 10
10036         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
10037
10038         do_facet mds1 $LCTL set_param fail_loc=0
10039         do_facet mds1 $LCTL set_param fail_val=0
10040         [ $lck_cnt -lt $unused ] ||
10041                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
10042
10043         rm $DIR/$tdir/m
10044         unlinkmany $DIR/$tdir/f $nr
10045 }
10046 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
10047
10048 test_134b() {
10049         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10050         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10051                 skip "Need MDS version at least 2.7.54" && return
10052
10053         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10054         cancel_lru_locks mdc
10055
10056         local low_wm=$(do_facet mds1 $LCTL get_param -n \
10057                         ldlm.lock_reclaim_threshold_mb)
10058         # disable reclaim temporarily
10059         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
10060
10061         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
10062         do_facet mds1 $LCTL set_param fail_loc=0x328
10063         do_facet mds1 $LCTL set_param fail_val=500
10064
10065         $LCTL set_param debug=+trace
10066
10067         local nr=600
10068         createmany -o $DIR/$tdir/f $nr &
10069         local create_pid=$!
10070
10071         echo "Sleep $TIMEOUT seconds ..."
10072         sleep $TIMEOUT
10073         if ! ps -p $create_pid  > /dev/null 2>&1; then
10074                 do_facet mds1 $LCTL set_param fail_loc=0
10075                 do_facet mds1 $LCTL set_param fail_val=0
10076                 do_facet mds1 $LCTL set_param \
10077                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
10078                 error "createmany finished incorrectly!"
10079         fi
10080         do_facet mds1 $LCTL set_param fail_loc=0
10081         do_facet mds1 $LCTL set_param fail_val=0
10082         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
10083         wait $create_pid || return 1
10084
10085         unlinkmany $DIR/$tdir/f $nr
10086 }
10087 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
10088
10089 test_140() { #bug-17379
10090         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10091         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
10092         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
10093         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
10094
10095         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
10096         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
10097         local i=0
10098         while i=`expr $i + 1`; do
10099                 test_mkdir -p $i || error "Creating dir $i"
10100                 cd $i || error "Changing to $i"
10101                 ln -s ../stat stat || error "Creating stat symlink"
10102                 # Read the symlink until ELOOP present,
10103                 # not LBUGing the system is considered success,
10104                 # we didn't overrun the stack.
10105                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
10106                 [ $ret -ne 0 ] && {
10107                         if [ $ret -eq 40 ]; then
10108                                 break  # -ELOOP
10109                         else
10110                                 error "Open stat symlink"
10111                                 return
10112                         fi
10113                 }
10114         done
10115         i=`expr $i - 1`
10116         echo "The symlink depth = $i"
10117         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
10118                                         error "Invalid symlink depth"
10119
10120         # Test recursive symlink
10121         ln -s symlink_self symlink_self
10122         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
10123         echo "open symlink_self returns $ret"
10124         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
10125 }
10126 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
10127
10128 test_150() {
10129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10130         local TF="$TMP/$tfile"
10131
10132         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10133         cp $TF $DIR/$tfile
10134         cancel_lru_locks osc
10135         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
10136         remount_client $MOUNT
10137         df -P $MOUNT
10138         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
10139
10140         $TRUNCATE $TF 6000
10141         $TRUNCATE $DIR/$tfile 6000
10142         cancel_lru_locks osc
10143         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
10144
10145         echo "12345" >>$TF
10146         echo "12345" >>$DIR/$tfile
10147         cancel_lru_locks osc
10148         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
10149
10150         echo "12345" >>$TF
10151         echo "12345" >>$DIR/$tfile
10152         cancel_lru_locks osc
10153         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
10154
10155         rm -f $TF
10156         true
10157 }
10158 run_test 150 "truncate/append tests"
10159
10160 #LU-2902 roc_hit was not able to read all values from lproc
10161 function roc_hit_init() {
10162         local list=$(comma_list $(osts_nodes))
10163         local dir=$DIR/$tdir-check
10164         local file=$dir/file
10165         local BEFORE
10166         local AFTER
10167         local idx
10168
10169         test_mkdir -p $dir
10170         #use setstripe to do a write to every ost
10171         for i in $(seq 0 $((OSTCOUNT-1))); do
10172                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
10173                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
10174                 idx=$(printf %04x $i)
10175                 BEFORE=$(get_osd_param $list *OST*$idx stats |
10176                         awk '$1 == "cache_access" {sum += $7}
10177                                 END { printf("%0.0f", sum) }')
10178
10179                 cancel_lru_locks osc
10180                 cat $file >/dev/null
10181
10182                 AFTER=$(get_osd_param $list *OST*$idx stats |
10183                         awk '$1 == "cache_access" {sum += $7}
10184                                 END { printf("%0.0f", sum) }')
10185
10186                 echo BEFORE:$BEFORE AFTER:$AFTER
10187                 if ! let "AFTER - BEFORE == 4"; then
10188                         rm -rf $dir
10189                         error "roc_hit is not safe to use"
10190                 fi
10191                 rm $file
10192         done
10193
10194         rm -rf $dir
10195 }
10196
10197 function roc_hit() {
10198         local list=$(comma_list $(osts_nodes))
10199         echo $(get_osd_param $list '' stats |
10200                 awk '$1 == "cache_hit" {sum += $7}
10201                         END { printf("%0.0f", sum) }')
10202 }
10203
10204 function set_cache() {
10205         local on=1
10206
10207         if [ "$2" == "off" ]; then
10208                 on=0;
10209         fi
10210         local list=$(comma_list $(osts_nodes))
10211         set_osd_param $list '' $1_cache_enable $on
10212
10213         cancel_lru_locks osc
10214 }
10215
10216 test_151() {
10217         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10218         remote_ost_nodsh && skip "remote OST with nodsh" && return
10219
10220         local CPAGES=3
10221         local list=$(comma_list $(osts_nodes))
10222
10223         # check whether obdfilter is cache capable at all
10224         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
10225                 echo "not cache-capable obdfilter"
10226                 return 0
10227         fi
10228
10229         # check cache is enabled on all obdfilters
10230         if get_osd_param $list '' read_cache_enable | grep 0; then
10231                 echo "oss cache is disabled"
10232                 return 0
10233         fi
10234
10235         set_osd_param $list '' writethrough_cache_enable 1
10236
10237         # check write cache is enabled on all obdfilters
10238         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
10239                 echo "oss write cache is NOT enabled"
10240                 return 0
10241         fi
10242
10243         roc_hit_init
10244
10245         #define OBD_FAIL_OBD_NO_LRU  0x609
10246         do_nodes $list $LCTL set_param fail_loc=0x609
10247
10248         # pages should be in the case right after write
10249         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
10250                 error "dd failed"
10251
10252         local BEFORE=$(roc_hit)
10253         cancel_lru_locks osc
10254         cat $DIR/$tfile >/dev/null
10255         local AFTER=$(roc_hit)
10256
10257         do_nodes $list $LCTL set_param fail_loc=0
10258
10259         if ! let "AFTER - BEFORE == CPAGES"; then
10260                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10261         fi
10262
10263         # the following read invalidates the cache
10264         cancel_lru_locks osc
10265         set_osd_param $list '' read_cache_enable 0
10266         cat $DIR/$tfile >/dev/null
10267
10268         # now data shouldn't be found in the cache
10269         BEFORE=$(roc_hit)
10270         cancel_lru_locks osc
10271         cat $DIR/$tfile >/dev/null
10272         AFTER=$(roc_hit)
10273         if let "AFTER - BEFORE != 0"; then
10274                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10275         fi
10276
10277         set_osd_param $list '' read_cache_enable 1
10278         rm -f $DIR/$tfile
10279 }
10280 run_test 151 "test cache on oss and controls ==============================="
10281
10282 test_152() {
10283         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10284         local TF="$TMP/$tfile"
10285
10286         # simulate ENOMEM during write
10287 #define OBD_FAIL_OST_NOMEM      0x226
10288         lctl set_param fail_loc=0x80000226
10289         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10290         cp $TF $DIR/$tfile
10291         sync || error "sync failed"
10292         lctl set_param fail_loc=0
10293
10294         # discard client's cache
10295         cancel_lru_locks osc
10296
10297         # simulate ENOMEM during read
10298         lctl set_param fail_loc=0x80000226
10299         cmp $TF $DIR/$tfile || error "cmp failed"
10300         lctl set_param fail_loc=0
10301
10302         rm -f $TF
10303 }
10304 run_test 152 "test read/write with enomem ============================"
10305
10306 test_153() {
10307         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
10308 }
10309 run_test 153 "test if fdatasync does not crash ======================="
10310
10311 dot_lustre_fid_permission_check() {
10312         local fid=$1
10313         local ffid=$MOUNT/.lustre/fid/$fid
10314         local test_dir=$2
10315
10316         echo "stat fid $fid"
10317         stat $ffid > /dev/null || error "stat $ffid failed."
10318         echo "touch fid $fid"
10319         touch $ffid || error "touch $ffid failed."
10320         echo "write to fid $fid"
10321         cat /etc/hosts > $ffid || error "write $ffid failed."
10322         echo "read fid $fid"
10323         diff /etc/hosts $ffid || error "read $ffid failed."
10324         echo "append write to fid $fid"
10325         cat /etc/hosts >> $ffid || error "append write $ffid failed."
10326         echo "rename fid $fid"
10327         mv $ffid $test_dir/$tfile.1 &&
10328                 error "rename $ffid to $tfile.1 should fail."
10329         touch $test_dir/$tfile.1
10330         mv $test_dir/$tfile.1 $ffid &&
10331                 error "rename $tfile.1 to $ffid should fail."
10332         rm -f $test_dir/$tfile.1
10333         echo "truncate fid $fid"
10334         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
10335         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
10336                 echo "link fid $fid"
10337                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
10338         fi
10339         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
10340                 echo "setfacl fid $fid"
10341                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
10342                 echo "getfacl fid $fid"
10343                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
10344         fi
10345         echo "unlink fid $fid"
10346         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
10347         echo "mknod fid $fid"
10348         mknod $ffid c 1 3 && error "mknod $ffid should fail."
10349
10350         fid=[0xf00000400:0x1:0x0]
10351         ffid=$MOUNT/.lustre/fid/$fid
10352
10353         echo "stat non-exist fid $fid"
10354         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
10355         echo "write to non-exist fid $fid"
10356         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
10357         echo "link new fid $fid"
10358         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
10359
10360         mkdir -p $test_dir/$tdir
10361         touch $test_dir/$tdir/$tfile
10362         fid=$($LFS path2fid $test_dir/$tdir)
10363         rc=$?
10364         [ $rc -ne 0 ] &&
10365                 error "error: could not get fid for $test_dir/$dir/$tfile."
10366
10367         ffid=$MOUNT/.lustre/fid/$fid
10368
10369         echo "ls $fid"
10370         ls $ffid > /dev/null || error "ls $ffid failed."
10371         echo "touch $fid/$tfile.1"
10372         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
10373
10374         echo "touch $MOUNT/.lustre/fid/$tfile"
10375         touch $MOUNT/.lustre/fid/$tfile && \
10376                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
10377
10378         echo "setxattr to $MOUNT/.lustre/fid"
10379         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
10380
10381         echo "listxattr for $MOUNT/.lustre/fid"
10382         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
10383
10384         echo "delxattr from $MOUNT/.lustre/fid"
10385         setfattr -x trusted.name1 $MOUNT/.lustre/fid
10386
10387         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
10388         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
10389                 error "touch invalid fid should fail."
10390
10391         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
10392         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
10393                 error "touch non-normal fid should fail."
10394
10395         echo "rename $tdir to $MOUNT/.lustre/fid"
10396         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
10397                 error "rename to $MOUNT/.lustre/fid should fail."
10398
10399         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
10400         then            # LU-3547
10401                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
10402                 local new_obf_mode=777
10403
10404                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
10405                 chmod $new_obf_mode $DIR/.lustre/fid ||
10406                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
10407
10408                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
10409                 [ $obf_mode -eq $new_obf_mode ] ||
10410                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
10411
10412                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
10413                 chmod $old_obf_mode $DIR/.lustre/fid ||
10414                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
10415         fi
10416
10417         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
10418         fid=$($LFS path2fid $test_dir/$tfile-2)
10419
10420         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
10421         then # LU-5424
10422                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
10423                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
10424                         error "create lov data thru .lustre failed"
10425         fi
10426         echo "cp /etc/passwd $test_dir/$tfile-2"
10427         cp /etc/passwd $test_dir/$tfile-2 ||
10428                 error "copy to $test_dir/$tfile-2 failed."
10429         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
10430         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
10431                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
10432
10433         rm -rf $test_dir/tfile.lnk
10434         rm -rf $test_dir/$tfile-2
10435 }
10436
10437 test_154A() {
10438         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10439                 skip "Need MDS version at least 2.4.1" && return
10440
10441         local tf=$DIR/$tfile
10442         touch $tf
10443
10444         local fid=$($LFS path2fid $tf)
10445         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
10446
10447         # check that we get the same pathname back
10448         local found=$($LFS fid2path $MOUNT "$fid")
10449         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
10450         [ "$found" == "$tf" ] ||
10451                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
10452 }
10453 run_test 154A "lfs path2fid and fid2path basic checks"
10454
10455 test_154B() {
10456         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10457                 skip "Need MDS version at least 2.4.1" && return
10458
10459         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
10460         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
10461         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
10462         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
10463
10464         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
10465         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
10466
10467         # check that we get the same pathname
10468         echo "PFID: $PFID, name: $name"
10469         local FOUND=$($LFS fid2path $MOUNT "$PFID")
10470         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
10471         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
10472                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
10473
10474         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
10475 }
10476 run_test 154B "verify the ll_decode_linkea tool"
10477
10478 test_154a() {
10479         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10480         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10481                 { skip "Need MDS version at least 2.2.51"; return 0; }
10482         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
10483         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10484
10485         cp /etc/hosts $DIR/$tfile
10486
10487         fid=$($LFS path2fid $DIR/$tfile)
10488         rc=$?
10489         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
10490
10491         dot_lustre_fid_permission_check "$fid" $DIR ||
10492                 error "dot lustre permission check $fid failed"
10493
10494         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
10495
10496         touch $MOUNT/.lustre/file &&
10497                 error "creation is not allowed under .lustre"
10498
10499         mkdir $MOUNT/.lustre/dir &&
10500                 error "mkdir is not allowed under .lustre"
10501
10502         rm -rf $DIR/$tfile
10503 }
10504 run_test 154a "Open-by-FID"
10505
10506 test_154b() {
10507         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10508         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10509                 { skip "Need MDS version at least 2.2.51"; return 0; }
10510         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10511
10512         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10513
10514         local remote_dir=$DIR/$tdir/remote_dir
10515         local MDTIDX=1
10516         local rc=0
10517
10518         mkdir -p $DIR/$tdir
10519         $LFS mkdir -i $MDTIDX $remote_dir ||
10520                 error "create remote directory failed"
10521
10522         cp /etc/hosts $remote_dir/$tfile
10523
10524         fid=$($LFS path2fid $remote_dir/$tfile)
10525         rc=$?
10526         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
10527
10528         dot_lustre_fid_permission_check "$fid" $remote_dir ||
10529                 error "dot lustre permission check $fid failed"
10530         rm -rf $DIR/$tdir
10531 }
10532 run_test 154b "Open-by-FID for remote directory"
10533
10534 test_154c() {
10535         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10536                 skip "Need MDS version at least 2.4.1" && return
10537
10538         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
10539         local FID1=$($LFS path2fid $DIR/$tfile.1)
10540         local FID2=$($LFS path2fid $DIR/$tfile.2)
10541         local FID3=$($LFS path2fid $DIR/$tfile.3)
10542
10543         local N=1
10544         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
10545                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
10546                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
10547                 local want=FID$N
10548                 [ "$FID" = "${!want}" ] ||
10549                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
10550                 N=$((N + 1))
10551         done
10552
10553         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10554         do
10555                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10556                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10557                 N=$((N + 1))
10558         done
10559 }
10560 run_test 154c "lfs path2fid and fid2path multiple arguments"
10561
10562 test_154d() {
10563         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10564         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10565                 skip "Need MDS version at least 2.5.53" && return
10566
10567         if remote_mds; then
10568                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10569         else
10570                 nid="0@lo"
10571         fi
10572         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10573         local fd
10574         local cmd
10575
10576         rm -f $DIR/$tfile
10577         touch $DIR/$tfile
10578
10579         local fid=$($LFS path2fid $DIR/$tfile)
10580         # Open the file
10581         fd=$(free_fd)
10582         cmd="exec $fd<$DIR/$tfile"
10583         eval $cmd
10584         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10585         echo "$fid_list" | grep "$fid"
10586         rc=$?
10587
10588         cmd="exec $fd>/dev/null"
10589         eval $cmd
10590         if [ $rc -ne 0 ]; then
10591                 error "FID $fid not found in open files list $fid_list"
10592         fi
10593 }
10594 run_test 154d "Verify open file fid"
10595
10596 test_154e()
10597 {
10598         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10599                 skip "Need MDS version at least 2.6.50" && return
10600
10601         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10602                 error ".lustre returned by readdir"
10603         fi
10604 }
10605 run_test 154e ".lustre is not returned by readdir"
10606
10607 test_154f() {
10608         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10609         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10610         test_mkdir -p -c1 $DIR/$tdir/d
10611         # test dirs inherit from its stripe
10612         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10613         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10614         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10615         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10616         touch $DIR/f
10617
10618         # get fid of parents
10619         local FID0=$($LFS path2fid $DIR/$tdir/d)
10620         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10621         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10622         local FID3=$($LFS path2fid $DIR)
10623
10624         # check that path2fid --parents returns expected <parent_fid>/name
10625         # 1) test for a directory (single parent)
10626         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
10627         [ "$parent" == "$FID0/foo1" ] ||
10628                 error "expected parent: $FID0/foo1, got: $parent"
10629
10630         # 2) test for a file with nlink > 1 (multiple parents)
10631         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
10632         echo "$parent" | grep -F "$FID1/$tfile" ||
10633                 error "$FID1/$tfile not returned in parent list"
10634         echo "$parent" | grep -F "$FID2/link" ||
10635                 error "$FID2/link not returned in parent list"
10636
10637         # 3) get parent by fid
10638         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
10639         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10640         echo "$parent" | grep -F "$FID1/$tfile" ||
10641                 error "$FID1/$tfile not returned in parent list (by fid)"
10642         echo "$parent" | grep -F "$FID2/link" ||
10643                 error "$FID2/link not returned in parent list (by fid)"
10644
10645         # 4) test for entry in root directory
10646         parent=$($LFS path2fid --parents $DIR/f)
10647         echo "$parent" | grep -F "$FID3/f" ||
10648                 error "$FID3/f not returned in parent list"
10649
10650         # 5) test it on root directory
10651         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
10652                 error "$MOUNT should not have parents"
10653
10654         # enable xattr caching and check that linkea is correctly updated
10655         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10656         save_lustre_params client "llite.*.xattr_cache" > $save
10657         lctl set_param llite.*.xattr_cache 1
10658
10659         # 6.1) linkea update on rename
10660         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
10661
10662         # get parents by fid
10663         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10664         # foo1 should no longer be returned in parent list
10665         echo "$parent" | grep -F "$FID1" &&
10666                 error "$FID1 should no longer be in parent list"
10667         # the new path should appear
10668         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
10669                 error "$FID2/$tfile.moved is not in parent list"
10670
10671         # 6.2) linkea update on unlink
10672         rm -f $DIR/$tdir/d/foo2/link
10673         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10674         # foo2/link should no longer be returned in parent list
10675         echo "$parent" | grep -F "$FID2/link" &&
10676                 error "$FID2/link should no longer be in parent list"
10677         true
10678
10679         rm -f $DIR/f
10680         restore_lustre_params < $save
10681         rm -f $save
10682 }
10683 run_test 154f "get parent fids by reading link ea"
10684
10685 test_154g()
10686 {
10687         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) ]] ||
10688                 { skip "Need MDS version at least 2.6.92"; return 0; }
10689         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10690
10691         mkdir -p $DIR/$tdir
10692         llapi_fid_test -d $DIR/$tdir
10693 }
10694 run_test 154g "various llapi FID tests"
10695
10696 test_155_small_load() {
10697     local temp=$TMP/$tfile
10698     local file=$DIR/$tfile
10699
10700     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
10701         error "dd of=$temp bs=6096 count=1 failed"
10702     cp $temp $file
10703     cancel_lru_locks osc
10704     cmp $temp $file || error "$temp $file differ"
10705
10706     $TRUNCATE $temp 6000
10707     $TRUNCATE $file 6000
10708     cmp $temp $file || error "$temp $file differ (truncate1)"
10709
10710     echo "12345" >>$temp
10711     echo "12345" >>$file
10712     cmp $temp $file || error "$temp $file differ (append1)"
10713
10714     echo "12345" >>$temp
10715     echo "12345" >>$file
10716     cmp $temp $file || error "$temp $file differ (append2)"
10717
10718     rm -f $temp $file
10719     true
10720 }
10721
10722 test_155_big_load() {
10723     remote_ost_nodsh && skip "remote OST with nodsh" && return
10724     local temp=$TMP/$tfile
10725     local file=$DIR/$tfile
10726
10727     free_min_max
10728     local cache_size=$(do_facet ost$((MAXI+1)) \
10729         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
10730     local large_file_size=$((cache_size * 2))
10731
10732     echo "OSS cache size: $cache_size KB"
10733     echo "Large file size: $large_file_size KB"
10734
10735     [ $MAXV -le $large_file_size ] && \
10736         skip_env "max available OST size needs > $large_file_size KB" && \
10737         return 0
10738
10739     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
10740
10741     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
10742         error "dd of=$temp bs=$large_file_size count=1k failed"
10743     cp $temp $file
10744     ls -lh $temp $file
10745     cancel_lru_locks osc
10746     cmp $temp $file || error "$temp $file differ"
10747
10748     rm -f $temp $file
10749     true
10750 }
10751
10752 save_writethrough() {
10753         local facets=$(get_facets OST)
10754
10755         save_lustre_params $facets "obdfilter.*.writethrough_cache_enable" > $1
10756         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" >> $1
10757 }
10758
10759 test_155a() {
10760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10761         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10762         save_writethrough $p
10763
10764         set_cache read on
10765         set_cache writethrough on
10766         test_155_small_load
10767         restore_lustre_params < $p
10768         rm -f $p
10769 }
10770 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10771
10772 test_155b() {
10773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10774         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10775         save_writethrough $p
10776
10777         set_cache read on
10778         set_cache writethrough off
10779         test_155_small_load
10780         restore_lustre_params < $p
10781         rm -f $p
10782 }
10783 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10784
10785 test_155c() {
10786         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10787         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10788         save_writethrough $p
10789
10790         set_cache read off
10791         set_cache writethrough on
10792         test_155_small_load
10793         restore_lustre_params < $p
10794         rm -f $p
10795 }
10796 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10797
10798 test_155d() {
10799         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10800         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10801         save_writethrough $p
10802
10803         set_cache read off
10804         set_cache writethrough off
10805         test_155_small_load
10806         restore_lustre_params < $p
10807         rm -f $p
10808 }
10809 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10810
10811 test_155e() {
10812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10813         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10814         save_writethrough $p
10815
10816         set_cache read on
10817         set_cache writethrough on
10818         test_155_big_load
10819         restore_lustre_params < $p
10820         rm -f $p
10821 }
10822 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10823
10824 test_155f() {
10825         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10826         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10827         save_writethrough $p
10828
10829         set_cache read on
10830         set_cache writethrough off
10831         test_155_big_load
10832         restore_lustre_params < $p
10833         rm -f $p
10834 }
10835 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10836
10837 test_155g() {
10838         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10839         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10840         save_writethrough $p
10841
10842         set_cache read off
10843         set_cache writethrough on
10844         test_155_big_load
10845         restore_lustre_params < $p
10846         rm -f $p
10847 }
10848 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10849
10850 test_155h() {
10851         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10852         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10853         save_writethrough $p
10854
10855         set_cache read off
10856         set_cache writethrough off
10857         test_155_big_load
10858         restore_lustre_params < $p
10859         rm -f $p
10860 }
10861 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10862
10863 test_156() {
10864         remote_ost_nodsh && skip "remote OST with nodsh" && return
10865         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10866         local CPAGES=3
10867         local BEFORE
10868         local AFTER
10869         local file="$DIR/$tfile"
10870         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10871
10872         [ "$(facet_fstype ost1)" = "zfs" -a \
10873            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
10874                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
10875                 return
10876
10877         save_writethrough $p
10878         roc_hit_init
10879
10880         log "Turn on read and write cache"
10881         set_cache read on
10882         set_cache writethrough on
10883
10884         log "Write data and read it back."
10885         log "Read should be satisfied from the cache."
10886         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10887         BEFORE=$(roc_hit)
10888         cancel_lru_locks osc
10889         cat $file >/dev/null
10890         AFTER=$(roc_hit)
10891         if ! let "AFTER - BEFORE == CPAGES"; then
10892                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10893         else
10894                 log "cache hits:: before: $BEFORE, after: $AFTER"
10895         fi
10896
10897         log "Read again; it should be satisfied from the cache."
10898         BEFORE=$AFTER
10899         cancel_lru_locks osc
10900         cat $file >/dev/null
10901         AFTER=$(roc_hit)
10902         if ! let "AFTER - BEFORE == CPAGES"; then
10903                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10904         else
10905                 log "cache hits:: before: $BEFORE, after: $AFTER"
10906         fi
10907
10908         log "Turn off the read cache and turn on the write cache"
10909         set_cache read off
10910         set_cache writethrough on
10911
10912         log "Read again; it should be satisfied from the cache."
10913         BEFORE=$(roc_hit)
10914         cancel_lru_locks osc
10915         cat $file >/dev/null
10916         AFTER=$(roc_hit)
10917         if ! let "AFTER - BEFORE == CPAGES"; then
10918                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10919         else
10920                 log "cache hits:: before: $BEFORE, after: $AFTER"
10921         fi
10922
10923         log "Read again; it should not be satisfied from the cache."
10924         BEFORE=$AFTER
10925         cancel_lru_locks osc
10926         cat $file >/dev/null
10927         AFTER=$(roc_hit)
10928         if ! let "AFTER - BEFORE == 0"; then
10929                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10930         else
10931                 log "cache hits:: before: $BEFORE, after: $AFTER"
10932         fi
10933
10934         log "Write data and read it back."
10935         log "Read should be satisfied from the cache."
10936         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10937         BEFORE=$(roc_hit)
10938         cancel_lru_locks osc
10939         cat $file >/dev/null
10940         AFTER=$(roc_hit)
10941         if ! let "AFTER - BEFORE == CPAGES"; then
10942                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10943         else
10944                 log "cache hits:: before: $BEFORE, after: $AFTER"
10945         fi
10946
10947         log "Read again; it should not be satisfied from the cache."
10948         BEFORE=$AFTER
10949         cancel_lru_locks osc
10950         cat $file >/dev/null
10951         AFTER=$(roc_hit)
10952         if ! let "AFTER - BEFORE == 0"; then
10953                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10954         else
10955                 log "cache hits:: before: $BEFORE, after: $AFTER"
10956         fi
10957
10958         log "Turn off read and write cache"
10959         set_cache read off
10960         set_cache writethrough off
10961
10962         log "Write data and read it back"
10963         log "It should not be satisfied from the cache."
10964         rm -f $file
10965         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10966         cancel_lru_locks osc
10967         BEFORE=$(roc_hit)
10968         cat $file >/dev/null
10969         AFTER=$(roc_hit)
10970         if ! let "AFTER - BEFORE == 0"; then
10971                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10972         else
10973                 log "cache hits:: before: $BEFORE, after: $AFTER"
10974         fi
10975
10976         log "Turn on the read cache and turn off the write cache"
10977         set_cache read on
10978         set_cache writethrough off
10979
10980         log "Write data and read it back"
10981         log "It should not be satisfied from the cache."
10982         rm -f $file
10983         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10984         BEFORE=$(roc_hit)
10985         cancel_lru_locks osc
10986         cat $file >/dev/null
10987         AFTER=$(roc_hit)
10988         if ! let "AFTER - BEFORE == 0"; then
10989                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10990         else
10991                 log "cache hits:: before: $BEFORE, after: $AFTER"
10992         fi
10993
10994         log "Read again; it should be satisfied from the cache."
10995         BEFORE=$(roc_hit)
10996         cancel_lru_locks osc
10997         cat $file >/dev/null
10998         AFTER=$(roc_hit)
10999         if ! let "AFTER - BEFORE == CPAGES"; then
11000                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11001         else
11002                 log "cache hits:: before: $BEFORE, after: $AFTER"
11003         fi
11004
11005         rm -f $file
11006         restore_lustre_params < $p
11007         rm -f $p
11008 }
11009 run_test 156 "Verification of tunables"
11010
11011 #Changelogs
11012 cleanup_changelog () {
11013         trap 0
11014         echo "Deregistering changelog client $CL_USER"
11015         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
11016 }
11017
11018 err17935 () {
11019         if [[ $MDSCOUNT -gt 1 ]]; then
11020                 error_ignore bz17935 $*
11021         else
11022                 error $*
11023         fi
11024 }
11025
11026 changelog_chmask()
11027 {
11028         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11029
11030         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
11031
11032         if [ $MASK -eq 1 ]; then
11033                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
11034         else
11035                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
11036         fi
11037 }
11038
11039 changelog_extract_field() {
11040         local mdt=$1
11041         local cltype=$2
11042         local file=$3
11043         local identifier=$4
11044
11045         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
11046                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
11047                 tail -1
11048 }
11049
11050 test_160a() {
11051         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11052         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11053         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11054                 { skip "Need MDS version at least 2.2.0"; return; }
11055
11056         local CL_USERS="mdd.$MDT0.changelog_users"
11057         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11058         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11059                 changelog_register -n)
11060         echo "Registered as changelog user $CL_USER"
11061         trap cleanup_changelog EXIT
11062         $GET_CL_USERS | grep -q $CL_USER ||
11063                 error "User $CL_USER not found in changelog_users"
11064
11065         # change something
11066         test_mkdir -p $DIR/$tdir/pics/2008/zachy
11067         touch $DIR/$tdir/pics/2008/zachy/timestamp
11068         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
11069         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
11070         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
11071         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
11072         rm $DIR/$tdir/pics/desktop.jpg
11073
11074         $LFS changelog $MDT0 | tail -5
11075
11076         echo "verifying changelog mask"
11077         changelog_chmask "MKDIR"
11078         changelog_chmask "CLOSE"
11079
11080         test_mkdir -p $DIR/$tdir/pics/zach/sofia
11081         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11082
11083         changelog_chmask "MKDIR"
11084         changelog_chmask "CLOSE"
11085
11086         test_mkdir -p $DIR/$tdir/pics/2008/sofia
11087         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11088
11089         $LFS changelog $MDT0
11090         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
11091         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
11092         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
11093         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
11094
11095         # verify contents
11096         echo "verifying target fid"
11097         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
11098         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
11099         [ "$fidc" == "$fidf" ] ||
11100                 err17935 "fid in changelog $fidc != file fid $fidf"
11101         echo "verifying parent fid"
11102         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
11103         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
11104         [ "$fidc" == "$fidf" ] ||
11105                 err17935 "pfid in changelog $fidc != dir fid $fidf"
11106
11107         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11108         $LFS changelog_clear $MDT0 $CL_USER $(($USER_REC1 + 5))
11109         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11110         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
11111         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
11112                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
11113
11114         MIN_REC=$($GET_CL_USERS |
11115                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
11116         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
11117         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
11118         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
11119                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
11120
11121         # LU-3446 changelog index reset on MDT restart
11122         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11123         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11124         $LFS changelog_clear $MDT0 $CL_USER 0
11125         stop $SINGLEMDS || error "Fail to stop MDT."
11126         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11127         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11128         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
11129         [ $CUR_REC1 == $CUR_REC2 ] ||
11130                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
11131
11132         echo "verifying user deregister"
11133         cleanup_changelog
11134         $GET_CL_USERS | grep -q $CL_USER &&
11135                 error "User $CL_USER still in changelog_users"
11136
11137         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
11138         if [ $CL_USER -eq 0 ]; then
11139                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11140                 touch $DIR/$tdir/chloe
11141                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11142                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
11143                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
11144         else
11145                 echo "$CL_USER other changelog users; can't verify off"
11146         fi
11147 }
11148 run_test 160a "changelog sanity"
11149
11150 test_160b() { # LU-3587
11151         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11152         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11153         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11154                 { skip "Need MDS version at least 2.2.0"; return; }
11155
11156         local CL_USERS="mdd.$MDT0.changelog_users"
11157         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11158         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11159                 changelog_register -n)
11160         echo "Registered as changelog user $CL_USER"
11161         trap cleanup_changelog EXIT
11162         $GET_CL_USERS | grep -q $CL_USER ||
11163                 error "User $CL_USER not found in changelog_users"
11164
11165         local LONGNAME1=$(str_repeat a 255)
11166         local LONGNAME2=$(str_repeat b 255)
11167
11168         cd $DIR
11169         echo "creating very long named file"
11170         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
11171         echo "moving very long named file"
11172         mv $LONGNAME1 $LONGNAME2
11173
11174         $LFS changelog $MDT0 | grep RENME
11175         rm -f $LONGNAME2
11176         cleanup_changelog
11177 }
11178 run_test 160b "Verify that very long rename doesn't crash in changelog"
11179
11180 test_160c() {
11181         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11182
11183         local rc=0
11184         local server_version=$(lustre_version_code $SINGLEMDS)
11185
11186         [[ $server_version -gt $(version_code 2.5.57) ]] ||
11187                 [[ $server_version -gt $(version_code 2.5.1) &&
11188                    $server_version -lt $(version_code 2.5.50) ]] ||
11189                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
11190         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11191
11192         # Registration step
11193         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11194                 changelog_register -n)
11195         trap cleanup_changelog EXIT
11196
11197         rm -rf $DIR/$tdir
11198         mkdir -p $DIR/$tdir
11199         $MCREATE $DIR/$tdir/foo_160c
11200         changelog_chmask "TRUNC"
11201         $TRUNCATE $DIR/$tdir/foo_160c 200
11202         changelog_chmask "TRUNC"
11203         $TRUNCATE $DIR/$tdir/foo_160c 199
11204         $LFS changelog $MDT0
11205         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
11206         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
11207         $LFS changelog_clear $MDT0 $CL_USER 0
11208
11209         # Deregistration step
11210         cleanup_changelog
11211 }
11212 run_test 160c "verify that changelog log catch the truncate event"
11213
11214 test_160d() {
11215         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11216         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11217
11218         local server_version=$(lustre_version_code mds1)
11219         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11220
11221         [[ $server_version -ge $(version_code 2.7.60) ]] ||
11222                 { skip "Need MDS version at least 2.7.60+"; return; }
11223         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11224
11225         # Registration step
11226         CL_USER=$(do_facet mds1 $LCTL --device $MDT0 \
11227                 changelog_register -n)
11228
11229         trap cleanup_changelog EXIT
11230         mkdir -p $DIR/$tdir/migrate_dir
11231         $LFS changelog_clear $MDT0 $CL_USER 0
11232
11233         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
11234         $LFS changelog $MDT0
11235         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
11236         $LFS changelog_clear $MDT0 $CL_USER 0
11237         [ $MIGRATES -eq 1 ] ||
11238                 error "MIGRATE changelog mask count $MIGRATES != 1"
11239
11240         # Deregistration step
11241         cleanup_changelog
11242 }
11243 run_test 160d "verify that changelog log catch the migrate event"
11244
11245 test_160e() {
11246         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11247
11248         # Create a user
11249         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11250                 changelog_register -n)
11251         echo "Registered as changelog user $CL_USER"
11252         trap cleanup_changelog EXIT
11253
11254         # Delete a future user (expect fail)
11255         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister cl77
11256         local rc=$?
11257
11258         if [ $rc -eq 0 ]; then
11259                 error "Deleted non-existant user cl77"
11260         elif [ $rc -ne 2 ]; then
11261                 error "changelog_deregister failed with $rc, " \
11262                         "expected 2 (ENOENT)"
11263         fi
11264
11265         # Clear to a bad index (1 billion should be safe)
11266         $LFS changelog_clear $MDT0 $CL_USER 1000000000
11267         rc=$?
11268
11269         if [ $rc -eq 0 ]; then
11270                 error "Successfully cleared to invalid CL index"
11271         elif [ $rc -ne 22 ]; then
11272                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
11273         fi
11274 }
11275 run_test 160e "changelog negative testing"
11276
11277 test_161a() {
11278         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11279         test_mkdir -p -c1 $DIR/$tdir
11280         cp /etc/hosts $DIR/$tdir/$tfile
11281         test_mkdir -c1 $DIR/$tdir/foo1
11282         test_mkdir -c1 $DIR/$tdir/foo2
11283         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
11284         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
11285         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
11286         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
11287         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
11288         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11289                 $LFS fid2path $DIR $FID
11290                 err17935 "bad link ea"
11291         fi
11292     # middle
11293     rm $DIR/$tdir/foo2/zachary
11294     # last
11295     rm $DIR/$tdir/foo2/thor
11296     # first
11297     rm $DIR/$tdir/$tfile
11298     # rename
11299     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
11300     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
11301         then
11302         $LFS fid2path $DIR $FID
11303         err17935 "bad link rename"
11304     fi
11305     rm $DIR/$tdir/foo2/maggie
11306
11307         # overflow the EA
11308         local longname=filename_avg_len_is_thirty_two_
11309         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
11310                 error "failed to hardlink many files"
11311         links=$($LFS fid2path $DIR $FID | wc -l)
11312         echo -n "${links}/1000 links in link EA"
11313         [[ $links -gt 60 ]] ||
11314                 err17935 "expected at least 60 links in link EA"
11315         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
11316                 error "failed to unlink many hardlinks"
11317 }
11318 run_test 161a "link ea sanity"
11319
11320 test_161b() {
11321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11322         [ $MDSCOUNT -lt 2 ] && skip "skipping remote directory test" && return
11323         local MDTIDX=1
11324         local remote_dir=$DIR/$tdir/remote_dir
11325
11326         mkdir -p $DIR/$tdir
11327         $LFS mkdir -i $MDTIDX $remote_dir ||
11328                 error "create remote directory failed"
11329
11330         cp /etc/hosts $remote_dir/$tfile
11331         mkdir -p $remote_dir/foo1
11332         mkdir -p $remote_dir/foo2
11333         ln $remote_dir/$tfile $remote_dir/foo1/sofia
11334         ln $remote_dir/$tfile $remote_dir/foo2/zachary
11335         ln $remote_dir/$tfile $remote_dir/foo1/luna
11336         ln $remote_dir/$tfile $remote_dir/foo2/thor
11337
11338         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
11339                      tr -d ']')
11340         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11341                 $LFS fid2path $DIR $FID
11342                 err17935 "bad link ea"
11343         fi
11344         # middle
11345         rm $remote_dir/foo2/zachary
11346         # last
11347         rm $remote_dir/foo2/thor
11348         # first
11349         rm $remote_dir/$tfile
11350         # rename
11351         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
11352         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
11353         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
11354                 $LFS fid2path $DIR $FID
11355                 err17935 "bad link rename"
11356         fi
11357         rm $remote_dir/foo2/maggie
11358
11359         # overflow the EA
11360         local longname=filename_avg_len_is_thirty_two_
11361         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
11362                 error "failed to hardlink many files"
11363         links=$($LFS fid2path $DIR $FID | wc -l)
11364         echo -n "${links}/1000 links in link EA"
11365         [[ ${links} -gt 60 ]] ||
11366                 err17935 "expected at least 60 links in link EA"
11367         unlinkmany $remote_dir/foo2/$longname 1000 ||
11368         error "failed to unlink many hardlinks"
11369 }
11370 run_test 161b "link ea sanity under remote directory"
11371
11372 test_161c() {
11373         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11374         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11375         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
11376                 skip "Need MDS version at least 2.1.5" && return
11377
11378         # define CLF_RENAME_LAST 0x0001
11379         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
11380         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11381                 changelog_register -n)
11382
11383         trap cleanup_changelog EXIT
11384         rm -rf $DIR/$tdir
11385         mkdir -p $DIR/$tdir
11386         touch $DIR/$tdir/foo_161c
11387         touch $DIR/$tdir/bar_161c
11388         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11389         $LFS changelog $MDT0 | grep RENME
11390         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
11391                 cut -f5 -d' ')
11392         $LFS changelog_clear $MDT0 $CL_USER 0
11393         if [ x$flags != "x0x1" ]; then
11394                 error "flag $flags is not 0x1"
11395         fi
11396         echo "rename overwrite a target having nlink = 1," \
11397                 "changelog record has flags of $flags"
11398
11399         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
11400         touch $DIR/$tdir/foo_161c
11401         touch $DIR/$tdir/bar_161c
11402         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11403         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11404         $LFS changelog $MDT0 | grep RENME
11405         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11406         $LFS changelog_clear $MDT0 $CL_USER 0
11407         if [ x$flags != "x0x0" ]; then
11408                 error "flag $flags is not 0x0"
11409         fi
11410         echo "rename overwrite a target having nlink > 1," \
11411                 "changelog record has flags of $flags"
11412
11413         # rename doesn't overwrite a target (changelog flag 0x0)
11414         touch $DIR/$tdir/foo_161c
11415         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
11416         $LFS changelog $MDT0 | grep RENME
11417         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11418         $LFS changelog_clear $MDT0 $CL_USER 0
11419         if [ x$flags != "x0x0" ]; then
11420                 error "flag $flags is not 0x0"
11421         fi
11422         echo "rename doesn't overwrite a target," \
11423                 "changelog record has flags of $flags"
11424
11425         # define CLF_UNLINK_LAST 0x0001
11426         # unlink a file having nlink = 1 (changelog flag 0x1)
11427         rm -f $DIR/$tdir/foo2_161c
11428         $LFS changelog $MDT0 | grep UNLNK
11429         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11430         $LFS changelog_clear $MDT0 $CL_USER 0
11431         if [ x$flags != "x0x1" ]; then
11432                 error "flag $flags is not 0x1"
11433         fi
11434         echo "unlink a file having nlink = 1," \
11435                 "changelog record has flags of $flags"
11436
11437         # unlink a file having nlink > 1 (changelog flag 0x0)
11438         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11439         rm -f $DIR/$tdir/foobar_161c
11440         $LFS changelog $MDT0 | grep UNLNK
11441         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11442         $LFS changelog_clear $MDT0 $CL_USER 0
11443         if [ x$flags != "x0x0" ]; then
11444                 error "flag $flags is not 0x0"
11445         fi
11446         echo "unlink a file having nlink > 1," \
11447                 "changelog record has flags of $flags"
11448         cleanup_changelog
11449 }
11450 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
11451
11452 test_161d() {
11453         local user
11454         local pid
11455         local fid
11456
11457         # cleanup previous run
11458         rm -rf $DIR/$tdir/$tfile
11459
11460         user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11461                 changelog_register -n)
11462         [[ $? -eq 0 ]] || error "changelog_register failed"
11463
11464         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
11465         # interfer with $MOUNT/.lustre/fid/ access
11466         mkdir $DIR/$tdir
11467         [[ $? -eq 0 ]] || error "mkdir failed"
11468
11469         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
11470         $LCTL set_param fail_loc=0x8000140c
11471         # 5s pause
11472         $LCTL set_param fail_val=5
11473
11474         # create file
11475         echo foofoo > $DIR/$tdir/$tfile &
11476         pid=$!
11477
11478         # wait for create to be delayed
11479         sleep 2
11480
11481         ps -p $pid
11482         [[ $? -eq 0 ]] || error "create should be blocked"
11483
11484         local tempfile=$(mktemp)
11485         fid=$(changelog_extract_field $MDT0 "CREAT" "$tfile" "t=")
11486         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
11487         # some delay may occur during ChangeLog publishing and file read just
11488         # above, that could allow file write to happen finally
11489         [[ -s $tempfile ]] && echo "file should be empty"
11490
11491         $LCTL set_param fail_loc=0
11492
11493         wait $pid
11494         [[ $? -eq 0 ]] || error "create failed"
11495
11496         $LFS changelog_clear $MDT0 $user 0
11497         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $user
11498 }
11499 run_test 161d "create with concurrent .lustre/fid access"
11500
11501 check_path() {
11502     local expected=$1
11503     shift
11504     local fid=$2
11505
11506     local path=$(${LFS} fid2path $*)
11507     # Remove the '//' indicating a remote directory
11508     path=$(echo $path | sed 's#//#/#g')
11509     RC=$?
11510
11511     if [ $RC -ne 0 ]; then
11512         err17935 "path looked up of $expected failed. Error $RC"
11513         return $RC
11514     elif [ "${path}" != "${expected}" ]; then
11515         err17935 "path looked up \"${path}\" instead of \"${expected}\""
11516         return 2
11517     fi
11518     echo "fid $fid resolves to path $path (expected $expected)"
11519 }
11520
11521 test_162a() { # was test_162
11522         # Make changes to filesystem
11523         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11524         test_mkdir -p -c1 $DIR/$tdir/d2
11525         touch $DIR/$tdir/d2/$tfile
11526         touch $DIR/$tdir/d2/x1
11527         touch $DIR/$tdir/d2/x2
11528         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
11529         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
11530         # regular file
11531         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
11532         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
11533                 error "check path $tdir/d2/$tfile failed"
11534
11535         # softlink
11536         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
11537         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
11538         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
11539                 error "check path $tdir/d2/p/q/r/slink failed"
11540
11541         # softlink to wrong file
11542         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
11543         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
11544         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
11545                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
11546
11547         # hardlink
11548         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
11549         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
11550         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
11551         # fid2path dir/fsname should both work
11552         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
11553                 error "check path $tdir/d2/a/b/c/new_file failed"
11554         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
11555                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
11556
11557         # hardlink count: check that there are 2 links
11558         # Doesnt work with CMD yet: 17935
11559         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
11560                 err17935 "expected 2 links"
11561
11562         # hardlink indexing: remove the first link
11563         rm $DIR/$tdir/d2/p/q/r/hlink
11564         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
11565                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
11566
11567         return 0
11568 }
11569 run_test 162a "path lookup sanity"
11570
11571 test_162b() {
11572         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11573         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11574
11575         mkdir $DIR/$tdir
11576         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
11577                                 error "create striped dir failed"
11578
11579         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
11580                                         tail -n 1 | awk '{print $2}')
11581         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
11582
11583         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
11584         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
11585
11586         # regular file
11587         for ((i=0;i<5;i++)); do
11588                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
11589                         error "get fid for f$i failed"
11590                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
11591                         error "check path $tdir/striped_dir/f$i failed"
11592
11593                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
11594                         error "get fid for d$i failed"
11595                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
11596                         error "check path $tdir/striped_dir/d$i failed"
11597         done
11598
11599         return 0
11600 }
11601 run_test 162b "striped directory path lookup sanity"
11602
11603 # LU-4239: Verify fid2path works with paths 100 or more directories deep
11604 test_162c() {
11605         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
11606                 skip "Need MDS version at least 2.7.51" && return
11607         test_mkdir $DIR/$tdir.local
11608         test_mkdir $DIR/$tdir.remote
11609         local lpath=$tdir.local
11610         local rpath=$tdir.remote
11611
11612         for ((i = 0; i <= 101; i++)); do
11613                 lpath="$lpath/$i"
11614                 mkdir $DIR/$lpath
11615                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
11616                         error "get fid for local directory $DIR/$lpath failed"
11617                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
11618                         error "check path for local directory $DIR/$lpath failed"
11619
11620                 rpath="$rpath/$i"
11621                 test_mkdir $DIR/$rpath
11622                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
11623                         error "get fid for remote directory $DIR/$rpath failed"
11624                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
11625                         error "check path for remote directory $DIR/$rpath failed"
11626         done
11627
11628         return 0
11629 }
11630 run_test 162c "fid2path works with paths 100 or more directories deep"
11631
11632 test_169() {
11633         # do directio so as not to populate the page cache
11634         log "creating a 10 Mb file"
11635         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11636         log "starting reads"
11637         dd if=$DIR/$tfile of=/dev/null bs=4096 &
11638         log "truncating the file"
11639         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11640         log "killing dd"
11641         kill %+ || true # reads might have finished
11642         echo "wait until dd is finished"
11643         wait
11644         log "removing the temporary file"
11645         rm -rf $DIR/$tfile || error "tmp file removal failed"
11646 }
11647 run_test 169 "parallel read and truncate should not deadlock"
11648
11649 test_170() {
11650         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11651         $LCTL clear     # bug 18514
11652         $LCTL debug_daemon start $TMP/${tfile}_log_good
11653         touch $DIR/$tfile
11654         $LCTL debug_daemon stop
11655         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
11656                error "sed failed to read log_good"
11657
11658         $LCTL debug_daemon start $TMP/${tfile}_log_good
11659         rm -rf $DIR/$tfile
11660         $LCTL debug_daemon stop
11661
11662         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
11663                error "lctl df log_bad failed"
11664
11665         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11666         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11667
11668         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
11669         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
11670
11671         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
11672                 error "bad_line good_line1 good_line2 are empty"
11673
11674         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11675         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
11676         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11677
11678         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
11679         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11680         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11681
11682         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
11683                 error "bad_line_new good_line_new are empty"
11684
11685         local expected_good=$((good_line1 + good_line2*2))
11686
11687         rm -f $TMP/${tfile}*
11688         # LU-231, short malformed line may not be counted into bad lines
11689         if [ $bad_line -ne $bad_line_new ] &&
11690                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
11691                 error "expected $bad_line bad lines, but got $bad_line_new"
11692                 return 1
11693         fi
11694
11695         if [ $expected_good -ne $good_line_new ]; then
11696                 error "expected $expected_good good lines, but got $good_line_new"
11697                 return 2
11698         fi
11699         true
11700 }
11701 run_test 170 "test lctl df to handle corrupted log ====================="
11702
11703 test_171() { # bug20592
11704         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11705 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
11706         $LCTL set_param fail_loc=0x50e
11707         $LCTL set_param fail_val=3000
11708         multiop_bg_pause $DIR/$tfile O_s || true
11709         local MULTIPID=$!
11710         kill -USR1 $MULTIPID
11711         # cause log dump
11712         sleep 3
11713         wait $MULTIPID
11714         if dmesg | grep "recursive fault"; then
11715                 error "caught a recursive fault"
11716         fi
11717         $LCTL set_param fail_loc=0
11718         true
11719 }
11720 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
11721
11722 # it would be good to share it with obdfilter-survey/iokit-libecho code
11723 setup_obdecho_osc () {
11724         local rc=0
11725         local ost_nid=$1
11726         local obdfilter_name=$2
11727         echo "Creating new osc for $obdfilter_name on $ost_nid"
11728         # make sure we can find loopback nid
11729         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
11730
11731         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
11732                            ${obdfilter_name}_osc_UUID || rc=2; }
11733         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
11734                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
11735         return $rc
11736 }
11737
11738 cleanup_obdecho_osc () {
11739         local obdfilter_name=$1
11740         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
11741         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
11742         return 0
11743 }
11744
11745 obdecho_test() {
11746         local OBD=$1
11747         local node=$2
11748         local pages=${3:-64}
11749         local rc=0
11750         local id
11751
11752         local count=10
11753         local obd_size=$(get_obd_size $node $OBD)
11754         local page_size=$(get_page_size $node)
11755         if [[ -n "$obd_size" ]]; then
11756                 local new_count=$((obd_size / (pages * page_size / 1024)))
11757                 [[ $new_count -ge $count ]] || count=$new_count
11758         fi
11759
11760         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
11761         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
11762                            rc=2; }
11763         if [ $rc -eq 0 ]; then
11764             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
11765             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
11766         fi
11767         echo "New object id is $id"
11768         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
11769                            rc=4; }
11770         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
11771                            "test_brw $count w v $pages $id" || rc=4; }
11772         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
11773                            rc=4; }
11774         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
11775                                         "cleanup" || rc=5; }
11776         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
11777                                         "detach" || rc=6; }
11778         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
11779         return $rc
11780 }
11781
11782 test_180a() {
11783         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11784         remote_ost_nodsh && skip "remote OST with nodsh" && return
11785         local rc=0
11786         local rmmod_local=0
11787
11788         if ! module_loaded obdecho; then
11789             load_module obdecho/obdecho
11790             rmmod_local=1
11791         fi
11792
11793         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
11794         local host=$(lctl get_param -n osc.$osc.import |
11795                              awk '/current_connection:/ {print $2}' )
11796         local target=$(lctl get_param -n osc.$osc.import |
11797                              awk '/target:/ {print $2}' )
11798         target=${target%_UUID}
11799
11800         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
11801         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
11802         [[ -n $target ]] && cleanup_obdecho_osc $target
11803         [ $rmmod_local -eq 1 ] && rmmod obdecho
11804         return $rc
11805 }
11806 run_test 180a "test obdecho on osc"
11807
11808 test_180b() {
11809         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11810         remote_ost_nodsh && skip "remote OST with nodsh" && return
11811         local rc=0
11812         local rmmod_remote=0
11813
11814         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11815                 rmmod_remote=true || error "failed to load module obdecho"
11816         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
11817         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
11818         $rmmod_remote && do_facet ost1 "rmmod obdecho"
11819         return $rc
11820 }
11821 run_test 180b "test obdecho directly on obdfilter"
11822
11823 test_180c() { # LU-2598
11824         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11825         remote_ost_nodsh && skip "remote OST with nodsh" && return
11826         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
11827                 skip "Need MDS version at least 2.4.0" && return
11828
11829         local rc=0
11830         local rmmod_remote=false
11831         local pages=16384 # 64MB bulk I/O RPC size
11832         local target
11833
11834         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11835                 rmmod_remote=true || error "failed to load module obdecho"
11836
11837         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
11838                 head -n1)
11839         if [ -n "$target" ]; then
11840                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
11841         else
11842                 echo "there is no obdfilter target on ost1"
11843                 rc=2
11844         fi
11845         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
11846         return $rc
11847 }
11848 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
11849
11850 test_181() { # bug 22177
11851         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11852         # create enough files to index the directory
11853         createmany -o $DIR/$tdir/foobar 4000
11854         # print attributes for debug purpose
11855         lsattr -d .
11856         # open dir
11857         multiop_bg_pause $DIR/$tdir D_Sc || return 1
11858         MULTIPID=$!
11859         # remove the files & current working dir
11860         unlinkmany $DIR/$tdir/foobar 4000
11861         rmdir $DIR/$tdir
11862         kill -USR1 $MULTIPID
11863         wait $MULTIPID
11864         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
11865         return 0
11866 }
11867 run_test 181 "Test open-unlinked dir ========================"
11868
11869 test_182() {
11870         local fcount=1000
11871         local tcount=10
11872
11873         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11874
11875         $LCTL set_param mdc.*.rpc_stats=clear
11876
11877         for (( i = 0; i < $tcount; i++ )) ; do
11878                 mkdir $DIR/$tdir/$i
11879         done
11880
11881         for (( i = 0; i < $tcount; i++ )) ; do
11882                 createmany -o $DIR/$tdir/$i/f- $fcount &
11883         done
11884         wait
11885
11886         for (( i = 0; i < $tcount; i++ )) ; do
11887                 unlinkmany $DIR/$tdir/$i/f- $fcount &
11888         done
11889         wait
11890
11891         $LCTL get_param mdc.*.rpc_stats
11892
11893         rm -rf $DIR/$tdir
11894 }
11895 run_test 182 "Test parallel modify metadata operations ================"
11896
11897 test_183() { # LU-2275
11898         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11899         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
11900                 skip "Need MDS version at least 2.3.56" && return
11901
11902         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11903         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11904         echo aaa > $DIR/$tdir/$tfile
11905
11906 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
11907         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
11908
11909         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
11910         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11911
11912         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11913
11914         # Flush negative dentry cache
11915         touch $DIR/$tdir/$tfile
11916
11917         # We are not checking for any leaked references here, they'll
11918         # become evident next time we do cleanup with module unload.
11919         rm -rf $DIR/$tdir
11920 }
11921 run_test 183 "No crash or request leak in case of strange dispositions ========"
11922
11923 # test suite 184 is for LU-2016, LU-2017
11924 test_184a() {
11925         check_swap_layouts_support && return 0
11926
11927         dir0=$DIR/$tdir/$testnum
11928         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
11929         ref1=/etc/passwd
11930         ref2=/etc/group
11931         file1=$dir0/f1
11932         file2=$dir0/f2
11933         $SETSTRIPE -c1 $file1
11934         cp $ref1 $file1
11935         $SETSTRIPE -c2 $file2
11936         cp $ref2 $file2
11937         gen1=$($GETSTRIPE -g $file1)
11938         gen2=$($GETSTRIPE -g $file2)
11939
11940         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11941         gen=$($GETSTRIPE -g $file1)
11942         [[ $gen1 != $gen ]] ||
11943                 "Layout generation on $file1 does not change"
11944         gen=$($GETSTRIPE -g $file2)
11945         [[ $gen2 != $gen ]] ||
11946                 "Layout generation on $file2 does not change"
11947
11948         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11949         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11950 }
11951 run_test 184a "Basic layout swap"
11952
11953 test_184b() {
11954         check_swap_layouts_support && return 0
11955
11956         dir0=$DIR/$tdir/$testnum
11957         mkdir -p $dir0 || error "creating dir $dir0"
11958         file1=$dir0/f1
11959         file2=$dir0/f2
11960         file3=$dir0/f3
11961         dir1=$dir0/d1
11962         dir2=$dir0/d2
11963         mkdir $dir1 $dir2
11964         $SETSTRIPE -c1 $file1
11965         $SETSTRIPE -c2 $file2
11966         $SETSTRIPE -c1 $file3
11967         chown $RUNAS_ID $file3
11968         gen1=$($GETSTRIPE -g $file1)
11969         gen2=$($GETSTRIPE -g $file2)
11970
11971         $LFS swap_layouts $dir1 $dir2 &&
11972                 error "swap of directories layouts should fail"
11973         $LFS swap_layouts $dir1 $file1 &&
11974                 error "swap of directory and file layouts should fail"
11975         $RUNAS $LFS swap_layouts $file1 $file2 &&
11976                 error "swap of file we cannot write should fail"
11977         $LFS swap_layouts $file1 $file3 &&
11978                 error "swap of file with different owner should fail"
11979         /bin/true # to clear error code
11980 }
11981 run_test 184b "Forbidden layout swap (will generate errors)"
11982
11983 test_184c() {
11984         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
11985         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n" && return
11986         check_swap_layouts_support && return 0
11987
11988         local dir0=$DIR/$tdir/$testnum
11989         mkdir -p $dir0 || error "creating dir $dir0"
11990
11991         local ref1=$dir0/ref1
11992         local ref2=$dir0/ref2
11993         local file1=$dir0/file1
11994         local file2=$dir0/file2
11995         # create a file large enough for the concurrent test
11996         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
11997         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
11998         echo "ref file size: ref1($(stat -c %s $ref1))," \
11999              "ref2($(stat -c %s $ref2))"
12000
12001         cp $ref2 $file2
12002         dd if=$ref1 of=$file1 bs=16k &
12003         local DD_PID=$!
12004
12005         # Make sure dd starts to copy file
12006         while [ ! -f $file1 ]; do sleep 0.1; done
12007
12008         $LFS swap_layouts $file1 $file2
12009         local rc=$?
12010         wait $DD_PID
12011         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
12012         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
12013
12014         # how many bytes copied before swapping layout
12015         local copied=$(stat -c %s $file2)
12016         local remaining=$(stat -c %s $ref1)
12017         remaining=$((remaining - copied))
12018         echo "Copied $copied bytes before swapping layout..."
12019
12020         cmp -n $copied $file1 $ref2 | grep differ &&
12021                 error "Content mismatch [0, $copied) of ref2 and file1"
12022         cmp -n $copied $file2 $ref1 ||
12023                 error "Content mismatch [0, $copied) of ref1 and file2"
12024         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
12025                 error "Content mismatch [$copied, EOF) of ref1 and file1"
12026
12027         # clean up
12028         rm -f $ref1 $ref2 $file1 $file2
12029 }
12030 run_test 184c "Concurrent write and layout swap"
12031
12032 test_184d() {
12033         check_swap_layouts_support && return 0
12034         [ -z "$(which getfattr 2>/dev/null)" ] &&
12035                 skip "no getfattr command" && return 0
12036
12037         local file1=$DIR/$tdir/$tfile-1
12038         local file2=$DIR/$tdir/$tfile-2
12039         local file3=$DIR/$tdir/$tfile-3
12040         local lovea1
12041         local lovea2
12042
12043         mkdir -p $DIR/$tdir
12044         touch $file1 || error "create $file1 failed"
12045         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12046                 error "create $file2 failed"
12047         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12048                 error "create $file3 failed"
12049         lovea1=$(get_layout_param $file1)
12050
12051         $LFS swap_layouts $file2 $file3 ||
12052                 error "swap $file2 $file3 layouts failed"
12053         $LFS swap_layouts $file1 $file2 ||
12054                 error "swap $file1 $file2 layouts failed"
12055
12056         lovea2=$(get_layout_param $file2)
12057         echo "$lovea1"
12058         echo "$lovea2"
12059         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
12060
12061         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12062         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
12063 }
12064 run_test 184d "allow stripeless layouts swap"
12065
12066 test_184e() {
12067         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
12068                 { skip "Need MDS version at least 2.6.94"; return 0; }
12069         check_swap_layouts_support && return 0
12070         [ -z "$(which getfattr 2>/dev/null)" ] &&
12071                 skip "no getfattr command" && return 0
12072
12073         local file1=$DIR/$tdir/$tfile-1
12074         local file2=$DIR/$tdir/$tfile-2
12075         local file3=$DIR/$tdir/$tfile-3
12076         local lovea
12077
12078         mkdir -p $DIR/$tdir
12079         touch $file1 || error "create $file1 failed"
12080         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12081                 error "create $file2 failed"
12082         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12083                 error "create $file3 failed"
12084
12085         $LFS swap_layouts $file1 $file2 ||
12086                 error "swap $file1 $file2 layouts failed"
12087
12088         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12089         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
12090
12091         echo 123 > $file1 || error "Should be able to write into $file1"
12092
12093         $LFS swap_layouts $file1 $file3 ||
12094                 error "swap $file1 $file3 layouts failed"
12095
12096         echo 123 > $file1 || error "Should be able to write into $file1"
12097
12098         rm -rf $file1 $file2 $file3
12099 }
12100 run_test 184e "Recreate layout after stripeless layout swaps"
12101
12102 test_185() { # LU-2441
12103         # LU-3553 - no volatile file support in old servers
12104         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
12105                 { skip "Need MDS version at least 2.3.60"; return 0; }
12106
12107         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12108         touch $DIR/$tdir/spoo
12109         local mtime1=$(stat -c "%Y" $DIR/$tdir)
12110         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
12111                 error "cannot create/write a volatile file"
12112         [ "$FILESET" == "" ] &&
12113         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
12114                 error "FID is still valid after close"
12115
12116         multiop_bg_pause $DIR/$tdir vVw4096_c
12117         local multi_pid=$!
12118
12119         local OLD_IFS=$IFS
12120         IFS=":"
12121         local fidv=($fid)
12122         IFS=$OLD_IFS
12123         # assume that the next FID for this client is sequential, since stdout
12124         # is unfortunately eaten by multiop_bg_pause
12125         local n=$((${fidv[1]} + 1))
12126         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
12127         if [ "$FILESET" == "" ]; then
12128                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
12129                         error "FID is missing before close"
12130         fi
12131         kill -USR1 $multi_pid
12132         # 1 second delay, so if mtime change we will see it
12133         sleep 1
12134         local mtime2=$(stat -c "%Y" $DIR/$tdir)
12135         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
12136 }
12137 run_test 185 "Volatile file support"
12138
12139 test_187a() {
12140         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12141         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12142                 skip "Need MDS version at least 2.3.0" && return
12143
12144         local dir0=$DIR/$tdir/$testnum
12145         mkdir -p $dir0 || error "creating dir $dir0"
12146
12147         local file=$dir0/file1
12148         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
12149         local dv1=$($LFS data_version $file)
12150         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
12151         local dv2=$($LFS data_version $file)
12152         [[ $dv1 != $dv2 ]] ||
12153                 error "data version did not change on write $dv1 == $dv2"
12154
12155         # clean up
12156         rm -f $file1
12157 }
12158 run_test 187a "Test data version change"
12159
12160 test_187b() {
12161         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12162         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12163                 skip "Need MDS version at least 2.3.0" && return
12164
12165         local dir0=$DIR/$tdir/$testnum
12166         mkdir -p $dir0 || error "creating dir $dir0"
12167
12168         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
12169         [[ ${DV[0]} != ${DV[1]} ]] ||
12170                 error "data version did not change on write"\
12171                       " ${DV[0]} == ${DV[1]}"
12172
12173         # clean up
12174         rm -f $file1
12175 }
12176 run_test 187b "Test data version change on volatile file"
12177
12178 test_200() {
12179         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12180         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12181         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
12182
12183         local POOL=${POOL:-cea1}
12184         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
12185         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
12186         # Pool OST targets
12187         local first_ost=0
12188         local last_ost=$(($OSTCOUNT - 1))
12189         local ost_step=2
12190         local ost_list=$(seq $first_ost $ost_step $last_ost)
12191         local ost_range="$first_ost $last_ost $ost_step"
12192         local test_path=$POOL_ROOT/$POOL_DIR_NAME
12193         local file_dir=$POOL_ROOT/file_tst
12194         local subdir=$test_path/subdir
12195
12196         local rc=0
12197         while : ; do
12198                 # former test_200a test_200b
12199                 pool_add $POOL                          || { rc=$? ; break; }
12200                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
12201                 # former test_200c test_200d
12202                 mkdir -p $test_path
12203                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
12204                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
12205                 mkdir -p $subdir
12206                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
12207                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
12208                                                         || { rc=$? ; break; }
12209                 # former test_200e test_200f
12210                 local files=$((OSTCOUNT*3))
12211                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
12212                                                         || { rc=$? ; break; }
12213                 pool_create_files $POOL $file_dir $files "$ost_list" \
12214                                                         || { rc=$? ; break; }
12215                 # former test_200g test_200h
12216                 pool_lfs_df $POOL                       || { rc=$? ; break; }
12217                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
12218
12219                 # former test_201a test_201b test_201c
12220                 pool_remove_first_target $POOL          || { rc=$? ; break; }
12221
12222                 local f=$test_path/$tfile
12223                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
12224                 pool_remove $POOL $f                    || { rc=$? ; break; }
12225                 break
12226         done
12227
12228         destroy_test_pools
12229         return $rc
12230 }
12231 run_test 200 "OST pools"
12232
12233 # usage: default_attr <count | size | offset>
12234 default_attr() {
12235         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
12236 }
12237
12238 # usage: check_default_stripe_attr
12239 check_default_stripe_attr() {
12240         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
12241         case $1 in
12242         --stripe-count|-c)
12243                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
12244         --stripe-size|-S)
12245                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
12246         --stripe-index|-i)
12247                 EXPECTED=-1;;
12248         *)
12249                 error "unknown getstripe attr '$1'"
12250         esac
12251
12252         [ $ACTUAL != $EXPECTED ] &&
12253                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
12254 }
12255
12256 test_204a() {
12257         test_mkdir -p $DIR/$tdir
12258         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
12259
12260         check_default_stripe_attr --stripe-count
12261         check_default_stripe_attr --stripe-size
12262         check_default_stripe_attr --stripe-index
12263
12264         return 0
12265 }
12266 run_test 204a "Print default stripe attributes ================="
12267
12268 test_204b() {
12269         test_mkdir -p $DIR/$tdir
12270         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12271
12272         check_default_stripe_attr --stripe-size
12273         check_default_stripe_attr --stripe-index
12274
12275         return 0
12276 }
12277 run_test 204b "Print default stripe size and offset  ==========="
12278
12279 test_204c() {
12280         test_mkdir -p $DIR/$tdir
12281         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12282
12283         check_default_stripe_attr --stripe-count
12284         check_default_stripe_attr --stripe-index
12285
12286         return 0
12287 }
12288 run_test 204c "Print default stripe count and offset ==========="
12289
12290 test_204d() {
12291         test_mkdir -p $DIR/$tdir
12292         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12293
12294         check_default_stripe_attr --stripe-count
12295         check_default_stripe_attr --stripe-size
12296
12297         return 0
12298 }
12299 run_test 204d "Print default stripe count and size ============="
12300
12301 test_204e() {
12302         test_mkdir -p $DIR/$tdir
12303         $SETSTRIPE -d $DIR/$tdir
12304
12305         check_default_stripe_attr --stripe-count --raw
12306         check_default_stripe_attr --stripe-size --raw
12307         check_default_stripe_attr --stripe-index --raw
12308
12309         return 0
12310 }
12311 run_test 204e "Print raw stripe attributes ================="
12312
12313 test_204f() {
12314         test_mkdir -p $DIR/$tdir
12315         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12316
12317         check_default_stripe_attr --stripe-size --raw
12318         check_default_stripe_attr --stripe-index --raw
12319
12320         return 0
12321 }
12322 run_test 204f "Print raw stripe size and offset  ==========="
12323
12324 test_204g() {
12325         test_mkdir -p $DIR/$tdir
12326         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12327
12328         check_default_stripe_attr --stripe-count --raw
12329         check_default_stripe_attr --stripe-index --raw
12330
12331         return 0
12332 }
12333 run_test 204g "Print raw stripe count and offset ==========="
12334
12335 test_204h() {
12336         test_mkdir -p $DIR/$tdir
12337         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12338
12339         check_default_stripe_attr --stripe-count --raw
12340         check_default_stripe_attr --stripe-size --raw
12341
12342         return 0
12343 }
12344 run_test 204h "Print raw stripe count and size ============="
12345
12346 # Figure out which job scheduler is being used, if any,
12347 # or use a fake one
12348 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
12349         JOBENV=SLURM_JOB_ID
12350 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
12351         JOBENV=LSB_JOBID
12352 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
12353         JOBENV=PBS_JOBID
12354 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
12355         JOBENV=LOADL_STEP_ID
12356 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
12357         JOBENV=JOB_ID
12358 else
12359         $LCTL list_param jobid_name > /dev/null 2>&1
12360         if [ $? -eq 0 ]; then
12361                 JOBENV=nodelocal
12362         else
12363                 JOBENV=FAKE_JOBID
12364         fi
12365 fi
12366
12367 verify_jobstats() {
12368         local cmd=($1)
12369         shift
12370         local facets="$@"
12371
12372 # we don't really need to clear the stats for this test to work, since each
12373 # command has a unique jobid, but it makes debugging easier if needed.
12374 #       for facet in $facets; do
12375 #               local dev=$(convert_facet2label $facet)
12376 #               # clear old jobstats
12377 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
12378 #       done
12379
12380         # use a new JobID for each test, or we might see an old one
12381         [ "$JOBENV" = "FAKE_JOBID" ] &&
12382                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12383
12384         JOBVAL=${!JOBENV}
12385
12386         [ "$JOBENV" = "nodelocal" ] && {
12387                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12388                 $LCTL set_param jobid_name=$FAKE_JOBID
12389                 JOBVAL=$FAKE_JOBID
12390         }
12391
12392         log "Test: ${cmd[*]}"
12393         log "Using JobID environment variable $JOBENV=$JOBVAL"
12394
12395         if [ $JOBENV = "FAKE_JOBID" ]; then
12396                 FAKE_JOBID=$JOBVAL ${cmd[*]}
12397         else
12398                 ${cmd[*]}
12399         fi
12400
12401         # all files are created on OST0000
12402         for facet in $facets; do
12403                 local stats="*.$(convert_facet2label $facet).job_stats"
12404                 if [ $(do_facet $facet lctl get_param $stats |
12405                        grep -c $JOBVAL) -ne 1 ]; then
12406                         do_facet $facet lctl get_param $stats
12407                         error "No jobstats for $JOBVAL found on $facet::$stats"
12408                 fi
12409         done
12410 }
12411
12412 jobstats_set() {
12413         trap 0
12414         NEW_JOBENV=${1:-$OLD_JOBENV}
12415         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
12416         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
12417 }
12418
12419 cleanup_205() {
12420         trap 0
12421         do_facet $SINGLEMDS \
12422                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
12423         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
12424         cleanup_changelog
12425 }
12426
12427 test_205() { # Job stats
12428         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.1) ]] ||
12429                 { skip "Need MDS version with at least 2.7.1"; return 0; }
12430
12431         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12432         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12433         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12434         remote_ost_nodsh && skip "remote OST with nodsh" && return
12435
12436         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
12437                 skip "Server doesn't support jobstats" && return 0
12438         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
12439
12440         OLD_JOBENV=$($LCTL get_param -n jobid_var)
12441         if [ $OLD_JOBENV != $JOBENV ]; then
12442                 jobstats_set $JOBENV
12443                 trap cleanup_205 EXIT
12444         fi
12445
12446         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
12447         echo "Registered as changelog user $CL_USER"
12448
12449         OLD_INTERVAL=$(do_facet $SINGLEMDS \
12450                        lctl get_param -n mdt.*.job_cleanup_interval)
12451         local interval_new=5
12452         do_facet $SINGLEMDS \
12453                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
12454         local start=$SECONDS
12455
12456         local cmd
12457         # mkdir
12458         cmd="mkdir $DIR/$tdir"
12459         verify_jobstats "$cmd" "$SINGLEMDS"
12460         # rmdir
12461         cmd="rmdir $DIR/$tdir"
12462         verify_jobstats "$cmd" "$SINGLEMDS"
12463         # mkdir on secondary MDT
12464         if [ $MDSCOUNT -gt 1 ]; then
12465                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
12466                 verify_jobstats "$cmd" "mds2"
12467         fi
12468         # mknod
12469         cmd="mknod $DIR/$tfile c 1 3"
12470         verify_jobstats "$cmd" "$SINGLEMDS"
12471         # unlink
12472         cmd="rm -f $DIR/$tfile"
12473         verify_jobstats "$cmd" "$SINGLEMDS"
12474         # create all files on OST0000 so verify_jobstats can find OST stats
12475         # open & close
12476         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
12477         verify_jobstats "$cmd" "$SINGLEMDS"
12478         # setattr
12479         cmd="touch $DIR/$tfile"
12480         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12481         # write
12482         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
12483         verify_jobstats "$cmd" "ost1"
12484         # read
12485         cancel_lru_locks osc
12486         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
12487         verify_jobstats "$cmd" "ost1"
12488         # truncate
12489         cmd="$TRUNCATE $DIR/$tfile 0"
12490         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12491         # rename
12492         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
12493         verify_jobstats "$cmd" "$SINGLEMDS"
12494         # jobstats expiry - sleep until old stats should be expired
12495         local left=$((interval_new + 5 - (SECONDS - start)))
12496         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
12497                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
12498                         "0" $left
12499         cmd="mkdir $DIR/$tdir.expire"
12500         verify_jobstats "$cmd" "$SINGLEMDS"
12501         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
12502             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
12503
12504         # Ensure that jobid are present in changelog (if supported by MDS)
12505         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
12506         then
12507                 $LFS changelog $MDT0 | tail -9
12508                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
12509                 [ $jobids -eq 9 ] ||
12510                         error "Wrong changelog jobid count $jobids != 9"
12511
12512                 # LU-5862
12513                 JOBENV="disable"
12514                 jobstats_set $JOBENV
12515                 touch $DIR/$tfile
12516                 $LFS changelog $MDT0 | tail -1
12517                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
12518                 [ $jobids -eq 0 ] ||
12519                         error "Unexpected jobids when jobid_var=$JOBENV"
12520         fi
12521
12522         cleanup_205
12523 }
12524 run_test 205 "Verify job stats"
12525
12526 # LU-1480, LU-1773 and LU-1657
12527 test_206() {
12528         mkdir -p $DIR/$tdir
12529         $SETSTRIPE -c -1 $DIR/$tdir
12530 #define OBD_FAIL_LOV_INIT 0x1403
12531         $LCTL set_param fail_loc=0xa0001403
12532         $LCTL set_param fail_val=1
12533         touch $DIR/$tdir/$tfile || true
12534 }
12535 run_test 206 "fail lov_init_raid0() doesn't lbug"
12536
12537 test_207a() {
12538         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12539         local fsz=`stat -c %s $DIR/$tfile`
12540         cancel_lru_locks mdc
12541
12542         # do not return layout in getattr intent
12543 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
12544         $LCTL set_param fail_loc=0x170
12545         local sz=`stat -c %s $DIR/$tfile`
12546
12547         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
12548
12549         rm -rf $DIR/$tfile
12550 }
12551 run_test 207a "can refresh layout at glimpse"
12552
12553 test_207b() {
12554         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12555         local cksum=`md5sum $DIR/$tfile`
12556         local fsz=`stat -c %s $DIR/$tfile`
12557         cancel_lru_locks mdc
12558         cancel_lru_locks osc
12559
12560         # do not return layout in getattr intent
12561 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
12562         $LCTL set_param fail_loc=0x171
12563
12564         # it will refresh layout after the file is opened but before read issues
12565         echo checksum is "$cksum"
12566         echo "$cksum" |md5sum -c --quiet || error "file differs"
12567
12568         rm -rf $DIR/$tfile
12569 }
12570 run_test 207b "can refresh layout at open"
12571
12572 test_208() {
12573         # FIXME: in this test suite, only RD lease is used. This is okay
12574         # for now as only exclusive open is supported. After generic lease
12575         # is done, this test suite should be revised. - Jinshan
12576
12577         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12578         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
12579                 { skip "Need MDS version at least 2.4.52"; return 0; }
12580
12581         echo "==== test 1: verify get lease work"
12582         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
12583
12584         echo "==== test 2: verify lease can be broken by upcoming open"
12585         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12586         local PID=$!
12587         sleep 1
12588
12589         $MULTIOP $DIR/$tfile oO_RDONLY:c
12590         kill -USR1 $PID && wait $PID || error "break lease error"
12591
12592         echo "==== test 3: verify lease can't be granted if an open already exists"
12593         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
12594         local PID=$!
12595         sleep 1
12596
12597         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
12598         kill -USR1 $PID && wait $PID || error "open file error"
12599
12600         echo "==== test 4: lease can sustain over recovery"
12601         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
12602         PID=$!
12603         sleep 1
12604
12605         fail mds1
12606
12607         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
12608
12609         echo "==== test 5: lease broken can't be regained by replay"
12610         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12611         PID=$!
12612         sleep 1
12613
12614         # open file to break lease and then recovery
12615         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
12616         fail mds1
12617
12618         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
12619
12620         rm -f $DIR/$tfile
12621 }
12622 run_test 208 "Exclusive open"
12623
12624 test_209() {
12625         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
12626                 skip_env "must have disp_stripe" && return
12627
12628         touch $DIR/$tfile
12629         sync; sleep 5; sync;
12630
12631         echo 3 > /proc/sys/vm/drop_caches
12632         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12633
12634         # open/close 500 times
12635         for i in $(seq 500); do
12636                 cat $DIR/$tfile
12637         done
12638
12639         echo 3 > /proc/sys/vm/drop_caches
12640         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12641
12642         echo "before: $req_before, after: $req_after"
12643         [ $((req_after - req_before)) -ge 300 ] &&
12644                 error "open/close requests are not freed"
12645         return 0
12646 }
12647 run_test 209 "read-only open/close requests should be freed promptly"
12648
12649 test_212() {
12650         size=`date +%s`
12651         size=$((size % 8192 + 1))
12652         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
12653         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
12654         rm -f $DIR/f212 $DIR/f212.xyz
12655 }
12656 run_test 212 "Sendfile test ============================================"
12657
12658 test_213() {
12659         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
12660         cancel_lru_locks osc
12661         lctl set_param fail_loc=0x8000040f
12662         # generate a read lock
12663         cat $DIR/$tfile > /dev/null
12664         # write to the file, it will try to cancel the above read lock.
12665         cat /etc/hosts >> $DIR/$tfile
12666 }
12667 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
12668
12669 test_214() { # for bug 20133
12670         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
12671         for (( i=0; i < 340; i++ )) ; do
12672                 touch $DIR/$tdir/d214c/a$i
12673         done
12674
12675         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
12676         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
12677         ls $DIR/d214c || error "ls $DIR/d214c failed"
12678         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
12679         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
12680 }
12681 run_test 214 "hash-indexed directory test - bug 20133"
12682
12683 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
12684 create_lnet_proc_files() {
12685         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
12686         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
12687
12688         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
12689         rm -f "$TMP/lnet_$1.sys_tmp"
12690 }
12691
12692 # counterpart of create_lnet_proc_files
12693 remove_lnet_proc_files() {
12694         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
12695 }
12696
12697 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12698 # 3rd arg as regexp for body
12699 check_lnet_proc_stats() {
12700         local l=$(cat "$TMP/lnet_$1" |wc -l)
12701         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
12702
12703         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
12704 }
12705
12706 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12707 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
12708 # optional and can be regexp for 2nd line (lnet.routes case)
12709 check_lnet_proc_entry() {
12710         local blp=2          # blp stands for 'position of 1st line of body'
12711         [ -z "$5" ] || blp=3 # lnet.routes case
12712
12713         local l=$(cat "$TMP/lnet_$1" |wc -l)
12714         # subtracting one from $blp because the body can be empty
12715         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
12716
12717         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
12718                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
12719
12720         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
12721                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
12722
12723         # bail out if any unexpected line happened
12724         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
12725         [ "$?" != 0 ] || error "$2 misformatted"
12726 }
12727
12728 test_215() { # for bugs 18102, 21079, 21517
12729         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12730         local N='(0|[1-9][0-9]*)'       # non-negative numeric
12731         local P='[1-9][0-9]*'           # positive numeric
12732         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
12733         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
12734         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
12735         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
12736
12737         local L1 # regexp for 1st line
12738         local L2 # regexp for 2nd line (optional)
12739         local BR # regexp for the rest (body)
12740
12741         # lnet.stats should look as 11 space-separated non-negative numerics
12742         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
12743         create_lnet_proc_files "stats"
12744         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
12745         remove_lnet_proc_files "stats"
12746
12747         # lnet.routes should look like this:
12748         # Routing disabled/enabled
12749         # net hops priority state router
12750         # where net is a string like tcp0, hops > 0, priority >= 0,
12751         # state is up/down,
12752         # router is a string like 192.168.1.1@tcp2
12753         L1="^Routing (disabled|enabled)$"
12754         L2="^net +hops +priority +state +router$"
12755         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
12756         create_lnet_proc_files "routes"
12757         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
12758         remove_lnet_proc_files "routes"
12759
12760         # lnet.routers should look like this:
12761         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
12762         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
12763         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
12764         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
12765         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
12766         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
12767         create_lnet_proc_files "routers"
12768         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
12769         remove_lnet_proc_files "routers"
12770
12771         # lnet.peers should look like this:
12772         # nid refs state last max rtr min tx min queue
12773         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
12774         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
12775         # numeric (0 or >0 or <0), queue >= 0.
12776         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
12777         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
12778         create_lnet_proc_files "peers"
12779         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
12780         remove_lnet_proc_files "peers"
12781
12782         # lnet.buffers  should look like this:
12783         # pages count credits min
12784         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
12785         L1="^pages +count +credits +min$"
12786         BR="^ +$N +$N +$I +$I$"
12787         create_lnet_proc_files "buffers"
12788         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
12789         remove_lnet_proc_files "buffers"
12790
12791         # lnet.nis should look like this:
12792         # nid status alive refs peer rtr max tx min
12793         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
12794         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
12795         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
12796         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
12797         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
12798         create_lnet_proc_files "nis"
12799         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
12800         remove_lnet_proc_files "nis"
12801
12802         # can we successfully write to lnet.stats?
12803         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
12804         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
12805 }
12806 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
12807
12808 test_216() { # bug 20317
12809         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12810         remote_ost_nodsh && skip "remote OST with nodsh" && return
12811
12812         local node
12813         local facets=$(get_facets OST)
12814         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
12815
12816         save_lustre_params client "osc.*.contention_seconds" > $p
12817         save_lustre_params $facets \
12818                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
12819         save_lustre_params $facets \
12820                 "ldlm.namespaces.filter-*.contended_locks" >> $p
12821         save_lustre_params $facets \
12822                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
12823         clear_stats osc.*.osc_stats
12824
12825         # agressive lockless i/o settings
12826         do_nodes $(comma_list $(osts_nodes)) \
12827                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
12828                         ldlm.namespaces.filter-*.contended_locks=0 \
12829                         ldlm.namespaces.filter-*.contention_seconds=60"
12830         lctl set_param -n osc.*.contention_seconds=60
12831
12832         $DIRECTIO write $DIR/$tfile 0 10 4096
12833         $CHECKSTAT -s 40960 $DIR/$tfile
12834
12835         # disable lockless i/o
12836         do_nodes $(comma_list $(osts_nodes)) \
12837                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
12838                         ldlm.namespaces.filter-*.contended_locks=32 \
12839                         ldlm.namespaces.filter-*.contention_seconds=0"
12840         lctl set_param -n osc.*.contention_seconds=0
12841         clear_stats osc.*.osc_stats
12842
12843         dd if=/dev/zero of=$DIR/$tfile count=0
12844         $CHECKSTAT -s 0 $DIR/$tfile
12845
12846         restore_lustre_params <$p
12847         rm -f $p
12848         rm $DIR/$tfile
12849 }
12850 run_test 216 "check lockless direct write updates file size and kms correctly"
12851
12852 test_217() { # bug 22430
12853         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12854         local node
12855         local nid
12856
12857         for node in $(nodes_list); do
12858                 nid=$(host_nids_address $node $NETTYPE)
12859                 if [[ $nid = *-* ]] ; then
12860                         echo "lctl ping $(h2nettype $nid)"
12861                         lctl ping $(h2nettype $nid)
12862                 else
12863                         echo "skipping $node (no hyphen detected)"
12864                 fi
12865         done
12866 }
12867 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
12868
12869 test_218() {
12870        # do directio so as not to populate the page cache
12871        log "creating a 10 Mb file"
12872        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12873        log "starting reads"
12874        dd if=$DIR/$tfile of=/dev/null bs=4096 &
12875        log "truncating the file"
12876        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12877        log "killing dd"
12878        kill %+ || true # reads might have finished
12879        echo "wait until dd is finished"
12880        wait
12881        log "removing the temporary file"
12882        rm -rf $DIR/$tfile || error "tmp file removal failed"
12883 }
12884 run_test 218 "parallel read and truncate should not deadlock ======================="
12885
12886 test_219() {
12887         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12888         # write one partial page
12889         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
12890         # set no grant so vvp_io_commit_write will do sync write
12891         $LCTL set_param fail_loc=0x411
12892         # write a full page at the end of file
12893         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
12894
12895         $LCTL set_param fail_loc=0
12896         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
12897         $LCTL set_param fail_loc=0x411
12898         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
12899
12900         # LU-4201
12901         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
12902         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
12903 }
12904 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
12905
12906 test_220() { #LU-325
12907         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12908         remote_ost_nodsh && skip "remote OST with nodsh" && return
12909         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12910         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12911         local OSTIDX=0
12912
12913         # create on MDT0000 so the last_id and next_id are correct
12914         mkdir $DIR/$tdir
12915         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
12916         OST=${OST%_UUID}
12917
12918         # on the mdt's osc
12919         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
12920         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
12921                         osc.$mdtosc_proc1.prealloc_last_id)
12922         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
12923                         osc.$mdtosc_proc1.prealloc_next_id)
12924
12925         $LFS df -i
12926
12927         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
12928         #define OBD_FAIL_OST_ENOINO              0x229
12929         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
12930         create_pool $FSNAME.$TESTNAME || return 1
12931         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
12932
12933         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
12934
12935         MDSOBJS=$((last_id - next_id))
12936         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
12937
12938         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
12939         echo "OST still has $count kbytes free"
12940
12941         echo "create $MDSOBJS files @next_id..."
12942         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
12943
12944         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12945                         osc.$mdtosc_proc1.prealloc_last_id)
12946         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12947                         osc.$mdtosc_proc1.prealloc_next_id)
12948
12949         echo "after creation, last_id=$last_id2, next_id=$next_id2"
12950         $LFS df -i
12951
12952         echo "cleanup..."
12953
12954         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
12955         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
12956
12957         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
12958         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
12959         echo "unlink $MDSOBJS files @$next_id..."
12960         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
12961 }
12962 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
12963
12964 test_221() {
12965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12966         dd if=`which date` of=$MOUNT/date oflag=sync
12967         chmod +x $MOUNT/date
12968
12969         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
12970         $LCTL set_param fail_loc=0x80001401
12971
12972         $MOUNT/date > /dev/null
12973         rm -f $MOUNT/date
12974 }
12975 run_test 221 "make sure fault and truncate race to not cause OOM"
12976
12977 test_222a () {
12978         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12979        rm -rf $DIR/$tdir
12980        test_mkdir -p $DIR/$tdir
12981        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12982        createmany -o $DIR/$tdir/$tfile 10
12983        cancel_lru_locks mdc
12984        cancel_lru_locks osc
12985        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12986        $LCTL set_param fail_loc=0x31a
12987        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
12988        $LCTL set_param fail_loc=0
12989        rm -r $DIR/$tdir
12990 }
12991 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
12992
12993 test_222b () {
12994         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12995         rm -rf $DIR/$tdir
12996         test_mkdir -p $DIR/$tdir
12997         $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12998         createmany -o $DIR/$tdir/$tfile 10
12999         cancel_lru_locks mdc
13000         cancel_lru_locks osc
13001         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
13002         $LCTL set_param fail_loc=0x31a
13003         rm -r $DIR/$tdir || error "AGL for rmdir failed"
13004         $LCTL set_param fail_loc=0
13005 }
13006 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
13007
13008 test_223 () {
13009         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13010        rm -rf $DIR/$tdir
13011        test_mkdir -p $DIR/$tdir
13012        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
13013        createmany -o $DIR/$tdir/$tfile 10
13014        cancel_lru_locks mdc
13015        cancel_lru_locks osc
13016        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
13017        $LCTL set_param fail_loc=0x31b
13018        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
13019        $LCTL set_param fail_loc=0
13020        rm -r $DIR/$tdir
13021 }
13022 run_test 223 "osc reenqueue if without AGL lock granted ======================="
13023
13024 test_224a() { # LU-1039, MRP-303
13025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13026         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
13027         $LCTL set_param fail_loc=0x508
13028         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
13029         $LCTL set_param fail_loc=0
13030         df $DIR
13031 }
13032 run_test 224a "Don't panic on bulk IO failure"
13033
13034 test_224b() { # LU-1039, MRP-303
13035         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13036         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
13037         cancel_lru_locks osc
13038         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
13039         $LCTL set_param fail_loc=0x515
13040         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
13041         $LCTL set_param fail_loc=0
13042         df $DIR
13043 }
13044 run_test 224b "Don't panic on bulk IO failure"
13045
13046 test_224c() { # LU-6441
13047         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13048         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13049
13050         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13051         save_writethrough $p
13052         set_cache writethrough on
13053
13054         local pages_per_rpc=$($LCTL get_param \
13055                                 osc.*.max_pages_per_rpc)
13056         local at_max=$($LCTL get_param -n at_max)
13057         local timeout=$($LCTL get_param -n timeout)
13058         local test_at="$LCTL get_param -n at_max"
13059         local param_at="$FSNAME.sys.at_max"
13060         local test_timeout="$LCTL get_param -n timeout"
13061         local param_timeout="$FSNAME.sys.timeout"
13062
13063         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
13064
13065         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
13066                 error "conf_param at_max=0 failed"
13067         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
13068                 error "conf_param timeout=5 failed"
13069
13070         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
13071         do_facet ost1 $LCTL set_param fail_loc=0x520
13072         $LFS setstripe -c 1 -i 0 $DIR/$tfile
13073         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
13074         sync
13075         do_facet ost1 $LCTL set_param fail_loc=0
13076
13077         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
13078                 error "conf_param at_max=$at_max failed"
13079         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
13080                 $timeout || error "conf_param timeout=$timeout failed"
13081
13082         $LCTL set_param -n $pages_per_rpc
13083         restore_lustre_params < $p
13084         rm -f $p
13085 }
13086 run_test 224c "Don't hang if one of md lost during large bulk RPC"
13087
13088 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
13089 test_225a () {
13090         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13091         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13092         if [ -z ${MDSSURVEY} ]; then
13093               skip_env "mds-survey not found" && return
13094         fi
13095
13096         [ $MDSCOUNT -ge 2 ] &&
13097                 skip "skipping now for more than one MDT" && return
13098
13099        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13100             { skip "Need MDS version at least 2.2.51"; return; }
13101
13102        local mds=$(facet_host $SINGLEMDS)
13103        local target=$(do_nodes $mds 'lctl dl' | \
13104                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13105
13106        local cmd1="file_count=1000 thrhi=4"
13107        local cmd2="dir_count=2 layer=mdd stripe_count=0"
13108        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13109        local cmd="$cmd1 $cmd2 $cmd3"
13110
13111        rm -f ${TMP}/mds_survey*
13112        echo + $cmd
13113        eval $cmd || error "mds-survey with zero-stripe failed"
13114        cat ${TMP}/mds_survey*
13115        rm -f ${TMP}/mds_survey*
13116 }
13117 run_test 225a "Metadata survey sanity with zero-stripe"
13118
13119 test_225b () {
13120         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13121         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13122         if [ -z ${MDSSURVEY} ]; then
13123               skip_env "mds-survey not found" && return
13124         fi
13125         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13126             { skip "Need MDS version at least 2.2.51"; return; }
13127
13128         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
13129               skip_env "Need to mount OST to test" && return
13130         fi
13131
13132         [ $MDSCOUNT -ge 2 ] &&
13133                 skip "skipping now for more than one MDT" && return
13134        local mds=$(facet_host $SINGLEMDS)
13135        local target=$(do_nodes $mds 'lctl dl' | \
13136                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13137
13138        local cmd1="file_count=1000 thrhi=4"
13139        local cmd2="dir_count=2 layer=mdd stripe_count=1"
13140        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13141        local cmd="$cmd1 $cmd2 $cmd3"
13142
13143        rm -f ${TMP}/mds_survey*
13144        echo + $cmd
13145        eval $cmd || error "mds-survey with stripe_count failed"
13146        cat ${TMP}/mds_survey*
13147        rm -f ${TMP}/mds_survey*
13148 }
13149 run_test 225b "Metadata survey sanity with stripe_count = 1"
13150
13151 mcreate_path2fid () {
13152         local mode=$1
13153         local major=$2
13154         local minor=$3
13155         local name=$4
13156         local desc=$5
13157         local path=$DIR/$tdir/$name
13158         local fid
13159         local rc
13160         local fid_path
13161
13162         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
13163                 error "cannot create $desc"
13164
13165         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
13166         rc=$?
13167         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
13168
13169         fid_path=$($LFS fid2path $MOUNT $fid)
13170         rc=$?
13171         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
13172
13173         [ "$path" == "$fid_path" ] ||
13174                 error "fid2path returned $fid_path, expected $path"
13175
13176         echo "pass with $path and $fid"
13177 }
13178
13179 test_226a () {
13180         rm -rf $DIR/$tdir
13181         mkdir -p $DIR/$tdir
13182
13183         mcreate_path2fid 0010666 0 0 fifo "FIFO"
13184         mcreate_path2fid 0020666 1 3 null "character special file (null)"
13185         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
13186         mcreate_path2fid 0040666 0 0 dir "directory"
13187         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
13188         mcreate_path2fid 0100666 0 0 file "regular file"
13189         mcreate_path2fid 0120666 0 0 link "symbolic link"
13190         mcreate_path2fid 0140666 0 0 sock "socket"
13191 }
13192 run_test 226a "call path2fid and fid2path on files of all type"
13193
13194 test_226b () {
13195         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13196         rm -rf $DIR/$tdir
13197         local MDTIDX=1
13198
13199         mkdir -p $DIR/$tdir
13200         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
13201                 error "create remote directory failed"
13202         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
13203         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
13204                                 "character special file (null)"
13205         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
13206                                 "character special file (no device)"
13207         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
13208         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
13209                                 "block special file (loop)"
13210         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
13211         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
13212         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
13213 }
13214 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
13215
13216 # LU-1299 Executing or running ldd on a truncated executable does not
13217 # cause an out-of-memory condition.
13218 test_227() {
13219         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13220         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
13221         dd if=$(which date) of=$MOUNT/date bs=1k count=1
13222         chmod +x $MOUNT/date
13223
13224         $MOUNT/date > /dev/null
13225         ldd $MOUNT/date > /dev/null
13226         rm -f $MOUNT/date
13227 }
13228 run_test 227 "running truncated executable does not cause OOM"
13229
13230 # LU-1512 try to reuse idle OI blocks
13231 test_228a() {
13232         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13233         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13234         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13235                 skip "ldiskfs only test" && return
13236
13237         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13238         local myDIR=$DIR/$tdir
13239
13240         mkdir -p $myDIR
13241         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13242         $LCTL set_param fail_loc=0x80001002
13243         createmany -o $myDIR/t- 10000
13244         $LCTL set_param fail_loc=0
13245         # The guard is current the largest FID holder
13246         touch $myDIR/guard
13247         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13248                     tr -d '[')
13249         local IDX=$(($SEQ % 64))
13250
13251         do_facet $SINGLEMDS sync
13252         # Make sure journal flushed.
13253         sleep 6
13254         local blk1=$(do_facet $SINGLEMDS \
13255                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13256                      grep Blockcount | awk '{print $4}')
13257
13258         # Remove old files, some OI blocks will become idle.
13259         unlinkmany $myDIR/t- 10000
13260         # Create new files, idle OI blocks should be reused.
13261         createmany -o $myDIR/t- 2000
13262         do_facet $SINGLEMDS sync
13263         # Make sure journal flushed.
13264         sleep 6
13265         local blk2=$(do_facet $SINGLEMDS \
13266                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13267                      grep Blockcount | awk '{print $4}')
13268
13269         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13270 }
13271 run_test 228a "try to reuse idle OI blocks"
13272
13273 test_228b() {
13274         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13275         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13276         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13277                 skip "ldiskfs only test" && return
13278
13279         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13280         local myDIR=$DIR/$tdir
13281
13282         mkdir -p $myDIR
13283         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13284         $LCTL set_param fail_loc=0x80001002
13285         createmany -o $myDIR/t- 10000
13286         $LCTL set_param fail_loc=0
13287         # The guard is current the largest FID holder
13288         touch $myDIR/guard
13289         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13290                     tr -d '[')
13291         local IDX=$(($SEQ % 64))
13292
13293         do_facet $SINGLEMDS sync
13294         # Make sure journal flushed.
13295         sleep 6
13296         local blk1=$(do_facet $SINGLEMDS \
13297                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13298                      grep Blockcount | awk '{print $4}')
13299
13300         # Remove old files, some OI blocks will become idle.
13301         unlinkmany $myDIR/t- 10000
13302
13303         # stop the MDT
13304         stop $SINGLEMDS || error "Fail to stop MDT."
13305         # remount the MDT
13306         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
13307
13308         df $MOUNT || error "Fail to df."
13309         # Create new files, idle OI blocks should be reused.
13310         createmany -o $myDIR/t- 2000
13311         do_facet $SINGLEMDS sync
13312         # Make sure journal flushed.
13313         sleep 6
13314         local blk2=$(do_facet $SINGLEMDS \
13315                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13316                      grep Blockcount | awk '{print $4}')
13317
13318         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13319 }
13320 run_test 228b "idle OI blocks can be reused after MDT restart"
13321
13322 #LU-1881
13323 test_228c() {
13324         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13325         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13326         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13327                 skip "ldiskfs only test" && return
13328
13329         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13330         local myDIR=$DIR/$tdir
13331
13332         mkdir -p $myDIR
13333         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13334         $LCTL set_param fail_loc=0x80001002
13335         # 20000 files can guarantee there are index nodes in the OI file
13336         createmany -o $myDIR/t- 20000
13337         $LCTL set_param fail_loc=0
13338         # The guard is current the largest FID holder
13339         touch $myDIR/guard
13340         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13341                     tr -d '[')
13342         local IDX=$(($SEQ % 64))
13343
13344         do_facet $SINGLEMDS sync
13345         # Make sure journal flushed.
13346         sleep 6
13347         local blk1=$(do_facet $SINGLEMDS \
13348                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13349                      grep Blockcount | awk '{print $4}')
13350
13351         # Remove old files, some OI blocks will become idle.
13352         unlinkmany $myDIR/t- 20000
13353         rm -f $myDIR/guard
13354         # The OI file should become empty now
13355
13356         # Create new files, idle OI blocks should be reused.
13357         createmany -o $myDIR/t- 2000
13358         do_facet $SINGLEMDS sync
13359         # Make sure journal flushed.
13360         sleep 6
13361         local blk2=$(do_facet $SINGLEMDS \
13362                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13363                      grep Blockcount | awk '{print $4}')
13364
13365         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13366 }
13367 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
13368
13369 test_229() { # LU-2482, LU-3448
13370         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
13371                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
13372                 return
13373         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13374         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
13375
13376         rm -f $DIR/$tfile
13377
13378         # Create a file with a released layout and stripe count 2.
13379         $MULTIOP $DIR/$tfile H2c ||
13380                 error "failed to create file with released layout"
13381
13382         $GETSTRIPE -v $DIR/$tfile
13383
13384         local pattern=$($GETSTRIPE -L $DIR/$tfile)
13385         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
13386
13387         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
13388         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
13389         stat $DIR/$tfile || error "failed to stat released file"
13390
13391         chown $RUNAS_ID $DIR/$tfile ||
13392                 error "chown $RUNAS_ID $DIR/$tfile failed"
13393
13394         chgrp $RUNAS_ID $DIR/$tfile ||
13395                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
13396
13397         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
13398         rm $DIR/$tfile || error "failed to remove released file"
13399 }
13400 run_test 229 "getstripe/stat/rm/attr changes work on released files"
13401
13402 test_230a() {
13403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13404         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13405         local MDTIDX=1
13406
13407         test_mkdir $DIR/$tdir
13408         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
13409         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
13410         [ $mdt_idx -ne 0 ] &&
13411                 error "create local directory on wrong MDT $mdt_idx"
13412
13413         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
13414                         error "create remote directory failed"
13415         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
13416         [ $mdt_idx -ne $MDTIDX ] &&
13417                 error "create remote directory on wrong MDT $mdt_idx"
13418
13419         createmany -o $DIR/$tdir/test_230/t- 10 ||
13420                 error "create files on remote directory failed"
13421         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
13422         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
13423         rm -r $DIR/$tdir || error "unlink remote directory failed"
13424 }
13425 run_test 230a "Create remote directory and files under the remote directory"
13426
13427 test_230b() {
13428         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13429         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13430         local MDTIDX=1
13431         local mdt_index
13432         local i
13433         local file
13434         local pid
13435         local stripe_count
13436         local migrate_dir=$DIR/$tdir/migrate_dir
13437         local other_dir=$DIR/$tdir/other_dir
13438
13439         test_mkdir $DIR/$tdir
13440         test_mkdir -i0 -c1 $migrate_dir
13441         test_mkdir -i0 -c1 $other_dir
13442         for ((i=0; i<10; i++)); do
13443                 mkdir -p $migrate_dir/dir_${i}
13444                 createmany -o $migrate_dir/dir_${i}/f 10 ||
13445                         error "create files under remote dir failed $i"
13446         done
13447
13448         cp /etc/passwd $migrate_dir/$tfile
13449         cp /etc/passwd $other_dir/$tfile
13450         chattr +SAD $migrate_dir
13451         chattr +SAD $migrate_dir/$tfile
13452
13453         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13454         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13455         local old_dir_mode=$(stat -c%f $migrate_dir)
13456         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
13457
13458         mkdir -p $migrate_dir/dir_default_stripe2
13459         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
13460         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
13461
13462         mkdir -p $other_dir
13463         ln $migrate_dir/$tfile $other_dir/luna
13464         ln $migrate_dir/$tfile $migrate_dir/sofia
13465         ln $other_dir/$tfile $migrate_dir/david
13466         ln -s $migrate_dir/$tfile $other_dir/zachary
13467         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
13468         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
13469
13470         $LFS migrate -m $MDTIDX $migrate_dir ||
13471                 error "fails on migrating remote dir to MDT1"
13472
13473         echo "migratate to MDT1, then checking.."
13474         for ((i = 0; i < 10; i++)); do
13475                 for file in $(find $migrate_dir/dir_${i}); do
13476                         mdt_index=$($LFS getstripe -M $file)
13477                         [ $mdt_index == $MDTIDX ] ||
13478                                 error "$file is not on MDT${MDTIDX}"
13479                 done
13480         done
13481
13482         # the multiple link file should still in MDT0
13483         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
13484         [ $mdt_index == 0 ] ||
13485                 error "$file is not on MDT${MDTIDX}"
13486
13487         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13488         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13489                 error " expect $old_dir_flag get $new_dir_flag"
13490
13491         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13492         [ "$old_file_flag" = "$new_file_flag" ] ||
13493                 error " expect $old_file_flag get $new_file_flag"
13494
13495         local new_dir_mode=$(stat -c%f $migrate_dir)
13496         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13497                 error "expect mode $old_dir_mode get $new_dir_mode"
13498
13499         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13500         [ "$old_file_mode" = "$new_file_mode" ] ||
13501                 error "expect mode $old_file_mode get $new_file_mode"
13502
13503         diff /etc/passwd $migrate_dir/$tfile ||
13504                 error "$tfile different after migration"
13505
13506         diff /etc/passwd $other_dir/luna ||
13507                 error "luna different after migration"
13508
13509         diff /etc/passwd $migrate_dir/sofia ||
13510                 error "sofia different after migration"
13511
13512         diff /etc/passwd $migrate_dir/david ||
13513                 error "david different after migration"
13514
13515         diff /etc/passwd $other_dir/zachary ||
13516                 error "zachary different after migration"
13517
13518         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13519                 error "${tfile}_ln different after migration"
13520
13521         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13522                 error "${tfile}_ln_other different after migration"
13523
13524         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
13525         [ $stripe_count = 2 ] ||
13526                 error "dir strpe_count $d != 2 after migration."
13527
13528         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
13529         [ $stripe_count = 2 ] ||
13530                 error "file strpe_count $d != 2 after migration."
13531
13532         #migrate back to MDT0
13533         MDTIDX=0
13534
13535         $LFS migrate -m $MDTIDX $migrate_dir ||
13536                 error "fails on migrating remote dir to MDT0"
13537
13538         echo "migrate back to MDT0, checking.."
13539         for file in $(find $migrate_dir); do
13540                 mdt_index=$($LFS getstripe -M $file)
13541                 [ $mdt_index == $MDTIDX ] ||
13542                         error "$file is not on MDT${MDTIDX}"
13543         done
13544
13545         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13546         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13547                 error " expect $old_dir_flag get $new_dir_flag"
13548
13549         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13550         [ "$old_file_flag" = "$new_file_flag" ] ||
13551                 error " expect $old_file_flag get $new_file_flag"
13552
13553         local new_dir_mode=$(stat -c%f $migrate_dir)
13554         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13555                 error "expect mode $old_dir_mode get $new_dir_mode"
13556
13557         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13558         [ "$old_file_mode" = "$new_file_mode" ] ||
13559                 error "expect mode $old_file_mode get $new_file_mode"
13560
13561         diff /etc/passwd ${migrate_dir}/$tfile ||
13562                 error "$tfile different after migration"
13563
13564         diff /etc/passwd ${other_dir}/luna ||
13565                 error "luna different after migration"
13566
13567         diff /etc/passwd ${migrate_dir}/sofia ||
13568                 error "sofia different after migration"
13569
13570         diff /etc/passwd ${other_dir}/zachary ||
13571                 error "zachary different after migration"
13572
13573         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13574                 error "${tfile}_ln different after migration"
13575
13576         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13577                 error "${tfile}_ln_other different after migration"
13578
13579         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
13580         [ $stripe_count = 2 ] ||
13581                 error "dir strpe_count $d != 2 after migration."
13582
13583         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
13584         [ $stripe_count = 2 ] ||
13585                 error "file strpe_count $d != 2 after migration."
13586
13587         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13588 }
13589 run_test 230b "migrate directory"
13590
13591 test_230c() {
13592         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13593         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13594         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13595         local MDTIDX=1
13596         local mdt_index
13597         local file
13598         local migrate_dir=$DIR/$tdir/migrate_dir
13599
13600         #If migrating directory fails in the middle, all entries of
13601         #the directory is still accessiable.
13602         test_mkdir $DIR/$tdir
13603         test_mkdir -i0 -c1 $migrate_dir
13604         stat $migrate_dir
13605         createmany -o $migrate_dir/f 10 ||
13606                 error "create files under ${migrate_dir} failed"
13607
13608         #failed after migrating 5 entries
13609         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
13610         do_facet mds1 lctl set_param fail_loc=0x20001801
13611         do_facet mds1 lctl  set_param fail_val=5
13612         local t=$(ls $migrate_dir | wc -l)
13613         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
13614                 error "migrate should fail after 5 entries"
13615
13616         mkdir $migrate_dir/dir &&
13617                 error "mkdir succeeds under migrating directory"
13618         touch $migrate_dir/file &&
13619                 error "touch file succeeds under migrating directory"
13620
13621         local u=$(ls $migrate_dir | wc -l)
13622         [ "$u" == "$t" ] || error "$u != $t during migration"
13623
13624         for file in $(find $migrate_dir); do
13625                 stat $file || error "stat $file failed"
13626         done
13627
13628         do_facet mds1 lctl set_param fail_loc=0
13629         do_facet mds1 lctl set_param fail_val=0
13630
13631         $LFS migrate -m $MDTIDX $migrate_dir ||
13632                 error "migrate open files should failed with open files"
13633
13634         echo "Finish migration, then checking.."
13635         for file in $(find $migrate_dir); do
13636                 mdt_index=$($LFS getstripe -M $file)
13637                 [ $mdt_index == $MDTIDX ] ||
13638                         error "$file is not on MDT${MDTIDX}"
13639         done
13640
13641         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13642 }
13643 run_test 230c "check directory accessiblity if migration is failed"
13644
13645 test_230d() {
13646         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13647         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13648         local MDTIDX=1
13649         local mdt_index
13650         local migrate_dir=$DIR/$tdir/migrate_dir
13651         local i
13652         local j
13653
13654         test_mkdir $DIR/$tdir
13655         test_mkdir -i0 -c1 $migrate_dir
13656
13657         for ((i=0; i<100; i++)); do
13658                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
13659                 createmany -o $migrate_dir/dir_${i}/f 100 ||
13660                         error "create files under remote dir failed $i"
13661         done
13662
13663         $LFS migrate -m $MDTIDX $migrate_dir ||
13664                 error "migrate remote dir error"
13665
13666         echo "Finish migration, then checking.."
13667         for file in $(find $migrate_dir); do
13668                 mdt_index=$($LFS getstripe -M $file)
13669                 [ $mdt_index == $MDTIDX ] ||
13670                         error "$file is not on MDT${MDTIDX}"
13671         done
13672
13673         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13674 }
13675 run_test 230d "check migrate big directory"
13676
13677 test_230e() {
13678         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13679         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13680         local i
13681         local j
13682         local a_fid
13683         local b_fid
13684
13685         mkdir -p $DIR/$tdir
13686         mkdir $DIR/$tdir/migrate_dir
13687         mkdir $DIR/$tdir/other_dir
13688         touch $DIR/$tdir/migrate_dir/a
13689         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
13690         ls $DIR/$tdir/other_dir
13691
13692         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13693                 error "migrate dir fails"
13694
13695         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13696         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13697
13698         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13699         [ $mdt_index == 0 ] || error "a is not on MDT0"
13700
13701         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
13702                 error "migrate dir fails"
13703
13704         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
13705         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
13706
13707         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13708         [ $mdt_index == 1 ] || error "a is not on MDT1"
13709
13710         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
13711         [ $mdt_index == 1 ] || error "b is not on MDT1"
13712
13713         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13714         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
13715
13716         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
13717
13718         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13719 }
13720 run_test 230e "migrate mulitple local link files"
13721
13722 test_230f() {
13723         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13724         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13725         local a_fid
13726         local ln_fid
13727
13728         mkdir -p $DIR/$tdir
13729         mkdir $DIR/$tdir/migrate_dir
13730         $LFS mkdir -i1 $DIR/$tdir/other_dir
13731         touch $DIR/$tdir/migrate_dir/a
13732         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
13733         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
13734         ls $DIR/$tdir/other_dir
13735
13736         # a should be migrated to MDT1, since no other links on MDT0
13737         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13738                 error "#1 migrate dir fails"
13739         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13740         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13741         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13742         [ $mdt_index == 1 ] || error "a is not on MDT1"
13743
13744         # a should stay on MDT1, because it is a mulitple link file
13745         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13746                 error "#2 migrate dir fails"
13747         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13748         [ $mdt_index == 1 ] || error "a is not on MDT1"
13749
13750         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13751                 error "#3 migrate dir fails"
13752
13753         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13754         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
13755         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
13756
13757         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
13758         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
13759
13760         # a should be migrated to MDT0, since no other links on MDT1
13761         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13762                 error "#4 migrate dir fails"
13763         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13764         [ $mdt_index == 0 ] || error "a is not on MDT0"
13765
13766         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13767 }
13768 run_test 230f "migrate mulitple remote link files"
13769
13770 test_230g() {
13771         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13772         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13773
13774         mkdir -p $DIR/$tdir/migrate_dir
13775
13776         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
13777                 error "migrating dir to non-exist MDT succeeds"
13778         true
13779 }
13780 run_test 230g "migrate dir to non-exist MDT"
13781
13782 test_230h() {
13783         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13784         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13785         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
13786                 skip "Need MDS version at least 2.7.64" && return
13787         local mdt_index
13788
13789         mkdir -p $DIR/$tdir/migrate_dir
13790
13791         $LFS migrate -m1 $DIR &&
13792                 error "migrating mountpoint1 should fail"
13793
13794         $LFS migrate -m1 $DIR/$tdir/.. &&
13795                 error "migrating mountpoint2 should fail"
13796
13797         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
13798                 error "migrating $tdir fail"
13799
13800         mdt_index=$($LFS getstripe -M $DIR/$tdir)
13801         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13802
13803         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13804         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13805
13806 }
13807 run_test 230h "migrate .. and root"
13808
13809 test_230i() {
13810         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13811         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13812
13813         mkdir -p $DIR/$tdir/migrate_dir
13814
13815         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
13816                 error "migration fails with a tailing slash"
13817
13818         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
13819                 error "migration fails with two tailing slashes"
13820 }
13821 run_test 230i "lfs migrate -m tolerates trailing slashes"
13822
13823 test_231a()
13824 {
13825         # For simplicity this test assumes that max_pages_per_rpc
13826         # is the same across all OSCs
13827         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
13828         local bulk_size=$((max_pages * 4096))
13829         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
13830                                        head -n 1)
13831
13832         mkdir -p $DIR/$tdir
13833         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
13834                 error "failed to set stripe with -S ${brw_size}M option"
13835
13836         # clear the OSC stats
13837         $LCTL set_param osc.*.stats=0 &>/dev/null
13838         stop_writeback
13839
13840         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
13841         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
13842                 oflag=direct &>/dev/null || error "dd failed"
13843
13844         sync; sleep 1; sync # just to be safe
13845         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
13846         if [ x$nrpcs != "x1" ]; then
13847                 $LCTL get_param osc.*.stats
13848                 error "found $nrpcs ost_write RPCs, not 1 as expected"
13849         fi
13850
13851         start_writeback
13852         # Drop the OSC cache, otherwise we will read from it
13853         cancel_lru_locks osc
13854
13855         # clear the OSC stats
13856         $LCTL set_param osc.*.stats=0 &>/dev/null
13857
13858         # Client reads $bulk_size.
13859         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
13860                 iflag=direct &>/dev/null || error "dd failed"
13861
13862         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
13863         if [ x$nrpcs != "x1" ]; then
13864                 $LCTL get_param osc.*.stats
13865                 error "found $nrpcs ost_read RPCs, not 1 as expected"
13866         fi
13867 }
13868 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
13869
13870 test_231b() {
13871         mkdir -p $DIR/$tdir
13872         local i
13873         for i in {0..1023}; do
13874                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
13875                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
13876                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
13877         done
13878         sync
13879 }
13880 run_test 231b "must not assert on fully utilized OST request buffer"
13881
13882 test_232() {
13883         mkdir -p $DIR/$tdir
13884         #define OBD_FAIL_LDLM_OST_LVB            0x31c
13885         $LCTL set_param fail_loc=0x31c
13886
13887         # ignore dd failure
13888         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
13889
13890         $LCTL set_param fail_loc=0
13891         umount_client $MOUNT || error "umount failed"
13892         mount_client $MOUNT || error "mount failed"
13893 }
13894 run_test 232 "failed lock should not block umount"
13895
13896 test_233a() {
13897         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
13898         { skip "Need MDS version at least 2.3.64"; return; }
13899         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13900
13901         local fid=$($LFS path2fid $MOUNT)
13902         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13903                 error "cannot access $MOUNT using its FID '$fid'"
13904 }
13905 run_test 233a "checking that OBF of the FS root succeeds"
13906
13907 test_233b() {
13908         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
13909         { skip "Need MDS version at least 2.5.90"; return; }
13910         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13911
13912         local fid=$($LFS path2fid $MOUNT/.lustre)
13913         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13914                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
13915
13916         fid=$($LFS path2fid $MOUNT/.lustre/fid)
13917         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13918                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
13919 }
13920 run_test 233b "checking that OBF of the FS .lustre succeeds"
13921
13922 test_234() {
13923         local p="$TMP/sanityN-$TESTNAME.parameters"
13924         save_lustre_params client "llite.*.xattr_cache" > $p
13925         lctl set_param llite.*.xattr_cache 1 ||
13926                 { skip "xattr cache is not supported"; return 0; }
13927
13928         mkdir -p $DIR/$tdir || error "mkdir failed"
13929         touch $DIR/$tdir/$tfile || error "touch failed"
13930         # OBD_FAIL_LLITE_XATTR_ENOMEM
13931         $LCTL set_param fail_loc=0x1405
13932         # output of the form: attr 2 4 44 3 fc13 x86_64
13933         V=($(IFS=".-" rpm -q attr))
13934         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
13935               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
13936                 # attr pre-2.4.44-7 had a bug with rc
13937                 # LU-3703 - SLES 11 and FC13 clients have older attr
13938                 getfattr -n user.attr $DIR/$tdir/$tfile &&
13939                         error "getfattr should have failed with ENOMEM"
13940         else
13941                 skip "LU-3703: attr version $(getfattr --version) too old"
13942         fi
13943         $LCTL set_param fail_loc=0x0
13944         rm -rf $DIR/$tdir
13945
13946         restore_lustre_params < $p
13947         rm -f $p
13948 }
13949 run_test 234 "xattr cache should not crash on ENOMEM"
13950
13951 test_235() {
13952         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
13953                 skip "Need MDS version at least 2.4.52" && return
13954         flock_deadlock $DIR/$tfile
13955         local RC=$?
13956         case $RC in
13957                 0)
13958                 ;;
13959                 124) error "process hangs on a deadlock"
13960                 ;;
13961                 *) error "error executing flock_deadlock $DIR/$tfile"
13962                 ;;
13963         esac
13964 }
13965 run_test 235 "LU-1715: flock deadlock detection does not work properly"
13966
13967 #LU-2935
13968 test_236() {
13969         check_swap_layouts_support && return 0
13970         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
13971
13972         local ref1=/etc/passwd
13973         local ref2=/etc/group
13974         local file1=$DIR/$tdir/f1
13975         local file2=$DIR/$tdir/f2
13976
13977         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
13978         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
13979         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
13980         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
13981         local fd=$(free_fd)
13982         local cmd="exec $fd<>$file2"
13983         eval $cmd
13984         rm $file2
13985         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
13986                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
13987         cmd="exec $fd>&-"
13988         eval $cmd
13989         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
13990
13991         #cleanup
13992         rm -rf $DIR/$tdir
13993 }
13994 run_test 236 "Layout swap on open unlinked file"
13995
13996 # test to verify file handle related system calls
13997 # (name_to_handle_at/open_by_handle_at)
13998 # The new system calls are supported in glibc >= 2.14.
13999
14000 test_237() {
14001         echo "Test file_handle syscalls" > $DIR/$tfile ||
14002                 error "write failed"
14003         check_fhandle_syscalls $DIR/$tfile ||
14004                 error "check_fhandle_syscalls failed"
14005 }
14006 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
14007
14008 # LU-4659 linkea consistency
14009 test_238() {
14010         local server_version=$(lustre_version_code $SINGLEMDS)
14011
14012         [[ $server_version -gt $(version_code 2.5.57) ]] ||
14013                 [[ $server_version -gt $(version_code 2.5.1) &&
14014                    $server_version -lt $(version_code 2.5.50) ]] ||
14015                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
14016
14017         touch $DIR/$tfile
14018         ln $DIR/$tfile $DIR/$tfile.lnk
14019         touch $DIR/$tfile.new
14020         mv $DIR/$tfile.new $DIR/$tfile
14021         local fid1=$($LFS path2fid $DIR/$tfile)
14022         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
14023         local path1=$($LFS fid2path $FSNAME "$fid1")
14024         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
14025         local path2=$($LFS fid2path $FSNAME "$fid2")
14026         [ $tfile.lnk == $path2 ] ||
14027                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
14028         rm -f $DIR/$tfile*
14029 }
14030 run_test 238 "Verify linkea consistency"
14031
14032 test_239() {
14033         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
14034                 skip "Need MDS version at least 2.5.60" && return
14035         local list=$(comma_list $(mdts_nodes))
14036
14037         mkdir -p $DIR/$tdir
14038         createmany -o $DIR/$tdir/f- 5000
14039         unlinkmany $DIR/$tdir/f- 5000
14040         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
14041         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
14042                         osc.*MDT*.sync_in_flight" | calc_sum)
14043         [ "$changes" -eq 0 ] || error "$changes not synced"
14044 }
14045 run_test 239 "osp_sync test"
14046
14047 test_239a() { #LU-5297
14048         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14049         touch $DIR/$tfile
14050         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
14051         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
14052         chgrp $RUNAS_GID $DIR/$tfile
14053         wait_delete_completed
14054 }
14055 run_test 239a "process invalid osp sync record correctly"
14056
14057 test_239b() { #LU-5297
14058         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14059         touch $DIR/$tfile1
14060         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
14061         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
14062         chgrp $RUNAS_GID $DIR/$tfile1
14063         wait_delete_completed
14064         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
14065         touch $DIR/$tfile2
14066         chgrp $RUNAS_GID $DIR/$tfile2
14067         wait_delete_completed
14068 }
14069 run_test 239b "process osp sync record with ENOMEM error correctly"
14070
14071 test_240() {
14072         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14073         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14074
14075         mkdir -p $DIR/$tdir
14076
14077         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
14078                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
14079         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
14080                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
14081
14082         umount_client $MOUNT || error "umount failed"
14083         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
14084         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
14085         mount_client $MOUNT || error "failed to mount client"
14086
14087         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
14088         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
14089 }
14090 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
14091
14092 test_241_bio() {
14093         for LOOP in $(seq $1); do
14094                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
14095                 cancel_lru_locks osc || true
14096         done
14097 }
14098
14099 test_241_dio() {
14100         for LOOP in $(seq $1); do
14101                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
14102                                                 iflag=direct 2>/dev/null
14103         done
14104 }
14105
14106 test_241a() { # was test_241
14107         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14108         ls -la $DIR/$tfile
14109         cancel_lru_locks osc
14110         test_241_bio 1000 &
14111         PID=$!
14112         test_241_dio 1000
14113         wait $PID
14114 }
14115 run_test 241a "bio vs dio"
14116
14117 test_241b() {
14118         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14119         ls -la $DIR/$tfile
14120         test_241_dio 1000 &
14121         PID=$!
14122         test_241_dio 1000
14123         wait $PID
14124 }
14125 run_test 241b "dio vs dio"
14126
14127 test_242() {
14128         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14129         mkdir -p $DIR/$tdir
14130         touch $DIR/$tdir/$tfile
14131
14132         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
14133         do_facet mds1 lctl set_param fail_loc=0x105
14134         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
14135
14136         do_facet mds1 lctl set_param fail_loc=0
14137         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
14138 }
14139 run_test 242 "mdt_readpage failure should not cause directory unreadable"
14140
14141 test_243()
14142 {
14143         test_mkdir -p $DIR/$tdir
14144         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
14145 }
14146 run_test 243 "various group lock tests"
14147
14148 test_244()
14149 {
14150         test_mkdir -p $DIR/$tdir
14151         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
14152         sendfile_grouplock $DIR/$tdir/$tfile || \
14153                 error "sendfile+grouplock failed"
14154         rm -rf $DIR/$tdir
14155 }
14156 run_test 244 "sendfile with group lock tests"
14157
14158 test_245() {
14159         local flagname="multi_mod_rpcs"
14160         local connect_data_name="max_mod_rpcs"
14161         local out
14162
14163         # check if multiple modify RPCs flag is set
14164         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
14165                 grep "connect_flags:")
14166         echo "$out"
14167
14168         echo "$out" | grep -qw $flagname
14169         if [ $? -ne 0 ]; then
14170                 echo "connect flag $flagname is not set"
14171                 return
14172         fi
14173
14174         # check if multiple modify RPCs data is set
14175         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
14176         echo "$out"
14177
14178         echo "$out" | grep -qw $connect_data_name ||
14179                 error "import should have connect data $connect_data_name"
14180 }
14181 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
14182
14183 test_246() { # LU-7371
14184         remote_ost_nodsh && skip "remote OST with nodsh" && return
14185         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
14186                 skip "Need OST version >= 2.7.62" && return 0
14187         do_facet ost1 $LCTL set_param fail_val=4095
14188 #define OBD_FAIL_OST_READ_SIZE          0x234
14189         do_facet ost1 $LCTL set_param fail_loc=0x234
14190         $LFS setstripe $DIR/$tfile -i 0 -c 1
14191         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
14192         cancel_lru_locks $FSNAME-OST0000
14193         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
14194 }
14195 run_test 246 "Read file of size 4095 should return right length"
14196
14197 test_247a() {
14198         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14199                 grep -q subtree ||
14200                 { skip "Fileset feature is not supported"; return; }
14201
14202         local submount=${MOUNT}_$tdir
14203
14204         mkdir $MOUNT/$tdir
14205         mkdir -p $submount || error "mkdir $submount failed"
14206         FILESET="$FILESET/$tdir" mount_client $submount ||
14207                 error "mount $submount failed"
14208         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
14209         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
14210                 error "read $MOUNT/$tdir/$tfile failed"
14211         umount_client $submount || error "umount $submount failed"
14212         rmdir $submount
14213 }
14214 run_test 247a "mount subdir as fileset"
14215
14216 test_247b() {
14217         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14218                 { skip "Fileset feature is not supported"; return; }
14219
14220         local submount=${MOUNT}_$tdir
14221
14222         rm -rf $MOUNT/$tdir
14223         mkdir -p $submount || error "mkdir $submount failed"
14224         SKIP_FILESET=1
14225         FILESET="$FILESET/$tdir" mount_client $submount &&
14226                 error "mount $submount should fail"
14227         rmdir $submount
14228 }
14229 run_test 247b "mount subdir that dose not exist"
14230
14231 test_247c() {
14232         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14233                 { skip "Fileset feature is not supported"; return; }
14234
14235         local submount=${MOUNT}_$tdir
14236
14237         mkdir -p $MOUNT/$tdir/dir1
14238         mkdir -p $submount || error "mkdir $submount failed"
14239         FILESET="$FILESET/$tdir" mount_client $submount ||
14240                 error "mount $submount failed"
14241         local fid=$($LFS path2fid $MOUNT/)
14242         $LFS fid2path $submount $fid && error "fid2path should fail"
14243         umount_client $submount || error "umount $submount failed"
14244         rmdir $submount
14245 }
14246 run_test 247c "running fid2path outside root"
14247
14248 test_247d() {
14249         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14250                 { skip "Fileset feature is not supported"; return; }
14251
14252         local submount=${MOUNT}_$tdir
14253
14254         mkdir -p $MOUNT/$tdir/dir1
14255         mkdir -p $submount || error "mkdir $submount failed"
14256         FILESET="$FILESET/$tdir" mount_client $submount ||
14257                 error "mount $submount failed"
14258         local fid=$($LFS path2fid $submount/dir1)
14259         $LFS fid2path $submount $fid || error "fid2path should succeed"
14260         umount_client $submount || error "umount $submount failed"
14261         rmdir $submount
14262 }
14263 run_test 247d "running fid2path inside root"
14264
14265 # LU-8037
14266 test_247e() {
14267         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14268                 grep -q subtree ||
14269                 { skip "Fileset feature is not supported"; return; }
14270
14271         local submount=${MOUNT}_$tdir
14272
14273         mkdir $MOUNT/$tdir
14274         mkdir -p $submount || error "mkdir $submount failed"
14275         FILESET="$FILESET/.." mount_client $submount &&
14276                 error "mount $submount should fail"
14277         rmdir $submount
14278 }
14279 run_test 247e "mount .. as fileset"
14280
14281 test_248() {
14282         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
14283         [ -z "$fast_read_sav" ] && skip "no fast read support" && return
14284
14285         # create a large file for fast read verification
14286         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
14287
14288         # make sure the file is created correctly
14289         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
14290                 { rm -f $DIR/$tfile; skip "file creation error" && return; }
14291
14292         echo "Test 1: verify that fast read is 4 times faster on cache read"
14293
14294         # small read with fast read enabled
14295         $LCTL set_param -n llite.*.fast_read=1
14296         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14297                 awk '/copied/ { print $6 }')
14298
14299         # small read with fast read disabled
14300         $LCTL set_param -n llite.*.fast_read=0
14301         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14302                 awk '/copied/ { print $6 }')
14303
14304         # verify that fast read is 4 times faster for cache read
14305         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
14306                 error_not_in_vm "fast read was not 4 times faster: " \
14307                            "$t_fast vs $t_slow"
14308
14309         echo "Test 2: verify the performance between big and small read"
14310         $LCTL set_param -n llite.*.fast_read=1
14311
14312         # 1k non-cache read
14313         cancel_lru_locks osc
14314         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14315                 awk '/copied/ { print $6 }')
14316
14317         # 1M non-cache read
14318         cancel_lru_locks osc
14319         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14320                 awk '/copied/ { print $6 }')
14321
14322         # verify that big IO is not 4 times faster than small IO
14323         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
14324                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
14325
14326         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
14327         rm -f $DIR/$tfile
14328 }
14329 run_test 248 "fast read verification"
14330
14331 test_249() { # LU-7890
14332         rm -f $DIR/$tfile
14333         $SETSTRIPE -c 1 $DIR/$tfile
14334
14335         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
14336         skip "Need at least version 2.8.54"
14337
14338         # Offset 2T == 4k * 512M
14339         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
14340                 error "dd to 2T offset failed"
14341 }
14342 run_test 249 "Write above 2T file size"
14343
14344 test_250() {
14345         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
14346          && skip "no 16TB file size limit on ZFS" && return
14347
14348         $SETSTRIPE -c 1 $DIR/$tfile
14349         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
14350         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
14351         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
14352         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
14353                 conv=notrunc,fsync && error "append succeeded"
14354         return 0
14355 }
14356 run_test 250 "Write above 16T limit"
14357
14358 test_251() {
14359         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
14360
14361         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
14362         #Skip once - writing the first stripe will succeed
14363         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14364         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
14365                 error "short write happened"
14366
14367         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14368         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
14369                 error "short read happened"
14370
14371         rm -f $DIR/$tfile
14372 }
14373 run_test 251 "Handling short read and write correctly"
14374
14375 test_252() {
14376         local tgt
14377         local dev
14378         local out
14379         local uuid
14380         local num
14381         local gen
14382
14383         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14384         remote_ost_nodsh && skip "remote OST with nodsh" && return
14385         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
14386              "$(facet_fstype mds1)" != "ldiskfs" ]; then
14387                 skip "ldiskfs only test"
14388                 return
14389         fi
14390
14391         # check lr_reader on OST0000
14392         tgt=ost1
14393         dev=$(facet_device $tgt)
14394         out=$(do_facet $tgt $LR_READER $dev)
14395         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14396         echo "$out"
14397         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
14398         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
14399                 error "Invalid uuid returned by $LR_READER on target $tgt"
14400         echo -e "uuid returned by $LR_READER is '$uuid'\n"
14401
14402         # check lr_reader -c on MDT0000
14403         tgt=mds1
14404         dev=$(facet_device $tgt)
14405         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
14406                 echo "$LR_READER does not support additional options"
14407                 return 0
14408         fi
14409         out=$(do_facet $tgt $LR_READER -c $dev)
14410         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14411         echo "$out"
14412         num=$(echo "$out" | grep -c "mdtlov")
14413         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
14414                 error "Invalid number of mdtlov clients returned by $LR_READER"
14415         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
14416
14417         # check lr_reader -cr on MDT0000
14418         out=$(do_facet $tgt $LR_READER -cr $dev)
14419         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14420         echo "$out"
14421         echo "$out" | grep -q "^reply_data:$" ||
14422                 error "$LR_READER should have returned 'reply_data' section"
14423         num=$(echo "$out" | grep -c "client_generation")
14424         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
14425 }
14426 run_test 252 "check lr_reader tool"
14427
14428 test_253_fill_ost() {
14429         local size_mb #how many MB should we write to pass watermark
14430         local lwm=$3  #low watermark
14431         local free_10mb #10% of free space
14432
14433         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14434         size_mb=$((free_kb / 1024 - lwm))
14435         free_10mb=$((free_kb / 10240))
14436         #If 10% of free space cross low watermark use it
14437         if (( free_10mb > size_mb )); then
14438                 size_mb=$free_10mb
14439         else
14440                 #At least we need to store 1.1 of difference between
14441                 #free space and low watermark
14442                 size_mb=$((size_mb + size_mb / 10))
14443         fi
14444         if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
14445                 dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
14446                          oflag=append conv=notrunc
14447         fi
14448
14449         sleep_maxage
14450
14451         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14452         echo "OST still has $((free_kb / 1024)) mbytes free"
14453 }
14454
14455 test_253() {
14456         local ostidx=0
14457         local rc=0
14458
14459         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14460         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14461         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
14462
14463         local ost_name=$($LFS osts |
14464                 sed -n 's/^'$ostidx': \(.*\)_UUID .*/\1/p')
14465         # on the mdt's osc
14466         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
14467         do_facet $SINGLEMDS $LCTL get_param -n \
14468                 osp.$mdtosc_proc1.reserved_mb_high ||
14469                 { skip  "remote MDS does not support reserved_mb_high" &&
14470                   return; }
14471
14472         rm -rf $DIR/$tdir
14473         wait_mds_ost_sync
14474         wait_delete_completed
14475         mkdir $DIR/$tdir
14476
14477         local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
14478                         osp.$mdtosc_proc1.reserved_mb_high)
14479         local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
14480                         osp.$mdtosc_proc1.reserved_mb_low)
14481         echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
14482
14483         create_pool $FSNAME.$TESTNAME || error "Pool creation failed"
14484         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
14485                 error "Adding $ost_name to pool failed"
14486
14487         # Wait for client to see a OST at pool
14488         wait_update $HOSTNAME "$LCTL get_param -n
14489                 lov.$FSNAME-*.pools.$TESTNAME | sort -u |
14490                 grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
14491                 error "Client can not see the pool"
14492         $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
14493                 error "Setstripe failed"
14494
14495         dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
14496         local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
14497         echo "OST still has $((blocks/1024)) mbytes free"
14498
14499         local new_lwm=$((blocks/1024-10))
14500         do_facet $SINGLEMDS $LCTL set_param \
14501                         osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
14502         do_facet $SINGLEMDS $LCTL set_param \
14503                         osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
14504
14505         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14506
14507         #First enospc could execute orphan deletion so repeat.
14508         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14509
14510         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14511                         osp.$mdtosc_proc1.prealloc_status)
14512         echo "prealloc_status $oa_status"
14513
14514         dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
14515                 error "File creation should fail"
14516         #object allocation was stopped, but we still able to append files
14517         dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
14518                 error "Append failed"
14519         rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
14520
14521         wait_delete_completed
14522
14523         sleep_maxage
14524
14525         for i in $(seq 10 12); do
14526                 dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
14527                         error "File creation failed after rm";
14528         done
14529
14530         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14531                         osp.$mdtosc_proc1.prealloc_status)
14532         echo "prealloc_status $oa_status"
14533
14534         if (( oa_status != 0 )); then
14535                 error "Object allocation still disable after rm"
14536         fi
14537         do_facet $SINGLEMDS $LCTL set_param \
14538                         osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
14539         do_facet $SINGLEMDS $LCTL set_param \
14540                         osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
14541
14542
14543         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
14544                 error "Remove $ost_name from pool failed"
14545         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
14546                 error "Pool destroy fialed"
14547 }
14548 run_test 253 "Check object allocation limit"
14549
14550 test_254() {
14551         local cl_user
14552
14553         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14554         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14555         do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
14556                 { skip "MDS does not support changelog_size" && return; }
14557
14558         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
14559         echo "Registered as changelog user $cl_user"
14560
14561         $LFS changelog_clear $MDT0 $cl_user 0
14562
14563         local size1=$(do_facet mds1 \
14564                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14565         echo "Changelog size $size1"
14566
14567         rm -rf $DIR/$tdir
14568         $LFS mkdir -i 0 $DIR/$tdir
14569         # change something
14570         mkdir -p $DIR/$tdir/pics/2008/zachy
14571         touch $DIR/$tdir/pics/2008/zachy/timestamp
14572         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
14573         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
14574         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
14575         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
14576         rm $DIR/$tdir/pics/desktop.jpg
14577
14578         local size2=$(do_facet mds1 \
14579                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14580         echo "Changelog size after work $size2"
14581
14582         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
14583
14584         if (( size2 <= size1 )); then
14585                 error "Changelog size after work should be greater than original"
14586         fi
14587         return 0
14588 }
14589 run_test 254 "Check changelog size"
14590
14591 ladvise_no_type()
14592 {
14593         local type=$1
14594         local file=$2
14595
14596         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
14597                 awk -F: '{print $2}' | grep $type > /dev/null
14598         if [ $? -ne 0 ]; then
14599                 return 0
14600         fi
14601         return 1
14602 }
14603
14604 ladvise_no_ioctl()
14605 {
14606         local file=$1
14607
14608         lfs ladvise -a willread $file > /dev/null 2>&1
14609         if [ $? -eq 0 ]; then
14610                 return 1
14611         fi
14612
14613         lfs ladvise -a willread $file 2>&1 |
14614                 grep "Inappropriate ioctl for device" > /dev/null
14615         if [ $? -eq 0 ]; then
14616                 return 0
14617         fi
14618         return 1
14619 }
14620
14621 percent() {
14622         bc <<<"scale=2; ($1 - $2) * 100 / $2"
14623 }
14624
14625 # run a random read IO workload
14626 # usage: random_read_iops <filename> <filesize> <iosize>
14627 random_read_iops() {
14628         local file=$1
14629         local fsize=$2
14630         local iosize=${3:-4096}
14631
14632         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
14633                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
14634 }
14635
14636 drop_file_oss_cache() {
14637         local file="$1"
14638         local nodes="$2"
14639
14640         $LFS ladvise -a dontneed $file 2>/dev/null ||
14641                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
14642 }
14643
14644 ladvise_willread_performance()
14645 {
14646         local repeat=10
14647         local average_origin=0
14648         local average_cache=0
14649         local average_ladvise=0
14650
14651         for ((i = 1; i <= $repeat; i++)); do
14652                 echo "Iter $i/$repeat: reading without willread hint"
14653                 cancel_lru_locks osc
14654                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
14655                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
14656                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
14657                 average_origin=$(bc <<<"$average_origin + $speed_origin")
14658
14659                 cancel_lru_locks osc
14660                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
14661                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
14662                 average_cache=$(bc <<<"$average_cache + $speed_cache")
14663
14664                 cancel_lru_locks osc
14665                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
14666                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
14667                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
14668                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
14669                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
14670         done
14671         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
14672         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
14673         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
14674
14675         speedup_cache=$(percent $average_cache $average_origin)
14676         speedup_ladvise=$(percent $average_ladvise $average_origin)
14677
14678         echo "Average uncached read: $average_origin"
14679         echo "Average speedup with OSS cached read: " \
14680                 "$average_cache = +$speedup_cache%"
14681         echo "Average speedup with ladvise willread: " \
14682                 "$average_ladvise = +$speedup_ladvise%"
14683
14684         local lowest_speedup=20
14685         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
14686                 echo "Speedup with OSS cached read less than $lowest_speedup%, " \
14687                         "got $average_cache%. Skipping ladvise willread check."
14688                 return 0
14689         fi
14690
14691         # the test won't work on ZFS until it supports 'ladvise dontneed', but
14692         # it is still good to run until then to exercise 'ladvise willread'
14693         ! $LFS ladvise -a dontneed $DIR/$tfile &&
14694                 [ "$(facet_fstype ost1)" = "zfs" ] &&
14695                 echo "osd-zfs does not support dontneed or drop_caches" &&
14696                 return 0
14697
14698         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
14699         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
14700                 error_not_in_vm "Speedup with willread is less than " \
14701                         "$lowest_speedup%, got $average_ladvise%"
14702 }
14703
14704 test_255a() {
14705         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
14706                 skip "lustre < 2.8.54 does not support ladvise " && return
14707         remote_ost_nodsh && skip "remote OST with nodsh" && return
14708
14709         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
14710
14711         ladvise_no_type willread $DIR/$tfile &&
14712                 skip "willread ladvise is not supported" && return
14713
14714         ladvise_no_ioctl $DIR/$tfile &&
14715                 skip "ladvise ioctl is not supported" && return
14716
14717         local size_mb=100
14718         local size=$((size_mb * 1048576))
14719         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
14720                 error "dd to $DIR/$tfile failed"
14721
14722         lfs ladvise -a willread $DIR/$tfile ||
14723                 error "Ladvise failed with no range argument"
14724
14725         lfs ladvise -a willread -s 0 $DIR/$tfile ||
14726                 error "Ladvise failed with no -l or -e argument"
14727
14728         lfs ladvise -a willread -e 1 $DIR/$tfile ||
14729                 error "Ladvise failed with only -e argument"
14730
14731         lfs ladvise -a willread -l 1 $DIR/$tfile ||
14732                 error "Ladvise failed with only -l argument"
14733
14734         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
14735                 error "End offset should not be smaller than start offset"
14736
14737         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
14738                 error "End offset should not be equal to start offset"
14739
14740         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
14741                 error "Ladvise failed with overflowing -s argument"
14742
14743         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
14744                 error "Ladvise failed with overflowing -e argument"
14745
14746         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
14747                 error "Ladvise failed with overflowing -l argument"
14748
14749         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
14750                 error "Ladvise succeeded with conflicting -l and -e arguments"
14751
14752         echo "Synchronous ladvise should wait"
14753         local delay=4
14754 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
14755         do_nodes $(comma_list $(osts_nodes)) \
14756                 $LCTL set_param fail_val=$delay fail_loc=0x237
14757
14758         local start_ts=$SECONDS
14759         lfs ladvise -a willread $DIR/$tfile ||
14760                 error "Ladvise failed with no range argument"
14761         local end_ts=$SECONDS
14762         local inteval_ts=$((end_ts - start_ts))
14763
14764         if [ $inteval_ts -lt $(($delay - 1)) ]; then
14765                 error "Synchronous advice didn't wait reply"
14766         fi
14767
14768         echo "Asynchronous ladvise shouldn't wait"
14769         local start_ts=$SECONDS
14770         lfs ladvise -a willread -b $DIR/$tfile ||
14771                 error "Ladvise failed with no range argument"
14772         local end_ts=$SECONDS
14773         local inteval_ts=$((end_ts - start_ts))
14774
14775         if [ $inteval_ts -gt $(($delay / 2)) ]; then
14776                 error "Asynchronous advice blocked"
14777         fi
14778
14779         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
14780         ladvise_willread_performance
14781 }
14782 run_test 255a "check 'lfs ladvise -a willread'"
14783
14784 facet_meminfo() {
14785         local facet=$1
14786         local info=$2
14787
14788         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
14789 }
14790
14791 test_255b() {
14792         remote_ost_nodsh && skip "remote OST with nodsh" && return
14793
14794         lfs setstripe -c 1 -i 0 $DIR/$tfile
14795
14796         ladvise_no_type dontneed $DIR/$tfile &&
14797                 skip "dontneed ladvise is not supported" && return
14798
14799         ladvise_no_ioctl $DIR/$tfile &&
14800                 skip "ladvise ioctl is not supported" && return
14801
14802         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
14803                 skip "lustre < 2.8.54 does not support ladvise" && return
14804
14805         ! $LFS ladvise -a dontneed $DIR/$tfile &&
14806                 [ "$(facet_fstype ost1)" = "zfs" ] &&
14807                 skip "zfs-osd does not support 'ladvise dontneed'" && return
14808
14809         local size_mb=100
14810         local size=$((size_mb * 1048576))
14811         # In order to prevent disturbance of other processes, only check 3/4
14812         # of the memory usage
14813         local kibibytes=$((size_mb * 1024 * 3 / 4))
14814
14815         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
14816                 error "dd to $DIR/$tfile failed"
14817
14818         local total=$(facet_meminfo ost1 MemTotal)
14819         echo "Total memory: $total KiB"
14820
14821         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
14822         local before_read=$(facet_meminfo ost1 Cached)
14823         echo "Cache used before read: $before_read KiB"
14824
14825         lfs ladvise -a willread $DIR/$tfile ||
14826                 error "Ladvise willread failed"
14827         local after_read=$(facet_meminfo ost1 Cached)
14828         echo "Cache used after read: $after_read KiB"
14829
14830         lfs ladvise -a dontneed $DIR/$tfile ||
14831                 error "Ladvise dontneed again failed"
14832         local no_read=$(facet_meminfo ost1 Cached)
14833         echo "Cache used after dontneed ladvise: $no_read KiB"
14834
14835         if [ $total -lt $((before_read + kibibytes)) ]; then
14836                 echo "Memory is too small, abort checking"
14837                 return 0
14838         fi
14839
14840         if [ $((before_read + kibibytes)) -gt $after_read ]; then
14841                 error "Ladvise willread should use more memory" \
14842                         "than $kibibytes KiB"
14843         fi
14844
14845         if [ $((no_read + kibibytes)) -gt $after_read ]; then
14846                 error "Ladvise dontneed should release more memory" \
14847                         "than $kibibytes KiB"
14848         fi
14849 }
14850 run_test 255b "check 'lfs ladvise -a dontneed'"
14851
14852 test_256() {
14853         local cl_user
14854         local cat_sl
14855         local mdt_dev
14856
14857         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14858         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14859         [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
14860                 skip "ldiskfs only test" && return
14861
14862         mdt_dev=$(mdsdevname 1)
14863         echo $mdt_dev
14864         cl_user=$(do_facet mds1 \
14865         "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
14866         if [[ -n $cl_user ]]; then
14867                 skip "active changelog user"
14868                 return
14869         fi
14870
14871         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
14872         echo "Registered as changelog user $cl_user"
14873
14874         rm -rf $DIR/$tdir
14875         mkdir -p $DIR/$tdir
14876
14877         $LFS changelog_clear $MDT0 $cl_user 0
14878
14879         # change something
14880         touch $DIR/$tdir/{1..10}
14881
14882         # stop the MDT
14883         stop mds1 || error "Fail to stop MDT."
14884
14885         # remount the MDT
14886         start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
14887
14888         #after mount new plainllog is used
14889         touch $DIR/$tdir/{11..19}
14890         local TEMP256FILE=$(mktemp TEMP256XXXXXX)
14891         cat_sl=$(do_facet mds1 \
14892         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
14893          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
14894         rm $TEMP256FILE
14895
14896         if (( cat_sl != 2 )); then
14897                 do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
14898                 error "Changelog catalog has wrong number of slots $cat_sl"
14899         fi
14900
14901         $LFS changelog_clear $MDT0 $cl_user 0
14902
14903         TEMP256FILE=$(mktemp TEMP256XXXXXX)
14904         cat_sl=$(do_facet mds1 \
14905         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
14906          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
14907         rm $TEMP256FILE
14908
14909         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
14910
14911         if (( cat_sl == 2 )); then
14912                 error "Empty plain llog was not deleted from changelog catalog"
14913         fi
14914         if (( cat_sl != 1 )); then
14915                 error "Active plain llog shouldn\`t be deleted from catalog"
14916         fi
14917 }
14918 run_test 256 "Check llog delete for empty and not full state"
14919
14920 test_257() {
14921         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14922         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
14923                 skip "Need MDS version at least 2.8.55" && return
14924
14925         test_mkdir -p $DIR/$tdir
14926
14927         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
14928                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
14929         stat $DIR/$tdir
14930
14931 #define OBD_FAIL_MDS_XATTR_REP                  0x161
14932         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
14933         local facet=mds$((mdtidx + 1))
14934         set_nodes_failloc $(facet_active_host $facet) 0x80000161
14935         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
14936
14937         stop $facet || error "stop MDS failed"
14938         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
14939                 error "start MDS fail"
14940 }
14941 run_test 257 "xattr locks are not lost"
14942
14943 # Verify we take the i_mutex when security requires it
14944 test_258a() {
14945 #define OBD_FAIL_IMUTEX_SEC 0x141c
14946         $LCTL set_param fail_loc=0x141c
14947         touch $DIR/$tfile
14948         chmod u+s $DIR/$tfile
14949         chmod a+rwx $DIR/$tfile
14950         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
14951         RC=$?
14952         if [ $RC -ne 0 ]; then
14953                 error "error, failed to take i_mutex, rc=$?"
14954         fi
14955         rm -f $DIR/$tfile
14956 }
14957 run_test 258a
14958
14959 # Verify we do NOT take the i_mutex in the normal case
14960 test_258b() {
14961 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
14962         $LCTL set_param fail_loc=0x141d
14963         touch $DIR/$tfile
14964         chmod a+rwx $DIR
14965         chmod a+rw $DIR/$tfile
14966         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
14967         RC=$?
14968         if [ $RC -ne 0 ]; then
14969                 error "error, took i_mutex unnecessarily, rc=$?"
14970         fi
14971         rm -f $DIR/$tfile
14972
14973 }
14974 run_test 258b "verify i_mutex security behavior"
14975
14976 test_260() {
14977 #define OBD_FAIL_MDC_CLOSE               0x806
14978         $LCTL set_param fail_loc=0x80000806
14979         touch $DIR/$tfile
14980
14981 }
14982 run_test 260 "Check mdc_close fail"
14983
14984 cleanup_test_300() {
14985         trap 0
14986         umask $SAVE_UMASK
14987 }
14988 test_striped_dir() {
14989         local mdt_index=$1
14990         local stripe_count
14991         local stripe_index
14992
14993         mkdir -p $DIR/$tdir
14994
14995         SAVE_UMASK=$(umask)
14996         trap cleanup_test_300 RETURN EXIT
14997
14998         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
14999                                                 $DIR/$tdir/striped_dir ||
15000                 error "set striped dir error"
15001
15002         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
15003         [ "$mode" = "755" ] || error "expect 755 got $mode"
15004
15005         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
15006                 error "getdirstripe failed"
15007         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
15008         if [ "$stripe_count" != "2" ]; then
15009                 error "1:stripe_count is $stripe_count, expect 2"
15010         fi
15011         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
15012         if [ "$stripe_count" != "2" ]; then
15013                 error "2:stripe_count is $stripe_count, expect 2"
15014         fi
15015
15016         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
15017         if [ "$stripe_index" != "$mdt_index" ]; then
15018                 error "stripe_index is $stripe_index, expect $mdt_index"
15019         fi
15020
15021         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15022                 error "nlink error after create striped dir"
15023
15024         mkdir $DIR/$tdir/striped_dir/a
15025         mkdir $DIR/$tdir/striped_dir/b
15026
15027         stat $DIR/$tdir/striped_dir/a ||
15028                 error "create dir under striped dir failed"
15029         stat $DIR/$tdir/striped_dir/b ||
15030                 error "create dir under striped dir failed"
15031
15032         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
15033                 error "nlink error after mkdir"
15034
15035         rmdir $DIR/$tdir/striped_dir/a
15036         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
15037                 error "nlink error after rmdir"
15038
15039         rmdir $DIR/$tdir/striped_dir/b
15040         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15041                 error "nlink error after rmdir"
15042
15043         chattr +i $DIR/$tdir/striped_dir
15044         createmany -o $DIR/$tdir/striped_dir/f 10 &&
15045                 error "immutable flags not working under striped dir!"
15046         chattr -i $DIR/$tdir/striped_dir
15047
15048         rmdir $DIR/$tdir/striped_dir ||
15049                 error "rmdir striped dir error"
15050
15051         cleanup_test_300
15052
15053         true
15054 }
15055
15056 test_300a() {
15057         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15058                 skip "skipped for lustre < 2.7.0" && return
15059         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15060         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15061
15062         test_striped_dir 0 || error "failed on striped dir on MDT0"
15063         test_striped_dir 1 || error "failed on striped dir on MDT0"
15064 }
15065 run_test 300a "basic striped dir sanity test"
15066
15067 test_300b() {
15068         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15069                 skip "skipped for lustre < 2.7.0" && return
15070         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15071         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15072         local i
15073         local mtime1
15074         local mtime2
15075         local mtime3
15076
15077         test_mkdir $DIR/$tdir || error "mkdir fail"
15078         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15079                 error "set striped dir error"
15080         for ((i=0; i<10; i++)); do
15081                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
15082                 sleep 1
15083                 touch $DIR/$tdir/striped_dir/file_$i ||
15084                                         error "touch error $i"
15085                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
15086                 [ $mtime1 -eq $mtime2 ] &&
15087                         error "mtime not change after create"
15088                 sleep 1
15089                 rm -f $DIR/$tdir/striped_dir/file_$i ||
15090                                         error "unlink error $i"
15091                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
15092                 [ $mtime2 -eq $mtime3 ] &&
15093                         error "mtime did not change after unlink"
15094         done
15095         true
15096 }
15097 run_test 300b "check ctime/mtime for striped dir"
15098
15099 test_300c() {
15100         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15101                 skip "skipped for lustre < 2.7.0" && return
15102         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15103         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15104         local file_count
15105
15106         mkdir -p $DIR/$tdir
15107         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
15108                 error "set striped dir error"
15109
15110         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
15111                 error "chown striped dir failed"
15112
15113         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
15114                 error "create 5k files failed"
15115
15116         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
15117
15118         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
15119
15120         rm -rf $DIR/$tdir
15121 }
15122 run_test 300c "chown && check ls under striped directory"
15123
15124 test_300d() {
15125         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15126                 skip "skipped for lustre < 2.7.0" && return
15127         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15128         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15129         local stripe_count
15130         local file
15131
15132         mkdir -p $DIR/$tdir
15133         $SETSTRIPE -c 2 $DIR/$tdir
15134
15135         #local striped directory
15136         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15137                 error "set striped dir error"
15138         createmany -o $DIR/$tdir/striped_dir/f 10 ||
15139                 error "create 10 files failed"
15140
15141         #remote striped directory
15142         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
15143                 error "set striped dir error"
15144         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
15145                 error "create 10 files failed"
15146
15147         for file in $(find $DIR/$tdir); do
15148                 stripe_count=$($GETSTRIPE -c $file)
15149                 [ $stripe_count -eq 2 ] ||
15150                         error "wrong stripe $stripe_count for $file"
15151         done
15152
15153         rm -rf $DIR/$tdir
15154 }
15155 run_test 300d "check default stripe under striped directory"
15156
15157 test_300e() {
15158         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15159                 skip "Need MDS version at least 2.7.55" && return
15160         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15161         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15162         local stripe_count
15163         local file
15164
15165         mkdir -p $DIR/$tdir
15166
15167         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15168                 error "set striped dir error"
15169
15170         touch $DIR/$tdir/striped_dir/a
15171         touch $DIR/$tdir/striped_dir/b
15172         touch $DIR/$tdir/striped_dir/c
15173
15174         mkdir $DIR/$tdir/striped_dir/dir_a
15175         mkdir $DIR/$tdir/striped_dir/dir_b
15176         mkdir $DIR/$tdir/striped_dir/dir_c
15177
15178         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
15179                 error "set striped adir under striped dir error"
15180
15181         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
15182                 error "set striped bdir under striped dir error"
15183
15184         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
15185                 error "set striped cdir under striped dir error"
15186
15187         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
15188                 error "rename dir under striped dir fails"
15189
15190         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
15191                 error "rename dir under different stripes fails"
15192
15193         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
15194                 error "rename file under striped dir should succeed"
15195
15196         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
15197                 error "rename dir under striped dir should succeed"
15198
15199         rm -rf $DIR/$tdir
15200 }
15201 run_test 300e "check rename under striped directory"
15202
15203 test_300f() {
15204         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15205                 skip "Need MDS version at least 2.7.55" && return
15206         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15207         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15208         local stripe_count
15209         local file
15210
15211         rm -rf $DIR/$tdir
15212         mkdir -p $DIR/$tdir
15213
15214         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15215                 error "set striped dir error"
15216
15217         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
15218                 error "set striped dir error"
15219
15220         touch $DIR/$tdir/striped_dir/a
15221         mkdir $DIR/$tdir/striped_dir/dir_a
15222         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
15223                 error "create striped dir under striped dir fails"
15224
15225         touch $DIR/$tdir/striped_dir1/b
15226         mkdir $DIR/$tdir/striped_dir1/dir_b
15227         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
15228                 error "create striped dir under striped dir fails"
15229
15230         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
15231                 error "rename dir under different striped dir should fail"
15232
15233         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
15234                 error "rename striped dir under diff striped dir should fail"
15235
15236         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
15237                 error "rename file under diff striped dirs fails"
15238
15239         rm -rf $DIR/$tdir
15240 }
15241 run_test 300f "check rename cross striped directory"
15242
15243 test_300_check_default_striped_dir()
15244 {
15245         local dirname=$1
15246         local default_count=$2
15247         local default_index=$3
15248         local stripe_count
15249         local stripe_index
15250         local dir_stripe_index
15251         local dir
15252
15253         echo "checking $dirname $default_count $default_index"
15254         $LFS setdirstripe -D -c $default_count -i $default_index \
15255                                 -t all_char $DIR/$tdir/$dirname ||
15256                 error "set default stripe on striped dir error"
15257         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
15258         [ $stripe_count -eq $default_count ] ||
15259                 error "expect $default_count get $stripe_count for $dirname"
15260
15261         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
15262         [ $stripe_index -eq $default_index ] ||
15263                 error "expect $default_index get $stripe_index for $dirname"
15264
15265         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
15266                                                 error "create dirs failed"
15267
15268         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
15269         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
15270         for dir in $(find $DIR/$tdir/$dirname/*); do
15271                 stripe_count=$($LFS getdirstripe -c $dir)
15272                 [ $stripe_count -eq $default_count ] ||
15273                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
15274                 error "stripe count $default_count != $stripe_count for $dir"
15275
15276                 stripe_index=$($LFS getdirstripe -i $dir)
15277                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
15278                         error "$stripe_index != $default_index for $dir"
15279
15280                 #check default stripe
15281                 stripe_count=$($LFS getdirstripe -D -c $dir)
15282                 [ $stripe_count -eq $default_count ] ||
15283                 error "default count $default_count != $stripe_count for $dir"
15284
15285                 stripe_index=$($LFS getdirstripe -D -i $dir)
15286                 [ $stripe_index -eq $default_index ] ||
15287                 error "default index $default_index != $stripe_index for $dir"
15288         done
15289         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
15290 }
15291
15292 test_300g() {
15293         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15294                 skip "Need MDS version at least 2.7.55" && return
15295         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15296         local dir
15297         local stripe_count
15298         local stripe_index
15299
15300         mkdir $DIR/$tdir
15301         mkdir $DIR/$tdir/normal_dir
15302
15303         #Checking when client cache stripe index
15304         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
15305         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
15306                 error "create striped_dir failed"
15307
15308         mkdir $DIR/$tdir/striped_dir/dir1 ||
15309                 error "create dir1 fails"
15310         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
15311         [ $stripe_index -eq 1 ] ||
15312                 error "dir1 expect 1 got $stripe_index"
15313
15314         $LFS setdirstripe -i2 $DIR/$tdir/striped_dir/dir2 ||
15315                 error "create dir2 fails"
15316         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir2)
15317         [ $stripe_index -eq 2 ] ||
15318                 error "dir2 expect 2 got $stripe_index"
15319
15320         #check default stripe count/stripe index
15321         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
15322         test_300_check_default_striped_dir normal_dir 1 0
15323         test_300_check_default_striped_dir normal_dir 2 1
15324         test_300_check_default_striped_dir normal_dir 2 -1
15325
15326         #delete default stripe information
15327         echo "delete default stripeEA"
15328         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
15329                 error "set default stripe on striped dir error"
15330
15331         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
15332         for dir in $(find $DIR/$tdir/normal_dir/*); do
15333                 stripe_count=$($LFS getdirstripe -c $dir)
15334                 [ $stripe_count -eq 0 ] ||
15335                         error "expect 1 get $stripe_count for $dir"
15336                 stripe_index=$($LFS getdirstripe -i $dir)
15337                 [ $stripe_index -eq 0 ] ||
15338                         error "expect 0 get $stripe_index for $dir"
15339         done
15340 }
15341 run_test 300g "check default striped directory for normal directory"
15342
15343 test_300h() {
15344         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15345                 skip "Need MDS version at least 2.7.55" && return
15346         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15347         local dir
15348         local stripe_count
15349
15350         mkdir $DIR/$tdir
15351         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
15352                                         $DIR/$tdir/striped_dir ||
15353                 error "set striped dir error"
15354
15355         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
15356         test_300_check_default_striped_dir striped_dir 1 0
15357         test_300_check_default_striped_dir striped_dir 2 1
15358         test_300_check_default_striped_dir striped_dir 2 -1
15359
15360         #delete default stripe information
15361         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
15362                 error "set default stripe on striped dir error"
15363
15364         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
15365         for dir in $(find $DIR/$tdir/striped_dir/*); do
15366                 stripe_count=$($LFS getdirstripe -c $dir)
15367                 [ $stripe_count -eq 0 ] ||
15368                         error "expect 1 get $stripe_count for $dir"
15369         done
15370 }
15371 run_test 300h "check default striped directory for striped directory"
15372
15373 test_300i() {
15374         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15375                 skip "Need MDS version at least 2.7.55" && return
15376         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15377         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15378         local stripe_count
15379         local file
15380
15381         mkdir $DIR/$tdir
15382
15383         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15384                 error "set striped dir error"
15385
15386         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15387                 error "create files under striped dir failed"
15388
15389         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
15390                 error "set striped hashdir error"
15391
15392         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
15393                 error "create dir0 under hash dir failed"
15394         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
15395                 error "create dir1 under hash dir failed"
15396
15397         # unfortunately, we need to umount to clear dir layout cache for now
15398         # once we fully implement dir layout, we can drop this
15399         umount_client $MOUNT || error "umount failed"
15400         mount_client $MOUNT || error "mount failed"
15401
15402         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
15403         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
15404         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
15405
15406         #set the stripe to be unknown hash type
15407         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
15408         $LCTL set_param fail_loc=0x1901
15409         for ((i = 0; i < 10; i++)); do
15410                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
15411                         error "stat f-$i failed"
15412                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
15413         done
15414
15415         touch $DIR/$tdir/striped_dir/f0 &&
15416                 error "create under striped dir with unknown hash should fail"
15417
15418         $LCTL set_param fail_loc=0
15419
15420         umount_client $MOUNT || error "umount failed"
15421         mount_client $MOUNT || error "mount failed"
15422
15423         return 0
15424 }
15425 run_test 300i "client handle unknown hash type striped directory"
15426
15427 test_300j() {
15428         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15429         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15430                 skip "Need MDS version at least 2.7.55" && return
15431         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15432         local stripe_count
15433         local file
15434
15435         mkdir $DIR/$tdir
15436
15437         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
15438         $LCTL set_param fail_loc=0x1702
15439         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15440                 error "set striped dir error"
15441
15442         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15443                 error "create files under striped dir failed"
15444
15445         $LCTL set_param fail_loc=0
15446
15447         rm -rf $DIR/$tdir || error "unlink striped dir fails"
15448
15449         return 0
15450 }
15451 run_test 300j "test large update record"
15452
15453 test_300k() {
15454         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15455                 skip "Need MDS version at least 2.7.55" && return
15456         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15457         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15458         local stripe_count
15459         local file
15460
15461         mkdir $DIR/$tdir
15462
15463         #define OBD_FAIL_LARGE_STRIPE   0x1703
15464         $LCTL set_param fail_loc=0x1703
15465         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
15466                 error "set striped dir error"
15467         $LCTL set_param fail_loc=0
15468
15469         $LFS getdirstripe $DIR/$tdir/striped_dir ||
15470                 error "getstripeddir fails"
15471         rm -rf $DIR/$tdir/striped_dir ||
15472                 error "unlink striped dir fails"
15473
15474         return 0
15475 }
15476 run_test 300k "test large striped directory"
15477
15478 test_300l() {
15479         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15480                 skip "Need MDS version at least 2.7.55" && return
15481         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15482         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15483         local stripe_index
15484
15485         test_mkdir -p $DIR/$tdir/striped_dir
15486         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
15487                         error "chown $RUNAS_ID failed"
15488         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
15489                 error "set default striped dir failed"
15490
15491         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
15492         $LCTL set_param fail_loc=0x80000158
15493         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
15494
15495         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
15496         [ $stripe_index -eq 1 ] ||
15497                 error "expect 1 get $stripe_index for $dir"
15498 }
15499 run_test 300l "non-root user to create dir under striped dir with stale layout"
15500
15501 test_300m() {
15502         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15503                 skip "Need MDS version at least 2.7.55" && return
15504         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15505         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
15506
15507         mkdir -p $DIR/$tdir/striped_dir
15508         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
15509                 error "set default stripes dir error"
15510
15511         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
15512
15513         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
15514         [ $stripe_count -eq 0 ] ||
15515                         error "expect 0 get $stripe_count for a"
15516
15517         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
15518                 error "set default stripes dir error"
15519
15520         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
15521
15522         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
15523         [ $stripe_count -eq 0 ] ||
15524                         error "expect 0 get $stripe_count for b"
15525
15526         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
15527                 error "set default stripes dir error"
15528
15529         mkdir $DIR/$tdir/striped_dir/c &&
15530                 error "default stripe_index is invalid, mkdir c should fails"
15531
15532         rm -rf $DIR/$tdir || error "rmdir fails"
15533 }
15534 run_test 300m "setstriped directory on single MDT FS"
15535
15536 cleanup_300n() {
15537         local list=$(comma_list $(mdts_nodes))
15538
15539         trap 0
15540         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15541 }
15542
15543 test_300n() {
15544         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15545                 skip "Need MDS version at least 2.7.55" && return
15546         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15547         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15548         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15549
15550         local stripe_index
15551         local list=$(comma_list $(mdts_nodes))
15552
15553         trap cleanup_300n RETURN EXIT
15554         mkdir -p $DIR/$tdir
15555         chmod 777 $DIR/$tdir
15556         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
15557                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
15558                 error "create striped dir succeeds with gid=0"
15559
15560         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
15561         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
15562                 error "create striped dir fails with gid=-1"
15563
15564         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15565         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
15566                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
15567                 error "set default striped dir succeeds with gid=0"
15568
15569
15570         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
15571         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
15572                 error "set default striped dir fails with gid=-1"
15573
15574
15575         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15576         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
15577                                         error "create test_dir fails"
15578         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
15579                                         error "create test_dir1 fails"
15580         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
15581                                         error "create test_dir2 fails"
15582         cleanup_300n
15583 }
15584 run_test 300n "non-root user to create dir under striped dir with default EA"
15585
15586 test_300o() {
15587         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15588                 skip "Need MDS version at least 2.7.55" && return
15589         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15590         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15591         local numfree1
15592         local numfree2
15593
15594         mkdir -p $DIR/$tdir
15595
15596         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
15597         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
15598         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
15599                 skip "not enough free inodes $numfree1 $numfree2"
15600                 return
15601         fi
15602
15603         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
15604         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
15605         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
15606                 skip "not enough free space $numfree1 $numfree2"
15607                 return
15608         fi
15609
15610         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
15611                 error "setdirstripe fails"
15612
15613         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
15614                 error "create dirs fails"
15615
15616         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
15617         ls $DIR/$tdir/striped_dir > /dev/null ||
15618                 error "ls striped dir fails"
15619         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
15620                 error "unlink big striped dir fails"
15621 }
15622 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
15623
15624 test_300p() {
15625         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15626         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15627         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15628
15629         mkdir -p $DIR/$tdir
15630
15631         #define OBD_FAIL_OUT_ENOSPC     0x1704
15632         do_facet mds2 lctl set_param fail_loc=0x80001704
15633         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
15634                         error "create striped directory should fail"
15635
15636         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
15637
15638         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
15639         true
15640 }
15641 run_test 300p "create striped directory without space"
15642
15643 test_300q() {
15644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15645         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15646
15647         local fd=$(free_fd)
15648         local cmd="exec $fd<$tdir"
15649         cd $DIR
15650         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
15651         eval $cmd
15652         cmd="exec $fd<&-"
15653         trap "eval $cmd" EXIT
15654         cd $tdir || error "cd $tdir fails"
15655         rmdir  ../$tdir || error "rmdir $tdir fails"
15656         mkdir local_dir && error "create dir succeeds"
15657         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
15658         eval $cmd
15659         return 0
15660 }
15661 run_test 300q "create remote directory under orphan directory"
15662
15663 prepare_remote_file() {
15664         mkdir $DIR/$tdir/src_dir ||
15665                 error "create remote source failed"
15666
15667         cp /etc/hosts $DIR/$tdir/src_dir/a || error
15668         touch $DIR/$tdir/src_dir/a
15669
15670         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
15671                 error "create remote target dir failed"
15672
15673         touch $DIR/$tdir/tgt_dir/b
15674
15675         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
15676                 error "rename dir cross MDT failed!"
15677
15678         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
15679                 error "src_child still exists after rename"
15680
15681         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
15682                 error "missing file(a) after rename"
15683
15684         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
15685                 error "diff after rename"
15686 }
15687
15688 test_310a() {
15689         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
15690         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15691         local remote_file=$DIR/$tdir/tgt_dir/b
15692
15693         mkdir -p $DIR/$tdir
15694
15695         prepare_remote_file || error "prepare remote file failed"
15696
15697         #open-unlink file
15698         $OPENUNLINK $remote_file $remote_file || error
15699         $CHECKSTAT -a $remote_file || error
15700 }
15701 run_test 310a "open unlink remote file"
15702
15703 test_310b() {
15704         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
15705         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15706         local remote_file=$DIR/$tdir/tgt_dir/b
15707
15708         mkdir -p $DIR/$tdir
15709
15710         prepare_remote_file || error "prepare remote file failed"
15711
15712         ln $remote_file $DIR/$tfile || error "link failed for remote file"
15713         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
15714         $CHECKSTAT -t file $remote_file || error "check file failed"
15715 }
15716 run_test 310b "unlink remote file with multiple links while open"
15717
15718 test_310c() {
15719         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
15720         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15721         local remote_file=$DIR/$tdir/tgt_dir/b
15722
15723         mkdir -p $DIR/$tdir
15724
15725         prepare_remote_file || error "prepare remote file failed"
15726
15727         ln $remote_file $DIR/$tfile || error "link failed for remote file"
15728         multiop_bg_pause $remote_file O_uc ||
15729                         error "mulitop failed for remote file"
15730         MULTIPID=$!
15731         $MULTIOP $DIR/$tfile Ouc
15732         kill -USR1 $MULTIPID
15733         wait $MULTIPID
15734 }
15735 run_test 310c "open-unlink remote file with multiple links"
15736
15737 #LU-4825
15738 test_311() {
15739         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.54) ] &&
15740                 skip "lustre < 2.8.54 does not contain LU-4825 fix" && return
15741         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15742         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15743
15744         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
15745
15746         mkdir -p $DIR/$tdir
15747         $SETSTRIPE -i 0 -c 1 $DIR/$tdir
15748         createmany -o $DIR/$tdir/$tfile. 1000
15749
15750         # statfs data is not real time, let's just calculate it
15751         old_iused=$((old_iused + 1000))
15752
15753         local count=$(do_facet $SINGLEMDS "lctl get_param -n \
15754                         osp.*OST0000*MDT0000.create_count")
15755         local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
15756                                 osp.*OST0000*MDT0000.max_create_count")
15757         for idx in $(seq $MDSCOUNT); do
15758                 do_facet mds$idx "lctl set_param -n \
15759                         osp.*OST0000*MDT000?.max_create_count=0"
15760         done
15761
15762         $SETSTRIPE -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
15763         local index=$($GETSTRIPE -i $DIR/$tdir/$tfile)
15764         [ $index -ne 0 ] || error "$tfile stripe index is 0"
15765
15766         unlinkmany $DIR/$tdir/$tfile. 1000
15767
15768         for idx in $(seq $MDSCOUNT); do
15769                 do_facet mds$idx "lctl set_param -n \
15770                         osp.*OST0000*MDT000?.max_create_count=$max_count"
15771                 do_facet mds$idx "lctl set_param -n \
15772                         osp.*OST0000*MDT000?.create_count=$count"
15773         done
15774
15775         local new_iused
15776         for i in $(seq 120); do
15777                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
15778                 # system may be too busy to destroy all objs in time, use
15779                 # a somewhat small value to not fail autotest
15780                 [ $((old_iused - new_iused)) -gt 400 ] && break
15781                 sleep 1
15782         done
15783
15784         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
15785         [ $((old_iused - new_iused)) -gt 400 ] ||
15786                 error "objs not destroyed after unlink"
15787 }
15788 run_test 311 "disable OSP precreate, and unlink should destroy objs"
15789
15790 zfs_oid_to_objid()
15791 {
15792         local ost=$1
15793         local objid=$2
15794
15795         local vdevdir=$(dirname $(facet_vdevice $ost))
15796         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
15797         local zfs_zapid=$(do_facet $ost $cmd |
15798                           grep -w "/O/0/d$((objid%32))" -C 5 |
15799                           awk '/Object/{getline; print $1}')
15800         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
15801                           awk "/$objid = /"'{printf $3}')
15802
15803         echo $zfs_objid
15804 }
15805
15806 zfs_object_blksz() {
15807         local ost=$1
15808         local objid=$2
15809
15810         local vdevdir=$(dirname $(facet_vdevice $ost))
15811         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
15812         local blksz=$(do_facet $ost $cmd $objid |
15813                       awk '/dblk/{getline; printf $4}')
15814
15815         case "${blksz: -1}" in
15816                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
15817                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
15818                 *) ;;
15819         esac
15820
15821         echo $blksz
15822 }
15823
15824 test_312() { # LU-4856
15825         remote_ost_nodsh && skip "remote OST with nodsh" && return
15826
15827         [ $(facet_fstype ost1) = "zfs" ] ||
15828                 { skip "the test only applies to zfs" && return; }
15829
15830         local max_blksz=$(do_facet ost1 \
15831                           $ZFS get -p recordsize $(facet_device ost1) |
15832                           awk '!/VALUE/{print $3}')
15833         local min_blksz=$(getconf PAGE_SIZE)
15834
15835         # to make life a little bit easier
15836         $LFS mkdir -c 1 -i 0 $DIR/$tdir
15837         $LFS setstripe -c 1 -i 0 $DIR/$tdir
15838
15839         local tf=$DIR/$tdir/$tfile
15840         touch $tf
15841         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
15842
15843         # Get ZFS object id
15844         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
15845
15846         # block size change by sequential over write
15847         local blksz
15848         for ((bs=$min_blksz; bs <= max_blksz; bs <<= 2)); do
15849                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
15850
15851                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
15852                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
15853         done
15854         rm -f $tf
15855
15856         # block size change by sequential append write
15857         dd if=/dev/zero of=$tf bs=$min_blksz count=1 oflag=sync conv=notrunc
15858         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
15859         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
15860
15861         for ((count = 1; count < $((max_blksz / min_blksz)); count *= 2)); do
15862                 dd if=/dev/zero of=$tf bs=$min_blksz count=$count seek=$count \
15863                         oflag=sync conv=notrunc
15864
15865                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
15866                 [ $blksz -eq $((2 * count * min_blksz)) ] ||
15867                         error "blksz error, actual $blksz, "    \
15868                                 "expected: 2 * $count * $min_blksz"
15869         done
15870         rm -f $tf
15871
15872         # random write
15873         touch $tf
15874         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
15875         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
15876
15877         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
15878         blksz=$(zfs_object_blksz ost1 $zfs_objid)
15879         [ $blksz -eq $min_blksz ] ||
15880                 error "blksz error: $blksz, expected: $min_blksz"
15881
15882         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
15883         blksz=$(zfs_object_blksz ost1 $zfs_objid)
15884         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
15885
15886         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
15887         blksz=$(zfs_object_blksz ost1 $zfs_objid)
15888         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
15889 }
15890 run_test 312 "make sure ZFS adjusts its block size by write pattern"
15891
15892 test_313() {
15893         remote_ost_nodsh && skip "remote OST with nodsh" && return
15894
15895         local file=$DIR/$tfile
15896         rm -f $file
15897         $SETSTRIPE -c 1 -i 0 $file || error "setstripe failed"
15898
15899         # define OBD_FAIL_TGT_RCVD_EIO           0x720
15900         do_facet ost1 "$LCTL set_param fail_loc=0x720"
15901         dd if=/dev/zero of=$file bs=4096 oflag=direct count=1 &&
15902                 error "write should failed"
15903         do_facet ost1 "$LCTL set_param fail_loc=0"
15904         rm -f $file
15905 }
15906 run_test 313 "io should fail after last_rcvd update fail"
15907
15908 test_fake_rw() {
15909         local read_write=$1
15910         if [ "$read_write" = "write" ]; then
15911                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
15912         elif [ "$read_write" = "read" ]; then
15913                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
15914         else
15915                 error "argument error"
15916         fi
15917
15918         # turn off debug for performance testing
15919         local saved_debug=$($LCTL get_param -n debug)
15920         $LCTL set_param debug=0
15921
15922         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
15923
15924         # get ost1 size - lustre-OST0000
15925         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
15926         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
15927         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
15928
15929         if [ "$read_write" = "read" ]; then
15930                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
15931         fi
15932
15933         local start_time=$(date +%s.%N)
15934         $dd_cmd bs=1M count=$blocks oflag=sync ||
15935                 error "real dd $read_write error"
15936         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
15937
15938         if [ "$read_write" = "write" ]; then
15939                 rm -f $DIR/$tfile
15940         fi
15941
15942         # define OBD_FAIL_OST_FAKE_RW           0x238
15943         do_facet ost1 $LCTL set_param fail_loc=0x238
15944
15945         local start_time=$(date +%s.%N)
15946         $dd_cmd bs=1M count=$blocks oflag=sync ||
15947                 error "fake dd $read_write error"
15948         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
15949
15950         if [ "$read_write" = "write" ]; then
15951                 # verify file size
15952                 cancel_lru_locks osc
15953                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
15954                         error "$tfile size not $blocks MB"
15955         fi
15956         do_facet ost1 $LCTL set_param fail_loc=0
15957
15958         echo "fake $read_write $duration_fake vs. normal $read_write" \
15959                 "$duration in seconds"
15960         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
15961                 error_not_in_vm "fake write is slower"
15962
15963         $LCTL set_param -n debug="$saved_debug"
15964         rm -f $DIR/$tfile
15965 }
15966 test_399a() { # LU-7655 for OST fake write
15967         remote_ost_nodsh && skip "remote OST with nodsh" && return
15968
15969         test_fake_rw write
15970 }
15971 run_test 399a "fake write should not be slower than normal write"
15972
15973 test_399b() { # LU-8726 for OST fake read
15974         remote_ost_nodsh && skip "remote OST with nodsh" && return
15975
15976         if [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
15977                 skip "ldiskfs only test" && return 0
15978         fi
15979         test_fake_rw read
15980 }
15981 run_test 399b "fake read should not be slower than normal read"
15982
15983 test_400a() { # LU-1606, was conf-sanity test_74
15984         local extra_flags=''
15985         local out=$TMP/$tfile
15986         local prefix=/usr/include/lustre
15987         local prog
15988
15989         if ! which $CC > /dev/null 2>&1; then
15990                 skip_env "$CC is not installed"
15991                 return 0
15992         fi
15993
15994         if ! [[ -d $prefix ]]; then
15995                 # Assume we're running in tree and fixup the include path.
15996                 extra_flags+=" -I$LUSTRE/../libcfs/include"
15997                 extra_flags+=" -I$LUSTRE/include"
15998                 extra_flags+=" -L$LUSTRE/utils"
15999         fi
16000
16001         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
16002                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
16003                         error "client api broken"
16004         done
16005         rm -f $out
16006 }
16007 run_test 400a "Lustre client api program can compile and link"
16008
16009 test_400b() { # LU-1606, LU-5011
16010         local header
16011         local out=$TMP/$tfile
16012         local prefix=/usr/include/lustre
16013
16014         # We use a hard coded prefix so that this test will not fail
16015         # when run in tree. There are headers in lustre/include/lustre/
16016         # that are not packaged (like lustre_idl.h) and have more
16017         # complicated include dependencies (like config.h and lnet/types.h).
16018         # Since this test about correct packaging we just skip them when
16019         # they don't exist (see below) rather than try to fixup cppflags.
16020
16021         if ! which $CC > /dev/null 2>&1; then
16022                 skip_env "$CC is not installed"
16023                 return 0
16024         fi
16025
16026         for header in $prefix/*.h; do
16027                 if ! [[ -f "$header" ]]; then
16028                         continue
16029                 fi
16030
16031                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
16032                         continue # liblustreapi.h is deprecated.
16033                 fi
16034
16035                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
16036                         error "cannot compile '$header'"
16037         done
16038         rm -f $out
16039 }
16040 run_test 400b "packaged headers can be compiled"
16041
16042 test_401a() { #LU-7437
16043         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
16044         [ -n "$printf_arg" ] && skip_env "find does not support -printf" &&
16045                 return
16046         #count the number of parameters by "list_param -R"
16047         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
16048         #count the number of parameters by listing proc files
16049         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
16050         echo "proc_dirs='$proc_dirs'"
16051         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
16052         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
16053                       sort -u | wc -l)
16054
16055         [ $params -eq $procs ] ||
16056                 error "found $params parameters vs. $procs proc files"
16057
16058         # test the list_param -D option only returns directories
16059         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
16060         #count the number of parameters by listing proc directories
16061         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
16062                 sort -u | wc -l)
16063
16064         [ $params -eq $procs ] ||
16065                 error "found $params parameters vs. $procs proc files"
16066 }
16067 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
16068
16069 test_401b() {
16070         local save=$($LCTL get_param -n jobid_var)
16071         local tmp=testing
16072
16073         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
16074                 error "no error returned when setting bad parameters"
16075
16076         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
16077         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
16078
16079         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
16080         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
16081         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
16082 }
16083 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
16084
16085 test_401c() {
16086         local jobid_var_old=$($LCTL get_param -n jobid_var)
16087         local jobid_var_new
16088
16089         $LCTL set_param jobid_var= &&
16090                 error "no error returned for 'set_param a='"
16091
16092         jobid_var_new=$($LCTL get_param -n jobid_var)
16093         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16094                 error "jobid_var was changed by setting without value"
16095
16096         $LCTL set_param jobid_var &&
16097                 error "no error returned for 'set_param a'"
16098
16099         jobid_var_new=$($LCTL get_param -n jobid_var)
16100         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16101                 error "jobid_var was changed by setting without value"
16102 }
16103 run_test 401c "Verify 'lctl set_param' without value fails in either format."
16104
16105 test_401d() {
16106         local jobid_var_old=$($LCTL get_param -n jobid_var)
16107         local jobid_var_new
16108         local new_value="foo=bar"
16109
16110         $LCTL set_param jobid_var=$new_value ||
16111                 error "'set_param a=b' did not accept a value containing '='"
16112
16113         jobid_var_new=$($LCTL get_param -n jobid_var)
16114         [[ "$jobid_var_new" == "$new_value" ]] ||
16115                 error "'set_param a=b' failed on a value containing '='"
16116
16117         # Reset the jobid_var to test the other format
16118         $LCTL set_param jobid_var=$jobid_var_old
16119         jobid_var_new=$($LCTL get_param -n jobid_var)
16120         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16121                 error "failed to reset jobid_var"
16122
16123         $LCTL set_param jobid_var $new_value ||
16124                 error "'set_param a b' did not accept a value containing '='"
16125
16126         jobid_var_new=$($LCTL get_param -n jobid_var)
16127         [[ "$jobid_var_new" == "$new_value" ]] ||
16128                 error "'set_param a b' failed on a value containing '='"
16129
16130         $LCTL set_param jobid_var $jobid_var_old
16131         jobid_var_new=$($LCTL get_param -n jobid_var)
16132         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16133                 error "failed to reset jobid_var"
16134 }
16135 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
16136
16137 test_402() {
16138         local server_version=$(lustre_version_code $SINGLEMDS)
16139         [[ $server_version -ge $(version_code 2.7.66) ]] ||
16140         [[ $server_version -ge $(version_code 2.7.18.4) &&
16141                 $server_version -lt $(version_code 2.7.50) ]] ||
16142         [[ $server_version -ge $(version_code 2.7.2) &&
16143                 $server_version -lt $(version_code 2.7.11) ]] ||
16144                 { skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+";
16145                         return; }
16146         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16147         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
16148 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
16149         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
16150         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
16151                 echo "Touch failed - OK"
16152 }
16153 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
16154
16155 test_403() {
16156         local file1=$DIR/$tfile.1
16157         local file2=$DIR/$tfile.2
16158         local tfile=$TMP/$tfile
16159
16160         rm -f $file1 $file2 $tfile
16161
16162         touch $file1
16163         ln $file1 $file2
16164
16165         # 30 sec OBD_TIMEOUT in ll_getattr()
16166         # right before populating st_nlink
16167         $LCTL set_param fail_loc=0x80001409
16168         stat -c %h $file1 > $tfile &
16169
16170         # create an alias, drop all locks and reclaim the dentry
16171         < $file2
16172         cancel_lru_locks mdc
16173         cancel_lru_locks osc
16174         sysctl -w vm.drop_caches=2
16175
16176         wait
16177
16178         [ `cat $tfile` -gt 0 ] || error "wrong nlink count: `cat $tfile`"
16179
16180         rm -f $tfile $file1 $file2
16181 }
16182 run_test 403 "i_nlink should not drop to zero due to aliasing"
16183
16184 test_404() { # LU-6601
16185         local server_version=$(lustre_version_code $SINGLEMDS)
16186         [[ $server_version -ge $(version_code 2.8.53) ]] ||
16187                 { skip "Need server version newer than 2.8.52"; return 0; }
16188
16189         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16190         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
16191                 awk '/osp .*-osc-MDT/ { print $4}')
16192
16193         local osp
16194         for osp in $mosps; do
16195                 echo "Deactivate: " $osp
16196                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
16197                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16198                         awk -vp=$osp '$4 == p { print $2 }')
16199                 [ $stat = IN ] || {
16200                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16201                         error "deactivate error"
16202                 }
16203                 echo "Activate: " $osp
16204                 do_facet $SINGLEMDS $LCTL --device %$osp activate
16205                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16206                         awk -vp=$osp '$4 == p { print $2 }')
16207                 [ $stat = UP ] || {
16208                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16209                         error "activate error"
16210                 }
16211         done
16212 }
16213 run_test 404 "validate manual {de}activated works properly for OSPs"
16214
16215 test_405() {
16216         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
16217                 skip "Layout swap lock is not supported" && return
16218
16219         check_swap_layouts_support && return 0
16220
16221         test_mkdir -p $DIR/$tdir
16222         swap_lock_test -d $DIR/$tdir ||
16223                 error "One layout swap locked test failed"
16224 }
16225 run_test 405 "Various layout swap lock tests"
16226
16227 test_406() {
16228         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16229         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
16230         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
16231         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16232         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.50) ] &&
16233                 skip "Need MDS version at least 2.8.50" && return
16234
16235         local def_stripenr=$($GETSTRIPE -c $MOUNT)
16236         local def_stripe_size=$($GETSTRIPE -S $MOUNT)
16237         local def_stripe_offset=$($GETSTRIPE -i $MOUNT)
16238         local def_pool=$($GETSTRIPE -p $MOUNT)
16239
16240         local test_pool=$TESTNAME
16241         pool_add $test_pool || error "pool_add failed"
16242         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
16243                 error "pool_add_targets failed"
16244
16245         # parent set default stripe count only, child will stripe from both
16246         # parent and fs default
16247         $SETSTRIPE -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
16248                 error "setstripe $MOUNT failed"
16249         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
16250         $SETSTRIPE -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
16251         for i in $(seq 10); do
16252                 local f=$DIR/$tdir/$tfile.$i
16253                 touch $f || error "touch failed"
16254                 local count=$($GETSTRIPE -c $f)
16255                 [ $count -eq $OSTCOUNT ] ||
16256                         error "$f stripe count $count != $OSTCOUNT"
16257                 local offset=$($GETSTRIPE -i $f)
16258                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
16259                 local size=$($GETSTRIPE -S $f)
16260                 [ $size -eq $((def_stripe_size * 2)) ] ||
16261                         error "$f stripe size $size != $((def_stripe_size * 2))"
16262                 local pool=$($GETSTRIPE -p $f)
16263                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
16264         done
16265
16266         # change fs default striping, delete parent default striping, now child
16267         # will stripe from new fs default striping only
16268         $SETSTRIPE -c 1 -S $def_stripe_size -i 0 $MOUNT ||
16269                 error "change $MOUNT default stripe failed"
16270         $SETSTRIPE -c 0 $DIR/$tdir || error "delete $tdir default stripe failed"
16271         for i in $(seq 11 20); do
16272                 local f=$DIR/$tdir/$tfile.$i
16273                 touch $f || error "touch $f failed"
16274                 local count=$($GETSTRIPE -c $f)
16275                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
16276                 local offset=$($GETSTRIPE -i $f)
16277                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
16278                 local size=$($GETSTRIPE -S $f)
16279                 [ $size -eq $def_stripe_size ] ||
16280                         error "$f stripe size $size != $def_stripe_size"
16281                 local pool=$($GETSTRIPE -p $f)
16282                 [ "#$pool" == "#" ] || error "$f pool $pool is set"
16283
16284         done
16285
16286         unlinkmany $DIR/$tdir/$tfile. 1 20
16287
16288         # restore FS default striping
16289         if [ -z $def_pool ]; then
16290                 $SETSTRIPE -c $def_stripenr -S $def_stripe_size \
16291                         -i $def_stripe_offset $MOUNT ||
16292                         error "restore default striping failed"
16293         else
16294                 $SETSTRIPE -c $def_stripenr -S $def_stripe_size -p $def_pool \
16295                         -i $def_stripe_offset $MOUNT ||
16296                         error "restore default striping with $def_pool failed"
16297         fi
16298
16299         local f=$DIR/$tdir/$tfile
16300         pool_remove_all_targets $test_pool $f
16301         pool_remove $test_pool $f
16302 }
16303 run_test 406 "DNE support fs default striping"
16304
16305 test_407() {
16306         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16307         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
16308                 skip "Need MDS version at least 2.8.55" && return
16309         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16310
16311         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
16312                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
16313         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
16314                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
16315         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
16316
16317         #define OBD_FAIL_DT_TXN_STOP    0x2019
16318         for idx in $(seq $MDSCOUNT); do
16319                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
16320         done
16321         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
16322         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
16323                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
16324         true
16325 }
16326 run_test 407 "transaction fail should cause operation fail"
16327
16328 test_408() {
16329         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
16330
16331         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
16332         lctl set_param fail_loc=0x8000040a
16333         # let ll_prepare_partial_page() fail
16334         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
16335
16336         rm -f $DIR/$tfile
16337
16338         # create at least 100 unused inodes so that
16339         # shrink_icache_memory(0) should not return 0
16340         touch $DIR/$tfile-{0..100}
16341         rm -f $DIR/$tfile-{0..100}
16342         sync
16343
16344         echo 2 > /proc/sys/vm/drop_caches
16345 }
16346 run_test 408 "drop_caches should not hang due to page leaks"
16347
16348 test_409()
16349 {
16350         [ $MDSCOUNT -lt 2 ] &&
16351                 skip "We need at least 2 MDTs for this test" && return
16352
16353         check_mount_and_prep
16354
16355         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
16356         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
16357         touch $DIR/$tdir/guard || error "(2) Fail to create"
16358
16359         local PREFIX=$(str_repeat 'A' 128)
16360         echo "Create 1K hard links start at $(date)"
16361         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16362                 error "(3) Fail to hard link"
16363
16364         echo "Links count should be right although linkEA overflow"
16365         stat $DIR/$tdir/guard || error "(4) Fail to stat"
16366         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
16367         [ $linkcount -eq 1001 ] ||
16368                 error "(5) Unexpected hard links count: $linkcount"
16369
16370         echo "List all links start at $(date)"
16371         ls -l $DIR/$tdir/foo > /dev/null ||
16372                 error "(6) Fail to list $DIR/$tdir/foo"
16373
16374         echo "Unlink hard links start at $(date)"
16375         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16376                 error "(7) Fail to unlink"
16377 }
16378 run_test 409 "Large amount of cross-MDTs hard links on the same file"
16379
16380 test_410()
16381 {
16382         # Create a file, and stat it from the kernel
16383         local testfile=$DIR/$tfile
16384         touch $testfile
16385
16386         local run_id=$RANDOM
16387         local my_ino=$(stat --format "%i" $testfile)
16388
16389         # Try to insert the module. This will always fail as the
16390         # module is designed to not be inserted.
16391         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
16392             &> /dev/null
16393
16394         # Anything but success is a test failure
16395         dmesg | grep -q \
16396             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
16397             error "no inode match"
16398 }
16399 run_test 410 "Test inode number returned from kernel thread"
16400
16401 prep_801() {
16402         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
16403         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
16404                 skip "Need server version at least 2.9.55" & exit 0
16405         start_full_debug_logging
16406 }
16407
16408 post_801() {
16409         stop_full_debug_logging
16410 }
16411
16412 barrier_stat() {
16413         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16414                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16415                            awk '/The barrier for/ { print $7 }')
16416                 echo $st
16417         else
16418                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
16419                 echo \'$st\'
16420         fi
16421 }
16422
16423 barrier_expired() {
16424         local expired
16425
16426         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16427                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16428                           awk '/will be expired/ { print $7 }')
16429         else
16430                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
16431         fi
16432
16433         echo $expired
16434 }
16435
16436 test_801a() {
16437         prep_801
16438
16439         echo "Start barrier_freeze at: $(date)"
16440         #define OBD_FAIL_BARRIER_DELAY          0x2202
16441         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
16442         do_facet mgs $LCTL barrier_freeze $FSNAME 10 &
16443
16444         sleep 2
16445         local b_status=$(barrier_stat)
16446         echo "Got barrier status at: $(date)"
16447         [ "$b_status" = "'freezing_p1'" ] ||
16448                 error "(1) unexpected barrier status $b_status"
16449
16450         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
16451         wait
16452         b_status=$(barrier_stat)
16453         [ "$b_status" = "'frozen'" ] ||
16454                 error "(2) unexpected barrier status $b_status"
16455
16456         local expired=$(barrier_expired)
16457         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
16458         sleep $((expired + 3))
16459
16460         b_status=$(barrier_stat)
16461         [ "$b_status" = "'expired'" ] ||
16462                 error "(3) unexpected barrier status $b_status"
16463
16464         do_facet mgs $LCTL barrier_freeze $FSNAME 10 ||
16465                 error "(4) fail to freeze barrier"
16466
16467         b_status=$(barrier_stat)
16468         [ "$b_status" = "'frozen'" ] ||
16469                 error "(5) unexpected barrier status $b_status"
16470
16471         echo "Start barrier_thaw at: $(date)"
16472         #define OBD_FAIL_BARRIER_DELAY          0x2202
16473         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
16474         do_facet mgs $LCTL barrier_thaw $FSNAME &
16475
16476         sleep 2
16477         b_status=$(barrier_stat)
16478         echo "Got barrier status at: $(date)"
16479         [ "$b_status" = "'thawing'" ] ||
16480                 error "(6) unexpected barrier status $b_status"
16481
16482         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
16483         wait
16484         b_status=$(barrier_stat)
16485         [ "$b_status" = "'thawed'" ] ||
16486                 error "(7) unexpected barrier status $b_status"
16487
16488         #define OBD_FAIL_BARRIER_FAILURE        0x2203
16489         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
16490         do_facet mgs $LCTL barrier_freeze $FSNAME
16491
16492         b_status=$(barrier_stat)
16493         [ "$b_status" = "'failed'" ] ||
16494                 error "(8) unexpected barrier status $b_status"
16495
16496         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
16497         do_facet mgs $LCTL barrier_thaw $FSNAME
16498
16499         post_801
16500 }
16501 run_test 801a "write barrier user interfaces and stat machine"
16502
16503 test_801b() {
16504         prep_801
16505
16506         mkdir $DIR/$tdir || error "(1) fail to mkdir"
16507         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
16508         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
16509         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
16510         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
16511
16512         cancel_lru_locks mdc
16513
16514         # 180 seconds should be long enough
16515         do_facet mgs $LCTL barrier_freeze $FSNAME 180
16516
16517         local b_status=$(barrier_stat)
16518         [ "$b_status" = "'frozen'" ] ||
16519                 error "(6) unexpected barrier status $b_status"
16520
16521         mkdir $DIR/$tdir/d0/d10 &
16522         mkdir_pid=$!
16523
16524         touch $DIR/$tdir/d1/f13 &
16525         touch_pid=$!
16526
16527         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
16528         ln_pid=$!
16529
16530         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
16531         mv_pid=$!
16532
16533         rm -f $DIR/$tdir/d4/f12 &
16534         rm_pid=$!
16535
16536         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
16537
16538         # To guarantee taht the 'stat' is not blocked
16539         b_status=$(barrier_stat)
16540         [ "$b_status" = "'frozen'" ] ||
16541                 error "(8) unexpected barrier status $b_status"
16542
16543         # let above commands to run at background
16544         sleep 5
16545
16546         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
16547         ps -p $touch_pid || error "(10) touch should be blocked"
16548         ps -p $ln_pid || error "(11) link should be blocked"
16549         ps -p $mv_pid || error "(12) rename should be blocked"
16550         ps -p $rm_pid || error "(13) unlink should be blocked"
16551
16552         b_status=$(barrier_stat)
16553         [ "$b_status" = "'frozen'" ] ||
16554                 error "(14) unexpected barrier status $b_status"
16555
16556         do_facet mgs $LCTL barrier_thaw $FSNAME
16557         b_status=$(barrier_stat)
16558         [ "$b_status" = "'thawed'" ] ||
16559                 error "(15) unexpected barrier status $b_status"
16560
16561         wait $mkdir_pid || error "(16) mkdir should succeed"
16562         wait $touch_pid || error "(17) touch should succeed"
16563         wait $ln_pid || error "(18) link should succeed"
16564         wait $mv_pid || error "(19) rename should succeed"
16565         wait $rm_pid || error "(20) unlink should succeed"
16566
16567         post_801
16568 }
16569 run_test 801b "modification will be blocked by write barrier"
16570
16571 test_801c() {
16572         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
16573
16574         prep_801
16575
16576         stop mds2 || error "(1) Fail to stop mds2"
16577
16578         do_facet mgs $LCTL barrier_freeze $FSNAME 30
16579
16580         local b_status=$(barrier_stat)
16581         [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || {
16582                 do_facet mgs $LCTL barrier_thaw $FSNAME
16583                 error "(2) unexpected barrier status $b_status"
16584         }
16585
16586         do_facet mgs $LCTL barrier_rescan $FSNAME ||
16587                 error "(3) Fail to rescan barrier bitmap"
16588
16589         do_facet mgs $LCTL barrier_freeze $FSNAME 10
16590
16591         b_status=$(barrier_stat)
16592         [ "$b_status" = "'frozen'" ] ||
16593                 error "(4) unexpected barrier status $b_status"
16594
16595         do_facet mgs $LCTL barrier_thaw $FSNAME
16596         b_status=$(barrier_stat)
16597         [ "$b_status" = "'thawed'" ] ||
16598                 error "(5) unexpected barrier status $b_status"
16599
16600         local devname=$(mdsdevname 2)
16601
16602         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
16603
16604         do_facet mgs $LCTL barrier_rescan $FSNAME ||
16605                 error "(7) Fail to rescan barrier bitmap"
16606
16607         post_801
16608 }
16609 run_test 801c "rescan barrier bitmap"
16610
16611 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
16612 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
16613 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
16614
16615 cleanup_802() {
16616         trap 0
16617
16618         stopall
16619         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
16620         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
16621         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
16622         setupall
16623 }
16624
16625 test_802() {
16626
16627         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
16628         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
16629                 skip "Need server version at least 2.9.55" & exit 0
16630
16631         mkdir $DIR/$tdir || error "(1) fail to mkdir"
16632
16633         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
16634                 error "(2) Fail to copy"
16635
16636         trap cleanup_802 EXIT
16637
16638         # sync by force before remount as readonly
16639         sync; sync_all_data; sleep 3; sync_all_data
16640
16641         stopall
16642
16643         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
16644         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
16645         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
16646
16647         echo "Mount the server as read only"
16648         setupall server_only || error "(3) Fail to start servers"
16649
16650         echo "Mount client without ro should fail"
16651         mount_client $MOUNT &&
16652                 error "(4) Mount client without 'ro' should fail"
16653
16654         echo "Mount client with ro should succeed"
16655         mount_client $MOUNT ro ||
16656                 error "(5) Mount client with 'ro' should succeed"
16657
16658         echo "Modify should be refused"
16659         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
16660
16661         echo "Read should be allowed"
16662         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
16663                 error "(7) Read should succeed under ro mode"
16664
16665         cleanup_802
16666 }
16667 run_test 802 "simulate readonly device"
16668
16669 #
16670 # tests that do cleanup/setup should be run at the end
16671 #
16672
16673 test_900() {
16674         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16675         local ls
16676         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
16677         $LCTL set_param fail_loc=0x903
16678
16679         cancel_lru_locks MGC
16680
16681         FAIL_ON_ERROR=true cleanup
16682         FAIL_ON_ERROR=true setup
16683 }
16684 run_test 900 "umount should not race with any mgc requeue thread"
16685
16686 complete $SECONDS
16687 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
16688 check_and_cleanup_lustre
16689 if [ "$I_MOUNTED" != "yes" ]; then
16690         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
16691 fi
16692 exit_status