Whamcloud - gitweb
LU-832 test: Add error check when running run-llog.sh
[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-2036 LU-8411 LU-9096 LU-9054
16 ALWAYS_EXCEPT="  76      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-1957
85         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  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") -ne 1 ] &&
1720                 error "$LFS getstripe -d $DIR/$tdir failed" || true
1721 }
1722 run_test 27w "check $LFS setstripe -S option"
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_lfsdf EXIT
4157
4158         # create files
4159         createmany -d $dir/d $nrdirs ||
4160                 error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
4161
4162         # really created :
4163         nrdirs=$(ls -U $dir | wc -l)
4164
4165         # unlink all but 100 subdirectories, then check it still works
4166         local left=100
4167         local delete=$((nrdirs - left))
4168
4169         $LFS df
4170         $LFS df -i
4171
4172         # for ldiskfs the nlink count should be 1, but this is OSD specific
4173         # and so this is listed for informational purposes only
4174         echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
4175         unlinkmany -d $dir/d $delete ||
4176                 error "unlink of first $delete subdirs failed"
4177
4178         echo "nlink between: $(stat -c %h $dir)"
4179         local found=$(ls -U $dir | wc -l)
4180         [ $found -ne $left ] &&
4181                 error "can't find subdirs: found only $found, expected $left"
4182
4183         unlinkmany -d $dir/d $delete $left ||
4184                 error "unlink of second $left subdirs failed"
4185         # regardless of whether the backing filesystem tracks nlink accurately
4186         # or not, the nlink count shouldn't be more than "." and ".." here
4187         local after=$(stat -c %h $dir)
4188         [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
4189                 echo "nlink after: $after"
4190
4191         cleanup_print_lfs_df
4192 }
4193 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
4194
4195 test_51d() {
4196         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4197         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
4198         test_mkdir -p $DIR/$tdir
4199         createmany -o $DIR/$tdir/t- 1000
4200         $GETSTRIPE $DIR/$tdir > $TMP/$tfile
4201         for N in $(seq 0 $((OSTCOUNT - 1))); do
4202                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4203                         END { printf("%0.0f", objs) }' $TMP/$tfile)
4204                 OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
4205                         '($1 == '$N') { objs += 1 } \
4206                         END { printf("%0.0f", objs) }')
4207                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4208         done
4209         unlinkmany $DIR/$tdir/t- 1000
4210
4211         NLAST=0
4212         for N in $(seq 1 $((OSTCOUNT - 1))); do
4213                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4214                         error "OST $N has less objects vs OST $NLAST" \
4215                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4216                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4217                         error "OST $N has less objects vs OST $NLAST" \
4218                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4219
4220                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4221                         error "OST $N has less #0 objects vs OST $NLAST" \
4222                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4223                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4224                         error "OST $N has less #0 objects vs OST $NLAST" \
4225                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4226                 NLAST=$N
4227         done
4228         rm -f $TMP/$tfile
4229 }
4230 run_test 51d "check object distribution"
4231
4232 test_51e() {
4233         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4234                 skip "ldiskfs only test"
4235                 return
4236         fi
4237
4238         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4239         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4240
4241         touch $DIR/$tdir/d0/foo
4242         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4243                 error "file exceed 65000 nlink limit!"
4244         unlinkmany $DIR/$tdir/d0/f- 65001
4245         return 0
4246 }
4247 run_test 51e "check file nlink limit"
4248
4249 test_51f() {
4250         test_mkdir $DIR/$tdir
4251
4252         local max=100000
4253         local ulimit_old=$(ulimit -n)
4254         local spare=20 # number of spare fd's for scripts/libraries, etc.
4255         local mdt=$(lfs getstripe -M $DIR/$tdir)
4256         local numfree=$(lfs df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
4257
4258         echo "MDT$mdt numfree=$numfree, max=$max"
4259         [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
4260         if [ $((numfree + spare)) -gt $ulimit_old ]; then
4261                 while ! ulimit -n $((numfree + spare)); do
4262                         numfree=$((numfree * 3 / 4))
4263                 done
4264                 echo "changed ulimit from $ulimit_old to $((numfree + spare))"
4265         else
4266                 echo "left ulimit at $ulimit_old"
4267         fi
4268
4269         createmany -o -k -t 120 $DIR/$tdir/f $numfree ||
4270                 error "create+open $numfree files in $DIR/$tdir failed"
4271         ulimit -n $ulimit_old
4272
4273         # if createmany exits at 120s there will be fewer than $numfree files
4274         unlinkmany $DIR/$tdir/f $numfree || true
4275 }
4276 run_test 51f "check many open files limit"
4277
4278 test_52a() {
4279         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4280         test_mkdir -p $DIR/$tdir
4281         touch $DIR/$tdir/foo
4282         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4283         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4284         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4285         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4286         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4287                                         error "link worked"
4288         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4289         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4290         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4291                                                      error "lsattr"
4292         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4293         cp -r $DIR/$tdir $TMP/
4294         rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
4295 }
4296 run_test 52a "append-only flag test (should return errors)"
4297
4298 test_52b() {
4299         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4300         test_mkdir -p $DIR/$tdir
4301         touch $DIR/$tdir/foo
4302         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4303         cat test > $DIR/$tdir/foo && error "cat test worked"
4304         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4305         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4306         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4307                                         error "link worked"
4308         echo foo >> $DIR/$tdir/foo && error "echo worked"
4309         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4310         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4311         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4312         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4313                                                         error "lsattr"
4314         chattr -i $DIR/$tdir/foo || error "chattr failed"
4315
4316         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4317 }
4318 run_test 52b "immutable flag test (should return errors) ======="
4319
4320 test_53() {
4321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4322         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4323         remote_ost_nodsh && skip "remote OST with nodsh" && return
4324
4325         local param
4326         local param_seq
4327         local ostname
4328         local mds_last
4329         local mds_last_seq
4330         local ost_last
4331         local ost_last_seq
4332         local ost_last_id
4333         local ostnum
4334         local node
4335         local found=false
4336         local support_last_seq=true
4337
4338         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4339                 support_last_seq=false
4340
4341         # only test MDT0000
4342         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4343         local value
4344         for value in $(do_facet $SINGLEMDS \
4345                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4346                 param=$(echo ${value[0]} | cut -d "=" -f1)
4347                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4348
4349                 if $support_last_seq; then
4350                         param_seq=$(echo $param |
4351                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4352                         mds_last_seq=$(do_facet $SINGLEMDS \
4353                                        $LCTL get_param -n $param_seq)
4354                 fi
4355                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4356
4357                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4358                 node=$(facet_active_host ost$((ostnum+1)))
4359                 param="obdfilter.$ostname.last_id"
4360                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4361                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4362                         ost_last_id=$ost_last
4363
4364                         if $support_last_seq; then
4365                                 ost_last_id=$(echo $ost_last |
4366                                               awk -F':' '{print $2}' |
4367                                               sed -e "s/^0x//g")
4368                                 ost_last_seq=$(echo $ost_last |
4369                                                awk -F':' '{print $1}')
4370                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4371                         fi
4372
4373                         if [[ $ost_last_id != $mds_last ]]; then
4374                                 error "$ost_last_id != $mds_last"
4375                         else
4376                                 found=true
4377                                 break
4378                         fi
4379                 done
4380         done
4381         $found || error "can not match last_seq/last_id for $mdtosc"
4382         return 0
4383 }
4384 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4385
4386 test_54a() {
4387         perl -MSocket -e ';' || { skip "no Socket perl module installed" && return; }
4388
4389         $SOCKETSERVER $DIR/socket ||
4390                 error "$SOCKETSERVER $DIR/socket failed: $?"
4391         $SOCKETCLIENT $DIR/socket ||
4392                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4393         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4394 }
4395 run_test 54a "unix domain socket test =========================="
4396
4397 test_54b() {
4398         f="$DIR/f54b"
4399         mknod $f c 1 3
4400         chmod 0666 $f
4401         dd if=/dev/zero of=$f bs=$(page_size) count=1
4402 }
4403 run_test 54b "char device works in lustre ======================"
4404
4405 find_loop_dev() {
4406         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4407         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4408         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4409
4410         for i in $(seq 3 7); do
4411                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4412                 LOOPDEV=$LOOPBASE$i
4413                 LOOPNUM=$i
4414                 break
4415         done
4416 }
4417
4418 cleanup_54c() {
4419         local rc=0
4420         loopdev="$DIR/loop54c"
4421
4422         trap 0
4423         $UMOUNT $DIR/$tdir || rc=$?
4424         losetup -d $loopdev || true
4425         losetup -d $LOOPDEV || true
4426         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4427         return $rc
4428 }
4429
4430 test_54c() {
4431         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4432         loopdev="$DIR/loop54c"
4433
4434         find_loop_dev
4435         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4436         trap cleanup_54c EXIT
4437         mknod $loopdev b 7 $LOOPNUM
4438         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4439         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4440         losetup $loopdev $DIR/$tfile ||
4441                 error "can't set up $loopdev for $DIR/$tfile"
4442         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4443         test_mkdir -p $DIR/$tdir
4444         mount -t ext2 $loopdev $DIR/$tdir ||
4445                 error "error mounting $loopdev on $DIR/$tdir"
4446         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4447                 error "dd write"
4448         df $DIR/$tdir
4449         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4450                 error "dd read"
4451         cleanup_54c
4452 }
4453 run_test 54c "block device works in lustre ====================="
4454
4455 test_54d() {
4456         f="$DIR/f54d"
4457         string="aaaaaa"
4458         mknod $f p
4459         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4460 }
4461 run_test 54d "fifo device works in lustre ======================"
4462
4463 test_54e() {
4464         f="$DIR/f54e"
4465         string="aaaaaa"
4466         cp -aL /dev/console $f
4467         echo $string > $f || error "echo $string to $f failed"
4468 }
4469 run_test 54e "console/tty device works in lustre ======================"
4470
4471 #The test_55 used to be iopen test and it was removed by bz#24037.
4472 #run_test 55 "check iopen_connect_dentry() ======================"
4473
4474 test_56a() {    # was test_56
4475         rm -rf $DIR/$tdir
4476         $SETSTRIPE -d $DIR
4477         test_mkdir -p $DIR/$tdir/dir
4478         NUMFILES=3
4479         NUMFILESx2=$(($NUMFILES * 2))
4480         for i in $(seq 1 $NUMFILES); do
4481                 touch $DIR/$tdir/file$i
4482                 touch $DIR/$tdir/dir/file$i
4483         done
4484
4485         # test lfs getstripe with --recursive
4486         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4487         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4488                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4489         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4490         [[ $FILENUM -eq $NUMFILES ]] ||
4491                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4492         echo "$GETSTRIPE --recursive passed."
4493
4494         # test lfs getstripe with file instead of dir
4495         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4496         [[ $FILENUM -eq 1 ]] ||
4497                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4498         echo "$GETSTRIPE file1 passed."
4499
4500         #test lfs getstripe with --verbose
4501         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4502                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4503                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4504         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4505                 error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4506
4507         #test lfs getstripe with -v prints lmm_fid
4508         [[ $($GETSTRIPE -v $DIR/$tdir | grep -c lmm_fid) -eq $NUMFILES ]] ||
4509                 error "$GETSTRIPE -v $DIR/$tdir: want $NUMFILES lmm_fid: lines"
4510         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_fid) -eq 0 ]] ||
4511                 error "$GETSTRIPE $DIR/$tdir: showed lmm_fid"
4512         echo "$GETSTRIPE --verbose passed."
4513
4514         #check for FID information
4515         local fid1=$($GETSTRIPE --fid $DIR/$tdir/file1)
4516         local fid2=$($GETSTRIPE --verbose $DIR/$tdir/file1 |
4517                        awk '/lmm_fid: / { print $2 }')
4518         local fid3=$($LFS path2fid $DIR/$tdir/file1)
4519         [ "$fid1" != "$fid2" ] &&
4520                 error "getstripe --fid $fid1 != getstripe --verbose $fid2"
4521         [ "$fid1" != "$fid3" ] &&
4522                 error "getstripe --fid $fid1 != lfs path2fid $fid3"
4523         echo "$GETSTRIPE --fid passed."
4524
4525         #test lfs getstripe with --obd
4526         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4527                 grep -q "unknown obduuid" ||
4528                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4529
4530         [[ $OSTCOUNT -lt 2 ]] &&
4531                 skip_env "skipping other $GETSTRIPE --obd test" && return
4532
4533         OSTIDX=1
4534         OBDUUID=$(ostuuid_from_index $OSTIDX)
4535         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4536         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4537         [[ $FOUND -eq $FILENUM ]] ||
4538                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4539         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4540                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4541                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4542                 error "$GETSTRIPE --obd: should not show file on other obd"
4543         echo "$GETSTRIPE --obd passed"
4544 }
4545 run_test 56a "check $GETSTRIPE"
4546
4547 test_56b() {
4548         test_mkdir $DIR/$tdir
4549         NUMDIRS=3
4550         for i in $(seq 1 $NUMDIRS); do
4551                 test_mkdir $DIR/$tdir/dir$i
4552         done
4553
4554         # test lfs getdirstripe default mode is non-recursion, which is
4555         # different from lfs getstripe
4556         dircnt=$($LFS getdirstripe $DIR/$tdir | grep -c lmv_stripe_count)
4557         [[ $dircnt -eq 1 ]] ||
4558                 error "$LFS getdirstripe: found $dircnt, not 1"
4559         dircnt=$($LFS getdirstripe --recursive $DIR/$tdir |
4560                 grep -c lmv_stripe_count)
4561         [[ $dircnt -eq $((NUMDIRS + 1)) ]] ||
4562                 error "$LFS getdirstripe --recursive: found $dircnt, \
4563                         not $((NUMDIRS + 1))"
4564 }
4565 run_test 56b "check $LFS getdirstripe"
4566
4567 test_56c() {
4568         local ost_idx=0
4569         local ost_name=$(ostname_from_index $ost_idx)
4570
4571         local old_status=$(ost_dev_status $ost_idx)
4572         [[ -z "$old_status" ]] ||
4573                 { skip_env "OST $ost_name is in $old_status status"; return 0; }
4574
4575         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
4576         sleep_maxage
4577
4578         local new_status=$(ost_dev_status $ost_idx)
4579         [[ "$new_status" = "D" ]] ||
4580                 error "OST $ost_name is in status of '$new_status', not 'D'"
4581
4582         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
4583         sleep_maxage
4584
4585         new_status=$(ost_dev_status $ost_idx)
4586         [[ -z "$new_status" ]] ||
4587                 error "OST $ost_name is in status of '$new_status', not ''"
4588 }
4589 run_test 56c "check 'lfs df' showing device status"
4590
4591 NUMFILES=3
4592 NUMDIRS=3
4593 setup_56() {
4594         local LOCAL_NUMFILES="$1"
4595         local LOCAL_NUMDIRS="$2"
4596         local MKDIR_PARAMS="$3"
4597         local DIR_STRIPE_PARAMS="$4"
4598
4599         if [ ! -d "$TDIR" ] ; then
4600                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4601                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4602                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4603                         touch $TDIR/file$i
4604                 done
4605                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4606                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4607                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4608                                 touch $TDIR/dir$i/file$j
4609                         done
4610                 done
4611         fi
4612 }
4613
4614 setup_56_special() {
4615         LOCAL_NUMFILES=$1
4616         LOCAL_NUMDIRS=$2
4617         setup_56 $1 $2
4618         if [ ! -e "$TDIR/loop1b" ] ; then
4619                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4620                         mknod $TDIR/loop${i}b b 7 $i
4621                         mknod $TDIR/null${i}c c 1 3
4622                         ln -s $TDIR/file1 $TDIR/link${i}l
4623                 done
4624                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4625                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4626                         mknod $TDIR/dir$i/null${i}c c 1 3
4627                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4628                 done
4629         fi
4630 }
4631
4632 test_56g() {
4633         $SETSTRIPE -d $DIR
4634
4635         TDIR=$DIR/${tdir}g
4636         setup_56 $NUMFILES $NUMDIRS
4637
4638         EXPECTED=$(($NUMDIRS + 2))
4639         # test lfs find with -name
4640         for i in $(seq 1 $NUMFILES) ; do
4641                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4642                 [ $NUMS -eq $EXPECTED ] ||
4643                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4644                               "found $NUMS, expected $EXPECTED"
4645         done
4646 }
4647 run_test 56g "check lfs find -name ============================="
4648
4649 test_56h() {
4650         $SETSTRIPE -d $DIR
4651
4652         TDIR=$DIR/${tdir}g
4653         setup_56 $NUMFILES $NUMDIRS
4654
4655         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4656         # test lfs find with ! -name
4657         for i in $(seq 1 $NUMFILES) ; do
4658                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4659                 [ $NUMS -eq $EXPECTED ] ||
4660                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4661                               "found $NUMS, expected $EXPECTED"
4662         done
4663 }
4664 run_test 56h "check lfs find ! -name ============================="
4665
4666 test_56i() {
4667        tdir=${tdir}i
4668        test_mkdir -p $DIR/$tdir
4669        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4670        CMD="$LFIND -ost $UUID $DIR/$tdir"
4671        OUT=$($CMD)
4672        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4673 }
4674 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4675
4676 test_56j() {
4677         TDIR=$DIR/${tdir}g
4678         setup_56_special $NUMFILES $NUMDIRS
4679
4680         EXPECTED=$((NUMDIRS + 1))
4681         CMD="$LFIND -type d $TDIR"
4682         NUMS=$($CMD | wc -l)
4683         [ $NUMS -eq $EXPECTED ] ||
4684                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4685 }
4686 run_test 56j "check lfs find -type d ============================="
4687
4688 test_56k() {
4689         TDIR=$DIR/${tdir}g
4690         setup_56_special $NUMFILES $NUMDIRS
4691
4692         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4693         CMD="$LFIND -type f $TDIR"
4694         NUMS=$($CMD | wc -l)
4695         [ $NUMS -eq $EXPECTED ] ||
4696                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4697 }
4698 run_test 56k "check lfs find -type f ============================="
4699
4700 test_56l() {
4701         TDIR=$DIR/${tdir}g
4702         setup_56_special $NUMFILES $NUMDIRS
4703
4704         EXPECTED=$((NUMDIRS + NUMFILES))
4705         CMD="$LFIND -type b $TDIR"
4706         NUMS=$($CMD | wc -l)
4707         [ $NUMS -eq $EXPECTED ] ||
4708                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4709 }
4710 run_test 56l "check lfs find -type b ============================="
4711
4712 test_56m() {
4713         TDIR=$DIR/${tdir}g
4714         setup_56_special $NUMFILES $NUMDIRS
4715
4716         EXPECTED=$((NUMDIRS + NUMFILES))
4717         CMD="$LFIND -type c $TDIR"
4718         NUMS=$($CMD | wc -l)
4719         [ $NUMS -eq $EXPECTED ] ||
4720                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4721 }
4722 run_test 56m "check lfs find -type c ============================="
4723
4724 test_56n() {
4725         TDIR=$DIR/${tdir}g
4726         setup_56_special $NUMFILES $NUMDIRS
4727
4728         EXPECTED=$((NUMDIRS + NUMFILES))
4729         CMD="$LFIND -type l $TDIR"
4730         NUMS=$($CMD | wc -l)
4731         [ $NUMS -eq $EXPECTED ] ||
4732                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4733 }
4734 run_test 56n "check lfs find -type l ============================="
4735
4736 test_56o() {
4737         TDIR=$DIR/${tdir}o
4738         setup_56 $NUMFILES $NUMDIRS
4739         utime $TDIR/file1 > /dev/null || error "utime (1)"
4740         utime $TDIR/file2 > /dev/null || error "utime (2)"
4741         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4742         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4743         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4744         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4745
4746         EXPECTED=4
4747         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4748         [ $NUMS -eq $EXPECTED ] || \
4749                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4750
4751         EXPECTED=12
4752         CMD="$LFIND -mtime 0 $TDIR"
4753         NUMS=$($CMD | wc -l)
4754         [ $NUMS -eq $EXPECTED ] ||
4755                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4756 }
4757 run_test 56o "check lfs find -mtime for old files =========================="
4758
4759 test_56p() {
4760         [ $RUNAS_ID -eq $UID ] &&
4761                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4762
4763         TDIR=$DIR/${tdir}p
4764         setup_56 $NUMFILES $NUMDIRS
4765
4766         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4767         EXPECTED=$NUMFILES
4768         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4769         NUMS=$($CMD | wc -l)
4770         [ $NUMS -eq $EXPECTED ] || \
4771                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4772
4773         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4774         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4775         NUMS=$($CMD | wc -l)
4776         [ $NUMS -eq $EXPECTED ] || \
4777                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4778 }
4779 run_test 56p "check lfs find -uid and ! -uid ==============================="
4780
4781 test_56q() {
4782         [ $RUNAS_ID -eq $UID ] &&
4783                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4784
4785         TDIR=$DIR/${tdir}q
4786         setup_56 $NUMFILES $NUMDIRS
4787
4788         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4789
4790         EXPECTED=$NUMFILES
4791         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4792         NUMS=$($CMD | wc -l)
4793         [ $NUMS -eq $EXPECTED ] ||
4794                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4795
4796         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4797         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4798         NUMS=$($CMD | wc -l)
4799         [ $NUMS -eq $EXPECTED ] ||
4800                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4801 }
4802 run_test 56q "check lfs find -gid and ! -gid ==============================="
4803
4804 test_56r() {
4805         TDIR=$DIR/${tdir}r
4806         setup_56 $NUMFILES $NUMDIRS
4807
4808         EXPECTED=12
4809         CMD="$LFIND -size 0 -type f $TDIR"
4810         NUMS=$($CMD | wc -l)
4811         [ $NUMS -eq $EXPECTED ] ||
4812                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4813         EXPECTED=0
4814         CMD="$LFIND ! -size 0 -type f $TDIR"
4815         NUMS=$($CMD | wc -l)
4816         [ $NUMS -eq $EXPECTED ] ||
4817                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4818         echo "test" > $TDIR/$tfile
4819         echo "test2" > $TDIR/$tfile.2 && sync
4820         EXPECTED=1
4821         CMD="$LFIND -size 5 -type f $TDIR"
4822         NUMS=$($CMD | wc -l)
4823         [ $NUMS -eq $EXPECTED ] ||
4824                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4825         EXPECTED=1
4826         CMD="$LFIND -size +5 -type f $TDIR"
4827         NUMS=$($CMD | wc -l)
4828         [ $NUMS -eq $EXPECTED ] ||
4829                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4830         EXPECTED=2
4831         CMD="$LFIND -size +0 -type f $TDIR"
4832         NUMS=$($CMD | wc -l)
4833         [ $NUMS -eq $EXPECTED ] ||
4834                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4835         EXPECTED=2
4836         CMD="$LFIND ! -size -5 -type f $TDIR"
4837         NUMS=$($CMD | wc -l)
4838         [ $NUMS -eq $EXPECTED ] ||
4839                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4840         EXPECTED=12
4841         CMD="$LFIND -size -5 -type f $TDIR"
4842         NUMS=$($CMD | wc -l)
4843         [ $NUMS -eq $EXPECTED ] ||
4844                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4845 }
4846 run_test 56r "check lfs find -size works =========================="
4847
4848 test_56s() { # LU-611
4849         TDIR=$DIR/${tdir}s
4850
4851         #LU-9369
4852         setup_56 0 $NUMDIRS
4853         for i in $(seq 1 $NUMDIRS); do
4854                 $SETSTRIPE -c $((OSTCOUNT + 1)) $TDIR/dir$i/$tfile
4855         done
4856         EXPECTED=$NUMDIRS
4857         CMD="$LFIND -c $OSTCOUNT $TDIR"
4858         NUMS=$($CMD | wc -l)
4859         [ $NUMS -eq $EXPECTED ] || {
4860                 $GETSTRIPE -R $TDIR
4861                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4862         }
4863         rm -rf $TDIR
4864
4865         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4866         if [[ $OSTCOUNT -gt 1 ]]; then
4867                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4868                 ONESTRIPE=4
4869                 EXTRA=4
4870         else
4871                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4872                 EXTRA=0
4873         fi
4874
4875         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4876         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4877         NUMS=$($CMD | wc -l)
4878         [ $NUMS -eq $EXPECTED ] || {
4879                 $GETSTRIPE -R $TDIR
4880                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4881         }
4882
4883         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4884         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4885         NUMS=$($CMD | wc -l)
4886         [ $NUMS -eq $EXPECTED ] || {
4887                 $GETSTRIPE -R $TDIR
4888                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4889         }
4890
4891         EXPECTED=$ONESTRIPE
4892         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4893         NUMS=$($CMD | wc -l)
4894         [ $NUMS -eq $EXPECTED ] || {
4895                 $GETSTRIPE -R $TDIR
4896                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4897         }
4898
4899         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4900         NUMS=$($CMD | wc -l)
4901         [ $NUMS -eq $EXPECTED ] || {
4902                 $GETSTRIPE -R $TDIR
4903                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4904         }
4905
4906         EXPECTED=0
4907         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4908         NUMS=$($CMD | wc -l)
4909         [ $NUMS -eq $EXPECTED ] || {
4910                 $GETSTRIPE -R $TDIR
4911                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4912         }
4913 }
4914 run_test 56s "check lfs find -stripe-count works"
4915
4916 test_56t() { # LU-611
4917         TDIR=$DIR/${tdir}t
4918
4919         #LU-9369
4920         setup_56 0 $NUMDIRS
4921         for i in $(seq 1 $NUMDIRS); do
4922                 $SETSTRIPE -S 4M $TDIR/dir$i/$tfile
4923         done
4924         EXPECTED=$NUMDIRS
4925         CMD="$LFIND -S 4M $TDIR"
4926         NUMS=$($CMD | wc -l)
4927         [ $NUMS -eq $EXPECTED ] || {
4928                 $GETSTRIPE -R $TDIR
4929                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4930         }
4931         rm -rf $TDIR
4932
4933         setup_56 $NUMFILES $NUMDIRS "--stripe-size 512k"
4934
4935         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4936
4937         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4938         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4939         NUMS=$($CMD | wc -l)
4940         [ $NUMS -eq $EXPECTED ] ||
4941                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4942
4943         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4944         NUMS=$($CMD | wc -l)
4945         [ $NUMS -eq $EXPECTED ] ||
4946                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4947
4948         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4949         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4950         NUMS=$($CMD | wc -l)
4951         [ $NUMS -eq $EXPECTED ] ||
4952                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4953
4954         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4955         NUMS=$($CMD | wc -l)
4956         [ $NUMS -eq $EXPECTED ] ||
4957                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4958
4959         EXPECTED=4
4960         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4961         NUMS=$($CMD | wc -l)
4962         [ $NUMS -eq $EXPECTED ] ||
4963                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4964
4965         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4966         NUMS=$($CMD | wc -l)
4967         [ $NUMS -eq $EXPECTED ] ||
4968                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4969
4970         EXPECTED=0
4971         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4972         NUMS=$($CMD | wc -l)
4973         [ $NUMS -eq $EXPECTED ] ||
4974                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4975 }
4976 run_test 56t "check lfs find -stripe-size works"
4977
4978 test_56u() { # LU-611
4979         TDIR=$DIR/${tdir}u
4980         setup_56 $NUMFILES $NUMDIRS "-i 0"
4981
4982         if [[ $OSTCOUNT -gt 1 ]]; then
4983                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4984                 ONESTRIPE=4
4985         else
4986                 ONESTRIPE=0
4987         fi
4988
4989         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4990         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4991         NUMS=$($CMD | wc -l)
4992         [ $NUMS -eq $EXPECTED ] ||
4993                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4994
4995         EXPECTED=$ONESTRIPE
4996         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4997         NUMS=$($CMD | wc -l)
4998         [ $NUMS -eq $EXPECTED ] ||
4999                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5000
5001         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
5002         NUMS=$($CMD | wc -l)
5003         [ $NUMS -eq $EXPECTED ] ||
5004                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5005
5006         EXPECTED=0
5007         # This should produce an error and not return any files
5008         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
5009         NUMS=$($CMD 2>/dev/null | wc -l)
5010         [ $NUMS -eq $EXPECTED ] ||
5011                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5012
5013         if [[ $OSTCOUNT -gt 1 ]]; then
5014                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
5015                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
5016                 NUMS=$($CMD | wc -l)
5017                 [ $NUMS -eq $EXPECTED ] ||
5018                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5019         fi
5020 }
5021 run_test 56u "check lfs find -stripe-index works"
5022
5023 test_56v() {
5024     local MDT_IDX=0
5025
5026     TDIR=$DIR/${tdir}v
5027     rm -rf $TDIR
5028     setup_56 $NUMFILES $NUMDIRS
5029
5030     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
5031     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
5032
5033     for file in $($LFIND -mdt $UUID $TDIR); do
5034         file_mdt_idx=$($GETSTRIPE -M $file)
5035         [ $file_mdt_idx -eq $MDT_IDX ] ||
5036             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
5037     done
5038 }
5039 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
5040
5041 test_56w() {
5042         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5043         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5044         TDIR=$DIR/${tdir}w
5045
5046         rm -rf $TDIR || error "remove $TDIR failed"
5047         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
5048
5049         local stripe_size
5050         stripe_size=$($GETSTRIPE -S -d $TDIR) ||
5051                 error "$GETSTRIPE -S -d $TDIR failed"
5052         stripe_size=${stripe_size%% *}
5053
5054         local file_size=$((stripe_size * OSTCOUNT))
5055         local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
5056         local required_space=$((file_num * file_size))
5057
5058         local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
5059                            head -n1)
5060         [[ $free_space -le $((required_space / 1024)) ]] &&
5061                 skip_env "need $required_space bytes, have $free_space KB" &&
5062                 return
5063
5064         local dd_bs=65536
5065         local dd_count=$((file_size / dd_bs))
5066
5067         # write data into the files
5068         local i
5069         local j
5070         local file
5071         for i in $(seq 1 $NUMFILES); do
5072                 file=$TDIR/file$i
5073                 yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5074                         error "write data into $file failed"
5075         done
5076         for i in $(seq 1 $NUMDIRS); do
5077                 for j in $(seq 1 $NUMFILES); do
5078                         file=$TDIR/dir$i/file$j
5079                         yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5080                                 error "write data into $file failed"
5081                 done
5082         done
5083
5084         # $LFS_MIGRATE will fail if hard link migration is unsupported
5085         if [[ $(lustre_version_code mds1) -gt $(version_code 2.5.55) ]]; then
5086                 createmany -l$TDIR/dir1/file1 $TDIR/dir1/link 200 ||
5087                         error "creating links to $TDIR/dir1/file1 failed"
5088         fi
5089
5090         local expected=-1
5091         [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
5092
5093         # lfs_migrate file
5094         local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
5095         echo "$cmd"
5096         eval $cmd || error "$cmd failed"
5097
5098         check_stripe_count $TDIR/file1 $expected
5099
5100         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
5101         then
5102                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
5103                 # OST 1 if it is on OST 0. This file is small enough to
5104                 # be on only one stripe.
5105                 file=$TDIR/migr_1_ost
5106                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
5107                         error "write data into $file failed"
5108                 local obdidx=$($LFS getstripe -i $file)
5109                 local oldmd5=$(md5sum $file)
5110                 local newobdidx=0
5111                 [[ $obdidx -eq 0 ]] && newobdidx=1
5112                 cmd="$LFS migrate -i $newobdidx $file"
5113                 echo $cmd
5114                 eval $cmd || error "$cmd failed"
5115                 local realobdix=$($LFS getstripe -i $file)
5116                 local newmd5=$(md5sum $file)
5117                 [[ $newobdidx -ne $realobdix ]] &&
5118                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
5119                 [[ "$oldmd5" != "$newmd5" ]] &&
5120                         error "md5sum differ: $oldmd5, $newmd5"
5121         fi
5122
5123     # lfs_migrate dir
5124     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
5125     echo "$cmd"
5126     eval $cmd || error "$cmd failed"
5127
5128     for j in $(seq 1 $NUMFILES); do
5129         check_stripe_count $TDIR/dir1/file$j $expected
5130     done
5131
5132     # lfs_migrate works with lfs find
5133     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
5134          $LFS_MIGRATE -y -c $expected"
5135     echo "$cmd"
5136     eval $cmd || error "$cmd failed"
5137
5138     for i in $(seq 2 $NUMFILES); do
5139         check_stripe_count $TDIR/file$i $expected
5140     done
5141     for i in $(seq 2 $NUMDIRS); do
5142         for j in $(seq 1 $NUMFILES); do
5143             check_stripe_count $TDIR/dir$i/file$j $expected
5144         done
5145     done
5146 }
5147 run_test 56w "check lfs_migrate -c stripe_count works"
5148
5149 test_56x() {
5150         check_swap_layouts_support && return 0
5151         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5152
5153         local dir0=$DIR/$tdir/$testnum
5154         test_mkdir -p $dir0 || error "creating dir $dir0"
5155
5156         local ref1=/etc/passwd
5157         local file1=$dir0/file1
5158
5159         $SETSTRIPE -c 2 $file1
5160         cp $ref1 $file1
5161         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
5162         stripe=$($GETSTRIPE -c $file1)
5163         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5164         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5165
5166         # clean up
5167         rm -f $file1
5168 }
5169 run_test 56x "lfs migration support"
5170
5171 test_56xa() {
5172         check_swap_layouts_support && return 0
5173         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5174
5175         local dir0=$DIR/$tdir/$testnum
5176         test_mkdir -p $dir0 || error "creating dir $dir0"
5177
5178         local ref1=/etc/passwd
5179         local file1=$dir0/file1
5180
5181         $SETSTRIPE -c 2 $file1
5182         cp $ref1 $file1
5183         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
5184         local stripe=$($GETSTRIPE -c $file1)
5185         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5186         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5187
5188         # clean up
5189         rm -f $file1
5190 }
5191 run_test 56xa "lfs migration --block support"
5192
5193 test_56y() {
5194         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
5195                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
5196                 return
5197
5198         local res=""
5199         local dir0=$DIR/$tdir/$testnum
5200         test_mkdir -p $dir0 || error "creating dir $dir0"
5201         local f1=$dir0/file1
5202         local f2=$dir0/file2
5203
5204         touch $f1 || error "creating std file $f1"
5205         $MULTIOP $f2 H2c || error "creating released file $f2"
5206
5207         # a directory can be raid0, so ask only for files
5208         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
5209         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
5210
5211         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
5212         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
5213
5214         # only files can be released, so no need to force file search
5215         res=$($LFIND $dir0 -L released)
5216         [[ $res == $f2 ]] || error "search released: found $res != $f2"
5217
5218         res=$($LFIND $dir0 \! -L released)
5219         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
5220
5221 }
5222 run_test 56y "lfs find -L raid0|released"
5223
5224 test_56z() { # LU-4824
5225         # This checks to make sure 'lfs find' continues after errors
5226         # There are two classes of errors that should be caught:
5227         # - If multiple paths are provided, all should be searched even if one
5228         #   errors out
5229         # - If errors are encountered during the search, it should not terminate
5230         #   early
5231         local i
5232         test_mkdir $DIR/$tdir
5233         for i in d{0..9}; do
5234                 test_mkdir $DIR/$tdir/$i
5235         done
5236         touch $DIR/$tdir/d{0..9}/$tfile
5237         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5238                 error "$LFS find did not return an error"
5239         # Make a directory unsearchable. This should NOT be the last entry in
5240         # directory order.  Arbitrarily pick the 6th entry
5241         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5242         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5243         # The user should be able to see 10 directories and 9 files
5244         [ $count == 19 ] || error "$LFS find did not continue after error"
5245 }
5246 run_test 56z "lfs find should continue after an error"
5247
5248 test_56aa() { # LU-5937
5249         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5250
5251         mkdir $DIR/$tdir
5252         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5253
5254         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5255         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5256
5257         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5258 }
5259 run_test 56aa "lfs find --size under striped dir"
5260
5261 test_57a() {
5262         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5263         # note test will not do anything if MDS is not local
5264         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5265                 skip "ldiskfs only test"
5266                 return
5267         fi
5268
5269         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5270         local MNTDEV="osd*.*MDT*.mntdev"
5271         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5272         [ -z "$DEV" ] && error "can't access $MNTDEV"
5273         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5274                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5275                         error "can't access $DEV"
5276                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5277                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5278                 rm $TMP/t57a.dump
5279         done
5280 }
5281 run_test 57a "verify MDS filesystem created with large inodes =="
5282
5283 test_57b() {
5284         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5285         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5286                 skip "ldiskfs only test"
5287                 return
5288         fi
5289
5290         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5291         local dir=$DIR/$tdir
5292
5293         local FILECOUNT=100
5294         local FILE1=$dir/f1
5295         local FILEN=$dir/f$FILECOUNT
5296
5297         rm -rf $dir || error "removing $dir"
5298         test_mkdir -p -c1 $dir || error "creating $dir"
5299         local mdtidx=$($LFS getstripe -M $dir)
5300         local mdtname=MDT$(printf %04x $mdtidx)
5301         local facet=mds$((mdtidx + 1))
5302
5303         echo "mcreating $FILECOUNT files"
5304         createmany -m $dir/f 1 $FILECOUNT || \
5305                 error "creating files in $dir"
5306
5307         # verify that files do not have EAs yet
5308         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5309         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5310
5311         sync
5312         sleep 1
5313         df $dir  #make sure we get new statfs data
5314         local MDSFREE=$(do_facet $facet \
5315                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5316         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5317         echo "opening files to create objects/EAs"
5318         local FILE
5319         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5320                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5321         done
5322
5323         # verify that files have EAs now
5324         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5325         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5326
5327         sleep 1  #make sure we get new statfs data
5328         df $dir
5329         local MDSFREE2=$(do_facet $facet \
5330                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5331         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5332         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5333                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5334                         error "MDC before $MDCFREE != after $MDCFREE2"
5335                 else
5336                         echo "MDC before $MDCFREE != after $MDCFREE2"
5337                         echo "unable to confirm if MDS has large inodes"
5338                 fi
5339         fi
5340         rm -rf $dir
5341 }
5342 run_test 57b "default LOV EAs are stored inside large inodes ==="
5343
5344 test_58() {
5345         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5346         [ -z "$(which wiretest 2>/dev/null)" ] &&
5347                         skip_env "could not find wiretest" && return
5348         wiretest
5349 }
5350 run_test 58 "verify cross-platform wire constants =============="
5351
5352 test_59() {
5353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5354         echo "touch 130 files"
5355         createmany -o $DIR/f59- 130
5356         echo "rm 130 files"
5357         unlinkmany $DIR/f59- 130
5358         sync
5359         # wait for commitment of removal
5360         wait_delete_completed
5361 }
5362 run_test 59 "verify cancellation of llog records async ========="
5363
5364 TEST60_HEAD="test_60 run $RANDOM"
5365 test_60a() {
5366         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5367         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5368         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5369                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5370                         skip_env "missing subtest run-llog.sh" && return
5371
5372         log "$TEST60_HEAD - from kernel mode"
5373         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5374         do_facet mgs "sh run-llog.sh" || error "run-llog.sh failed"
5375         do_facet mgs $LCTL dk > $TMP/$tfile
5376
5377         # LU-6388: test llog_reader
5378         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5379         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5380         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5381                         skip_env "missing llog_reader" && return
5382         local fstype=$(facet_fstype mgs)
5383         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5384                 skip_env "Only for ldiskfs or zfs type mgs" && return
5385
5386         local mntpt=$(facet_mntpt mgs)
5387         local mgsdev=$(mgsdevname 1)
5388         local fid_list
5389         local fid
5390         local rec_list
5391         local rec
5392         local rec_type
5393         local obj_file
5394         local path
5395         local seq
5396         local oid
5397         local pass=true
5398
5399         #get fid and record list
5400         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5401                 tail -n 4))
5402         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5403                 tail -n 4))
5404         #remount mgs as ldiskfs or zfs type
5405         stop mgs || error "stop mgs failed"
5406         mount_fstype mgs || error "remount mgs failed"
5407         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5408                 fid=${fid_list[i]}
5409                 rec=${rec_list[i]}
5410                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5411                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5412                 oid=$((16#$oid))
5413
5414                 case $fstype in
5415                         ldiskfs )
5416                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5417                         zfs )
5418                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5419                 esac
5420                 echo "obj_file is $obj_file"
5421                 do_facet mgs $llog_reader $obj_file
5422
5423                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5424                         awk '{ print $3 }' | sed -e "s/^type=//g")
5425                 if [ $rec_type != $rec ]; then
5426                         echo "FAILED test_60a wrong record type $rec_type," \
5427                               "should be $rec"
5428                         pass=false
5429                         break
5430                 fi
5431
5432                 #check obj path if record type is LLOG_LOGID_MAGIC
5433                 if [ "$rec" == "1064553b" ]; then
5434                         path=$(do_facet mgs $llog_reader $obj_file |
5435                                 grep "path=" | awk '{ print $NF }' |
5436                                 sed -e "s/^path=//g")
5437                         if [ $obj_file != $mntpt/$path ]; then
5438                                 echo "FAILED test_60a wrong obj path" \
5439                                       "$montpt/$path, should be $obj_file"
5440                                 pass=false
5441                                 break
5442                         fi
5443                 fi
5444         done
5445         rm -f $TMP/$tfile
5446         #restart mgs before "error", otherwise it will block the next test
5447         stop mgs || error "stop mgs failed"
5448         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5449         $pass || error "test failed, see FAILED test_60a messages for specifics"
5450 }
5451 run_test 60a "llog_test run from kernel module and test llog_reader"
5452
5453 test_60aa() {
5454         # test old logid format
5455         if [ $(lustre_version_code mgs) -le $(version_code 3.1.53) ]; then
5456                 do_facet mgs $LCTL dl | grep MGS
5457                 do_facet mgs "$LCTL --device %MGS llog_print \\\\\\\$$FSNAME-client" ||
5458                         error "old llog_print failed"
5459         fi
5460
5461         # test new logid format
5462         if [ $(lustre_version_code mgs) -ge $(version_code 2.9.53) ]; then
5463                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
5464                         error "new llog_print failed"
5465         fi
5466 }
5467 run_test 60aa "llog_print works with FIDs and simple names"
5468
5469 test_60b() { # bug 6411
5470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5471         dmesg > $DIR/$tfile
5472         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
5473                                 /llog.test/ {
5474                                         if (marker)
5475                                                 from_marker++
5476                                         from_begin++
5477                                 }
5478                                 END {
5479                                         if (marker)
5480                                                 print from_marker
5481                                         else
5482                                                 print from_begin
5483                                 }")
5484         [[ $LLOG_COUNT -gt 100 ]] &&
5485                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5486 }
5487 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5488
5489 test_60c() {
5490         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5491         echo "create 5000 files"
5492         createmany -o $DIR/f60c- 5000
5493 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5494         lctl set_param fail_loc=0x80000137
5495         unlinkmany $DIR/f60c- 5000
5496         lctl set_param fail_loc=0
5497 }
5498 run_test 60c "unlink file when mds full"
5499
5500 test_60d() {
5501         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5502         SAVEPRINTK=$(lctl get_param -n printk)
5503
5504         # verify "lctl mark" is even working"
5505         MESSAGE="test message ID $RANDOM $$"
5506         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5507         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5508
5509         lctl set_param printk=0 || error "set lnet.printk failed"
5510         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5511         MESSAGE="new test message ID $RANDOM $$"
5512         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5513         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5514         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5515
5516         lctl set_param -n printk="$SAVEPRINTK"
5517 }
5518 run_test 60d "test printk console message masking"
5519
5520 test_60e() {
5521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5522         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5523         touch $DIR/$tfile
5524 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5525         do_facet mds1 lctl set_param fail_loc=0x15b
5526         rm $DIR/$tfile
5527 }
5528 run_test 60e "no space while new llog is being created"
5529
5530 test_61() {
5531         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5532         f="$DIR/f61"
5533         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5534         cancel_lru_locks osc
5535         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5536         sync
5537 }
5538 run_test 61 "mmap() writes don't make sync hang ================"
5539
5540 # bug 2330 - insufficient obd_match error checking causes LBUG
5541 test_62() {
5542         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5543         f="$DIR/f62"
5544         echo foo > $f
5545         cancel_lru_locks osc
5546         lctl set_param fail_loc=0x405
5547         cat $f && error "cat succeeded, expect -EIO"
5548         lctl set_param fail_loc=0
5549 }
5550 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5551 # match every page all of the time.
5552 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5553
5554 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5555 # Though this test is irrelevant anymore, it helped to reveal some
5556 # other grant bugs (LU-4482), let's keep it.
5557 test_63a() {   # was test_63
5558         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5559         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5560         for i in `seq 10` ; do
5561                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5562                 sleep 5
5563                 kill $!
5564                 sleep 1
5565         done
5566
5567         rm -f $DIR/f63 || true
5568 }
5569 run_test 63a "Verify oig_wait interruption does not crash ======="
5570
5571 # bug 2248 - async write errors didn't return to application on sync
5572 # bug 3677 - async write errors left page locked
5573 test_63b() {
5574         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5575         debugsave
5576         lctl set_param debug=-1
5577
5578         # ensure we have a grant to do async writes
5579         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5580         rm $DIR/$tfile
5581
5582         sync    # sync lest earlier test intercept the fail_loc
5583
5584         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5585         lctl set_param fail_loc=0x80000406
5586         $MULTIOP $DIR/$tfile Owy && \
5587                 error "sync didn't return ENOMEM"
5588         sync; sleep 2; sync     # do a real sync this time to flush page
5589         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5590                 error "locked page left in cache after async error" || true
5591         debugrestore
5592 }
5593 run_test 63b "async write errors should be returned to fsync ==="
5594
5595 test_64a () {
5596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5597         df $DIR
5598         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5599 }
5600 run_test 64a "verify filter grant calculations (in kernel) ====="
5601
5602 test_64b () {
5603         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5604         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5605 }
5606 run_test 64b "check out-of-space detection on client ==========="
5607
5608 test_64c() {
5609         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5610 }
5611 run_test 64c "verify grant shrink ========================------"
5612
5613 # bug 1414 - set/get directories' stripe info
5614 test_65a() {
5615         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5616         test_mkdir -p $DIR/$tdir
5617         touch $DIR/$tdir/f1
5618         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5619 }
5620 run_test 65a "directory with no stripe info ===================="
5621
5622 test_65b() {
5623         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5624         test_mkdir -p $DIR/$tdir
5625         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5626
5627         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5628                                                 error "setstripe"
5629         touch $DIR/$tdir/f2
5630         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5631 }
5632 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
5633
5634 test_65c() {
5635         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5636         if [[ $OSTCOUNT -gt 1 ]]; then
5637                 test_mkdir -p $DIR/$tdir
5638                 local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5639
5640                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5641                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5642                 touch $DIR/$tdir/f3
5643                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5644         fi
5645 }
5646 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
5647
5648 test_65d() {
5649         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5650         test_mkdir -p $DIR/$tdir
5651         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
5652         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5653
5654         if [[ $STRIPECOUNT -le 0 ]]; then
5655                 sc=1
5656         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5657 #LOV_MAX_STRIPE_COUNT is 2000
5658                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5659         else
5660                 sc=$(($STRIPECOUNT - 1))
5661         fi
5662         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5663         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5664         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5665                 error "lverify failed"
5666 }
5667 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
5668
5669 test_65e() {
5670         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5671         test_mkdir -p $DIR/$tdir
5672
5673         $SETSTRIPE $DIR/$tdir || error "setstripe"
5674         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5675                                         error "no stripe info failed"
5676         touch $DIR/$tdir/f6
5677         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5678 }
5679 run_test 65e "directory setstripe defaults ======================="
5680
5681 test_65f() {
5682         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5683         test_mkdir -p $DIR/${tdir}f
5684         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5685 }
5686 run_test 65f "dir setstripe permission (should return error) ==="
5687
5688 test_65g() {
5689         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5690         test_mkdir -p $DIR/$tdir
5691         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5692
5693         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5694                                                         error "setstripe"
5695         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5696         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5697                 error "delete default stripe failed"
5698 }
5699 run_test 65g "directory setstripe -d ==========================="
5700
5701 test_65h() {
5702         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5703         test_mkdir -p $DIR/$tdir
5704         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5705
5706         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5707                                                         error "setstripe"
5708         test_mkdir -p $DIR/$tdir/dd1
5709         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5710                 error "stripe info inherit failed"
5711 }
5712 run_test 65h "directory stripe info inherit ===================="
5713
5714 test_65i() { # bug6367
5715         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5716         $SETSTRIPE -S 65536 -c -1 $MOUNT
5717 }
5718 run_test 65i "set non-default striping on root directory (bug 6367)="
5719
5720 test_65ia() { # bug12836
5721         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5722         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5723 }
5724 run_test 65ia "getstripe on -1 default directory striping"
5725
5726 test_65ib() { # bug12836
5727         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5728         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5729 }
5730 run_test 65ib "getstripe -v on -1 default directory striping"
5731
5732 test_65ic() { # bug12836
5733         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5734         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5735 }
5736 run_test 65ic "new find on -1 default directory striping"
5737
5738 test_65j() { # bug6367
5739         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5740         sync; sleep 1
5741         # if we aren't already remounting for each test, do so for this test
5742         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5743                 cleanup || error "failed to unmount"
5744                 setup
5745         fi
5746         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5747 }
5748 run_test 65j "set default striping on root directory (bug 6367)="
5749
5750 test_65k() { # bug11679
5751         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5752         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5753         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5754
5755         local disable_precreate=true
5756         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.8.54) ] &&
5757                 disable_precreate=false
5758
5759         echo "Check OST status: "
5760         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
5761                 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
5762
5763         for OSC in $MDS_OSCS; do
5764                 echo $OSC "is active"
5765                 do_facet $SINGLEMDS lctl --device %$OSC activate
5766         done
5767
5768         for INACTIVE_OSC in $MDS_OSCS; do
5769                 local ost=$(osc_to_ost $INACTIVE_OSC)
5770                 local ostnum=$(do_facet $SINGLEMDS lctl get_param -n \
5771                                lov.*md*.target_obd |
5772                                awk -F: /$ost/'{ print $1 }' | head -n 1)
5773
5774                 mkdir -p $DIR/$tdir
5775                 $SETSTRIPE -i $ostnum -c 1 $DIR/$tdir
5776                 createmany -o $DIR/$tdir/$tfile.$ostnum. 1000
5777
5778                 echo "Deactivate: " $INACTIVE_OSC
5779                 do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5780
5781                 local count=$(do_facet $SINGLEMDS "lctl get_param -n \
5782                               osp.$ost*MDT0000.create_count")
5783                 local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
5784                                   osp.$ost*MDT0000.max_create_count")
5785                 $disable_precreate &&
5786                         do_facet $SINGLEMDS "lctl set_param -n \
5787                                 osp.$ost*MDT0000.max_create_count=0"
5788
5789                 for idx in $(seq 0 $((OSTCOUNT - 1))); do
5790                         [ -f $DIR/$tdir/$idx ] && continue
5791                         echo "$SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx"
5792                         $SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx ||
5793                                 error "setstripe $idx should succeed"
5794                         rm -f $DIR/$tdir/$idx || error "rm $idx failed"
5795                 done
5796                 unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
5797                 rmdir $DIR/$tdir
5798
5799                 do_facet $SINGLEMDS "lctl set_param -n \
5800                         osp.$ost*MDT0000.max_create_count=$max_count"
5801                 do_facet $SINGLEMDS "lctl set_param -n \
5802                         osp.$ost*MDT0000.create_count=$count"
5803                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5804                 echo $INACTIVE_OSC "is Activate"
5805
5806                 wait_osc_import_state mds ost$ostnum FULL
5807         done
5808 }
5809 run_test 65k "validate manual striping works properly with deactivated OSCs"
5810
5811 test_65l() { # bug 12836
5812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5813         test_mkdir -p $DIR/$tdir/test_dir
5814         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5815         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5816 }
5817 run_test 65l "lfs find on -1 stripe dir ========================"
5818
5819 test_65m() {
5820         $RUNAS $SETSTRIPE -c 2 $MOUNT && error "setstripe should fail"
5821         true
5822 }
5823 run_test 65m "normal user can't set filesystem default stripe"
5824
5825 # bug 2543 - update blocks count on client
5826 test_66() {
5827         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5828         COUNT=${COUNT:-8}
5829         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5830         sync; sync_all_data; sync; sync_all_data
5831         cancel_lru_locks osc
5832         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5833         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5834 }
5835 run_test 66 "update inode blocks count on client ==============="
5836
5837 meminfo() {
5838         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5839 }
5840
5841 swap_used() {
5842         swapon -s | awk '($1 == "'$1'") { print $4 }'
5843 }
5844
5845 # bug5265, obdfilter oa2dentry return -ENOENT
5846 # #define OBD_FAIL_SRV_ENOENT 0x217
5847 test_69() {
5848         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5849         remote_ost_nodsh && skip "remote OST with nodsh" && return
5850
5851         f="$DIR/$tfile"
5852         $SETSTRIPE -c 1 -i 0 $f
5853
5854         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5855
5856         do_facet ost1 lctl set_param fail_loc=0x217
5857         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5858         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5859
5860         do_facet ost1 lctl set_param fail_loc=0
5861         $DIRECTIO write $f 0 2 || error "write error"
5862
5863         cancel_lru_locks osc
5864         $DIRECTIO read $f 0 1 || error "read error"
5865
5866         do_facet ost1 lctl set_param fail_loc=0x217
5867         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5868
5869         do_facet ost1 lctl set_param fail_loc=0
5870         rm -f $f
5871 }
5872 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5873
5874 test_71() {
5875         test_mkdir -p $DIR/$tdir
5876         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
5877         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5878 }
5879 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5880
5881 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5882         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5883         [ "$RUNAS_ID" = "$UID" ] &&
5884                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5885
5886         # Check that testing environment is properly set up. Skip if not
5887         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5888                 skip_env "User $RUNAS_ID does not exist - skipping"
5889                 return 0
5890         }
5891         touch $DIR/$tfile
5892         chmod 777 $DIR/$tfile
5893         chmod ug+s $DIR/$tfile
5894         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5895                 error "$RUNAS dd $DIR/$tfile failed"
5896         # See if we are still setuid/sgid
5897         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5898                 error "S/gid is not dropped on write"
5899         # Now test that MDS is updated too
5900         cancel_lru_locks mdc
5901         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5902                 error "S/gid is not dropped on MDS"
5903         rm -f $DIR/$tfile
5904 }
5905 run_test 72a "Test that remove suid works properly (bug5695) ===="
5906
5907 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5908         local perm
5909
5910         [ "$RUNAS_ID" = "$UID" ] && \
5911                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5912         [ "$RUNAS_ID" -eq 0 ] && \
5913                 skip_env "RUNAS_ID = 0 -- skipping" && return
5914
5915         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5916         # Check that testing environment is properly set up. Skip if not
5917         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5918                 skip_env "User $RUNAS_ID does not exist - skipping"
5919                 return 0
5920         }
5921         touch $DIR/${tfile}-f{g,u}
5922         test_mkdir $DIR/${tfile}-dg
5923         test_mkdir $DIR/${tfile}-du
5924         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5925         chmod g+s $DIR/${tfile}-{f,d}g
5926         chmod u+s $DIR/${tfile}-{f,d}u
5927         for perm in 777 2777 4777; do
5928                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5929                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5930                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5931                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5932         done
5933         true
5934 }
5935 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5936
5937 # bug 3462 - multiple simultaneous MDC requests
5938 test_73() {
5939         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5940         test_mkdir $DIR/d73-1
5941         test_mkdir $DIR/d73-2
5942         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5943         pid1=$!
5944
5945         lctl set_param fail_loc=0x80000129
5946         $MULTIOP $DIR/d73-1/f73-2 Oc &
5947         sleep 1
5948         lctl set_param fail_loc=0
5949
5950         $MULTIOP $DIR/d73-2/f73-3 Oc &
5951         pid3=$!
5952
5953         kill -USR1 $pid1
5954         wait $pid1 || return 1
5955
5956         sleep 25
5957
5958         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5959         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5960         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5961
5962         rm -rf $DIR/d73-*
5963 }
5964 run_test 73 "multiple MDC requests (should not deadlock)"
5965
5966 test_74a() { # bug 6149, 6184
5967         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5968         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5969         #
5970         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5971         # will spin in a tight reconnection loop
5972         touch $DIR/f74a
5973         $LCTL set_param fail_loc=0x8000030e
5974         # get any lock that won't be difficult - lookup works.
5975         ls $DIR/f74a
5976         $LCTL set_param fail_loc=0
5977         rm -f $DIR/f74a
5978         true
5979 }
5980 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5981
5982 test_74b() { # bug 13310
5983         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5984         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5985         #
5986         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5987         # will spin in a tight reconnection loop
5988         $LCTL set_param fail_loc=0x8000030e
5989         # get a "difficult" lock
5990         touch $DIR/f74b
5991         $LCTL set_param fail_loc=0
5992         rm -f $DIR/f74b
5993         true
5994 }
5995 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5996
5997 test_74c() {
5998         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5999         #define OBD_FAIL_LDLM_NEW_LOCK
6000         $LCTL set_param fail_loc=0x319
6001         touch $DIR/$tfile && error "touch successful"
6002         $LCTL set_param fail_loc=0
6003         true
6004 }
6005 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
6006
6007 num_inodes() {
6008         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
6009 }
6010
6011 get_inode_slab_tunables() {
6012         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
6013 }
6014
6015 set_inode_slab_tunables() {
6016         echo "lustre_inode_cache $1" > /proc/slabinfo
6017 }
6018
6019 test_76() { # Now for bug 20433, added originally in bug 1443
6020         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6021         local SLAB_SETTINGS=$(get_inode_slab_tunables)
6022         local CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
6023         # we cannot set limit below 1 which means 1 inode in each
6024         # per-cpu cache is still allowed
6025         set_inode_slab_tunables "1 1 0"
6026         cancel_lru_locks osc
6027         BEFORE_INODES=$(num_inodes)
6028         echo "before inodes: $BEFORE_INODES"
6029         local COUNT=1000
6030         [ "$SLOW" = "no" ] && COUNT=100
6031         for i in $(seq $COUNT); do
6032                 touch $DIR/$tfile
6033                 rm -f $DIR/$tfile
6034         done
6035         cancel_lru_locks osc
6036         AFTER_INODES=$(num_inodes)
6037         echo "after inodes: $AFTER_INODES"
6038         local wait=0
6039         while [[ $((AFTER_INODES-1*${CPUS:-1})) -gt $BEFORE_INODES ]]; do
6040                 sleep 2
6041                 AFTER_INODES=$(num_inodes)
6042                 wait=$((wait+2))
6043                 echo "wait $wait seconds inodes: $AFTER_INODES"
6044                 if [ $wait -gt 30 ]; then
6045                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
6046                 fi
6047         done
6048         set_inode_slab_tunables "$SLAB_SETTINGS"
6049 }
6050 run_test 76 "confirm clients recycle inodes properly ===="
6051
6052
6053 export ORIG_CSUM=""
6054 set_checksums()
6055 {
6056         # Note: in sptlrpc modes which enable its own bulk checksum, the
6057         # original crc32_le bulk checksum will be automatically disabled,
6058         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
6059         # will be checked by sptlrpc code against sptlrpc bulk checksum.
6060         # In this case set_checksums() will not be no-op, because sptlrpc
6061         # bulk checksum will be enabled all through the test.
6062
6063         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
6064         lctl set_param -n osc.*.checksums $1
6065         return 0
6066 }
6067
6068 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
6069                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
6070 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
6071 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
6072 set_checksum_type()
6073 {
6074         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
6075         log "set checksum type to $1"
6076         return 0
6077 }
6078 F77_TMP=$TMP/f77-temp
6079 F77SZ=8
6080 setup_f77() {
6081         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
6082                 error "error writing to $F77_TMP"
6083 }
6084
6085 test_77a() { # bug 10889
6086         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6087         $GSS && skip "could not run with gss" && return
6088         [ ! -f $F77_TMP ] && setup_f77
6089         set_checksums 1
6090         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
6091         set_checksums 0
6092         rm -f $DIR/$tfile
6093 }
6094 run_test 77a "normal checksum read/write operation"
6095
6096 test_77b() { # bug 10889
6097         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6098         $GSS && skip "could not run with gss" && return
6099         [ ! -f $F77_TMP ] && setup_f77
6100         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6101         $LCTL set_param fail_loc=0x80000409
6102         set_checksums 1
6103
6104         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6105                 error "dd error: $?"
6106         $LCTL set_param fail_loc=0
6107
6108         for algo in $CKSUM_TYPES; do
6109                 cancel_lru_locks osc
6110                 set_checksum_type $algo
6111                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6112                 $LCTL set_param fail_loc=0x80000408
6113                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6114                 $LCTL set_param fail_loc=0
6115         done
6116         set_checksums 0
6117         set_checksum_type $ORIG_CSUM_TYPE
6118         rm -f $DIR/$tfile
6119 }
6120 run_test 77b "checksum error on client write, read"
6121
6122 cleanup_77c() {
6123         trap 0
6124         set_checksums 0
6125         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
6126         $check_ost &&
6127                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
6128         [ -n $osc_file_prefix ] && rm -f ${osc_file_prefix}*
6129         $check_ost && [ -n $ost_file_prefix ] &&
6130                 do_facet ost1 rm -f ${ost_file_prefix}\*
6131 }
6132
6133 test_77c() {
6134         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6135         $GSS && skip "could not run with gss" && return
6136
6137         local bad1
6138         local osc_file_prefix
6139         local osc_file
6140         local check_ost=false
6141         local ost_file_prefix
6142         local ost_file
6143         local orig_cksum
6144         local dump_cksum
6145         local fid
6146
6147         # ensure corruption will occur on first OSS/OST
6148         $LFS setstripe -i 0 $DIR/$tfile
6149
6150         [ ! -f $F77_TMP ] && setup_f77
6151         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6152                 error "dd write error: $?"
6153         fid=$($LFS path2fid $DIR/$tfile)
6154
6155         if [ $(lustre_version_code ost1) -ge $(version_code 2.9.57) ]
6156         then
6157                 check_ost=true
6158                 ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
6159                 ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
6160         else
6161                 echo "OSS do not support bulk pages dump upon error"
6162         fi
6163
6164         osc_file_prefix=$($LCTL get_param -n debug_path)
6165         osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
6166
6167         trap cleanup_77c EXIT
6168
6169         set_checksums 1
6170         # enable bulk pages dump upon error on Client
6171         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
6172         # enable bulk pages dump upon error on OSS
6173         $check_ost &&
6174                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
6175
6176         # flush Client cache to allow next read to reach OSS
6177         cancel_lru_locks osc
6178
6179         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
6180         $LCTL set_param fail_loc=0x80000408
6181         dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
6182         $LCTL set_param fail_loc=0
6183
6184         rm -f $DIR/$tfile
6185
6186         # check cksum dump on Client
6187         osc_file=$(ls ${osc_file_prefix}*)
6188         [ -n "$osc_file" ] || error "no checksum dump file on Client"
6189         # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
6190         bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
6191         [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
6192         orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
6193                      cksum)
6194         dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
6195         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6196                 error "dump content does not match on Client"
6197
6198         $check_ost || skip "No need to check cksum dump on OSS"
6199
6200         # check cksum dump on OSS
6201         ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
6202         [ -n "$ost_file" ] || error "no checksum dump file on OSS"
6203         orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
6204         dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
6205         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6206                 error "dump content does not match on OSS"
6207
6208         cleanup_77c
6209 }
6210 run_test 77c "checksum error on client read with debug"
6211
6212 test_77d() { # bug 10889
6213         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6214         $GSS && skip "could not run with gss" && return
6215         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6216         $LCTL set_param fail_loc=0x80000409
6217         set_checksums 1
6218         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6219                 error "direct write: rc=$?"
6220         $LCTL set_param fail_loc=0
6221         set_checksums 0
6222
6223         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6224         $LCTL set_param fail_loc=0x80000408
6225         set_checksums 1
6226         cancel_lru_locks osc
6227         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6228                 error "direct read: rc=$?"
6229         $LCTL set_param fail_loc=0
6230         set_checksums 0
6231 }
6232 run_test 77d "checksum error on OST direct write, read"
6233
6234 test_77f() { # bug 10889
6235         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6236         $GSS && skip "could not run with gss" && return
6237         set_checksums 1
6238         for algo in $CKSUM_TYPES; do
6239                 cancel_lru_locks osc
6240                 set_checksum_type $algo
6241                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6242                 $LCTL set_param fail_loc=0x409
6243                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
6244                         error "direct write succeeded"
6245                 $LCTL set_param fail_loc=0
6246         done
6247         set_checksum_type $ORIG_CSUM_TYPE
6248         set_checksums 0
6249 }
6250 run_test 77f "repeat checksum error on write (expect error)"
6251
6252 test_77g() { # bug 10889
6253         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6254         $GSS && skip "could not run with gss" && return
6255         remote_ost_nodsh && skip "remote OST with nodsh" && return
6256
6257         [ ! -f $F77_TMP ] && setup_f77
6258
6259         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
6260         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
6261         do_facet ost1 lctl set_param fail_loc=0x8000021a
6262         set_checksums 1
6263         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
6264                 error "write error: rc=$?"
6265         do_facet ost1 lctl set_param fail_loc=0
6266         set_checksums 0
6267
6268         cancel_lru_locks osc
6269         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
6270         do_facet ost1 lctl set_param fail_loc=0x8000021b
6271         set_checksums 1
6272         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6273         do_facet ost1 lctl set_param fail_loc=0
6274         set_checksums 0
6275 }
6276 run_test 77g "checksum error on OST write, read"
6277
6278 test_77j() { # bug 13805
6279         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6280         $GSS && skip "could not run with gss" && return
6281         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6282         lctl set_param fail_loc=0x40c
6283         remount_client $MOUNT
6284         lctl set_param fail_loc=0
6285         # wait async osc connect to finish and reflect updated state value
6286         local i
6287         for (( i=0; i < OSTCOUNT; i++ )) ; do
6288                 wait_osc_import_state client ost$((i+1)) FULL
6289         done
6290
6291         for VALUE in $(lctl get_param osc.*osc-[^mM]*.checksum_type); do
6292                 PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
6293                 algo=$(lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g')
6294                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6295         done
6296         remount_client $MOUNT
6297 }
6298 run_test 77j "client only supporting ADLER32"
6299
6300 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6301 rm -f $F77_TMP
6302 unset F77_TMP
6303
6304 cleanup_test_78() {
6305         trap 0
6306         rm -f $DIR/$tfile
6307 }
6308
6309 test_78() { # bug 10901
6310         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6311         remote_ost || { skip_env "local OST" && return; }
6312
6313         NSEQ=5
6314         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6315         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6316         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6317         echo "MemTotal: $MEMTOTAL"
6318
6319         # reserve 256MB of memory for the kernel and other running processes,
6320         # and then take 1/2 of the remaining memory for the read/write buffers.
6321         if [ $MEMTOTAL -gt 512 ] ;then
6322                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6323         else
6324                 # for those poor memory-starved high-end clusters...
6325                 MEMTOTAL=$((MEMTOTAL / 2))
6326         fi
6327         echo "Mem to use for directio: $MEMTOTAL"
6328
6329         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6330         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6331         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6332         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6333                 head -n1)
6334         echo "Smallest OST: $SMALLESTOST"
6335         [[ $SMALLESTOST -lt 10240 ]] &&
6336                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6337
6338         trap cleanup_test_78 EXIT
6339
6340         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6341                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6342
6343         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6344         echo "File size: $F78SIZE"
6345         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6346         for i in $(seq 1 $NSEQ); do
6347                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6348                 echo directIO rdwr round $i of $NSEQ
6349                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6350         done
6351
6352         cleanup_test_78
6353 }
6354 run_test 78 "handle large O_DIRECT writes correctly ============"
6355
6356 test_79() { # bug 12743
6357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6358         wait_delete_completed
6359
6360         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6361         BKFREE=$(calc_osc_kbytes kbytesfree)
6362         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6363
6364         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6365         DFTOTAL=`echo $STRING | cut -d, -f1`
6366         DFUSED=`echo $STRING  | cut -d, -f2`
6367         DFAVAIL=`echo $STRING | cut -d, -f3`
6368         DFFREE=$(($DFTOTAL - $DFUSED))
6369
6370         ALLOWANCE=$((64 * $OSTCOUNT))
6371
6372         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6373            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6374                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6375         fi
6376         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6377            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6378                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6379         fi
6380         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6381            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6382                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6383         fi
6384 }
6385 run_test 79 "df report consistency check ======================="
6386
6387 test_80() { # bug 10718
6388         remote_ost_nodsh && skip "remote OST with nodsh" && return
6389         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6390         # relax strong synchronous semantics for slow backends like ZFS
6391         local soc="obdfilter.*.sync_on_lock_cancel"
6392         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6393         local hosts=
6394         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6395                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6396                           facet_active_host $host; done | sort -u)
6397                 do_nodes $hosts lctl set_param $soc=never
6398         fi
6399
6400         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6401         sync; sleep 1; sync
6402         local BEFORE=`date +%s`
6403         cancel_lru_locks osc
6404         local AFTER=`date +%s`
6405         local DIFF=$((AFTER-BEFORE))
6406         if [ $DIFF -gt 1 ] ; then
6407                 error "elapsed for 1M@1T = $DIFF"
6408         fi
6409
6410         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6411
6412         rm -f $DIR/$tfile
6413 }
6414 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6415
6416 test_81a() { # LU-456
6417         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6418         remote_ost_nodsh && skip "remote OST with nodsh" && return
6419         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6420         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6421         do_facet ost1 lctl set_param fail_loc=0x80000228
6422
6423         # write should trigger a retry and success
6424         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6425         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6426         RC=$?
6427         if [ $RC -ne 0 ] ; then
6428                 error "write should success, but failed for $RC"
6429         fi
6430 }
6431 run_test 81a "OST should retry write when get -ENOSPC ==============="
6432
6433 test_81b() { # LU-456
6434         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6435         remote_ost_nodsh && skip "remote OST with nodsh" && return
6436         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6437         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6438         do_facet ost1 lctl set_param fail_loc=0x228
6439
6440         # write should retry several times and return -ENOSPC finally
6441         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6442         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6443         RC=$?
6444         ENOSPC=28
6445         if [ $RC -ne $ENOSPC ] ; then
6446                 error "dd should fail for -ENOSPC, but succeed."
6447         fi
6448 }
6449 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6450
6451 test_82() { # LU-1031
6452         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6453         local gid1=14091995
6454         local gid2=16022000
6455
6456         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6457         local MULTIPID1=$!
6458         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6459         local MULTIPID2=$!
6460         kill -USR1 $MULTIPID2
6461         sleep 2
6462         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6463                 error "First grouplock does not block second one"
6464         else
6465                 echo "Second grouplock blocks first one"
6466         fi
6467         kill -USR1 $MULTIPID1
6468         wait $MULTIPID1
6469         wait $MULTIPID2
6470 }
6471 run_test 82 "Basic grouplock test ==============================="
6472
6473 test_83() {
6474         local sfile="/boot/System.map-$(uname -r)"
6475         # define OBD_FAIL_LLITE_PTASK_IO_FAIL 0x140d
6476         $LCTL set_param fail_loc=0x140d
6477         cp $sfile $DIR/$tfile || error "write failed"
6478         diff -c $sfile $DIR/$tfile || error "files are different"
6479         $LCTL set_param fail_loc=0
6480         rm -f $DIR/$tfile
6481 }
6482 run_test 83 "Short write in ptask ==============================="
6483
6484 test_99a() {
6485         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6486                 return
6487         test_mkdir -p $DIR/d99cvsroot
6488         chown $RUNAS_ID $DIR/d99cvsroot
6489         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6490         cd $TMP
6491
6492         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6493         cd $oldPWD
6494 }
6495 run_test 99a "cvs init ========================================="
6496
6497 test_99b() {
6498         [ -z "$(which cvs 2>/dev/null)" ] &&
6499                 skip_env "could not find cvs" && return
6500         [ ! -d $DIR/d99cvsroot ] && test_99a
6501         cd /etc/init.d
6502         # some versions of cvs import exit(1) when asked to import links or
6503         # files they can't read.  ignore those files.
6504         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6505                         ! -perm /4 -printf '-I %f\n')
6506         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6507                 d99reposname vtag rtag
6508 }
6509 run_test 99b "cvs import ======================================="
6510
6511 test_99c() {
6512         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6513         [ ! -d $DIR/d99cvsroot ] && test_99b
6514         cd $DIR
6515         test_mkdir -p $DIR/d99reposname
6516         chown $RUNAS_ID $DIR/d99reposname
6517         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6518 }
6519 run_test 99c "cvs checkout ====================================="
6520
6521 test_99d() {
6522         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6523         [ ! -d $DIR/d99cvsroot ] && test_99c
6524         cd $DIR/d99reposname
6525         $RUNAS touch foo99
6526         $RUNAS cvs add -m 'addmsg' foo99
6527 }
6528 run_test 99d "cvs add =========================================="
6529
6530 test_99e() {
6531         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6532         [ ! -d $DIR/d99cvsroot ] && test_99c
6533         cd $DIR/d99reposname
6534         $RUNAS cvs update
6535 }
6536 run_test 99e "cvs update ======================================="
6537
6538 test_99f() {
6539         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6540         [ ! -d $DIR/d99cvsroot ] && test_99d
6541         cd $DIR/d99reposname
6542         $RUNAS cvs commit -m 'nomsg' foo99
6543     rm -fr $DIR/d99cvsroot
6544 }
6545 run_test 99f "cvs commit ======================================="
6546
6547 test_100() {
6548         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6549         [[ "$NETTYPE" =~ tcp ]] ||
6550                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" &&
6551                         return ; }
6552
6553         remote_ost_nodsh && skip "remote OST with nodsh" && return
6554         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6555         remote_servers ||
6556                 { skip "useless for local single node setup" && return; }
6557
6558         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6559                 [ "$PROT" != "tcp" ] && continue
6560                 RPORT=$(echo $REMOTE | cut -d: -f2)
6561                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6562
6563                 rc=0
6564                 LPORT=`echo $LOCAL | cut -d: -f2`
6565                 if [ $LPORT -ge 1024 ]; then
6566                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6567                         netstat -tna
6568                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6569                 fi
6570         done
6571         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6572 }
6573 run_test 100 "check local port using privileged port ==========="
6574
6575 function get_named_value()
6576 {
6577     local tag
6578
6579     tag=$1
6580     while read ;do
6581         line=$REPLY
6582         case $line in
6583         $tag*)
6584             echo $line | sed "s/^$tag[ ]*//"
6585             break
6586             ;;
6587         esac
6588     done
6589 }
6590
6591 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6592                    awk '/^max_cached_mb/ { print $2 }')
6593
6594 cleanup_101a() {
6595         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6596         trap 0
6597 }
6598
6599 test_101a() {
6600         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6601         [ $MDSCOUNT -ge 2 ] && skip "needs < 2 MDTs" && return #LU-4322
6602         local s
6603         local discard
6604         local nreads=10000
6605         local cache_limit=32
6606
6607         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6608         trap cleanup_101a EXIT
6609         $LCTL set_param -n llite.*.read_ahead_stats 0
6610         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6611
6612         #
6613         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6614         #
6615         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6616         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6617
6618         discard=0
6619         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6620                 get_named_value 'read but discarded' | cut -d" " -f1); do
6621                         discard=$(($discard + $s))
6622         done
6623         cleanup_101a
6624
6625         if [[ $(($discard * 10)) -gt $nreads ]]; then
6626                 $LCTL get_param osc.*-osc*.rpc_stats
6627                 $LCTL get_param llite.*.read_ahead_stats
6628                 error "too many ($discard) discarded pages"
6629         fi
6630         rm -f $DIR/$tfile || true
6631 }
6632 run_test 101a "check read-ahead for random reads ================"
6633
6634 setup_test101bc() {
6635         test_mkdir -p $DIR/$tdir
6636         local STRIPE_SIZE=$1
6637         local FILE_LENGTH=$2
6638         STRIPE_OFFSET=0
6639
6640         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6641
6642         local list=$(comma_list $(osts_nodes))
6643         set_osd_param $list '' read_cache_enable 0
6644         set_osd_param $list '' writethrough_cache_enable 0
6645
6646         trap cleanup_test101bc EXIT
6647         # prepare the read-ahead file
6648         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6649
6650         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6651                                 count=$FILE_SIZE_MB 2> /dev/null
6652
6653 }
6654
6655 cleanup_test101bc() {
6656         trap 0
6657         rm -rf $DIR/$tdir
6658         rm -f $DIR/$tfile
6659
6660         local list=$(comma_list $(osts_nodes))
6661         set_osd_param $list '' read_cache_enable 1
6662         set_osd_param $list '' writethrough_cache_enable 1
6663 }
6664
6665 calc_total() {
6666         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6667 }
6668
6669 ra_check_101() {
6670         local READ_SIZE=$1
6671         local STRIPE_SIZE=$2
6672         local FILE_LENGTH=$3
6673         local RA_INC=1048576
6674         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6675         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6676                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6677         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6678                         get_named_value 'read but discarded' |
6679                         cut -d" " -f1 | calc_total)
6680         if [[ $DISCARD -gt $discard_limit ]]; then
6681                 $LCTL get_param llite.*.read_ahead_stats
6682                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6683         else
6684                 echo "Read-ahead success for size ${READ_SIZE}"
6685         fi
6686 }
6687
6688 test_101b() {
6689         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6690         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
6691         local STRIPE_SIZE=1048576
6692         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6693         if [ $SLOW == "yes" ]; then
6694                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6695         else
6696                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6697         fi
6698
6699         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6700
6701         # prepare the read-ahead file
6702         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6703         cancel_lru_locks osc
6704         for BIDX in 2 4 8 16 32 64 128 256
6705         do
6706                 local BSIZE=$((BIDX*4096))
6707                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6708                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6709                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6710                 $LCTL set_param -n llite.*.read_ahead_stats 0
6711                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6712                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6713                 cancel_lru_locks osc
6714                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6715         done
6716         cleanup_test101bc
6717         true
6718 }
6719 run_test 101b "check stride-io mode read-ahead ================="
6720
6721 test_101c() {
6722         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6723         local STRIPE_SIZE=1048576
6724         local FILE_LENGTH=$((STRIPE_SIZE*100))
6725         local nreads=10000
6726         local osc_rpc_stats
6727
6728         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6729
6730         cancel_lru_locks osc
6731         $LCTL set_param osc.*.rpc_stats 0
6732         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6733         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6734                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6735                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6736                 local size
6737
6738                 if [ $lines -le 20 ]; then
6739                         continue
6740                 fi
6741                 for size in 1 2 4 8; do
6742                         local rpc=$(echo "$stats" |
6743                                     awk '($1 == "'$size':") {print $2; exit; }')
6744                         [ $rpc != 0 ] &&
6745                                 error "Small $((size*4))k read IO $rpc !"
6746                 done
6747                 echo "$osc_rpc_stats check passed!"
6748         done
6749         cleanup_test101bc
6750         true
6751 }
6752 run_test 101c "check stripe_size aligned read-ahead ================="
6753
6754 set_read_ahead() {
6755         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6756         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6757 }
6758
6759 test_101d() {
6760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6761         local file=$DIR/$tfile
6762         local sz_MB=${FILESIZE_101d:-500}
6763         local ra_MB=${READAHEAD_MB:-40}
6764
6765         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6766         [ $free_MB -lt $sz_MB ] &&
6767                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6768
6769         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6770         $SETSTRIPE -c -1 $file || error "setstripe failed"
6771
6772         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6773         echo Cancel LRU locks on lustre client to flush the client cache
6774         cancel_lru_locks osc
6775
6776         echo Disable read-ahead
6777         local old_READAHEAD=$(set_read_ahead 0)
6778
6779         echo Reading the test file $file with read-ahead disabled
6780         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6781
6782         echo Cancel LRU locks on lustre client to flush the client cache
6783         cancel_lru_locks osc
6784         echo Enable read-ahead with ${ra_MB}MB
6785         set_read_ahead $ra_MB
6786
6787         echo Reading the test file $file with read-ahead enabled
6788         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6789
6790         echo "read-ahead disabled time read $raOFF"
6791         echo "read-ahead enabled  time read $raON"
6792
6793         set_read_ahead $old_READAHEAD
6794         rm -f $file
6795         wait_delete_completed
6796
6797         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6798                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6799 }
6800 run_test 101d "file read with and without read-ahead enabled"
6801
6802 test_101e() {
6803         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6804         local file=$DIR/$tfile
6805         local size_KB=500  #KB
6806         local count=100
6807         local bsize=1024
6808
6809         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6810         local need_KB=$((count * size_KB))
6811         [[ $free_KB -le $need_KB ]] &&
6812                 skip_env "Need free space $need_KB, have $free_KB" && return
6813
6814         echo "Creating $count ${size_KB}K test files"
6815         for ((i = 0; i < $count; i++)); do
6816                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6817         done
6818
6819         echo "Cancel LRU locks on lustre client to flush the client cache"
6820         cancel_lru_locks osc
6821
6822         echo "Reset readahead stats"
6823         $LCTL set_param -n llite.*.read_ahead_stats 0
6824
6825         for ((i = 0; i < $count; i++)); do
6826                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6827         done
6828
6829         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6830                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6831
6832         for ((i = 0; i < $count; i++)); do
6833                 rm -rf $file.$i 2>/dev/null
6834         done
6835
6836         #10000 means 20% reads are missing in readahead
6837         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6838 }
6839 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6840
6841 test_101f() {
6842         which iozone || { skip "no iozone installed" && return; }
6843
6844         local old_debug=$($LCTL get_param debug)
6845         old_debug=${old_debug#*=}
6846         $LCTL set_param debug="reada mmap"
6847
6848         # create a test file
6849         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
6850
6851         echo Cancel LRU locks on lustre client to flush the client cache
6852         cancel_lru_locks osc
6853
6854         echo Reset readahead stats
6855         $LCTL set_param -n llite.*.read_ahead_stats 0
6856
6857         echo mmap read the file with small block size
6858         iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
6859                 > /dev/null 2>&1
6860
6861         echo checking missing pages
6862         $LCTL get_param llite.*.read_ahead_stats
6863         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6864                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
6865
6866         $LCTL set_param debug="$old_debug"
6867         [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
6868         rm -f $DIR/$tfile
6869 }
6870 run_test 101f "check mmap read performance"
6871
6872 test_101g_brw_size_test() {
6873         local mb=$1
6874         local pages=$((mb * 1048576 / $(page_size)))
6875
6876         $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
6877                 { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
6878         for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
6879                 [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
6880                         return 2
6881         done
6882
6883         $LCTL set_param -n osc.*.rpc_stats=0
6884
6885         # 10 RPCs should be enough for the test
6886         local count=10
6887         dd if=/dev/zero of=$DIR/$tfile bs=${mb}M count=$count ||
6888                 { error "dd write ${mb} MB blocks failed"; return 3; }
6889         cancel_lru_locks osc
6890         dd of=/dev/null if=$DIR/$tfile bs=${mb}M count=$count ||
6891                 { error "dd write ${mb} MB blocks failed"; return 4; }
6892
6893         # calculate number of full-sized read and write RPCs
6894         rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
6895                 sed -n '/pages per rpc/,/^$/p' |
6896                 awk '/'$pages':/ { reads += $2; writes += $6 }; \
6897                 END { print reads,writes }'))
6898         [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
6899                 return 5
6900         [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
6901                 return 6
6902
6903         return 0
6904 }
6905
6906 test_101g() {
6907         local rpcs
6908         local osts=$(get_facets OST)
6909         local list=$(comma_list $(osts_nodes))
6910         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
6911         local brw_size="obdfilter.*.brw_size"
6912
6913         $LFS setstripe -i 0 -c 1 $DIR/$tfile
6914
6915         local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
6916         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.52) ]; then
6917                 [ $(lustre_version_code ost1) -ge $(version_code 2.9.52) ] &&
6918                         suffix="M"
6919                 if [[ $orig_mb -lt 16 ]]; then
6920                         save_lustre_params $osts "$brw_size" > $p
6921                         do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
6922                                 error "set 16MB RPC size failed"
6923
6924                         echo "remount client to enable new RPC size"
6925                         remount_client $MOUNT || error "remount_client failed"
6926                 fi
6927
6928                 test_101g_brw_size_test 16 || error "16MB RPC test failed"
6929                 # should be able to set brw_size=12, but no rpc_stats for that
6930                 test_101g_brw_size_test 8 || error "8MB RPC test failed"
6931         fi
6932
6933         test_101g_brw_size_test 4 || error "4MB RPC test failed"
6934
6935         if [[ $orig_mb -lt 16 ]]; then
6936                 restore_lustre_params < $p
6937                 remount_client $MOUNT || error "remount_client restore failed"
6938         fi
6939
6940         rm -f $p $DIR/$tfile
6941 }
6942 run_test 101g "Big bulk(4/16 MiB) readahead"
6943
6944 setup_test102() {
6945         test_mkdir -p $DIR/$tdir
6946         chown $RUNAS_ID $DIR/$tdir
6947         STRIPE_SIZE=65536
6948         STRIPE_OFFSET=1
6949         STRIPE_COUNT=$OSTCOUNT
6950         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6951
6952         trap cleanup_test102 EXIT
6953         cd $DIR
6954         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6955         cd $DIR/$tdir
6956         for num in 1 2 3 4; do
6957                 for count in $(seq 1 $STRIPE_COUNT); do
6958                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6959                                 local size=`expr $STRIPE_SIZE \* $num`
6960                                 local file=file"$num-$idx-$count"
6961                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6962                         done
6963                 done
6964         done
6965
6966         cd $DIR
6967         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6968 }
6969
6970 cleanup_test102() {
6971         trap 0
6972         rm -f $TMP/f102.tar
6973         rm -rf $DIR/d0.sanity/d102
6974 }
6975
6976 test_102a() {
6977         local testfile=$DIR/$tfile
6978
6979         touch $testfile
6980
6981         [ "$UID" != 0 ] && skip_env "must run as root" && return
6982         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6983                 skip_env "must have user_xattr" && return
6984
6985         [ -z "$(which setfattr 2>/dev/null)" ] &&
6986                 skip_env "could not find setfattr" && return
6987
6988         echo "set/get xattr..."
6989         setfattr -n trusted.name1 -v value1 $testfile ||
6990                 error "setfattr -n trusted.name1=value1 $testfile failed"
6991         getfattr -n trusted.name1 $testfile 2> /dev/null |
6992           grep "trusted.name1=.value1" ||
6993                 error "$testfile missing trusted.name1=value1"
6994
6995         setfattr -n user.author1 -v author1 $testfile ||
6996                 error "setfattr -n user.author1=author1 $testfile failed"
6997         getfattr -n user.author1 $testfile 2> /dev/null |
6998           grep "user.author1=.author1" ||
6999                 error "$testfile missing trusted.author1=author1"
7000
7001         echo "listxattr..."
7002         setfattr -n trusted.name2 -v value2 $testfile ||
7003                 error "$testfile unable to set trusted.name2"
7004         setfattr -n trusted.name3 -v value3 $testfile ||
7005                 error "$testfile unable to set trusted.name3"
7006         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
7007             grep "trusted.name" | wc -l) -eq 3 ] ||
7008                 error "$testfile missing 3 trusted.name xattrs"
7009
7010         setfattr -n user.author2 -v author2 $testfile ||
7011                 error "$testfile unable to set user.author2"
7012         setfattr -n user.author3 -v author3 $testfile ||
7013                 error "$testfile unable to set user.author3"
7014         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
7015             grep "user.author" | wc -l) -eq 3 ] ||
7016                 error "$testfile missing 3 user.author xattrs"
7017
7018         echo "remove xattr..."
7019         setfattr -x trusted.name1 $testfile ||
7020                 error "$testfile error deleting trusted.name1"
7021         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
7022                 error "$testfile did not delete trusted.name1 xattr"
7023
7024         setfattr -x user.author1 $testfile ||
7025                 error "$testfile error deleting user.author1"
7026         echo "set lustre special xattr ..."
7027         $LFS setstripe -c1 $testfile
7028         local lovea=$(getfattr -n "trusted.lov" -e hex $testfile |
7029                 awk -F "=" '/trusted.lov/ { print $2 }' )
7030         setfattr -n "trusted.lov" -v $lovea $testfile ||
7031                 error "$testfile doesn't ignore setting trusted.lov again"
7032         setfattr -n "trusted.lov" -v "invalid_value" $testfile &&
7033                 error "$testfile allow setting invalid trusted.lov"
7034         rm -f $testfile
7035 }
7036 run_test 102a "user xattr test =================================="
7037
7038 test_102b() {
7039         [ -z "$(which setfattr 2>/dev/null)" ] &&
7040                 skip_env "could not find setfattr" && return
7041
7042         # b10930: get/set/list trusted.lov xattr
7043         echo "get/set/list trusted.lov xattr ..."
7044         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7045         local testfile=$DIR/$tfile
7046         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7047                 error "setstripe failed"
7048         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
7049                 error "getstripe failed"
7050         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
7051                 error "can't get trusted.lov from $testfile"
7052
7053         local testfile2=${testfile}2
7054         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
7055                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
7056
7057         $MCREATE $testfile2
7058         setfattr -n trusted.lov -v $value $testfile2
7059         local stripe_size=$($GETSTRIPE -S $testfile2)
7060         local stripe_count=$($GETSTRIPE -c $testfile2)
7061         [[ $stripe_size -eq 65536 ]] ||
7062                 error "stripe size $stripe_size != 65536"
7063         [[ $stripe_count -eq $STRIPECOUNT ]] ||
7064                 error "stripe count $stripe_count != $STRIPECOUNT"
7065         rm -f $DIR/$tfile
7066 }
7067 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
7068
7069 test_102c() {
7070         [ -z "$(which setfattr 2>/dev/null)" ] &&
7071                 skip_env "could not find setfattr" && return
7072
7073         # b10930: get/set/list lustre.lov xattr
7074         echo "get/set/list lustre.lov xattr ..."
7075         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7076         test_mkdir -p $DIR/$tdir
7077         chown $RUNAS_ID $DIR/$tdir
7078         local testfile=$DIR/$tdir/$tfile
7079         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7080                 error "setstripe failed"
7081         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
7082                 error "getstripe failed"
7083         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
7084         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
7085
7086         local testfile2=${testfile}2
7087         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
7088                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
7089
7090         $RUNAS $MCREATE $testfile2
7091         $RUNAS setfattr -n lustre.lov -v $value $testfile2
7092         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
7093         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
7094         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
7095         [ $stripe_count -eq $STRIPECOUNT ] ||
7096                 error "stripe count $stripe_count != $STRIPECOUNT"
7097 }
7098 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
7099
7100 compare_stripe_info1() {
7101         local stripe_index_all_zero=true
7102
7103         for num in 1 2 3 4; do
7104                 for count in $(seq 1 $STRIPE_COUNT); do
7105                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
7106                                 local size=$((STRIPE_SIZE * num))
7107                                 local file=file"$num-$offset-$count"
7108                                 stripe_size=$($LFS getstripe -S $PWD/$file)
7109                                 [[ $stripe_size -ne $size ]] &&
7110                                     error "$file: size $stripe_size != $size"
7111                                 stripe_count=$($LFS getstripe -c $PWD/$file)
7112                                 # allow fewer stripes to be created, ORI-601
7113                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
7114                                     error "$file: count $stripe_count != $count"
7115                                 stripe_index=$($LFS getstripe -i $PWD/$file)
7116                                 [[ $stripe_index -ne 0 ]] &&
7117                                         stripe_index_all_zero=false
7118                         done
7119                 done
7120         done
7121         $stripe_index_all_zero &&
7122                 error "all files are being extracted starting from OST index 0"
7123         return 0
7124 }
7125
7126 find_lustre_tar() {
7127         [ -n "$(which tar 2>/dev/null)" ] &&
7128                 strings $(which tar) | grep -q "lustre" && echo tar
7129 }
7130
7131 test_102d() {
7132         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7133         # b10930: tar test for trusted.lov xattr
7134         TAR=$(find_lustre_tar)
7135         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
7136         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7137         setup_test102
7138         test_mkdir -p $DIR/d102d
7139         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
7140         cd $DIR/d102d/$tdir
7141         compare_stripe_info1
7142 }
7143 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
7144
7145 test_102f() {
7146         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7147         # b10930: tar test for trusted.lov xattr
7148         TAR=$(find_lustre_tar)
7149         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
7150         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7151         setup_test102
7152         test_mkdir -p $DIR/d102f
7153         cd $DIR
7154         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
7155         cd $DIR/d102f/$tdir
7156         compare_stripe_info1
7157 }
7158 run_test 102f "tar copy files, not keep osts ==========="
7159
7160 grow_xattr() {
7161         local xsize=${1:-1024}  # in bytes
7162         local file=$DIR/$tfile
7163
7164         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
7165                 skip "must have user_xattr" && return 0
7166         [ -z "$(which setfattr 2>/dev/null)" ] &&
7167                 skip_env "could not find setfattr" && return 0
7168         [ -z "$(which getfattr 2>/dev/null)" ] &&
7169                 skip_env "could not find getfattr" && return 0
7170
7171         touch $file
7172
7173         local value="$(generate_string $xsize)"
7174
7175         local xbig=trusted.big
7176         log "save $xbig on $file"
7177         setfattr -n $xbig -v $value $file ||
7178                 error "saving $xbig on $file failed"
7179
7180         local orig=$(get_xattr_value $xbig $file)
7181         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
7182
7183         local xsml=trusted.sml
7184         log "save $xsml on $file"
7185         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
7186
7187         local new=$(get_xattr_value $xbig $file)
7188         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
7189
7190         log "grow $xsml on $file"
7191         setfattr -n $xsml -v "$value" $file ||
7192                 error "growing $xsml on $file failed"
7193
7194         new=$(get_xattr_value $xbig $file)
7195         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
7196         log "$xbig still valid after growing $xsml"
7197
7198         rm -f $file
7199 }
7200
7201 test_102h() { # bug 15777
7202         grow_xattr 1024
7203 }
7204 run_test 102h "grow xattr from inside inode to external block"
7205
7206 test_102ha() {
7207         large_xattr_enabled || { skip "large_xattr disabled" && return; }
7208         grow_xattr $(max_xattr_size)
7209 }
7210 run_test 102ha "grow xattr from inside inode to external inode"
7211
7212 test_102i() { # bug 17038
7213         [ -z "$(which getfattr 2>/dev/null)" ] &&
7214                 skip "could not find getfattr" && return
7215         touch $DIR/$tfile
7216         ln -s $DIR/$tfile $DIR/${tfile}link
7217         getfattr -n trusted.lov $DIR/$tfile ||
7218                 error "lgetxattr on $DIR/$tfile failed"
7219         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
7220                 grep -i "no such attr" ||
7221                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
7222         rm -f $DIR/$tfile $DIR/${tfile}link
7223 }
7224 run_test 102i "lgetxattr test on symbolic link ============"
7225
7226 test_102j() {
7227         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7228         TAR=$(find_lustre_tar)
7229         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
7230         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7231         setup_test102 "$RUNAS"
7232         test_mkdir -p $DIR/d102j
7233         chown $RUNAS_ID $DIR/d102j
7234         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
7235         cd $DIR/d102j/$tdir
7236         compare_stripe_info1 "$RUNAS"
7237 }
7238 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
7239
7240 test_102k() {
7241         [ -z "$(which setfattr 2>/dev/null)" ] &&
7242                 skip "could not find setfattr" && return
7243         touch $DIR/$tfile
7244         # b22187 just check that does not crash for regular file.
7245         setfattr -n trusted.lov $DIR/$tfile
7246         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
7247         local test_kdir=$DIR/d102k
7248         test_mkdir $test_kdir
7249         local default_size=`$GETSTRIPE -S $test_kdir`
7250         local default_count=`$GETSTRIPE -c $test_kdir`
7251         local default_offset=`$GETSTRIPE -i $test_kdir`
7252         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
7253                 error 'dir setstripe failed'
7254         setfattr -n trusted.lov $test_kdir
7255         local stripe_size=`$GETSTRIPE -S $test_kdir`
7256         local stripe_count=`$GETSTRIPE -c $test_kdir`
7257         local stripe_offset=`$GETSTRIPE -i $test_kdir`
7258         [ $stripe_size -eq $default_size ] ||
7259                 error "stripe size $stripe_size != $default_size"
7260         [ $stripe_count -eq $default_count ] ||
7261                 error "stripe count $stripe_count != $default_count"
7262         [ $stripe_offset -eq $default_offset ] ||
7263                 error "stripe offset $stripe_offset != $default_offset"
7264         rm -rf $DIR/$tfile $test_kdir
7265 }
7266 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
7267
7268 test_102l() {
7269         [ -z "$(which getfattr 2>/dev/null)" ] &&
7270                 skip "could not find getfattr" && return
7271
7272         # LU-532 trusted. xattr is invisible to non-root
7273         local testfile=$DIR/$tfile
7274
7275         touch $testfile
7276
7277         echo "listxattr as user..."
7278         chown $RUNAS_ID $testfile
7279         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
7280             grep -q "trusted" &&
7281                 error "$testfile trusted xattrs are user visible"
7282
7283         return 0;
7284 }
7285 run_test 102l "listxattr size test =================================="
7286
7287 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
7288         local path=$DIR/$tfile
7289         touch $path
7290
7291         listxattr_size_check $path || error "listattr_size_check $path failed"
7292 }
7293 run_test 102m "Ensure listxattr fails on small bufffer ========"
7294
7295 cleanup_test102
7296
7297 getxattr() { # getxattr path name
7298         # Return the base64 encoding of the value of xattr name on path.
7299         local path=$1
7300         local name=$2
7301
7302         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
7303         # file: $path
7304         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7305         #
7306         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7307
7308         getfattr --absolute-names --encoding=base64 --name=$name $path |
7309                 awk -F= -v name=$name '$1 == name {
7310                         print substr($0, index($0, "=") + 1);
7311         }'
7312 }
7313
7314 test_102n() { # LU-4101 mdt: protect internal xattrs
7315         [ -z "$(which setfattr 2>/dev/null)" ] &&
7316                 skip "could not find setfattr" && return
7317         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
7318         then
7319                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
7320                 return
7321         fi
7322
7323         local file0=$DIR/$tfile.0
7324         local file1=$DIR/$tfile.1
7325         local xattr0=$TMP/$tfile.0
7326         local xattr1=$TMP/$tfile.1
7327         local namelist="lov lma lmv link fid version som hsm"
7328         local name
7329         local value
7330
7331         rm -rf $file0 $file1 $xattr0 $xattr1
7332         touch $file0 $file1
7333
7334         # Get 'before' xattrs of $file1.
7335         getfattr --absolute-names --dump --match=- $file1 > $xattr0
7336
7337         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
7338                 namelist+=" lfsck_namespace"
7339         for name in $namelist; do
7340                 # Try to copy xattr from $file0 to $file1.
7341                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7342
7343                 setfattr --name=trusted.$name --value="$value" $file1 ||
7344                         error "setxattr 'trusted.$name' failed"
7345
7346                 # Try to set a garbage xattr.
7347                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7348
7349                 if [[ x$name == "xlov" ]]; then
7350                         setfattr --name=trusted.lov --value="$value" $file1 &&
7351                         error "setxattr invalid 'trusted.lov' success"
7352                 else
7353                         setfattr --name=trusted.$name --value="$value" $file1 ||
7354                                 error "setxattr invalid 'trusted.$name' failed"
7355                 fi
7356
7357                 # Try to remove the xattr from $file1. We don't care if this
7358                 # appears to succeed or fail, we just don't want there to be
7359                 # any changes or crashes.
7360                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7361         done
7362
7363         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
7364         then
7365                 name="lfsck_ns"
7366                 # Try to copy xattr from $file0 to $file1.
7367                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7368
7369                 setfattr --name=trusted.$name --value="$value" $file1 ||
7370                         error "setxattr 'trusted.$name' failed"
7371
7372                 # Try to set a garbage xattr.
7373                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7374
7375                 setfattr --name=trusted.$name --value="$value" $file1 ||
7376                         error "setxattr 'trusted.$name' failed"
7377
7378                 # Try to remove the xattr from $file1. We don't care if this
7379                 # appears to succeed or fail, we just don't want there to be
7380                 # any changes or crashes.
7381                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7382         fi
7383
7384         # Get 'after' xattrs of file1.
7385         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7386
7387         if ! diff $xattr0 $xattr1; then
7388                 error "before and after xattrs of '$file1' differ"
7389         fi
7390
7391         rm -rf $file0 $file1 $xattr0 $xattr1
7392
7393         return 0
7394 }
7395 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7396
7397 test_102p() { # LU-4703 setxattr did not check ownership
7398         local testfile=$DIR/$tfile
7399
7400         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7401                 skip "MDS needs to be at least 2.5.56" && return
7402
7403         touch $testfile
7404
7405         echo "setfacl as user..."
7406         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7407         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7408
7409         echo "setfattr as user..."
7410         setfacl -m "u:$RUNAS_ID:---" $testfile
7411         $RUNAS setfattr -x system.posix_acl_access $testfile
7412         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7413 }
7414 run_test 102p "check setxattr(2) correctly fails without permission"
7415
7416 test_102q() {
7417         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7418                 skip "MDS needs to be at least 2.6.92" && return
7419         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7420 }
7421 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7422
7423 test_102r() {
7424         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7425                 skip "MDS needs to be at least 2.6.93" && return
7426         touch $DIR/$tfile || error "touch"
7427         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7428         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7429         rm $DIR/$tfile || error "rm"
7430
7431         #normal directory
7432         mkdir -p $DIR/$tdir || error "mkdir"
7433         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7434         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7435         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7436                 error "$testfile error deleting user.author1"
7437         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7438                 grep "user.$(basename $tdir)" &&
7439                 error "$tdir did not delete user.$(basename $tdir)"
7440         rmdir $DIR/$tdir || error "rmdir"
7441
7442         #striped directory
7443         test_mkdir -p $DIR/$tdir || error "make striped dir"
7444         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7445         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7446         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7447                 error "$testfile error deleting user.author1"
7448         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7449                 grep "user.$(basename $tdir)" &&
7450                 error "$tdir did not delete user.$(basename $tdir)"
7451         rmdir $DIR/$tdir || error "rm striped dir"
7452 }
7453 run_test 102r "set EAs with empty values"
7454
7455 run_acl_subtest()
7456 {
7457     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7458     return $?
7459 }
7460
7461 test_103a() {
7462         [ "$UID" != 0 ] && skip_env "must run as root" && return
7463         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7464                 skip "must have acl enabled" && return
7465         [ -z "$(which setfacl 2>/dev/null)" ] &&
7466                 skip_env "could not find setfacl" && return
7467         $GSS && skip "could not run under gss" && return
7468         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7469
7470         gpasswd -a daemon bin                           # LU-5641
7471         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7472
7473         declare -a identity_old
7474
7475         for num in $(seq $MDSCOUNT); do
7476                 switch_identity $num true || identity_old[$num]=$?
7477         done
7478
7479         SAVE_UMASK=$(umask)
7480         umask 0022
7481         mkdir -p $DIR/$tdir
7482         cd $DIR/$tdir
7483
7484         echo "performing cp ..."
7485         run_acl_subtest cp || error "run_acl_subtest cp failed"
7486         echo "performing getfacl-noacl..."
7487         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7488         echo "performing misc..."
7489         run_acl_subtest misc || error  "misc test failed"
7490         echo "performing permissions..."
7491         run_acl_subtest permissions || error "permissions failed"
7492         # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
7493         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.8.55) -o \
7494              \( $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6) -a \
7495              $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.29) \) ]
7496         then
7497                 echo "performing permissions xattr..."
7498                 run_acl_subtest permissions_xattr ||
7499                         error "permissions_xattr failed"
7500         fi
7501         echo "performing setfacl..."
7502         run_acl_subtest setfacl || error  "setfacl test failed"
7503
7504         # inheritance test got from HP
7505         echo "performing inheritance..."
7506         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7507         chmod +x make-tree || error "chmod +x failed"
7508         run_acl_subtest inheritance || error "inheritance test failed"
7509         rm -f make-tree
7510
7511         echo "LU-974 ignore umask when acl is enabled..."
7512         run_acl_subtest 974 || error "LU-974 umask test failed"
7513         if [ $MDSCOUNT -ge 2 ]; then
7514                 run_acl_subtest 974_remote ||
7515                         error "LU-974 umask test failed under remote dir"
7516         fi
7517
7518         echo "LU-2561 newly created file is same size as directory..."
7519         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7520                 run_acl_subtest 2561 || error "LU-2561 test failed"
7521         else
7522                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7523         fi
7524
7525         run_acl_subtest 4924 || error "LU-4924 test failed"
7526
7527         cd $SAVE_PWD
7528         umask $SAVE_UMASK
7529
7530         for num in $(seq $MDSCOUNT); do
7531                 if [ "${identity_old[$num]}" = 1 ]; then
7532                         switch_identity $num false || identity_old[$num]=$?
7533                 fi
7534         done
7535 }
7536 run_test 103a "acl test ========================================="
7537
7538 test_103c() {
7539         mkdir -p $DIR/$tdir
7540         cp -rp $DIR/$tdir $DIR/$tdir.bak
7541
7542         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7543                 error "$DIR/$tdir shouldn't contain default ACL"
7544         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7545                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7546         true
7547 }
7548 run_test 103c "'cp -rp' won't set empty acl"
7549
7550 test_104a() {
7551         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7552         touch $DIR/$tfile
7553         lfs df || error "lfs df failed"
7554         lfs df -ih || error "lfs df -ih failed"
7555         lfs df -h $DIR || error "lfs df -h $DIR failed"
7556         lfs df -i $DIR || error "lfs df -i $DIR failed"
7557         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7558         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7559
7560         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7561         lctl --device %$OSC deactivate
7562         lfs df || error "lfs df with deactivated OSC failed"
7563         lctl --device %$OSC activate
7564         # wait the osc back to normal
7565         wait_osc_import_state client ost FULL
7566
7567         lfs df || error "lfs df with reactivated OSC failed"
7568         rm -f $DIR/$tfile
7569 }
7570 run_test 104a "lfs df [-ih] [path] test ========================="
7571
7572 test_104b() {
7573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7574         [ $RUNAS_ID -eq $UID ] &&
7575                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7576         chmod 666 /dev/obd
7577         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7578                         grep "Permission denied" | wc -l)))
7579         if [ $denied_cnt -ne 0 ]; then
7580                 error "lfs check servers test failed"
7581         fi
7582 }
7583 run_test 104b "$RUNAS lfs check servers test ===================="
7584
7585 test_105a() {
7586         # doesn't work on 2.4 kernels
7587         touch $DIR/$tfile
7588         if $(flock_is_enabled); then
7589                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7590         else
7591                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7592         fi
7593         rm -f $DIR/$tfile
7594 }
7595 run_test 105a "flock when mounted without -o flock test ========"
7596
7597 test_105b() {
7598         touch $DIR/$tfile
7599         if $(flock_is_enabled); then
7600                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7601         else
7602                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7603         fi
7604         rm -f $DIR/$tfile
7605 }
7606 run_test 105b "fcntl when mounted without -o flock test ========"
7607
7608 test_105c() {
7609         touch $DIR/$tfile
7610         if $(flock_is_enabled); then
7611                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7612         else
7613                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7614         fi
7615         rm -f $DIR/$tfile
7616 }
7617 run_test 105c "lockf when mounted without -o flock test ========"
7618
7619 test_105d() { # bug 15924
7620         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7621         test_mkdir -p $DIR/$tdir
7622         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7623         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7624         $LCTL set_param fail_loc=0x80000315
7625         flocks_test 2 $DIR/$tdir
7626 }
7627 run_test 105d "flock race (should not freeze) ========"
7628
7629 test_105e() { # bug 22660 && 22040
7630         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7631         touch $DIR/$tfile
7632         flocks_test 3 $DIR/$tfile
7633 }
7634 run_test 105e "Two conflicting flocks from same process ======="
7635
7636 test_106() { #bug 10921
7637         test_mkdir -p $DIR/$tdir
7638         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7639         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7640 }
7641 run_test 106 "attempt exec of dir followed by chown of that dir"
7642
7643 test_107() {
7644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7645         CDIR=`pwd`
7646         cd $DIR
7647
7648         local file=core
7649         rm -f $file
7650
7651         local save_pattern=$(sysctl -n kernel.core_pattern)
7652         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7653         sysctl -w kernel.core_pattern=$file
7654         sysctl -w kernel.core_uses_pid=0
7655
7656         ulimit -c unlimited
7657         sleep 60 &
7658         SLEEPPID=$!
7659
7660         sleep 1
7661
7662         kill -s 11 $SLEEPPID
7663         wait $SLEEPPID
7664         if [ -e $file ]; then
7665                 size=`stat -c%s $file`
7666                 [ $size -eq 0 ] && error "Fail to create core file $file"
7667         else
7668                 error "Fail to create core file $file"
7669         fi
7670         rm -f $file
7671         sysctl -w kernel.core_pattern=$save_pattern
7672         sysctl -w kernel.core_uses_pid=$save_uses_pid
7673         cd $CDIR
7674 }
7675 run_test 107 "Coredump on SIG"
7676
7677 test_110() {
7678         test_mkdir -p $DIR/$tdir
7679         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7680                 error "mkdir with 255 char failed"
7681         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7682                 error "mkdir with 256 char should fail, but did not"
7683         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7684                 error "create with 255 char failed"
7685         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7686                 error "create with 256 char should fail, but did not"
7687
7688         ls -l $DIR/$tdir
7689         rm -rf $DIR/$tdir
7690 }
7691 run_test 110 "filename length checking"
7692
7693 #
7694 # Purpose: To verify dynamic thread (OSS) creation.
7695 #
7696 test_115() {
7697         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7698         remote_ost_nodsh && skip "remote OST with nodsh" && return
7699
7700         # Lustre does not stop service threads once they are started.
7701         # Reset number of running threads to default.
7702         stopall
7703         setupall
7704
7705         local OSTIO_pre
7706         local save_params="$TMP/sanity-$TESTNAME.parameters"
7707
7708         # Get ll_ost_io count before I/O
7709         OSTIO_pre=$(do_facet ost1 \
7710                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
7711         # Exit if lustre is not running (ll_ost_io not running).
7712         [ -z "$OSTIO_pre" ] && error "no OSS threads"
7713
7714         echo "Starting with $OSTIO_pre threads"
7715         local thread_max=$((OSTIO_pre * 2))
7716         local rpc_in_flight=$((thread_max * 2))
7717         # Number of I/O Process proposed to be started.
7718         local nfiles
7719         local facets=$(get_facets OST)
7720
7721         save_lustre_params client \
7722                 "osc.*OST*.max_rpcs_in_flight" > $save_params
7723         save_lustre_params $facets \
7724                 "ost.OSS.ost_io.threads_max" >> $save_params
7725
7726         # Set in_flight to $rpc_in_flight
7727         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
7728                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
7729         nfiles=${rpc_in_flight}
7730         # Set ost thread_max to $thread_max
7731         do_facet ost1 \
7732                 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
7733
7734         # 5 Minutes should be sufficient for max number of OSS
7735         # threads(thread_max) to be created.
7736         local timeout=300
7737
7738         # Start I/O.
7739         local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
7740         mkdir -p $DIR/$tdir
7741         for i in $(seq $nfiles); do
7742                 local file=$DIR/$tdir/${tfile}-$i
7743                 $LFS setstripe -c -1 -i 0 $file
7744                 ($WTL $file $timeout)&
7745         done
7746
7747         # I/O Started - Wait for thread_started to reach thread_max or report
7748         # error if thread_started is more than thread_max.
7749         echo "Waiting for thread_started to reach thread_max"
7750         local thread_started=0
7751         local end_time=$((SECONDS + timeout))
7752
7753         while [ $SECONDS -le $end_time ] ; do
7754                 echo -n "."
7755                 # Get ost i/o thread_started count.
7756                 thread_started=$(do_facet ost1 \
7757                         "$LCTL get_param \
7758                         ost.OSS.ost_io.threads_started | cut -d= -f2")
7759                 # Break out if thread_started is equal/greater than thread_max
7760                 if [[ $thread_started -ge $thread_max ]]; then
7761                         echo ll_ost_io thread_started $thread_started, \
7762                                 equal/greater than thread_max $thread_max
7763                         break
7764                 fi
7765                 sleep 1
7766         done
7767
7768         # Cleanup - We have the numbers, Kill i/o jobs if running.
7769         jobcount=($(jobs -p))
7770         for i in $(seq 0 $((${#jobcount[@]}-1)))
7771         do
7772                 kill -9 ${jobcount[$i]}
7773                 if [ $? -ne 0 ] ; then
7774                         echo Warning: \
7775                         Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
7776                 fi
7777         done
7778
7779         # Cleanup files left by WTL binary.
7780         for i in $(seq $nfiles); do
7781                 local file=$DIR/$tdir/${tfile}-$i
7782                 rm -rf $file
7783                 if [ $? -ne 0 ] ; then
7784                         echo "Warning: Failed to delete file $file"
7785                 fi
7786         done
7787
7788         restore_lustre_params <$save_params
7789         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
7790
7791         # Error out if no new thread has started or Thread started is greater
7792         # than thread max.
7793         if [[ $thread_started -le $OSTIO_pre ||
7794                         $thread_started -gt $thread_max ]]; then
7795                 error "ll_ost_io: thread_started $thread_started" \
7796                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
7797                       "No new thread started or thread started greater " \
7798                       "than thread_max."
7799         fi
7800 }
7801 run_test 115 "verify dynamic thread creation===================="
7802
7803 free_min_max () {
7804         wait_delete_completed
7805         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7806         echo "OST kbytes available: ${AVAIL[@]}"
7807         MAXV=${AVAIL[0]}
7808         MAXI=0
7809         MINV=${AVAIL[0]}
7810         MINI=0
7811         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7812                 #echo OST $i: ${AVAIL[i]}kb
7813                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7814                         MAXV=${AVAIL[i]}
7815                         MAXI=$i
7816                 fi
7817                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7818                         MINV=${AVAIL[i]}
7819                         MINI=$i
7820                 fi
7821         done
7822         echo "Min free space: OST $MINI: $MINV"
7823         echo "Max free space: OST $MAXI: $MAXV"
7824 }
7825
7826 test_116a() { # was previously test_116()
7827         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7828         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7829
7830         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7831
7832         echo -n "Free space priority "
7833         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7834                 head -n1
7835         declare -a AVAIL
7836         free_min_max
7837
7838         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7839         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7840                 && return
7841         trap simple_cleanup_common EXIT
7842
7843
7844         # Check if we need to generate uneven OSTs
7845         test_mkdir -p $DIR/$tdir/OST${MINI}
7846         local FILL=$((MINV / 4))
7847         local DIFF=$((MAXV - MINV))
7848         local DIFF2=$((DIFF * 100 / MINV))
7849
7850         local threshold=$(do_facet $SINGLEMDS \
7851                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7852         threshold=${threshold%%%}
7853         echo -n "Check for uneven OSTs: "
7854         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7855
7856         if [[ $DIFF2 -gt $threshold ]]; then
7857                 echo "ok"
7858                 echo "Don't need to fill OST$MINI"
7859         else
7860                 # generate uneven OSTs. Write 2% over the QOS threshold value
7861                 echo "no"
7862                 DIFF=$((threshold - DIFF2 + 2))
7863                 DIFF2=$((MINV * DIFF / 100))
7864                 echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
7865                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7866                         error "setstripe failed"
7867                 DIFF=$((DIFF2 / 2048))
7868                 i=0
7869                 while [ $i -lt $DIFF ]; do
7870                         i=$((i + 1))
7871                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7872                                 bs=2M count=1 2>/dev/null
7873                         echo -n .
7874                 done
7875                 echo .
7876                 sync
7877                 sleep_maxage
7878                 free_min_max
7879         fi
7880
7881         DIFF=$((MAXV - MINV))
7882         DIFF2=$((DIFF * 100 / MINV))
7883         echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
7884         if [ $DIFF2 -gt $threshold ]; then
7885                 echo "ok"
7886         else
7887                 echo "failed - QOS mode won't be used"
7888                 skip "QOS imbalance criteria not met"
7889                 simple_cleanup_common
7890                 return
7891         fi
7892
7893         MINI1=$MINI
7894         MINV1=$MINV
7895         MAXI1=$MAXI
7896         MAXV1=$MAXV
7897
7898         # now fill using QOS
7899         $SETSTRIPE -c 1 $DIR/$tdir
7900         FILL=$((FILL / 200))
7901         if [ $FILL -gt 600 ]; then
7902                 FILL=600
7903         fi
7904         echo "writing $FILL files to QOS-assigned OSTs"
7905         i=0
7906         while [ $i -lt $FILL ]; do
7907                 i=$((i + 1))
7908                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7909                         count=1 2>/dev/null
7910                 echo -n .
7911         done
7912         echo "wrote $i 200k files"
7913         sync
7914         sleep_maxage
7915
7916         echo "Note: free space may not be updated, so measurements might be off"
7917         free_min_max
7918         DIFF2=$((MAXV - MINV))
7919         echo "free space delta: orig $DIFF final $DIFF2"
7920         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7921         DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
7922         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7923         DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
7924         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7925         if [[ $DIFF -gt 0 ]]; then
7926                 FILL=$((DIFF2 * 100 / DIFF - 100))
7927                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7928         fi
7929
7930         # Figure out which files were written where
7931         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7932                awk '/'$MINI1': / {print $2; exit}')
7933         echo $UUID
7934         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7935         echo "$MINC files created on smaller OST $MINI1"
7936         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7937                awk '/'$MAXI1': / {print $2; exit}')
7938         echo $UUID
7939         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7940         echo "$MAXC files created on larger OST $MAXI1"
7941         if [[ $MINC -gt 0 ]]; then
7942                 FILL=$((MAXC * 100 / MINC - 100))
7943                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7944         fi
7945         [[ $MAXC -gt $MINC ]] ||
7946                 error_ignore LU-9 "stripe QOS didn't balance free space"
7947         simple_cleanup_common
7948 }
7949 run_test 116a "stripe QOS: free space balance ==================="
7950
7951 test_116b() { # LU-2093
7952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7953         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7954
7955 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7956         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7957                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7958         [ -z "$old_rr" ] && skip "no QOS" && return 0
7959         do_facet $SINGLEMDS lctl set_param \
7960                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7961         mkdir -p $DIR/$tdir
7962         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7963         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7964         do_facet $SINGLEMDS lctl set_param fail_loc=0
7965         rm -rf $DIR/$tdir
7966         do_facet $SINGLEMDS lctl set_param \
7967                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7968 }
7969 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7970
7971 test_117() # bug 10891
7972 {
7973         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7974         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7975         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7976         lctl set_param fail_loc=0x21e
7977         > $DIR/$tfile || error "truncate failed"
7978         lctl set_param fail_loc=0
7979         echo "Truncate succeeded."
7980         rm -f $DIR/$tfile
7981 }
7982 run_test 117 "verify osd extend =========="
7983
7984 NO_SLOW_RESENDCOUNT=4
7985 export OLD_RESENDCOUNT=""
7986 set_resend_count () {
7987         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7988         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7989         lctl set_param -n $PROC_RESENDCOUNT $1
7990         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7991 }
7992
7993 # for reduce test_118* time (b=14842)
7994 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7995
7996 # Reset async IO behavior after error case
7997 reset_async() {
7998         FILE=$DIR/reset_async
7999
8000         # Ensure all OSCs are cleared
8001         $SETSTRIPE -c -1 $FILE
8002         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
8003         sync
8004         rm $FILE
8005 }
8006
8007 test_118a() #bug 11710
8008 {
8009         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8010         reset_async
8011
8012         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8013         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8014         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8015
8016         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8017                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8018                 return 1;
8019         fi
8020         rm -f $DIR/$tfile
8021 }
8022 run_test 118a "verify O_SYNC works =========="
8023
8024 test_118b()
8025 {
8026         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8027         remote_ost_nodsh && skip "remote OST with nodsh" && return
8028
8029         reset_async
8030
8031         #define OBD_FAIL_SRV_ENOENT 0x217
8032         set_nodes_failloc "$(osts_nodes)" 0x217
8033         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8034         RC=$?
8035         set_nodes_failloc "$(osts_nodes)" 0
8036         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8037         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8038                     grep -c writeback)
8039
8040         if [[ $RC -eq 0 ]]; then
8041                 error "Must return error due to dropped pages, rc=$RC"
8042                 return 1;
8043         fi
8044
8045         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8046                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8047                 return 1;
8048         fi
8049
8050         echo "Dirty pages not leaked on ENOENT"
8051
8052         # Due to the above error the OSC will issue all RPCs syncronously
8053         # until a subsequent RPC completes successfully without error.
8054         $MULTIOP $DIR/$tfile Ow4096yc
8055         rm -f $DIR/$tfile
8056
8057         return 0
8058 }
8059 run_test 118b "Reclaim dirty pages on fatal error =========="
8060
8061 test_118c()
8062 {
8063         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8064
8065         # for 118c, restore the original resend count, LU-1940
8066         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
8067                                 set_resend_count $OLD_RESENDCOUNT
8068         remote_ost_nodsh && skip "remote OST with nodsh" && return
8069
8070         reset_async
8071
8072         #define OBD_FAIL_OST_EROFS               0x216
8073         set_nodes_failloc "$(osts_nodes)" 0x216
8074
8075         # multiop should block due to fsync until pages are written
8076         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8077         MULTIPID=$!
8078         sleep 1
8079
8080         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8081                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8082         fi
8083
8084         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8085                     grep -c writeback)
8086         if [[ $WRITEBACK -eq 0 ]]; then
8087                 error "No page in writeback, writeback=$WRITEBACK"
8088         fi
8089
8090         set_nodes_failloc "$(osts_nodes)" 0
8091         wait $MULTIPID
8092         RC=$?
8093         if [[ $RC -ne 0 ]]; then
8094                 error "Multiop fsync failed, rc=$RC"
8095         fi
8096
8097         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8098         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8099                     grep -c writeback)
8100         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8101                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8102         fi
8103
8104         rm -f $DIR/$tfile
8105         echo "Dirty pages flushed via fsync on EROFS"
8106         return 0
8107 }
8108 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
8109
8110 # continue to use small resend count to reduce test_118* time (b=14842)
8111 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8112
8113 test_118d()
8114 {
8115         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8116         remote_ost_nodsh && skip "remote OST with nodsh" && return
8117
8118         reset_async
8119
8120         #define OBD_FAIL_OST_BRW_PAUSE_BULK
8121         set_nodes_failloc "$(osts_nodes)" 0x214
8122         # multiop should block due to fsync until pages are written
8123         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8124         MULTIPID=$!
8125         sleep 1
8126
8127         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8128                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8129         fi
8130
8131         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8132                     grep -c writeback)
8133         if [[ $WRITEBACK -eq 0 ]]; then
8134                 error "No page in writeback, writeback=$WRITEBACK"
8135         fi
8136
8137         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
8138         set_nodes_failloc "$(osts_nodes)" 0
8139
8140         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8141         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8142                     grep -c writeback)
8143         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8144                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8145         fi
8146
8147         rm -f $DIR/$tfile
8148         echo "Dirty pages gaurenteed flushed via fsync"
8149         return 0
8150 }
8151 run_test 118d "Fsync validation inject a delay of the bulk =========="
8152
8153 test_118f() {
8154         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8155         reset_async
8156
8157         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
8158         lctl set_param fail_loc=0x8000040a
8159
8160         # Should simulate EINVAL error which is fatal
8161         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8162         RC=$?
8163         if [[ $RC -eq 0 ]]; then
8164                 error "Must return error due to dropped pages, rc=$RC"
8165         fi
8166
8167         lctl set_param fail_loc=0x0
8168
8169         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8170         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8171         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8172                     grep -c writeback)
8173         if [[ $LOCKED -ne 0 ]]; then
8174                 error "Locked pages remain in cache, locked=$LOCKED"
8175         fi
8176
8177         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8178                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8179         fi
8180
8181         rm -f $DIR/$tfile
8182         echo "No pages locked after fsync"
8183
8184         reset_async
8185         return 0
8186 }
8187 run_test 118f "Simulate unrecoverable OSC side error =========="
8188
8189 test_118g() {
8190         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8191         reset_async
8192
8193         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
8194         lctl set_param fail_loc=0x406
8195
8196         # simulate local -ENOMEM
8197         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8198         RC=$?
8199
8200         lctl set_param fail_loc=0
8201         if [[ $RC -eq 0 ]]; then
8202                 error "Must return error due to dropped pages, rc=$RC"
8203         fi
8204
8205         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8206         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8207         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8208                         grep -c writeback)
8209         if [[ $LOCKED -ne 0 ]]; then
8210                 error "Locked pages remain in cache, locked=$LOCKED"
8211         fi
8212
8213         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8214                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8215         fi
8216
8217         rm -f $DIR/$tfile
8218         echo "No pages locked after fsync"
8219
8220         reset_async
8221         return 0
8222 }
8223 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
8224
8225 test_118h() {
8226         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8227         remote_ost_nodsh && skip "remote OST with nodsh" && return
8228
8229         reset_async
8230
8231         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8232         set_nodes_failloc "$(osts_nodes)" 0x20e
8233         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8234         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8235         RC=$?
8236
8237         set_nodes_failloc "$(osts_nodes)" 0
8238         if [[ $RC -eq 0 ]]; then
8239                 error "Must return error due to dropped pages, rc=$RC"
8240         fi
8241
8242         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8243         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8244         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8245                     grep -c writeback)
8246         if [[ $LOCKED -ne 0 ]]; then
8247                 error "Locked pages remain in cache, locked=$LOCKED"
8248         fi
8249
8250         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8251                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8252         fi
8253
8254         rm -f $DIR/$tfile
8255         echo "No pages locked after fsync"
8256
8257         return 0
8258 }
8259 run_test 118h "Verify timeout in handling recoverables errors  =========="
8260
8261 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8262
8263 test_118i() {
8264         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8265         remote_ost_nodsh && skip "remote OST with nodsh" && return
8266
8267         reset_async
8268
8269         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8270         set_nodes_failloc "$(osts_nodes)" 0x20e
8271
8272         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8273         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8274         PID=$!
8275         sleep 5
8276         set_nodes_failloc "$(osts_nodes)" 0
8277
8278         wait $PID
8279         RC=$?
8280         if [[ $RC -ne 0 ]]; then
8281                 error "got error, but should be not, rc=$RC"
8282         fi
8283
8284         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8285         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8286         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8287         if [[ $LOCKED -ne 0 ]]; then
8288                 error "Locked pages remain in cache, locked=$LOCKED"
8289         fi
8290
8291         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8292                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8293         fi
8294
8295         rm -f $DIR/$tfile
8296         echo "No pages locked after fsync"
8297
8298         return 0
8299 }
8300 run_test 118i "Fix error before timeout in recoverable error  =========="
8301
8302 [ "$SLOW" = "no" ] && set_resend_count 4
8303
8304 test_118j() {
8305         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8306         remote_ost_nodsh && skip "remote OST with nodsh" && return
8307
8308         reset_async
8309
8310         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
8311         set_nodes_failloc "$(osts_nodes)" 0x220
8312
8313         # return -EIO from OST
8314         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8315         RC=$?
8316         set_nodes_failloc "$(osts_nodes)" 0x0
8317         if [[ $RC -eq 0 ]]; then
8318                 error "Must return error due to dropped pages, rc=$RC"
8319         fi
8320
8321         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8322         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8323         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8324         if [[ $LOCKED -ne 0 ]]; then
8325                 error "Locked pages remain in cache, locked=$LOCKED"
8326         fi
8327
8328         # in recoverable error on OST we want resend and stay until it finished
8329         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8330                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8331         fi
8332
8333         rm -f $DIR/$tfile
8334         echo "No pages locked after fsync"
8335
8336         return 0
8337 }
8338 run_test 118j "Simulate unrecoverable OST side error =========="
8339
8340 test_118k()
8341 {
8342         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8343         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
8344
8345         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8346         set_nodes_failloc "$(osts_nodes)" 0x20e
8347         test_mkdir -p $DIR/$tdir
8348
8349         for ((i=0;i<10;i++)); do
8350                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
8351                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
8352                 SLEEPPID=$!
8353                 sleep 0.500s
8354                 kill $SLEEPPID
8355                 wait $SLEEPPID
8356         done
8357
8358         set_nodes_failloc "$(osts_nodes)" 0
8359         rm -rf $DIR/$tdir
8360 }
8361 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
8362
8363 test_118l()
8364 {
8365         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8366         # LU-646
8367         test_mkdir -p $DIR/$tdir
8368         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
8369         rm -rf $DIR/$tdir
8370 }
8371 run_test 118l "fsync dir ========="
8372
8373 test_118m() # LU-3066
8374 {
8375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8376         test_mkdir -p $DIR/$tdir
8377         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
8378         rm -rf $DIR/$tdir
8379 }
8380 run_test 118m "fdatasync dir ========="
8381
8382 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8383
8384 test_119a() # bug 11737
8385 {
8386         BSIZE=$((512 * 1024))
8387         directio write $DIR/$tfile 0 1 $BSIZE
8388         # We ask to read two blocks, which is more than a file size.
8389         # directio will indicate an error when requested and actual
8390         # sizes aren't equeal (a normal situation in this case) and
8391         # print actual read amount.
8392         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
8393         if [ "$NOB" != "$BSIZE" ]; then
8394                 error "read $NOB bytes instead of $BSIZE"
8395         fi
8396         rm -f $DIR/$tfile
8397 }
8398 run_test 119a "Short directIO read must return actual read amount"
8399
8400 test_119b() # bug 11737
8401 {
8402         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
8403
8404         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
8405         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
8406         sync
8407         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
8408                 error "direct read failed"
8409         rm -f $DIR/$tfile
8410 }
8411 run_test 119b "Sparse directIO read must return actual read amount"
8412
8413 test_119c() # bug 13099
8414 {
8415         BSIZE=1048576
8416         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
8417         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
8418         rm -f $DIR/$tfile
8419 }
8420 run_test 119c "Testing for direct read hitting hole"
8421
8422 test_119d() # bug 15950
8423 {
8424         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8425         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
8426         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
8427         BSIZE=1048576
8428         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
8429         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
8430         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
8431         lctl set_param fail_loc=0x40d
8432         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
8433         pid_dio=$!
8434         sleep 1
8435         cat $DIR/$tfile > /dev/null &
8436         lctl set_param fail_loc=0
8437         pid_reads=$!
8438         wait $pid_dio
8439         log "the DIO writes have completed, now wait for the reads (should not block very long)"
8440         sleep 2
8441         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8442         error "the read rpcs have not completed in 2s"
8443         rm -f $DIR/$tfile
8444         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8445 }
8446 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8447
8448 test_120a() {
8449         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8450         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8451         test_mkdir -p $DIR/$tdir
8452         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8453                skip "no early lock cancel on server" && return 0
8454
8455         lru_resize_disable mdc
8456         lru_resize_disable osc
8457         cancel_lru_locks mdc
8458         # asynchronous object destroy at MDT could cause bl ast to client
8459         cancel_lru_locks osc
8460
8461         stat $DIR/$tdir > /dev/null
8462         can1=$(do_facet $SINGLEMDS \
8463                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8464                awk '/ldlm_cancel/ {print $2}')
8465         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8466                awk '/ldlm_bl_callback/ {print $2}')
8467         test_mkdir -c1 $DIR/$tdir/d1
8468         can2=$(do_facet $SINGLEMDS \
8469                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8470                awk '/ldlm_cancel/ {print $2}')
8471         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8472                awk '/ldlm_bl_callback/ {print $2}')
8473         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8474         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8475         lru_resize_enable mdc
8476         lru_resize_enable osc
8477 }
8478 run_test 120a "Early Lock Cancel: mkdir test"
8479
8480 test_120b() {
8481         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8482         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8483         test_mkdir $DIR/$tdir
8484         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8485                skip "no early lock cancel on server" && return 0
8486         lru_resize_disable mdc
8487         lru_resize_disable osc
8488         cancel_lru_locks mdc
8489         stat $DIR/$tdir > /dev/null
8490         can1=$(do_facet $SINGLEMDS \
8491                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8492                awk '/ldlm_cancel/ {print $2}')
8493         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8494                awk '/ldlm_bl_callback/ {print $2}')
8495         touch $DIR/$tdir/f1
8496         can2=$(do_facet $SINGLEMDS \
8497                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8498                awk '/ldlm_cancel/ {print $2}')
8499         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8500                awk '/ldlm_bl_callback/ {print $2}')
8501         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8502         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8503         lru_resize_enable mdc
8504         lru_resize_enable osc
8505 }
8506 run_test 120b "Early Lock Cancel: create test"
8507
8508 test_120c() {
8509         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8510         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8511         test_mkdir -c1 $DIR/$tdir
8512         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8513                skip "no early lock cancel on server" && return 0
8514         lru_resize_disable mdc
8515         lru_resize_disable osc
8516         test_mkdir -p -c1 $DIR/$tdir/d1
8517         test_mkdir -p -c1 $DIR/$tdir/d2
8518         touch $DIR/$tdir/d1/f1
8519         cancel_lru_locks mdc
8520         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8521         can1=$(do_facet $SINGLEMDS \
8522                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8523                awk '/ldlm_cancel/ {print $2}')
8524         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8525                awk '/ldlm_bl_callback/ {print $2}')
8526         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8527         can2=$(do_facet $SINGLEMDS \
8528                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8529                awk '/ldlm_cancel/ {print $2}')
8530         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8531                awk '/ldlm_bl_callback/ {print $2}')
8532         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8533         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8534         lru_resize_enable mdc
8535         lru_resize_enable osc
8536 }
8537 run_test 120c "Early Lock Cancel: link test"
8538
8539 test_120d() {
8540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8541         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8542         test_mkdir -p -c1 $DIR/$tdir
8543         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8544                skip "no early lock cancel on server" && return 0
8545         lru_resize_disable mdc
8546         lru_resize_disable osc
8547         touch $DIR/$tdir
8548         cancel_lru_locks mdc
8549         stat $DIR/$tdir > /dev/null
8550         can1=$(do_facet $SINGLEMDS \
8551                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8552                awk '/ldlm_cancel/ {print $2}')
8553         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8554                awk '/ldlm_bl_callback/ {print $2}')
8555         chmod a+x $DIR/$tdir
8556         can2=$(do_facet $SINGLEMDS \
8557                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8558                awk '/ldlm_cancel/ {print $2}')
8559         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8560                awk '/ldlm_bl_callback/ {print $2}')
8561         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8562         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8563         lru_resize_enable mdc
8564         lru_resize_enable osc
8565 }
8566 run_test 120d "Early Lock Cancel: setattr test"
8567
8568 test_120e() {
8569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8570         ! $($LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_can) &&
8571                 skip "no early lock cancel on server" && return 0
8572         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8573         local dlmtrace_set=false
8574
8575         test_mkdir -p -c1 $DIR/$tdir
8576         lru_resize_disable mdc
8577         lru_resize_disable osc
8578         ! $LCTL get_param debug | grep -q dlmtrace &&
8579                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
8580         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8581         cancel_lru_locks mdc
8582         cancel_lru_locks osc
8583         dd if=$DIR/$tdir/f1 of=/dev/null
8584         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8585         # XXX client can not do early lock cancel of OST lock
8586         # during unlink (LU-4206), so cancel osc lock now.
8587         sleep 2
8588         cancel_lru_locks osc
8589         can1=$(do_facet $SINGLEMDS \
8590                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8591                awk '/ldlm_cancel/ {print $2}')
8592         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8593                awk '/ldlm_bl_callback/ {print $2}')
8594         unlink $DIR/$tdir/f1
8595         sleep 5
8596         can2=$(do_facet $SINGLEMDS \
8597                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8598                awk '/ldlm_cancel/ {print $2}')
8599         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8600                awk '/ldlm_bl_callback/ {print $2}')
8601         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
8602                 $LCTL dk $TMP/cancel.debug.txt
8603         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
8604                 $LCTL dk $TMP/blocking.debug.txt
8605         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
8606         lru_resize_enable mdc
8607         lru_resize_enable osc
8608 }
8609 run_test 120e "Early Lock Cancel: unlink test"
8610
8611 test_120f() {
8612         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8613         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8614                skip "no early lock cancel on server" && return 0
8615         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8616         test_mkdir -p -c1 $DIR/$tdir
8617         lru_resize_disable mdc
8618         lru_resize_disable osc
8619         test_mkdir -p -c1 $DIR/$tdir/d1
8620         test_mkdir -p -c1 $DIR/$tdir/d2
8621         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8622         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8623         cancel_lru_locks mdc
8624         cancel_lru_locks osc
8625         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8626         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8627         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8628         # XXX client can not do early lock cancel of OST lock
8629         # during rename (LU-4206), so cancel osc lock now.
8630         sleep 2
8631         cancel_lru_locks osc
8632         can1=$(do_facet $SINGLEMDS \
8633                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8634                awk '/ldlm_cancel/ {print $2}')
8635         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8636                awk '/ldlm_bl_callback/ {print $2}')
8637         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8638         sleep 5
8639         can2=$(do_facet $SINGLEMDS \
8640                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8641                awk '/ldlm_cancel/ {print $2}')
8642         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8643                awk '/ldlm_bl_callback/ {print $2}')
8644         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8645         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8646         lru_resize_enable mdc
8647         lru_resize_enable osc
8648 }
8649 run_test 120f "Early Lock Cancel: rename test"
8650
8651 test_120g() {
8652         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8653         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8654                skip "no early lock cancel on server" && return 0
8655         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8656         lru_resize_disable mdc
8657         lru_resize_disable osc
8658         count=10000
8659         echo create $count files
8660         test_mkdir -p $DIR/$tdir
8661         cancel_lru_locks mdc
8662         cancel_lru_locks osc
8663         t0=`date +%s`
8664
8665         can0=$(do_facet $SINGLEMDS \
8666                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8667                awk '/ldlm_cancel/ {print $2}')
8668         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8669                awk '/ldlm_bl_callback/ {print $2}')
8670         createmany -o $DIR/$tdir/f $count
8671         sync
8672         can1=$(do_facet $SINGLEMDS \
8673                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8674                awk '/ldlm_cancel/ {print $2}')
8675         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8676                awk '/ldlm_bl_callback/ {print $2}')
8677         t1=$(date +%s)
8678         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8679         echo rm $count files
8680         rm -r $DIR/$tdir
8681         sync
8682         can2=$(do_facet $SINGLEMDS \
8683                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8684                awk '/ldlm_cancel/ {print $2}')
8685         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8686                awk '/ldlm_bl_callback/ {print $2}')
8687         t2=$(date +%s)
8688         echo total: $count removes in $((t2-t1))
8689         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8690         sleep 2
8691         # wait for commitment of removal
8692         lru_resize_enable mdc
8693         lru_resize_enable osc
8694 }
8695 run_test 120g "Early Lock Cancel: performance test"
8696
8697 test_121() { #bug #10589
8698         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8699         rm -rf $DIR/$tfile
8700         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8701 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8702         lctl set_param fail_loc=0x310
8703         cancel_lru_locks osc > /dev/null
8704         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8705         lctl set_param fail_loc=0
8706         [[ $reads -eq $writes ]] ||
8707                 error "read $reads blocks, must be $writes blocks"
8708 }
8709 run_test 121 "read cancel race ========="
8710
8711 test_123a() { # was test 123, statahead(bug 11401)
8712         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8713         SLOWOK=0
8714         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8715             log "testing on UP system. Performance may be not as good as expected."
8716                         SLOWOK=1
8717         fi
8718
8719         rm -rf $DIR/$tdir
8720         test_mkdir -p $DIR/$tdir
8721         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8722         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8723         MULT=10
8724         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8725                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8726
8727                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8728                 lctl set_param -n llite.*.statahead_max 0
8729                 lctl get_param llite.*.statahead_max
8730                 cancel_lru_locks mdc
8731                 cancel_lru_locks osc
8732                 stime=`date +%s`
8733                 time ls -l $DIR/$tdir | wc -l
8734                 etime=`date +%s`
8735                 delta=$((etime - stime))
8736                 log "ls $i files without statahead: $delta sec"
8737                 lctl set_param llite.*.statahead_max=$max
8738
8739                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8740                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8741                 cancel_lru_locks mdc
8742                 cancel_lru_locks osc
8743                 stime=`date +%s`
8744                 time ls -l $DIR/$tdir | wc -l
8745                 etime=`date +%s`
8746                 delta_sa=$((etime - stime))
8747                 log "ls $i files with statahead: $delta_sa sec"
8748                 lctl get_param -n llite.*.statahead_stats
8749                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8750
8751                 [[ $swrong -lt $ewrong ]] &&
8752                         log "statahead was stopped, maybe too many locks held!"
8753                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8754
8755                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8756                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8757                     lctl set_param -n llite.*.statahead_max 0
8758                     lctl get_param llite.*.statahead_max
8759                     cancel_lru_locks mdc
8760                     cancel_lru_locks osc
8761                     stime=`date +%s`
8762                     time ls -l $DIR/$tdir | wc -l
8763                     etime=`date +%s`
8764                     delta=$((etime - stime))
8765                     log "ls $i files again without statahead: $delta sec"
8766                     lctl set_param llite.*.statahead_max=$max
8767                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8768                         if [  $SLOWOK -eq 0 ]; then
8769                                 error "ls $i files is slower with statahead!"
8770                         else
8771                                 log "ls $i files is slower with statahead!"
8772                         fi
8773                         break
8774                     fi
8775                 fi
8776
8777                 [ $delta -gt 20 ] && break
8778                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8779                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8780         done
8781         log "ls done"
8782
8783         stime=`date +%s`
8784         rm -r $DIR/$tdir
8785         sync
8786         etime=`date +%s`
8787         delta=$((etime - stime))
8788         log "rm -r $DIR/$tdir/: $delta seconds"
8789         log "rm done"
8790         lctl get_param -n llite.*.statahead_stats
8791 }
8792 run_test 123a "verify statahead work"
8793
8794 test_123b () { # statahead(bug 15027)
8795         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8796         test_mkdir -p $DIR/$tdir
8797         createmany -o $DIR/$tdir/$tfile-%d 1000
8798
8799         cancel_lru_locks mdc
8800         cancel_lru_locks osc
8801
8802 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8803         lctl set_param fail_loc=0x80000803
8804         ls -lR $DIR/$tdir > /dev/null
8805         log "ls done"
8806         lctl set_param fail_loc=0x0
8807         lctl get_param -n llite.*.statahead_stats
8808         rm -r $DIR/$tdir
8809         sync
8810
8811 }
8812 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8813
8814 test_124a() {
8815         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8816         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8817                 skip "no lru resize on server" && return 0
8818         local NR=2000
8819         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8820
8821         log "create $NR files at $DIR/$tdir"
8822         createmany -o $DIR/$tdir/f $NR ||
8823                 error "failed to create $NR files in $DIR/$tdir"
8824
8825         cancel_lru_locks mdc
8826         ls -l $DIR/$tdir > /dev/null
8827
8828         local NSDIR=""
8829         local LRU_SIZE=0
8830         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8831                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8832                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8833                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8834                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8835                         log "NSDIR=$NSDIR"
8836                         log "NS=$(basename $NSDIR)"
8837                         break
8838                 fi
8839         done
8840
8841         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8842                 skip "Not enough cached locks created!"
8843                 return 0
8844         fi
8845         log "LRU=$LRU_SIZE"
8846
8847         local SLEEP=30
8848
8849         # We know that lru resize allows one client to hold $LIMIT locks
8850         # for 10h. After that locks begin to be killed by client.
8851         local MAX_HRS=10
8852         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8853         log "LIMIT=$LIMIT"
8854         if [ $LIMIT -lt $LRU_SIZE ]; then
8855             skip "Limit is too small $LIMIT"
8856             return 0
8857         fi
8858
8859         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8860         # killing locks. Some time was spent for creating locks. This means
8861         # that up to the moment of sleep finish we must have killed some of
8862         # them (10-100 locks). This depends on how fast ther were created.
8863         # Many of them were touched in almost the same moment and thus will
8864         # be killed in groups.
8865         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8866
8867         # Use $LRU_SIZE_B here to take into account real number of locks
8868         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8869         local LRU_SIZE_B=$LRU_SIZE
8870         log "LVF=$LVF"
8871         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8872         log "OLD_LVF=$OLD_LVF"
8873         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8874
8875         # Let's make sure that we really have some margin. Client checks
8876         # cached locks every 10 sec.
8877         SLEEP=$((SLEEP+20))
8878         log "Sleep ${SLEEP} sec"
8879         local SEC=0
8880         while ((SEC<$SLEEP)); do
8881                 echo -n "..."
8882                 sleep 5
8883                 SEC=$((SEC+5))
8884                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8885                 echo -n "$LRU_SIZE"
8886         done
8887         echo ""
8888         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8889         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8890
8891         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8892                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8893                 unlinkmany $DIR/$tdir/f $NR
8894                 return
8895         }
8896
8897         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8898         log "unlink $NR files at $DIR/$tdir"
8899         unlinkmany $DIR/$tdir/f $NR
8900 }
8901 run_test 124a "lru resize ======================================="
8902
8903 get_max_pool_limit()
8904 {
8905         local limit=$($LCTL get_param \
8906                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8907         local max=0
8908         for l in $limit; do
8909                 if [[ $l -gt $max ]]; then
8910                         max=$l
8911                 fi
8912         done
8913         echo $max
8914 }
8915
8916 test_124b() {
8917         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8918         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8919                 skip "no lru resize on server" && return 0
8920
8921         LIMIT=$(get_max_pool_limit)
8922
8923         NR=$(($(default_lru_size)*20))
8924         if [[ $NR -gt $LIMIT ]]; then
8925                 log "Limit lock number by $LIMIT locks"
8926                 NR=$LIMIT
8927         fi
8928
8929         IFree=$(mdsrate_inodes_available)
8930         if [ $IFree -lt $NR ]; then
8931                 log "Limit lock number by $IFree inodes"
8932                 NR=$IFree
8933         fi
8934
8935         lru_resize_disable mdc
8936         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8937                 error "failed to create $DIR/$tdir/disable_lru_resize"
8938
8939         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8940         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8941         cancel_lru_locks mdc
8942         stime=`date +%s`
8943         PID=""
8944         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8945         PID="$PID $!"
8946         sleep 2
8947         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8948         PID="$PID $!"
8949         sleep 2
8950         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8951         PID="$PID $!"
8952         wait $PID
8953         etime=`date +%s`
8954         nolruresize_delta=$((etime-stime))
8955         log "ls -la time: $nolruresize_delta seconds"
8956         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8957         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8958
8959         lru_resize_enable mdc
8960         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8961                 error "failed to create $DIR/$tdir/enable_lru_resize"
8962
8963         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8964         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8965         cancel_lru_locks mdc
8966         stime=`date +%s`
8967         PID=""
8968         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8969         PID="$PID $!"
8970         sleep 2
8971         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8972         PID="$PID $!"
8973         sleep 2
8974         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8975         PID="$PID $!"
8976         wait $PID
8977         etime=`date +%s`
8978         lruresize_delta=$((etime-stime))
8979         log "ls -la time: $lruresize_delta seconds"
8980         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8981
8982         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8983                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8984         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8985                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8986         else
8987                 log "lru resize performs the same with no lru resize"
8988         fi
8989         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8990 }
8991 run_test 124b "lru resize (performance test) ======================="
8992
8993 test_124c() {
8994         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8995         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8996                 skip "no lru resize on server" && return 0
8997
8998         # cache ununsed locks on client
8999         local nr=100
9000         cancel_lru_locks mdc
9001         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9002         createmany -o $DIR/$tdir/f $nr ||
9003                 error "failed to create $nr files in $DIR/$tdir"
9004         ls -l $DIR/$tdir > /dev/null
9005
9006         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9007         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9008         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
9009         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
9010         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
9011
9012         # set lru_max_age to 1 sec
9013         $LCTL set_param $nsdir.lru_max_age=1000 # jiffies
9014         echo "sleep $((recalc_p * 2)) seconds..."
9015         sleep $((recalc_p * 2))
9016
9017         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
9018         # restore lru_max_age
9019         $LCTL set_param -n $nsdir.lru_max_age $max_age
9020         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
9021         unlinkmany $DIR/$tdir/f $nr
9022 }
9023 run_test 124c "LRUR cancel very aged locks"
9024
9025 test_125() { # 13358
9026         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
9027         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
9028         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9029         test_mkdir -p $DIR/d125 || error "mkdir failed"
9030         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
9031         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
9032         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
9033 }
9034 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
9035
9036 test_126() { # bug 12829/13455
9037         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
9038         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
9039         $GSS && skip "must run as gss disabled" && return
9040
9041         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
9042         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
9043         rm -f $DIR/$tfile
9044         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
9045 }
9046 run_test 126 "check that the fsgid provided by the client is taken into account"
9047
9048 test_127a() { # bug 15521
9049         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9050         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
9051         $LCTL set_param osc.*.stats=0
9052         FSIZE=$((2048 * 1024))
9053         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9054         cancel_lru_locks osc
9055         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
9056
9057         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
9058         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9059                 echo "got $COUNT $NAME"
9060                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
9061                 eval $NAME=$COUNT || error "Wrong proc format"
9062
9063                 case $NAME in
9064                         read_bytes|write_bytes)
9065                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
9066                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
9067                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
9068                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
9069                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
9070                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
9071                                 error "sumsquare is too small: $SUMSQ"
9072                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
9073                                 error "sumsquare is too big: $SUMSQ"
9074                         ;;
9075                         *) ;;
9076                 esac
9077         done < $DIR/${tfile}.tmp
9078
9079         #check that we actually got some stats
9080         [ "$read_bytes" ] || error "Missing read_bytes stats"
9081         [ "$write_bytes" ] || error "Missing write_bytes stats"
9082         [ "$read_bytes" != 0 ] || error "no read done"
9083         [ "$write_bytes" != 0 ] || error "no write done"
9084 }
9085 run_test 127a "verify the client stats are sane"
9086
9087 test_127b() { # bug LU-333
9088         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9089         $LCTL set_param llite.*.stats=0
9090         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
9091         # perform 2 reads and writes so MAX is different from SUM.
9092         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9093         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9094         cancel_lru_locks osc
9095         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9096         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9097
9098         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
9099         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9100                 echo "got $COUNT $NAME"
9101                 eval $NAME=$COUNT || error "Wrong proc format"
9102
9103         case $NAME in
9104                 read_bytes)
9105                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9106                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9107                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9108                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9109                         ;;
9110                 write_bytes)
9111                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9112                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9113                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9114                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9115                         ;;
9116                         *) ;;
9117                 esac
9118         done < $TMP/${tfile}.tmp
9119
9120         #check that we actually got some stats
9121         [ "$read_bytes" ] || error "Missing read_bytes stats"
9122         [ "$write_bytes" ] || error "Missing write_bytes stats"
9123         [ "$read_bytes" != 0 ] || error "no read done"
9124         [ "$write_bytes" != 0 ] || error "no write done"
9125
9126         rm -f $TMP/${tfile}.tmp
9127 }
9128 run_test 127b "verify the llite client stats are sane"
9129
9130 test_128() { # bug 15212
9131         touch $DIR/$tfile
9132         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
9133                 find $DIR/$tfile
9134                 find $DIR/$tfile
9135         EOF
9136
9137         result=$(grep error $TMP/$tfile.log)
9138         rm -f $DIR/$tfile $TMP/$tfile.log
9139         [ -z "$result" ] ||
9140                 error "consecutive find's under interactive lfs failed"
9141 }
9142 run_test 128 "interactive lfs for 2 consecutive find's"
9143
9144 set_dir_limits () {
9145         local mntdev
9146         local canondev
9147         local node
9148
9149         local ldproc=/proc/fs/ldiskfs
9150         local facets=$(get_facets MDS)
9151
9152         for facet in ${facets//,/ }; do
9153                 canondev=$(ldiskfs_canon \
9154                            *.$(convert_facet2label $facet).mntdev $facet)
9155                 do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
9156                         ldproc=/sys/fs/ldiskfs
9157                 do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
9158                 do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
9159         done
9160 }
9161
9162 check_mds_dmesg() {
9163         local facets=$(get_facets MDS)
9164         for facet in ${facets//,/ }; do
9165                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
9166         done
9167         return 1
9168 }
9169
9170 test_129() {
9171         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.56) ]] ||
9172                 { skip "Need MDS version with at least 2.5.56"; return 0; }
9173
9174         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9175         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
9176                 skip "ldiskfs only test"
9177                 return
9178         fi
9179         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9180         local ENOSPC=28
9181         local EFBIG=27
9182         local has_warning=false
9183
9184         rm -rf $DIR/$tdir
9185         mkdir -p $DIR/$tdir
9186
9187         # block size of mds1
9188         local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
9189         set_dir_limits $maxsize $maxsize
9190         local dirsize=$(stat -c%s "$DIR/$tdir")
9191         local nfiles=0
9192         while [[ $dirsize -le $maxsize ]]; do
9193                 $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
9194                 rc=$?
9195                 if ! $has_warning; then
9196                         check_mds_dmesg '"is approaching"' && has_warning=true
9197                 fi
9198                 # check two errors:
9199                 # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
9200                 # EFBIG for previous versions included in ldiskfs series
9201                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
9202                         set_dir_limits 0 0
9203                         echo "return code $rc received as expected"
9204
9205                         createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
9206                                 error_exit "create failed w/o dir size limit"
9207
9208                         check_mds_dmesg '"has reached"' ||
9209                                 error_exit "reached message should be output"
9210
9211                         [ $has_warning -eq 0 ] &&
9212                                 error_exit "warning message should be output"
9213
9214                         dirsize=$(stat -c%s "$DIR/$tdir")
9215
9216                         [[ $dirsize -ge $maxsize ]] && return 0
9217                         error_exit "current dir size $dirsize, " \
9218                                    "previous limit $maxsize"
9219                 elif [ $rc -ne 0 ]; then
9220                         set_dir_limits 0 0
9221                         error_exit "return $rc received instead of expected " \
9222                                    "$EFBIG or $ENOSPC, files in dir $dirsize"
9223                 fi
9224                 nfiles=$((nfiles + 1))
9225                 dirsize=$(stat -c%s "$DIR/$tdir")
9226         done
9227
9228         set_dir_limits 0 0
9229         error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
9230 }
9231 run_test 129 "test directory size limit ========================"
9232
9233 OLDIFS="$IFS"
9234 cleanup_130() {
9235         trap 0
9236         IFS="$OLDIFS"
9237 }
9238
9239 test_130a() {
9240         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9241         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9242                 return
9243
9244         trap cleanup_130 EXIT RETURN
9245
9246         local fm_file=$DIR/$tfile
9247         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
9248         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
9249                 error "dd failed for $fm_file"
9250
9251         # LU-1795: test filefrag/FIEMAP once, even if unsupported
9252         filefrag -ves $fm_file
9253         RC=$?
9254         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9255                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9256         [ $RC != 0 ] && error "filefrag $fm_file failed"
9257
9258         filefrag_op=$(filefrag -ve $fm_file |
9259                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9260         lun=$($GETSTRIPE -i $fm_file)
9261
9262         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
9263         IFS=$'\n'
9264         tot_len=0
9265         for line in $filefrag_op
9266         do
9267                 frag_lun=`echo $line | cut -d: -f5`
9268                 ext_len=`echo $line | cut -d: -f4`
9269                 if (( $frag_lun != $lun )); then
9270                         cleanup_130
9271                         error "FIEMAP on 1-stripe file($fm_file) failed"
9272                         return
9273                 fi
9274                 (( tot_len += ext_len ))
9275         done
9276
9277         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
9278                 cleanup_130
9279                 error "FIEMAP on 1-stripe file($fm_file) failed;"
9280                 return
9281         fi
9282
9283         cleanup_130
9284
9285         echo "FIEMAP on single striped file succeeded"
9286 }
9287 run_test 130a "FIEMAP (1-stripe file)"
9288
9289 test_130b() {
9290         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
9291
9292         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9293         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9294                 return
9295
9296         trap cleanup_130 EXIT RETURN
9297
9298         local fm_file=$DIR/$tfile
9299         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9300                         error "setstripe on $fm_file"
9301         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9302                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9303
9304         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
9305                 error "dd failed on $fm_file"
9306
9307         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9308         filefrag_op=$(filefrag -ve $fm_file |
9309                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9310
9311         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9312                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9313
9314         IFS=$'\n'
9315         tot_len=0
9316         num_luns=1
9317         for line in $filefrag_op
9318         do
9319                 frag_lun=$(echo $line | cut -d: -f5 |
9320                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9321                 ext_len=$(echo $line | cut -d: -f4)
9322                 if (( $frag_lun != $last_lun )); then
9323                         if (( tot_len != 1024 )); then
9324                                 cleanup_130
9325                                 error "FIEMAP on $fm_file failed; returned " \
9326                                 "len $tot_len for OST $last_lun instead of 1024"
9327                                 return
9328                         else
9329                                 (( num_luns += 1 ))
9330                                 tot_len=0
9331                         fi
9332                 fi
9333                 (( tot_len += ext_len ))
9334                 last_lun=$frag_lun
9335         done
9336         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
9337                 cleanup_130
9338                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9339                         "luns or wrong len for OST $last_lun"
9340                 return
9341         fi
9342
9343         cleanup_130
9344
9345         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
9346 }
9347 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
9348
9349 test_130c() {
9350         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9351
9352         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9353         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9354                 return
9355
9356         trap cleanup_130 EXIT RETURN
9357
9358         local fm_file=$DIR/$tfile
9359         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
9360         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9361                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9362
9363         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
9364                         error "dd failed on $fm_file"
9365
9366         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9367         filefrag_op=$(filefrag -ve $fm_file |
9368                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9369
9370         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9371                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9372
9373         IFS=$'\n'
9374         tot_len=0
9375         num_luns=1
9376         for line in $filefrag_op
9377         do
9378                 frag_lun=$(echo $line | cut -d: -f5 |
9379                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9380                 ext_len=$(echo $line | cut -d: -f4)
9381                 if (( $frag_lun != $last_lun )); then
9382                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
9383                         if (( logical != 512 )); then
9384                                 cleanup_130
9385                                 error "FIEMAP on $fm_file failed; returned " \
9386                                 "logical start for lun $logical instead of 512"
9387                                 return
9388                         fi
9389                         if (( tot_len != 512 )); then
9390                                 cleanup_130
9391                                 error "FIEMAP on $fm_file failed; returned " \
9392                                 "len $tot_len for OST $last_lun instead of 1024"
9393                                 return
9394                         else
9395                                 (( num_luns += 1 ))
9396                                 tot_len=0
9397                         fi
9398                 fi
9399                 (( tot_len += ext_len ))
9400                 last_lun=$frag_lun
9401         done
9402         if (( num_luns != 2 || tot_len != 512 )); then
9403                 cleanup_130
9404                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9405                         "luns or wrong len for OST $last_lun"
9406                 return
9407         fi
9408
9409         cleanup_130
9410
9411         echo "FIEMAP on 2-stripe file with hole succeeded"
9412 }
9413 run_test 130c "FIEMAP (2-stripe file with hole)"
9414
9415 test_130d() {
9416         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
9417
9418         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9419         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9420                 return
9421
9422         trap cleanup_130 EXIT RETURN
9423
9424         local fm_file=$DIR/$tfile
9425         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9426                         error "setstripe on $fm_file"
9427         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9428                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9429
9430         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
9431         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
9432                 error "dd failed on $fm_file"
9433
9434         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9435         filefrag_op=$(filefrag -ve $fm_file |
9436                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9437
9438         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9439                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9440
9441         IFS=$'\n'
9442         tot_len=0
9443         num_luns=1
9444         for line in $filefrag_op
9445         do
9446                 frag_lun=$(echo $line | cut -d: -f5 |
9447                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9448                 ext_len=$(echo $line | cut -d: -f4)
9449                 if (( $frag_lun != $last_lun )); then
9450                         if (( tot_len != 1024 )); then
9451                                 cleanup_130
9452                                 error "FIEMAP on $fm_file failed; returned " \
9453                                 "len $tot_len for OST $last_lun instead of 1024"
9454                                 return
9455                         else
9456                                 (( num_luns += 1 ))
9457                                 tot_len=0
9458                         fi
9459                 fi
9460                 (( tot_len += ext_len ))
9461                 last_lun=$frag_lun
9462         done
9463         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
9464                 cleanup_130
9465                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9466                         "luns or wrong len for OST $last_lun"
9467                 return
9468         fi
9469
9470         cleanup_130
9471
9472         echo "FIEMAP on N-stripe file succeeded"
9473 }
9474 run_test 130d "FIEMAP (N-stripe file)"
9475
9476 test_130e() {
9477         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9478
9479         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9480         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9481
9482         trap cleanup_130 EXIT RETURN
9483
9484         local fm_file=$DIR/$tfile
9485         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9486         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9487                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9488
9489         NUM_BLKS=512
9490         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9491         for ((i = 0; i < $NUM_BLKS; i++))
9492         do
9493                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9494         done
9495
9496         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9497         filefrag_op=$(filefrag -ve $fm_file |
9498                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9499
9500         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9501                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9502
9503         IFS=$'\n'
9504         tot_len=0
9505         num_luns=1
9506         for line in $filefrag_op
9507         do
9508                 frag_lun=$(echo $line | cut -d: -f5 |
9509                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9510                 ext_len=$(echo $line | cut -d: -f4)
9511                 if (( $frag_lun != $last_lun )); then
9512                         if (( tot_len != $EXPECTED_LEN )); then
9513                                 cleanup_130
9514                                 error "FIEMAP on $fm_file failed; returned " \
9515                                 "len $tot_len for OST $last_lun instead " \
9516                                 "of $EXPECTED_LEN"
9517                                 return
9518                         else
9519                                 (( num_luns += 1 ))
9520                                 tot_len=0
9521                         fi
9522                 fi
9523                 (( tot_len += ext_len ))
9524                 last_lun=$frag_lun
9525         done
9526         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9527                 cleanup_130
9528                 error "FIEMAP on $fm_file failed; returned wrong number " \
9529                         "of luns or wrong len for OST $last_lun"
9530                 return
9531         fi
9532
9533         cleanup_130
9534
9535         echo "FIEMAP with continuation calls succeeded"
9536 }
9537 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9538
9539 # Test for writev/readv
9540 test_131a() {
9541         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
9542                 error "writev test failed"
9543         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 ||
9544                 error "readv failed"
9545         rm -f $DIR/$tfile
9546 }
9547 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9548
9549 test_131b() {
9550         local fsize=$((524288 + 1048576 + 1572864))
9551         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 &&
9552                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9553                         error "append writev test failed"
9554
9555         ((fsize += 1572864 + 1048576))
9556         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 &&
9557                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9558                         error "append writev test failed"
9559         rm -f $DIR/$tfile
9560 }
9561 run_test 131b "test append writev"
9562
9563 test_131c() {
9564         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9565         error "NOT PASS"
9566 }
9567 run_test 131c "test read/write on file w/o objects"
9568
9569 test_131d() {
9570         rwv -f $DIR/$tfile -w -n 1 1572864
9571         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9572         if [ "$NOB" != 1572864 ]; then
9573                 error "Short read filed: read $NOB bytes instead of 1572864"
9574         fi
9575         rm -f $DIR/$tfile
9576 }
9577 run_test 131d "test short read"
9578
9579 test_131e() {
9580         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9581         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9582         error "read hitting hole failed"
9583         rm -f $DIR/$tfile
9584 }
9585 run_test 131e "test read hitting hole"
9586
9587 check_stats() {
9588         local facet=$1
9589         local op=$2
9590         local want=${3:-0}
9591         local res
9592
9593         case $facet in
9594         mds*) res=$(do_facet $facet \
9595                    $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
9596                  ;;
9597         ost*) res=$(do_facet $facet \
9598                    $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
9599                  ;;
9600         *) error "Wrong facet '$facet'" ;;
9601         esac
9602         echo $res
9603         [ "$res" ] || error "The counter for $op on $facet was not incremented"
9604         # if the argument $3 is zero, it means any stat increment is ok.
9605         if [[ $want -gt 0 ]]; then
9606                 local count=$(echo $res | awk '{ print $2 }')
9607                 [[ $count -ne $want ]] &&
9608                         error "The $op counter on $facet is $count, not $want"
9609         fi
9610 }
9611
9612 test_133a() {
9613         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9614         remote_ost_nodsh && skip "remote OST with nodsh" && return
9615         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9616
9617         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9618                 { skip "MDS doesn't support rename stats"; return; }
9619         local testdir=$DIR/${tdir}/stats_testdir
9620         mkdir -p $DIR/${tdir}
9621
9622         # clear stats.
9623         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9624         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9625
9626         # verify mdt stats first.
9627         mkdir ${testdir} || error "mkdir failed"
9628         check_stats $SINGLEMDS "mkdir" 1
9629         touch ${testdir}/${tfile} || error "touch failed"
9630         check_stats $SINGLEMDS "open" 1
9631         check_stats $SINGLEMDS "close" 1
9632         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ] && {
9633                 mknod ${testdir}/${tfile}-pipe p || error "mknod failed"
9634                 check_stats $SINGLEMDS "mknod" 2
9635         }
9636         rm -f ${testdir}/${tfile}-pipe || error "pipe remove failed"
9637         check_stats $SINGLEMDS "unlink" 1
9638         rm -f ${testdir}/${tfile} || error "file remove failed"
9639         check_stats $SINGLEMDS "unlink" 2
9640
9641         # remove working dir and check mdt stats again.
9642         rmdir ${testdir} || error "rmdir failed"
9643         check_stats $SINGLEMDS "rmdir" 1
9644
9645         local testdir1=$DIR/${tdir}/stats_testdir1
9646         mkdir -p ${testdir}
9647         mkdir -p ${testdir1}
9648         touch ${testdir1}/test1
9649         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9650         check_stats $SINGLEMDS "crossdir_rename" 1
9651
9652         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9653         check_stats $SINGLEMDS "samedir_rename" 1
9654
9655         rm -rf $DIR/${tdir}
9656 }
9657 run_test 133a "Verifying MDT stats ========================================"
9658
9659 test_133b() {
9660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9661         remote_ost_nodsh && skip "remote OST with nodsh" && return
9662         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9663         local testdir=$DIR/${tdir}/stats_testdir
9664         mkdir -p ${testdir} || error "mkdir failed"
9665         touch ${testdir}/${tfile} || error "touch failed"
9666         cancel_lru_locks mdc
9667
9668         # clear stats.
9669         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9670         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9671
9672         # extra mdt stats verification.
9673         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9674         check_stats $SINGLEMDS "setattr" 1
9675         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9676         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9677         then            # LU-1740
9678                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9679                 check_stats $SINGLEMDS "getattr" 1
9680         fi
9681         $LFS df || error "lfs failed"
9682         check_stats $SINGLEMDS "statfs" 1
9683
9684         rm -rf $DIR/${tdir}
9685 }
9686 run_test 133b "Verifying extra MDT stats =================================="
9687
9688 test_133c() {
9689         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9690         remote_ost_nodsh && skip "remote OST with nodsh" && return
9691         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9692         local testdir=$DIR/${tdir}/stats_testdir
9693         test_mkdir -p ${testdir} || error "mkdir failed"
9694
9695         # verify obdfilter stats.
9696         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9697         sync
9698         cancel_lru_locks osc
9699         wait_delete_completed
9700
9701         # clear stats.
9702         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9703         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9704
9705         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9706         sync
9707         cancel_lru_locks osc
9708         check_stats ost1 "write" 1
9709
9710         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9711         check_stats ost1 "read" 1
9712
9713         > ${testdir}/${tfile} || error "truncate failed"
9714         check_stats ost1 "punch" 1
9715
9716         rm -f ${testdir}/${tfile} || error "file remove failed"
9717         wait_delete_completed
9718         check_stats ost1 "destroy" 1
9719
9720         rm -rf $DIR/${tdir}
9721 }
9722 run_test 133c "Verifying OST stats ========================================"
9723
9724 order_2() {
9725         local value=$1
9726         local orig=$value
9727         local order=1
9728
9729         while [ $value -ge 2 ]; do
9730                 order=$((order*2))
9731                 value=$((value/2))
9732         done
9733
9734         if [ $orig -gt $order ]; then
9735                 order=$((order*2))
9736         fi
9737         echo $order
9738 }
9739
9740 size_in_KMGT() {
9741     local value=$1
9742     local size=('K' 'M' 'G' 'T');
9743     local i=0
9744     local size_string=$value
9745
9746     while [ $value -ge 1024 ]; do
9747         if [ $i -gt 3 ]; then
9748             #T is the biggest unit we get here, if that is bigger,
9749             #just return XXXT
9750             size_string=${value}T
9751             break
9752         fi
9753         value=$((value >> 10))
9754         if [ $value -lt 1024 ]; then
9755             size_string=${value}${size[$i]}
9756             break
9757         fi
9758         i=$((i + 1))
9759     done
9760
9761     echo $size_string
9762 }
9763
9764 get_rename_size() {
9765     local size=$1
9766     local context=${2:-.}
9767     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9768                 grep -A1 $context |
9769                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9770     echo $sample
9771 }
9772
9773 test_133d() {
9774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9775         remote_ost_nodsh && skip "remote OST with nodsh" && return
9776         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9777         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9778         { skip "MDS doesn't support rename stats"; return; }
9779
9780         local testdir1=$DIR/${tdir}/stats_testdir1
9781         local testdir2=$DIR/${tdir}/stats_testdir2
9782
9783         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9784
9785         mkdir -p ${testdir1} || error "mkdir failed"
9786         mkdir -p ${testdir2} || error "mkdir failed"
9787
9788         createmany -o $testdir1/test 512 || error "createmany failed"
9789
9790         # check samedir rename size
9791         mv ${testdir1}/test0 ${testdir1}/test_0
9792
9793         local testdir1_size=$(ls -l $DIR/${tdir} |
9794                 awk '/stats_testdir1/ {print $5}')
9795         local testdir2_size=$(ls -l $DIR/${tdir} |
9796                 awk '/stats_testdir2/ {print $5}')
9797
9798         testdir1_size=$(order_2 $testdir1_size)
9799         testdir2_size=$(order_2 $testdir2_size)
9800
9801         testdir1_size=$(size_in_KMGT $testdir1_size)
9802         testdir2_size=$(size_in_KMGT $testdir2_size)
9803
9804         echo "source rename dir size: ${testdir1_size}"
9805         echo "target rename dir size: ${testdir2_size}"
9806
9807         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9808         eval $cmd || error "$cmd failed"
9809         local samedir=$($cmd | grep 'same_dir')
9810         local same_sample=$(get_rename_size $testdir1_size)
9811         [ -z "$samedir" ] && error "samedir_rename_size count error"
9812         [[ $same_sample -eq 1 ]] ||
9813                 error "samedir_rename_size error $same_sample"
9814         echo "Check same dir rename stats success"
9815
9816         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9817
9818         # check crossdir rename size
9819         mv ${testdir1}/test_0 ${testdir2}/test_0
9820
9821         testdir1_size=$(ls -l $DIR/${tdir} |
9822                 awk '/stats_testdir1/ {print $5}')
9823         testdir2_size=$(ls -l $DIR/${tdir} |
9824                 awk '/stats_testdir2/ {print $5}')
9825
9826         testdir1_size=$(order_2 $testdir1_size)
9827         testdir2_size=$(order_2 $testdir2_size)
9828
9829         testdir1_size=$(size_in_KMGT $testdir1_size)
9830         testdir2_size=$(size_in_KMGT $testdir2_size)
9831
9832         echo "source rename dir size: ${testdir1_size}"
9833         echo "target rename dir size: ${testdir2_size}"
9834
9835         eval $cmd || error "$cmd failed"
9836         local crossdir=$($cmd | grep 'crossdir')
9837         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9838         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9839         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9840         [[ $src_sample -eq 1 ]] ||
9841                 error "crossdir_rename_size error $src_sample"
9842         [[ $tgt_sample -eq 1 ]] ||
9843                 error "crossdir_rename_size error $tgt_sample"
9844         echo "Check cross dir rename stats success"
9845         rm -rf $DIR/${tdir}
9846 }
9847 run_test 133d "Verifying rename_stats ========================================"
9848
9849 test_133e() {
9850         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9851         remote_ost_nodsh && skip "remote OST with nodsh" && return
9852         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9853         local testdir=$DIR/${tdir}/stats_testdir
9854         local ctr f0 f1 bs=32768 count=42 sum
9855
9856         mkdir -p ${testdir} || error "mkdir failed"
9857
9858         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9859
9860         for ctr in {write,read}_bytes; do
9861                 sync
9862                 cancel_lru_locks osc
9863
9864                 do_facet ost1 $LCTL set_param -n \
9865                         "obdfilter.*.exports.clear=clear"
9866
9867                 if [ $ctr = write_bytes ]; then
9868                         f0=/dev/zero
9869                         f1=${testdir}/${tfile}
9870                 else
9871                         f0=${testdir}/${tfile}
9872                         f1=/dev/null
9873                 fi
9874
9875                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9876                         error "dd failed"
9877                 sync
9878                 cancel_lru_locks osc
9879
9880                 sum=$(do_facet ost1 $LCTL get_param \
9881                         "obdfilter.*.exports.*.stats" |
9882                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9883                                 $1 == ctr { sum += $7 }
9884                                 END { printf("%0.0f", sum) }')
9885
9886                 if ((sum != bs * count)); then
9887                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9888                 fi
9889         done
9890
9891         rm -rf $DIR/${tdir}
9892 }
9893 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9894
9895 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
9896
9897 test_133f() {
9898         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9899         remote_ost_nodsh && skip "remote OST with nodsh" && return
9900         # First without trusting modes.
9901         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
9902         echo "proc_dirs='$proc_dirs'"
9903         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
9904         find $proc_dirs -exec cat '{}' \; &> /dev/null
9905
9906         # Second verifying readability.
9907         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
9908
9909         # eventually, this can also be replaced with "lctl get_param -R",
9910         # but not until that option is always available on the server
9911         local facet
9912         for facet in mds1 ost1; do
9913                 local facet_proc_dirs=$(do_facet $facet \
9914                                         \\\ls -d $proc_regexp 2>/dev/null)
9915                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
9916                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
9917                 do_facet $facet find $facet_proc_dirs \
9918                         ! -name req_history \
9919                         -exec cat '{}' \\\; &> /dev/null
9920
9921                 do_facet $facet find $facet_proc_dirs \
9922                         ! -name req_history \
9923                         -type f \
9924                         -exec cat '{}' \\\; &> /dev/null ||
9925                                 error "proc file read failed"
9926         done
9927 }
9928 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9929
9930 test_133g() {
9931         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9932         remote_ost_nodsh && skip "remote OST with nodsh" && return
9933         # Second verifying writability.
9934         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
9935         echo "proc_dirs='$proc_dirs'"
9936         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
9937         find $proc_dirs \
9938                 -type f \
9939                 -not -name force_lbug \
9940                 -not -name changelog_mask \
9941                 -exec badarea_io '{}' \; &> /dev/null ||
9942                 error "find $proc_dirs failed"
9943
9944         local facet
9945         for facet in mds1 ost1; do
9946                 [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
9947                         skip "Too old lustre on $facet" && continue
9948                 local facet_proc_dirs=$(do_facet $facet \
9949                                         \\\ls -d $proc_regexp 2> /dev/null)
9950                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
9951                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
9952                 do_facet $facet find $facet_proc_dirs \
9953                         -type f \
9954                         -not -name force_lbug \
9955                         -not -name changelog_mask \
9956                         -exec badarea_io '{}' \\\; &> /dev/null ||
9957                                 error "$facet find $facet_proc_dirs failed"
9958         done
9959
9960         # remount the FS in case writes/reads /proc break the FS
9961         cleanup || error "failed to unmount"
9962         setup || error "failed to setup"
9963         true
9964 }
9965 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9966
9967 test_133h() {
9968         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9969         remote_ost_nodsh && skip "remote OST with nodsh" && return
9970         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.54) ]] &&
9971                 skip "Need MDS version at least 2.9.54" && return
9972
9973         local facet
9974         for facet in client mds1 ost1; do
9975                 local facet_proc_dirs=$(do_facet $facet \
9976                                         \\\ls -d $proc_regexp 2> /dev/null)
9977                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
9978                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
9979                 # Get the list of files that are missing the terminating newline
9980                 local missing=($(do_facet $facet \
9981                         find ${facet_proc_dirs} -type f \|              \
9982                                 while read F\; do                       \
9983                                         awk -v FS='\v' -v RS='\v\v'     \
9984                                         "'END { if(NR>0 &&              \
9985                                         \\\$NF !~ /.*\\\n\$/)           \
9986                                                 print FILENAME}'"       \
9987                                         '\$F'\;                         \
9988                                 done 2>/dev/null))
9989                 [ ${#missing[*]} -eq 0 ] ||
9990                         error "files do not end with newline: ${missing[*]}"
9991         done
9992 }
9993 run_test 133h "Proc files should end with newlines"
9994
9995 test_134a() {
9996         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9997         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9998                 skip "Need MDS version at least 2.7.54" && return
9999
10000         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10001         cancel_lru_locks mdc
10002
10003         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
10004         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10005         [ $unused -eq 0 ] || error "$unused locks are not cleared"
10006
10007         local nr=1000
10008         createmany -o $DIR/$tdir/f $nr ||
10009                 error "failed to create $nr files in $DIR/$tdir"
10010         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10011
10012         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
10013         do_facet mds1 $LCTL set_param fail_loc=0x327
10014         do_facet mds1 $LCTL set_param fail_val=500
10015         touch $DIR/$tdir/m
10016
10017         echo "sleep 10 seconds ..."
10018         sleep 10
10019         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
10020
10021         do_facet mds1 $LCTL set_param fail_loc=0
10022         do_facet mds1 $LCTL set_param fail_val=0
10023         [ $lck_cnt -lt $unused ] ||
10024                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
10025
10026         rm $DIR/$tdir/m
10027         unlinkmany $DIR/$tdir/f $nr
10028 }
10029 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
10030
10031 test_134b() {
10032         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10033         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10034                 skip "Need MDS version at least 2.7.54" && return
10035
10036         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10037         cancel_lru_locks mdc
10038
10039         local low_wm=$(do_facet mds1 $LCTL get_param -n \
10040                         ldlm.lock_reclaim_threshold_mb)
10041         # disable reclaim temporarily
10042         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
10043
10044         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
10045         do_facet mds1 $LCTL set_param fail_loc=0x328
10046         do_facet mds1 $LCTL set_param fail_val=500
10047
10048         $LCTL set_param debug=+trace
10049
10050         local nr=600
10051         createmany -o $DIR/$tdir/f $nr &
10052         local create_pid=$!
10053
10054         echo "Sleep $TIMEOUT seconds ..."
10055         sleep $TIMEOUT
10056         if ! ps -p $create_pid  > /dev/null 2>&1; then
10057                 do_facet mds1 $LCTL set_param fail_loc=0
10058                 do_facet mds1 $LCTL set_param fail_val=0
10059                 do_facet mds1 $LCTL set_param \
10060                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
10061                 error "createmany finished incorrectly!"
10062         fi
10063         do_facet mds1 $LCTL set_param fail_loc=0
10064         do_facet mds1 $LCTL set_param fail_val=0
10065         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
10066         wait $create_pid || return 1
10067
10068         unlinkmany $DIR/$tdir/f $nr
10069 }
10070 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
10071
10072 test_140() { #bug-17379
10073         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10074         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
10075         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
10076         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
10077
10078         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
10079         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
10080         local i=0
10081         while i=`expr $i + 1`; do
10082                 test_mkdir -p $i || error "Creating dir $i"
10083                 cd $i || error "Changing to $i"
10084                 ln -s ../stat stat || error "Creating stat symlink"
10085                 # Read the symlink until ELOOP present,
10086                 # not LBUGing the system is considered success,
10087                 # we didn't overrun the stack.
10088                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
10089                 [ $ret -ne 0 ] && {
10090                         if [ $ret -eq 40 ]; then
10091                                 break  # -ELOOP
10092                         else
10093                                 error "Open stat symlink"
10094                                 return
10095                         fi
10096                 }
10097         done
10098         i=`expr $i - 1`
10099         echo "The symlink depth = $i"
10100         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
10101                                         error "Invalid symlink depth"
10102
10103         # Test recursive symlink
10104         ln -s symlink_self symlink_self
10105         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
10106         echo "open symlink_self returns $ret"
10107         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
10108 }
10109 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
10110
10111 test_150() {
10112         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10113         local TF="$TMP/$tfile"
10114
10115         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10116         cp $TF $DIR/$tfile
10117         cancel_lru_locks osc
10118         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
10119         remount_client $MOUNT
10120         df -P $MOUNT
10121         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
10122
10123         $TRUNCATE $TF 6000
10124         $TRUNCATE $DIR/$tfile 6000
10125         cancel_lru_locks osc
10126         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
10127
10128         echo "12345" >>$TF
10129         echo "12345" >>$DIR/$tfile
10130         cancel_lru_locks osc
10131         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
10132
10133         echo "12345" >>$TF
10134         echo "12345" >>$DIR/$tfile
10135         cancel_lru_locks osc
10136         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
10137
10138         rm -f $TF
10139         true
10140 }
10141 run_test 150 "truncate/append tests"
10142
10143 #LU-2902 roc_hit was not able to read all values from lproc
10144 function roc_hit_init() {
10145         local list=$(comma_list $(osts_nodes))
10146         local dir=$DIR/$tdir-check
10147         local file=$dir/file
10148         local BEFORE
10149         local AFTER
10150         local idx
10151
10152         test_mkdir -p $dir
10153         #use setstripe to do a write to every ost
10154         for i in $(seq 0 $((OSTCOUNT-1))); do
10155                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
10156                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
10157                 idx=$(printf %04x $i)
10158                 BEFORE=$(get_osd_param $list *OST*$idx stats |
10159                         awk '$1 == "cache_access" {sum += $7}
10160                                 END { printf("%0.0f", sum) }')
10161
10162                 cancel_lru_locks osc
10163                 cat $file >/dev/null
10164
10165                 AFTER=$(get_osd_param $list *OST*$idx stats |
10166                         awk '$1 == "cache_access" {sum += $7}
10167                                 END { printf("%0.0f", sum) }')
10168
10169                 echo BEFORE:$BEFORE AFTER:$AFTER
10170                 if ! let "AFTER - BEFORE == 4"; then
10171                         rm -rf $dir
10172                         error "roc_hit is not safe to use"
10173                 fi
10174                 rm $file
10175         done
10176
10177         rm -rf $dir
10178 }
10179
10180 function roc_hit() {
10181         local list=$(comma_list $(osts_nodes))
10182         echo $(get_osd_param $list '' stats |
10183                 awk '$1 == "cache_hit" {sum += $7}
10184                         END { printf("%0.0f", sum) }')
10185 }
10186
10187 function set_cache() {
10188         local on=1
10189
10190         if [ "$2" == "off" ]; then
10191                 on=0;
10192         fi
10193         local list=$(comma_list $(osts_nodes))
10194         set_osd_param $list '' $1_cache_enable $on
10195
10196         cancel_lru_locks osc
10197 }
10198
10199 test_151() {
10200         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10201         remote_ost_nodsh && skip "remote OST with nodsh" && return
10202
10203         local CPAGES=3
10204         local list=$(comma_list $(osts_nodes))
10205
10206         # check whether obdfilter is cache capable at all
10207         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
10208                 echo "not cache-capable obdfilter"
10209                 return 0
10210         fi
10211
10212         # check cache is enabled on all obdfilters
10213         if get_osd_param $list '' read_cache_enable | grep 0; then
10214                 echo "oss cache is disabled"
10215                 return 0
10216         fi
10217
10218         set_osd_param $list '' writethrough_cache_enable 1
10219
10220         # check write cache is enabled on all obdfilters
10221         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
10222                 echo "oss write cache is NOT enabled"
10223                 return 0
10224         fi
10225
10226         roc_hit_init
10227
10228         #define OBD_FAIL_OBD_NO_LRU  0x609
10229         do_nodes $list $LCTL set_param fail_loc=0x609
10230
10231         # pages should be in the case right after write
10232         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
10233                 error "dd failed"
10234
10235         local BEFORE=$(roc_hit)
10236         cancel_lru_locks osc
10237         cat $DIR/$tfile >/dev/null
10238         local AFTER=$(roc_hit)
10239
10240         do_nodes $list $LCTL set_param fail_loc=0
10241
10242         if ! let "AFTER - BEFORE == CPAGES"; then
10243                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10244         fi
10245
10246         # the following read invalidates the cache
10247         cancel_lru_locks osc
10248         set_osd_param $list '' read_cache_enable 0
10249         cat $DIR/$tfile >/dev/null
10250
10251         # now data shouldn't be found in the cache
10252         BEFORE=$(roc_hit)
10253         cancel_lru_locks osc
10254         cat $DIR/$tfile >/dev/null
10255         AFTER=$(roc_hit)
10256         if let "AFTER - BEFORE != 0"; then
10257                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10258         fi
10259
10260         set_osd_param $list '' read_cache_enable 1
10261         rm -f $DIR/$tfile
10262 }
10263 run_test 151 "test cache on oss and controls ==============================="
10264
10265 test_152() {
10266         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10267         local TF="$TMP/$tfile"
10268
10269         # simulate ENOMEM during write
10270 #define OBD_FAIL_OST_NOMEM      0x226
10271         lctl set_param fail_loc=0x80000226
10272         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10273         cp $TF $DIR/$tfile
10274         sync || error "sync failed"
10275         lctl set_param fail_loc=0
10276
10277         # discard client's cache
10278         cancel_lru_locks osc
10279
10280         # simulate ENOMEM during read
10281         lctl set_param fail_loc=0x80000226
10282         cmp $TF $DIR/$tfile || error "cmp failed"
10283         lctl set_param fail_loc=0
10284
10285         rm -f $TF
10286 }
10287 run_test 152 "test read/write with enomem ============================"
10288
10289 test_153() {
10290         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
10291 }
10292 run_test 153 "test if fdatasync does not crash ======================="
10293
10294 dot_lustre_fid_permission_check() {
10295         local fid=$1
10296         local ffid=$MOUNT/.lustre/fid/$fid
10297         local test_dir=$2
10298
10299         echo "stat fid $fid"
10300         stat $ffid > /dev/null || error "stat $ffid failed."
10301         echo "touch fid $fid"
10302         touch $ffid || error "touch $ffid failed."
10303         echo "write to fid $fid"
10304         cat /etc/hosts > $ffid || error "write $ffid failed."
10305         echo "read fid $fid"
10306         diff /etc/hosts $ffid || error "read $ffid failed."
10307         echo "append write to fid $fid"
10308         cat /etc/hosts >> $ffid || error "append write $ffid failed."
10309         echo "rename fid $fid"
10310         mv $ffid $test_dir/$tfile.1 &&
10311                 error "rename $ffid to $tfile.1 should fail."
10312         touch $test_dir/$tfile.1
10313         mv $test_dir/$tfile.1 $ffid &&
10314                 error "rename $tfile.1 to $ffid should fail."
10315         rm -f $test_dir/$tfile.1
10316         echo "truncate fid $fid"
10317         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
10318         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
10319                 echo "link fid $fid"
10320                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
10321         fi
10322         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
10323                 echo "setfacl fid $fid"
10324                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
10325                 echo "getfacl fid $fid"
10326                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
10327         fi
10328         echo "unlink fid $fid"
10329         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
10330         echo "mknod fid $fid"
10331         mknod $ffid c 1 3 && error "mknod $ffid should fail."
10332
10333         fid=[0xf00000400:0x1:0x0]
10334         ffid=$MOUNT/.lustre/fid/$fid
10335
10336         echo "stat non-exist fid $fid"
10337         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
10338         echo "write to non-exist fid $fid"
10339         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
10340         echo "link new fid $fid"
10341         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
10342
10343         mkdir -p $test_dir/$tdir
10344         touch $test_dir/$tdir/$tfile
10345         fid=$($LFS path2fid $test_dir/$tdir)
10346         rc=$?
10347         [ $rc -ne 0 ] &&
10348                 error "error: could not get fid for $test_dir/$dir/$tfile."
10349
10350         ffid=$MOUNT/.lustre/fid/$fid
10351
10352         echo "ls $fid"
10353         ls $ffid > /dev/null || error "ls $ffid failed."
10354         echo "touch $fid/$tfile.1"
10355         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
10356
10357         echo "touch $MOUNT/.lustre/fid/$tfile"
10358         touch $MOUNT/.lustre/fid/$tfile && \
10359                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
10360
10361         echo "setxattr to $MOUNT/.lustre/fid"
10362         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
10363
10364         echo "listxattr for $MOUNT/.lustre/fid"
10365         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
10366
10367         echo "delxattr from $MOUNT/.lustre/fid"
10368         setfattr -x trusted.name1 $MOUNT/.lustre/fid
10369
10370         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
10371         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
10372                 error "touch invalid fid should fail."
10373
10374         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
10375         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
10376                 error "touch non-normal fid should fail."
10377
10378         echo "rename $tdir to $MOUNT/.lustre/fid"
10379         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
10380                 error "rename to $MOUNT/.lustre/fid should fail."
10381
10382         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
10383         then            # LU-3547
10384                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
10385                 local new_obf_mode=777
10386
10387                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
10388                 chmod $new_obf_mode $DIR/.lustre/fid ||
10389                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
10390
10391                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
10392                 [ $obf_mode -eq $new_obf_mode ] ||
10393                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
10394
10395                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
10396                 chmod $old_obf_mode $DIR/.lustre/fid ||
10397                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
10398         fi
10399
10400         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
10401         fid=$($LFS path2fid $test_dir/$tfile-2)
10402
10403         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
10404         then # LU-5424
10405                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
10406                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
10407                         error "create lov data thru .lustre failed"
10408         fi
10409         echo "cp /etc/passwd $test_dir/$tfile-2"
10410         cp /etc/passwd $test_dir/$tfile-2 ||
10411                 error "copy to $test_dir/$tfile-2 failed."
10412         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
10413         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
10414                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
10415
10416         rm -rf $test_dir/tfile.lnk
10417         rm -rf $test_dir/$tfile-2
10418 }
10419
10420 test_154A() {
10421         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10422                 skip "Need MDS version at least 2.4.1" && return
10423
10424         local tf=$DIR/$tfile
10425         touch $tf
10426
10427         local fid=$($LFS path2fid $tf)
10428         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
10429
10430         # check that we get the same pathname back
10431         local found=$($LFS fid2path $MOUNT "$fid")
10432         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
10433         [ "$found" == "$tf" ] ||
10434                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
10435 }
10436 run_test 154A "lfs path2fid and fid2path basic checks"
10437
10438 test_154B() {
10439         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10440                 skip "Need MDS version at least 2.4.1" && return
10441
10442         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
10443         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
10444         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
10445         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
10446
10447         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
10448         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
10449
10450         # check that we get the same pathname
10451         echo "PFID: $PFID, name: $name"
10452         local FOUND=$($LFS fid2path $MOUNT "$PFID")
10453         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
10454         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
10455                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
10456
10457         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
10458 }
10459 run_test 154B "verify the ll_decode_linkea tool"
10460
10461 test_154a() {
10462         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10463         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10464                 { skip "Need MDS version at least 2.2.51"; return 0; }
10465         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
10466         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10467
10468         cp /etc/hosts $DIR/$tfile
10469
10470         fid=$($LFS path2fid $DIR/$tfile)
10471         rc=$?
10472         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
10473
10474         dot_lustre_fid_permission_check "$fid" $DIR ||
10475                 error "dot lustre permission check $fid failed"
10476
10477         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
10478
10479         touch $MOUNT/.lustre/file &&
10480                 error "creation is not allowed under .lustre"
10481
10482         mkdir $MOUNT/.lustre/dir &&
10483                 error "mkdir is not allowed under .lustre"
10484
10485         rm -rf $DIR/$tfile
10486 }
10487 run_test 154a "Open-by-FID"
10488
10489 test_154b() {
10490         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10491         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10492                 { skip "Need MDS version at least 2.2.51"; return 0; }
10493         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10494
10495         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10496
10497         local remote_dir=$DIR/$tdir/remote_dir
10498         local MDTIDX=1
10499         local rc=0
10500
10501         mkdir -p $DIR/$tdir
10502         $LFS mkdir -i $MDTIDX $remote_dir ||
10503                 error "create remote directory failed"
10504
10505         cp /etc/hosts $remote_dir/$tfile
10506
10507         fid=$($LFS path2fid $remote_dir/$tfile)
10508         rc=$?
10509         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
10510
10511         dot_lustre_fid_permission_check "$fid" $remote_dir ||
10512                 error "dot lustre permission check $fid failed"
10513         rm -rf $DIR/$tdir
10514 }
10515 run_test 154b "Open-by-FID for remote directory"
10516
10517 test_154c() {
10518         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10519                 skip "Need MDS version at least 2.4.1" && return
10520
10521         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
10522         local FID1=$($LFS path2fid $DIR/$tfile.1)
10523         local FID2=$($LFS path2fid $DIR/$tfile.2)
10524         local FID3=$($LFS path2fid $DIR/$tfile.3)
10525
10526         local N=1
10527         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
10528                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
10529                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
10530                 local want=FID$N
10531                 [ "$FID" = "${!want}" ] ||
10532                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
10533                 N=$((N + 1))
10534         done
10535
10536         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10537         do
10538                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10539                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10540                 N=$((N + 1))
10541         done
10542 }
10543 run_test 154c "lfs path2fid and fid2path multiple arguments"
10544
10545 test_154d() {
10546         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10547         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10548                 skip "Need MDS version at least 2.5.53" && return
10549
10550         if remote_mds; then
10551                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10552         else
10553                 nid="0@lo"
10554         fi
10555         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10556         local fd
10557         local cmd
10558
10559         rm -f $DIR/$tfile
10560         touch $DIR/$tfile
10561
10562         local fid=$($LFS path2fid $DIR/$tfile)
10563         # Open the file
10564         fd=$(free_fd)
10565         cmd="exec $fd<$DIR/$tfile"
10566         eval $cmd
10567         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10568         echo "$fid_list" | grep "$fid"
10569         rc=$?
10570
10571         cmd="exec $fd>/dev/null"
10572         eval $cmd
10573         if [ $rc -ne 0 ]; then
10574                 error "FID $fid not found in open files list $fid_list"
10575         fi
10576 }
10577 run_test 154d "Verify open file fid"
10578
10579 test_154e()
10580 {
10581         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10582                 skip "Need MDS version at least 2.6.50" && return
10583
10584         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10585                 error ".lustre returned by readdir"
10586         fi
10587 }
10588 run_test 154e ".lustre is not returned by readdir"
10589
10590 test_154f() {
10591         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10592         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10593         test_mkdir -p -c1 $DIR/$tdir/d
10594         # test dirs inherit from its stripe
10595         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10596         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10597         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10598         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10599         touch $DIR/f
10600
10601         # get fid of parents
10602         local FID0=$($LFS path2fid $DIR/$tdir/d)
10603         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10604         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10605         local FID3=$($LFS path2fid $DIR)
10606
10607         # check that path2fid --parents returns expected <parent_fid>/name
10608         # 1) test for a directory (single parent)
10609         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
10610         [ "$parent" == "$FID0/foo1" ] ||
10611                 error "expected parent: $FID0/foo1, got: $parent"
10612
10613         # 2) test for a file with nlink > 1 (multiple parents)
10614         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
10615         echo "$parent" | grep -F "$FID1/$tfile" ||
10616                 error "$FID1/$tfile not returned in parent list"
10617         echo "$parent" | grep -F "$FID2/link" ||
10618                 error "$FID2/link not returned in parent list"
10619
10620         # 3) get parent by fid
10621         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
10622         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10623         echo "$parent" | grep -F "$FID1/$tfile" ||
10624                 error "$FID1/$tfile not returned in parent list (by fid)"
10625         echo "$parent" | grep -F "$FID2/link" ||
10626                 error "$FID2/link not returned in parent list (by fid)"
10627
10628         # 4) test for entry in root directory
10629         parent=$($LFS path2fid --parents $DIR/f)
10630         echo "$parent" | grep -F "$FID3/f" ||
10631                 error "$FID3/f not returned in parent list"
10632
10633         # 5) test it on root directory
10634         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
10635                 error "$MOUNT should not have parents"
10636
10637         # enable xattr caching and check that linkea is correctly updated
10638         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10639         save_lustre_params client "llite.*.xattr_cache" > $save
10640         lctl set_param llite.*.xattr_cache 1
10641
10642         # 6.1) linkea update on rename
10643         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
10644
10645         # get parents by fid
10646         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10647         # foo1 should no longer be returned in parent list
10648         echo "$parent" | grep -F "$FID1" &&
10649                 error "$FID1 should no longer be in parent list"
10650         # the new path should appear
10651         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
10652                 error "$FID2/$tfile.moved is not in parent list"
10653
10654         # 6.2) linkea update on unlink
10655         rm -f $DIR/$tdir/d/foo2/link
10656         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10657         # foo2/link should no longer be returned in parent list
10658         echo "$parent" | grep -F "$FID2/link" &&
10659                 error "$FID2/link should no longer be in parent list"
10660         true
10661
10662         rm -f $DIR/f
10663         restore_lustre_params < $save
10664         rm -f $save
10665 }
10666 run_test 154f "get parent fids by reading link ea"
10667
10668 test_154g()
10669 {
10670         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) ]] ||
10671                 { skip "Need MDS version at least 2.6.92"; return 0; }
10672         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10673
10674         mkdir -p $DIR/$tdir
10675         llapi_fid_test -d $DIR/$tdir
10676 }
10677 run_test 154g "various llapi FID tests"
10678
10679 test_155_small_load() {
10680     local temp=$TMP/$tfile
10681     local file=$DIR/$tfile
10682
10683     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
10684         error "dd of=$temp bs=6096 count=1 failed"
10685     cp $temp $file
10686     cancel_lru_locks osc
10687     cmp $temp $file || error "$temp $file differ"
10688
10689     $TRUNCATE $temp 6000
10690     $TRUNCATE $file 6000
10691     cmp $temp $file || error "$temp $file differ (truncate1)"
10692
10693     echo "12345" >>$temp
10694     echo "12345" >>$file
10695     cmp $temp $file || error "$temp $file differ (append1)"
10696
10697     echo "12345" >>$temp
10698     echo "12345" >>$file
10699     cmp $temp $file || error "$temp $file differ (append2)"
10700
10701     rm -f $temp $file
10702     true
10703 }
10704
10705 test_155_big_load() {
10706     remote_ost_nodsh && skip "remote OST with nodsh" && return
10707     local temp=$TMP/$tfile
10708     local file=$DIR/$tfile
10709
10710     free_min_max
10711     local cache_size=$(do_facet ost$((MAXI+1)) \
10712         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
10713     local large_file_size=$((cache_size * 2))
10714
10715     echo "OSS cache size: $cache_size KB"
10716     echo "Large file size: $large_file_size KB"
10717
10718     [ $MAXV -le $large_file_size ] && \
10719         skip_env "max available OST size needs > $large_file_size KB" && \
10720         return 0
10721
10722     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
10723
10724     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
10725         error "dd of=$temp bs=$large_file_size count=1k failed"
10726     cp $temp $file
10727     ls -lh $temp $file
10728     cancel_lru_locks osc
10729     cmp $temp $file || error "$temp $file differ"
10730
10731     rm -f $temp $file
10732     true
10733 }
10734
10735 save_writethrough() {
10736         local facets=$(get_facets OST)
10737
10738         save_lustre_params $facets "obdfilter.*.writethrough_cache_enable" > $1
10739         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" >> $1
10740 }
10741
10742 test_155a() {
10743         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10744         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10745         save_writethrough $p
10746
10747         set_cache read on
10748         set_cache writethrough on
10749         test_155_small_load
10750         restore_lustre_params < $p
10751         rm -f $p
10752 }
10753 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10754
10755 test_155b() {
10756         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10757         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10758         save_writethrough $p
10759
10760         set_cache read on
10761         set_cache writethrough off
10762         test_155_small_load
10763         restore_lustre_params < $p
10764         rm -f $p
10765 }
10766 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10767
10768 test_155c() {
10769         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10770         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10771         save_writethrough $p
10772
10773         set_cache read off
10774         set_cache writethrough on
10775         test_155_small_load
10776         restore_lustre_params < $p
10777         rm -f $p
10778 }
10779 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10780
10781 test_155d() {
10782         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10783         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10784         save_writethrough $p
10785
10786         set_cache read off
10787         set_cache writethrough off
10788         test_155_small_load
10789         restore_lustre_params < $p
10790         rm -f $p
10791 }
10792 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10793
10794 test_155e() {
10795         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10796         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10797         save_writethrough $p
10798
10799         set_cache read on
10800         set_cache writethrough on
10801         test_155_big_load
10802         restore_lustre_params < $p
10803         rm -f $p
10804 }
10805 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10806
10807 test_155f() {
10808         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10809         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10810         save_writethrough $p
10811
10812         set_cache read on
10813         set_cache writethrough off
10814         test_155_big_load
10815         restore_lustre_params < $p
10816         rm -f $p
10817 }
10818 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10819
10820 test_155g() {
10821         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10822         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10823         save_writethrough $p
10824
10825         set_cache read off
10826         set_cache writethrough on
10827         test_155_big_load
10828         restore_lustre_params < $p
10829         rm -f $p
10830 }
10831 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10832
10833 test_155h() {
10834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10835         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10836         save_writethrough $p
10837
10838         set_cache read off
10839         set_cache writethrough off
10840         test_155_big_load
10841         restore_lustre_params < $p
10842         rm -f $p
10843 }
10844 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10845
10846 test_156() {
10847         remote_ost_nodsh && skip "remote OST with nodsh" && return
10848         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10849         local CPAGES=3
10850         local BEFORE
10851         local AFTER
10852         local file="$DIR/$tfile"
10853         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10854
10855         [ "$(facet_fstype ost1)" = "zfs" -a \
10856            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
10857                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
10858                 return
10859
10860         save_writethrough $p
10861         roc_hit_init
10862
10863         log "Turn on read and write cache"
10864         set_cache read on
10865         set_cache writethrough on
10866
10867         log "Write data and read it back."
10868         log "Read should be satisfied from the cache."
10869         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10870         BEFORE=$(roc_hit)
10871         cancel_lru_locks osc
10872         cat $file >/dev/null
10873         AFTER=$(roc_hit)
10874         if ! let "AFTER - BEFORE == CPAGES"; then
10875                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10876         else
10877                 log "cache hits:: before: $BEFORE, after: $AFTER"
10878         fi
10879
10880         log "Read again; it should be satisfied from the cache."
10881         BEFORE=$AFTER
10882         cancel_lru_locks osc
10883         cat $file >/dev/null
10884         AFTER=$(roc_hit)
10885         if ! let "AFTER - BEFORE == CPAGES"; then
10886                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10887         else
10888                 log "cache hits:: before: $BEFORE, after: $AFTER"
10889         fi
10890
10891         log "Turn off the read cache and turn on the write cache"
10892         set_cache read off
10893         set_cache writethrough on
10894
10895         log "Read again; it should be satisfied from the cache."
10896         BEFORE=$(roc_hit)
10897         cancel_lru_locks osc
10898         cat $file >/dev/null
10899         AFTER=$(roc_hit)
10900         if ! let "AFTER - BEFORE == CPAGES"; then
10901                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10902         else
10903                 log "cache hits:: before: $BEFORE, after: $AFTER"
10904         fi
10905
10906         log "Read again; it should not be satisfied from the cache."
10907         BEFORE=$AFTER
10908         cancel_lru_locks osc
10909         cat $file >/dev/null
10910         AFTER=$(roc_hit)
10911         if ! let "AFTER - BEFORE == 0"; then
10912                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10913         else
10914                 log "cache hits:: before: $BEFORE, after: $AFTER"
10915         fi
10916
10917         log "Write data and read it back."
10918         log "Read should be satisfied from the cache."
10919         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10920         BEFORE=$(roc_hit)
10921         cancel_lru_locks osc
10922         cat $file >/dev/null
10923         AFTER=$(roc_hit)
10924         if ! let "AFTER - BEFORE == CPAGES"; then
10925                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10926         else
10927                 log "cache hits:: before: $BEFORE, after: $AFTER"
10928         fi
10929
10930         log "Read again; it should not be satisfied from the cache."
10931         BEFORE=$AFTER
10932         cancel_lru_locks osc
10933         cat $file >/dev/null
10934         AFTER=$(roc_hit)
10935         if ! let "AFTER - BEFORE == 0"; then
10936                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10937         else
10938                 log "cache hits:: before: $BEFORE, after: $AFTER"
10939         fi
10940
10941         log "Turn off read and write cache"
10942         set_cache read off
10943         set_cache writethrough off
10944
10945         log "Write data and read it back"
10946         log "It should not be satisfied from the cache."
10947         rm -f $file
10948         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10949         cancel_lru_locks osc
10950         BEFORE=$(roc_hit)
10951         cat $file >/dev/null
10952         AFTER=$(roc_hit)
10953         if ! let "AFTER - BEFORE == 0"; then
10954                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10955         else
10956                 log "cache hits:: before: $BEFORE, after: $AFTER"
10957         fi
10958
10959         log "Turn on the read cache and turn off the write cache"
10960         set_cache read on
10961         set_cache writethrough off
10962
10963         log "Write data and read it back"
10964         log "It should not be satisfied from the cache."
10965         rm -f $file
10966         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10967         BEFORE=$(roc_hit)
10968         cancel_lru_locks osc
10969         cat $file >/dev/null
10970         AFTER=$(roc_hit)
10971         if ! let "AFTER - BEFORE == 0"; then
10972                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10973         else
10974                 log "cache hits:: before: $BEFORE, after: $AFTER"
10975         fi
10976
10977         log "Read again; it should be satisfied from the cache."
10978         BEFORE=$(roc_hit)
10979         cancel_lru_locks osc
10980         cat $file >/dev/null
10981         AFTER=$(roc_hit)
10982         if ! let "AFTER - BEFORE == CPAGES"; then
10983                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10984         else
10985                 log "cache hits:: before: $BEFORE, after: $AFTER"
10986         fi
10987
10988         rm -f $file
10989         restore_lustre_params < $p
10990         rm -f $p
10991 }
10992 run_test 156 "Verification of tunables"
10993
10994 #Changelogs
10995 cleanup_changelog () {
10996         trap 0
10997         echo "Deregistering changelog client $CL_USER"
10998         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
10999 }
11000
11001 err17935 () {
11002         if [[ $MDSCOUNT -gt 1 ]]; then
11003                 error_ignore bz17935 $*
11004         else
11005                 error $*
11006         fi
11007 }
11008
11009 changelog_chmask()
11010 {
11011         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11012
11013         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
11014
11015         if [ $MASK -eq 1 ]; then
11016                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
11017         else
11018                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
11019         fi
11020 }
11021
11022 changelog_extract_field() {
11023         local mdt=$1
11024         local cltype=$2
11025         local file=$3
11026         local identifier=$4
11027
11028         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
11029                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
11030                 tail -1
11031 }
11032
11033 test_160a() {
11034         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11035         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11036         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11037                 { skip "Need MDS version at least 2.2.0"; return; }
11038
11039         local CL_USERS="mdd.$MDT0.changelog_users"
11040         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11041         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11042                 changelog_register -n)
11043         echo "Registered as changelog user $CL_USER"
11044         trap cleanup_changelog EXIT
11045         $GET_CL_USERS | grep -q $CL_USER ||
11046                 error "User $CL_USER not found in changelog_users"
11047
11048         # change something
11049         test_mkdir -p $DIR/$tdir/pics/2008/zachy
11050         touch $DIR/$tdir/pics/2008/zachy/timestamp
11051         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
11052         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
11053         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
11054         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
11055         rm $DIR/$tdir/pics/desktop.jpg
11056
11057         $LFS changelog $MDT0 | tail -5
11058
11059         echo "verifying changelog mask"
11060         changelog_chmask "MKDIR"
11061         changelog_chmask "CLOSE"
11062
11063         test_mkdir -p $DIR/$tdir/pics/zach/sofia
11064         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11065
11066         changelog_chmask "MKDIR"
11067         changelog_chmask "CLOSE"
11068
11069         test_mkdir -p $DIR/$tdir/pics/2008/sofia
11070         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11071
11072         $LFS changelog $MDT0
11073         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
11074         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
11075         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
11076         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
11077
11078         # verify contents
11079         echo "verifying target fid"
11080         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
11081         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
11082         [ "$fidc" == "$fidf" ] ||
11083                 err17935 "fid in changelog $fidc != file fid $fidf"
11084         echo "verifying parent fid"
11085         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
11086         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
11087         [ "$fidc" == "$fidf" ] ||
11088                 err17935 "pfid in changelog $fidc != dir fid $fidf"
11089
11090         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11091         $LFS changelog_clear $MDT0 $CL_USER $(($USER_REC1 + 5))
11092         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11093         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
11094         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
11095                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
11096
11097         MIN_REC=$($GET_CL_USERS |
11098                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
11099         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
11100         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
11101         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
11102                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
11103
11104         # LU-3446 changelog index reset on MDT restart
11105         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11106         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11107         $LFS changelog_clear $MDT0 $CL_USER 0
11108         stop $SINGLEMDS || error "Fail to stop MDT."
11109         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11110         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11111         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
11112         [ $CUR_REC1 == $CUR_REC2 ] ||
11113                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
11114
11115         echo "verifying user deregister"
11116         cleanup_changelog
11117         $GET_CL_USERS | grep -q $CL_USER &&
11118                 error "User $CL_USER still in changelog_users"
11119
11120         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
11121         if [ $CL_USER -eq 0 ]; then
11122                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11123                 touch $DIR/$tdir/chloe
11124                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11125                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
11126                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
11127         else
11128                 echo "$CL_USER other changelog users; can't verify off"
11129         fi
11130 }
11131 run_test 160a "changelog sanity"
11132
11133 test_160b() { # LU-3587
11134         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11135         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11136         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11137                 { skip "Need MDS version at least 2.2.0"; return; }
11138
11139         local CL_USERS="mdd.$MDT0.changelog_users"
11140         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11141         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11142                 changelog_register -n)
11143         echo "Registered as changelog user $CL_USER"
11144         trap cleanup_changelog EXIT
11145         $GET_CL_USERS | grep -q $CL_USER ||
11146                 error "User $CL_USER not found in changelog_users"
11147
11148         local LONGNAME1=$(str_repeat a 255)
11149         local LONGNAME2=$(str_repeat b 255)
11150
11151         cd $DIR
11152         echo "creating very long named file"
11153         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
11154         echo "moving very long named file"
11155         mv $LONGNAME1 $LONGNAME2
11156
11157         $LFS changelog $MDT0 | grep RENME
11158         rm -f $LONGNAME2
11159         cleanup_changelog
11160 }
11161 run_test 160b "Verify that very long rename doesn't crash in changelog"
11162
11163 test_160c() {
11164         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11165
11166         local rc=0
11167         local server_version=$(lustre_version_code $SINGLEMDS)
11168
11169         [[ $server_version -gt $(version_code 2.5.57) ]] ||
11170                 [[ $server_version -gt $(version_code 2.5.1) &&
11171                    $server_version -lt $(version_code 2.5.50) ]] ||
11172                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
11173         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11174
11175         # Registration step
11176         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11177                 changelog_register -n)
11178         trap cleanup_changelog EXIT
11179
11180         rm -rf $DIR/$tdir
11181         mkdir -p $DIR/$tdir
11182         $MCREATE $DIR/$tdir/foo_160c
11183         changelog_chmask "TRUNC"
11184         $TRUNCATE $DIR/$tdir/foo_160c 200
11185         changelog_chmask "TRUNC"
11186         $TRUNCATE $DIR/$tdir/foo_160c 199
11187         $LFS changelog $MDT0
11188         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
11189         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
11190         $LFS changelog_clear $MDT0 $CL_USER 0
11191
11192         # Deregistration step
11193         cleanup_changelog
11194 }
11195 run_test 160c "verify that changelog log catch the truncate event"
11196
11197 test_160d() {
11198         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11199         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11200
11201         local server_version=$(lustre_version_code mds1)
11202         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11203
11204         [[ $server_version -ge $(version_code 2.7.60) ]] ||
11205                 { skip "Need MDS version at least 2.7.60+"; return; }
11206         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11207
11208         # Registration step
11209         CL_USER=$(do_facet mds1 $LCTL --device $MDT0 \
11210                 changelog_register -n)
11211
11212         trap cleanup_changelog EXIT
11213         mkdir -p $DIR/$tdir/migrate_dir
11214         $LFS changelog_clear $MDT0 $CL_USER 0
11215
11216         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
11217         $LFS changelog $MDT0
11218         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
11219         $LFS changelog_clear $MDT0 $CL_USER 0
11220         [ $MIGRATES -eq 1 ] ||
11221                 error "MIGRATE changelog mask count $MIGRATES != 1"
11222
11223         # Deregistration step
11224         cleanup_changelog
11225 }
11226 run_test 160d "verify that changelog log catch the migrate event"
11227
11228 test_160e() {
11229         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11230
11231         # Create a user
11232         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11233                 changelog_register -n)
11234         echo "Registered as changelog user $CL_USER"
11235         trap cleanup_changelog EXIT
11236
11237         # Delete a future user (expect fail)
11238         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister cl77
11239         local rc=$?
11240
11241         if [ $rc -eq 0 ]; then
11242                 error "Deleted non-existant user cl77"
11243         elif [ $rc -ne 2 ]; then
11244                 error "changelog_deregister failed with $rc, " \
11245                         "expected 2 (ENOENT)"
11246         fi
11247
11248         # Clear to a bad index (1 billion should be safe)
11249         $LFS changelog_clear $MDT0 $CL_USER 1000000000
11250         rc=$?
11251
11252         if [ $rc -eq 0 ]; then
11253                 error "Successfully cleared to invalid CL index"
11254         elif [ $rc -ne 22 ]; then
11255                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
11256         fi
11257 }
11258 run_test 160e "changelog negative testing"
11259
11260 test_161a() {
11261         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11262         test_mkdir -p -c1 $DIR/$tdir
11263         cp /etc/hosts $DIR/$tdir/$tfile
11264         test_mkdir -c1 $DIR/$tdir/foo1
11265         test_mkdir -c1 $DIR/$tdir/foo2
11266         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
11267         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
11268         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
11269         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
11270         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
11271         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11272                 $LFS fid2path $DIR $FID
11273                 err17935 "bad link ea"
11274         fi
11275     # middle
11276     rm $DIR/$tdir/foo2/zachary
11277     # last
11278     rm $DIR/$tdir/foo2/thor
11279     # first
11280     rm $DIR/$tdir/$tfile
11281     # rename
11282     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
11283     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
11284         then
11285         $LFS fid2path $DIR $FID
11286         err17935 "bad link rename"
11287     fi
11288     rm $DIR/$tdir/foo2/maggie
11289
11290         # overflow the EA
11291         local longname=filename_avg_len_is_thirty_two_
11292         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
11293                 error "failed to hardlink many files"
11294         links=$($LFS fid2path $DIR $FID | wc -l)
11295         echo -n "${links}/1000 links in link EA"
11296         [[ $links -gt 60 ]] ||
11297                 err17935 "expected at least 60 links in link EA"
11298         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
11299                 error "failed to unlink many hardlinks"
11300 }
11301 run_test 161a "link ea sanity"
11302
11303 test_161b() {
11304         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11305         [ $MDSCOUNT -lt 2 ] && skip "skipping remote directory test" && return
11306         local MDTIDX=1
11307         local remote_dir=$DIR/$tdir/remote_dir
11308
11309         mkdir -p $DIR/$tdir
11310         $LFS mkdir -i $MDTIDX $remote_dir ||
11311                 error "create remote directory failed"
11312
11313         cp /etc/hosts $remote_dir/$tfile
11314         mkdir -p $remote_dir/foo1
11315         mkdir -p $remote_dir/foo2
11316         ln $remote_dir/$tfile $remote_dir/foo1/sofia
11317         ln $remote_dir/$tfile $remote_dir/foo2/zachary
11318         ln $remote_dir/$tfile $remote_dir/foo1/luna
11319         ln $remote_dir/$tfile $remote_dir/foo2/thor
11320
11321         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
11322                      tr -d ']')
11323         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11324                 $LFS fid2path $DIR $FID
11325                 err17935 "bad link ea"
11326         fi
11327         # middle
11328         rm $remote_dir/foo2/zachary
11329         # last
11330         rm $remote_dir/foo2/thor
11331         # first
11332         rm $remote_dir/$tfile
11333         # rename
11334         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
11335         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
11336         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
11337                 $LFS fid2path $DIR $FID
11338                 err17935 "bad link rename"
11339         fi
11340         rm $remote_dir/foo2/maggie
11341
11342         # overflow the EA
11343         local longname=filename_avg_len_is_thirty_two_
11344         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
11345                 error "failed to hardlink many files"
11346         links=$($LFS fid2path $DIR $FID | wc -l)
11347         echo -n "${links}/1000 links in link EA"
11348         [[ ${links} -gt 60 ]] ||
11349                 err17935 "expected at least 60 links in link EA"
11350         unlinkmany $remote_dir/foo2/$longname 1000 ||
11351         error "failed to unlink many hardlinks"
11352 }
11353 run_test 161b "link ea sanity under remote directory"
11354
11355 test_161c() {
11356         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11358         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
11359                 skip "Need MDS version at least 2.1.5" && return
11360
11361         # define CLF_RENAME_LAST 0x0001
11362         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
11363         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11364                 changelog_register -n)
11365
11366         trap cleanup_changelog EXIT
11367         rm -rf $DIR/$tdir
11368         mkdir -p $DIR/$tdir
11369         touch $DIR/$tdir/foo_161c
11370         touch $DIR/$tdir/bar_161c
11371         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11372         $LFS changelog $MDT0 | grep RENME
11373         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
11374                 cut -f5 -d' ')
11375         $LFS changelog_clear $MDT0 $CL_USER 0
11376         if [ x$flags != "x0x1" ]; then
11377                 error "flag $flags is not 0x1"
11378         fi
11379         echo "rename overwrite a target having nlink = 1," \
11380                 "changelog record has flags of $flags"
11381
11382         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
11383         touch $DIR/$tdir/foo_161c
11384         touch $DIR/$tdir/bar_161c
11385         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11386         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11387         $LFS changelog $MDT0 | grep RENME
11388         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11389         $LFS changelog_clear $MDT0 $CL_USER 0
11390         if [ x$flags != "x0x0" ]; then
11391                 error "flag $flags is not 0x0"
11392         fi
11393         echo "rename overwrite a target having nlink > 1," \
11394                 "changelog record has flags of $flags"
11395
11396         # rename doesn't overwrite a target (changelog flag 0x0)
11397         touch $DIR/$tdir/foo_161c
11398         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
11399         $LFS changelog $MDT0 | grep RENME
11400         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11401         $LFS changelog_clear $MDT0 $CL_USER 0
11402         if [ x$flags != "x0x0" ]; then
11403                 error "flag $flags is not 0x0"
11404         fi
11405         echo "rename doesn't overwrite a target," \
11406                 "changelog record has flags of $flags"
11407
11408         # define CLF_UNLINK_LAST 0x0001
11409         # unlink a file having nlink = 1 (changelog flag 0x1)
11410         rm -f $DIR/$tdir/foo2_161c
11411         $LFS changelog $MDT0 | grep UNLNK
11412         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11413         $LFS changelog_clear $MDT0 $CL_USER 0
11414         if [ x$flags != "x0x1" ]; then
11415                 error "flag $flags is not 0x1"
11416         fi
11417         echo "unlink a file having nlink = 1," \
11418                 "changelog record has flags of $flags"
11419
11420         # unlink a file having nlink > 1 (changelog flag 0x0)
11421         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11422         rm -f $DIR/$tdir/foobar_161c
11423         $LFS changelog $MDT0 | grep UNLNK
11424         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11425         $LFS changelog_clear $MDT0 $CL_USER 0
11426         if [ x$flags != "x0x0" ]; then
11427                 error "flag $flags is not 0x0"
11428         fi
11429         echo "unlink a file having nlink > 1," \
11430                 "changelog record has flags of $flags"
11431         cleanup_changelog
11432 }
11433 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
11434
11435 test_161d() {
11436         local user
11437         local pid
11438         local fid
11439
11440         # cleanup previous run
11441         rm -rf $DIR/$tdir/$tfile
11442
11443         user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11444                 changelog_register -n)
11445         [[ $? -eq 0 ]] || error "changelog_register failed"
11446
11447         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
11448         # interfer with $MOUNT/.lustre/fid/ access
11449         mkdir $DIR/$tdir
11450         [[ $? -eq 0 ]] || error "mkdir failed"
11451
11452         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
11453         $LCTL set_param fail_loc=0x8000140c
11454         # 5s pause
11455         $LCTL set_param fail_val=5
11456
11457         # create file
11458         echo foofoo > $DIR/$tdir/$tfile &
11459         pid=$!
11460
11461         # wait for create to be delayed
11462         sleep 2
11463
11464         ps -p $pid
11465         [[ $? -eq 0 ]] || error "create should be blocked"
11466
11467         local tempfile=$(mktemp)
11468         fid=$(changelog_extract_field $MDT0 "CREAT" "$tfile" "t=")
11469         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
11470         # some delay may occur during ChangeLog publishing and file read just
11471         # above, that could allow file write to happen finally
11472         [[ -s $tempfile ]] && echo "file should be empty"
11473
11474         $LCTL set_param fail_loc=0
11475
11476         wait $pid
11477         [[ $? -eq 0 ]] || error "create failed"
11478
11479         $LFS changelog_clear $MDT0 $user 0
11480         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $user
11481 }
11482 run_test 161d "create with concurrent .lustre/fid access"
11483
11484 check_path() {
11485     local expected=$1
11486     shift
11487     local fid=$2
11488
11489     local path=$(${LFS} fid2path $*)
11490     # Remove the '//' indicating a remote directory
11491     path=$(echo $path | sed 's#//#/#g')
11492     RC=$?
11493
11494     if [ $RC -ne 0 ]; then
11495         err17935 "path looked up of $expected failed. Error $RC"
11496         return $RC
11497     elif [ "${path}" != "${expected}" ]; then
11498         err17935 "path looked up \"${path}\" instead of \"${expected}\""
11499         return 2
11500     fi
11501     echo "fid $fid resolves to path $path (expected $expected)"
11502 }
11503
11504 test_162a() { # was test_162
11505         # Make changes to filesystem
11506         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11507         test_mkdir -p -c1 $DIR/$tdir/d2
11508         touch $DIR/$tdir/d2/$tfile
11509         touch $DIR/$tdir/d2/x1
11510         touch $DIR/$tdir/d2/x2
11511         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
11512         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
11513         # regular file
11514         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
11515         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
11516                 error "check path $tdir/d2/$tfile failed"
11517
11518         # softlink
11519         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
11520         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
11521         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
11522                 error "check path $tdir/d2/p/q/r/slink failed"
11523
11524         # softlink to wrong file
11525         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
11526         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
11527         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
11528                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
11529
11530         # hardlink
11531         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
11532         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
11533         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
11534         # fid2path dir/fsname should both work
11535         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
11536                 error "check path $tdir/d2/a/b/c/new_file failed"
11537         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
11538                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
11539
11540         # hardlink count: check that there are 2 links
11541         # Doesnt work with CMD yet: 17935
11542         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
11543                 err17935 "expected 2 links"
11544
11545         # hardlink indexing: remove the first link
11546         rm $DIR/$tdir/d2/p/q/r/hlink
11547         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
11548                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
11549
11550         return 0
11551 }
11552 run_test 162a "path lookup sanity"
11553
11554 test_162b() {
11555         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11556         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11557
11558         mkdir $DIR/$tdir
11559         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
11560                                 error "create striped dir failed"
11561
11562         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
11563                                         tail -n 1 | awk '{print $2}')
11564         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
11565
11566         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
11567         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
11568
11569         # regular file
11570         for ((i=0;i<5;i++)); do
11571                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
11572                         error "get fid for f$i failed"
11573                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
11574                         error "check path $tdir/striped_dir/f$i failed"
11575
11576                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
11577                         error "get fid for d$i failed"
11578                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
11579                         error "check path $tdir/striped_dir/d$i failed"
11580         done
11581
11582         return 0
11583 }
11584 run_test 162b "striped directory path lookup sanity"
11585
11586 # LU-4239: Verify fid2path works with paths 100 or more directories deep
11587 test_162c() {
11588         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
11589                 skip "Need MDS version at least 2.7.51" && return
11590         test_mkdir $DIR/$tdir.local
11591         test_mkdir $DIR/$tdir.remote
11592         local lpath=$tdir.local
11593         local rpath=$tdir.remote
11594
11595         for ((i = 0; i <= 101; i++)); do
11596                 lpath="$lpath/$i"
11597                 mkdir $DIR/$lpath
11598                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
11599                         error "get fid for local directory $DIR/$lpath failed"
11600                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
11601                         error "check path for local directory $DIR/$lpath failed"
11602
11603                 rpath="$rpath/$i"
11604                 test_mkdir $DIR/$rpath
11605                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
11606                         error "get fid for remote directory $DIR/$rpath failed"
11607                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
11608                         error "check path for remote directory $DIR/$rpath failed"
11609         done
11610
11611         return 0
11612 }
11613 run_test 162c "fid2path works with paths 100 or more directories deep"
11614
11615 test_169() {
11616         # do directio so as not to populate the page cache
11617         log "creating a 10 Mb file"
11618         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11619         log "starting reads"
11620         dd if=$DIR/$tfile of=/dev/null bs=4096 &
11621         log "truncating the file"
11622         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11623         log "killing dd"
11624         kill %+ || true # reads might have finished
11625         echo "wait until dd is finished"
11626         wait
11627         log "removing the temporary file"
11628         rm -rf $DIR/$tfile || error "tmp file removal failed"
11629 }
11630 run_test 169 "parallel read and truncate should not deadlock"
11631
11632 test_170() {
11633         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11634         $LCTL clear     # bug 18514
11635         $LCTL debug_daemon start $TMP/${tfile}_log_good
11636         touch $DIR/$tfile
11637         $LCTL debug_daemon stop
11638         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
11639                error "sed failed to read log_good"
11640
11641         $LCTL debug_daemon start $TMP/${tfile}_log_good
11642         rm -rf $DIR/$tfile
11643         $LCTL debug_daemon stop
11644
11645         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
11646                error "lctl df log_bad failed"
11647
11648         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11649         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11650
11651         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
11652         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
11653
11654         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
11655                 error "bad_line good_line1 good_line2 are empty"
11656
11657         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11658         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
11659         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11660
11661         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
11662         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11663         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11664
11665         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
11666                 error "bad_line_new good_line_new are empty"
11667
11668         local expected_good=$((good_line1 + good_line2*2))
11669
11670         rm -f $TMP/${tfile}*
11671         # LU-231, short malformed line may not be counted into bad lines
11672         if [ $bad_line -ne $bad_line_new ] &&
11673                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
11674                 error "expected $bad_line bad lines, but got $bad_line_new"
11675                 return 1
11676         fi
11677
11678         if [ $expected_good -ne $good_line_new ]; then
11679                 error "expected $expected_good good lines, but got $good_line_new"
11680                 return 2
11681         fi
11682         true
11683 }
11684 run_test 170 "test lctl df to handle corrupted log ====================="
11685
11686 test_171() { # bug20592
11687         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11688 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
11689         $LCTL set_param fail_loc=0x50e
11690         $LCTL set_param fail_val=3000
11691         multiop_bg_pause $DIR/$tfile O_s || true
11692         local MULTIPID=$!
11693         kill -USR1 $MULTIPID
11694         # cause log dump
11695         sleep 3
11696         wait $MULTIPID
11697         if dmesg | grep "recursive fault"; then
11698                 error "caught a recursive fault"
11699         fi
11700         $LCTL set_param fail_loc=0
11701         true
11702 }
11703 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
11704
11705 # it would be good to share it with obdfilter-survey/iokit-libecho code
11706 setup_obdecho_osc () {
11707         local rc=0
11708         local ost_nid=$1
11709         local obdfilter_name=$2
11710         echo "Creating new osc for $obdfilter_name on $ost_nid"
11711         # make sure we can find loopback nid
11712         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
11713
11714         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
11715                            ${obdfilter_name}_osc_UUID || rc=2; }
11716         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
11717                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
11718         return $rc
11719 }
11720
11721 cleanup_obdecho_osc () {
11722         local obdfilter_name=$1
11723         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
11724         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
11725         return 0
11726 }
11727
11728 obdecho_test() {
11729         local OBD=$1
11730         local node=$2
11731         local pages=${3:-64}
11732         local rc=0
11733         local id
11734
11735         local count=10
11736         local obd_size=$(get_obd_size $node $OBD)
11737         local page_size=$(get_page_size $node)
11738         if [[ -n "$obd_size" ]]; then
11739                 local new_count=$((obd_size / (pages * page_size / 1024)))
11740                 [[ $new_count -ge $count ]] || count=$new_count
11741         fi
11742
11743         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
11744         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
11745                            rc=2; }
11746         if [ $rc -eq 0 ]; then
11747             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
11748             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
11749         fi
11750         echo "New object id is $id"
11751         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
11752                            rc=4; }
11753         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
11754                            "test_brw $count w v $pages $id" || rc=4; }
11755         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
11756                            rc=4; }
11757         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
11758                                         "cleanup" || rc=5; }
11759         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
11760                                         "detach" || rc=6; }
11761         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
11762         return $rc
11763 }
11764
11765 test_180a() {
11766         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11767         remote_ost_nodsh && skip "remote OST with nodsh" && return
11768         local rc=0
11769         local rmmod_local=0
11770
11771         if ! module_loaded obdecho; then
11772             load_module obdecho/obdecho
11773             rmmod_local=1
11774         fi
11775
11776         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
11777         local host=$(lctl get_param -n osc.$osc.import |
11778                              awk '/current_connection:/ {print $2}' )
11779         local target=$(lctl get_param -n osc.$osc.import |
11780                              awk '/target:/ {print $2}' )
11781         target=${target%_UUID}
11782
11783         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
11784         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
11785         [[ -n $target ]] && cleanup_obdecho_osc $target
11786         [ $rmmod_local -eq 1 ] && rmmod obdecho
11787         return $rc
11788 }
11789 run_test 180a "test obdecho on osc"
11790
11791 test_180b() {
11792         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11793         remote_ost_nodsh && skip "remote OST with nodsh" && return
11794         local rc=0
11795         local rmmod_remote=0
11796
11797         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11798                 rmmod_remote=true || error "failed to load module obdecho"
11799         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
11800         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
11801         $rmmod_remote && do_facet ost1 "rmmod obdecho"
11802         return $rc
11803 }
11804 run_test 180b "test obdecho directly on obdfilter"
11805
11806 test_180c() { # LU-2598
11807         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11808         remote_ost_nodsh && skip "remote OST with nodsh" && return
11809         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
11810                 skip "Need MDS version at least 2.4.0" && return
11811
11812         local rc=0
11813         local rmmod_remote=false
11814         local pages=16384 # 64MB bulk I/O RPC size
11815         local target
11816
11817         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11818                 rmmod_remote=true || error "failed to load module obdecho"
11819
11820         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
11821                 head -n1)
11822         if [ -n "$target" ]; then
11823                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
11824         else
11825                 echo "there is no obdfilter target on ost1"
11826                 rc=2
11827         fi
11828         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
11829         return $rc
11830 }
11831 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
11832
11833 test_181() { # bug 22177
11834         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11835         # create enough files to index the directory
11836         createmany -o $DIR/$tdir/foobar 4000
11837         # print attributes for debug purpose
11838         lsattr -d .
11839         # open dir
11840         multiop_bg_pause $DIR/$tdir D_Sc || return 1
11841         MULTIPID=$!
11842         # remove the files & current working dir
11843         unlinkmany $DIR/$tdir/foobar 4000
11844         rmdir $DIR/$tdir
11845         kill -USR1 $MULTIPID
11846         wait $MULTIPID
11847         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
11848         return 0
11849 }
11850 run_test 181 "Test open-unlinked dir ========================"
11851
11852 test_182() {
11853         local fcount=1000
11854         local tcount=10
11855
11856         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11857
11858         $LCTL set_param mdc.*.rpc_stats=clear
11859
11860         for (( i = 0; i < $tcount; i++ )) ; do
11861                 mkdir $DIR/$tdir/$i
11862         done
11863
11864         for (( i = 0; i < $tcount; i++ )) ; do
11865                 createmany -o $DIR/$tdir/$i/f- $fcount &
11866         done
11867         wait
11868
11869         for (( i = 0; i < $tcount; i++ )) ; do
11870                 unlinkmany $DIR/$tdir/$i/f- $fcount &
11871         done
11872         wait
11873
11874         $LCTL get_param mdc.*.rpc_stats
11875
11876         rm -rf $DIR/$tdir
11877 }
11878 run_test 182 "Test parallel modify metadata operations ================"
11879
11880 test_183() { # LU-2275
11881         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11882         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
11883                 skip "Need MDS version at least 2.3.56" && return
11884
11885         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11886         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11887         echo aaa > $DIR/$tdir/$tfile
11888
11889 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
11890         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
11891
11892         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
11893         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11894
11895         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11896
11897         # Flush negative dentry cache
11898         touch $DIR/$tdir/$tfile
11899
11900         # We are not checking for any leaked references here, they'll
11901         # become evident next time we do cleanup with module unload.
11902         rm -rf $DIR/$tdir
11903 }
11904 run_test 183 "No crash or request leak in case of strange dispositions ========"
11905
11906 # test suite 184 is for LU-2016, LU-2017
11907 test_184a() {
11908         check_swap_layouts_support && return 0
11909
11910         dir0=$DIR/$tdir/$testnum
11911         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
11912         ref1=/etc/passwd
11913         ref2=/etc/group
11914         file1=$dir0/f1
11915         file2=$dir0/f2
11916         $SETSTRIPE -c1 $file1
11917         cp $ref1 $file1
11918         $SETSTRIPE -c2 $file2
11919         cp $ref2 $file2
11920         gen1=$($GETSTRIPE -g $file1)
11921         gen2=$($GETSTRIPE -g $file2)
11922
11923         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11924         gen=$($GETSTRIPE -g $file1)
11925         [[ $gen1 != $gen ]] ||
11926                 "Layout generation on $file1 does not change"
11927         gen=$($GETSTRIPE -g $file2)
11928         [[ $gen2 != $gen ]] ||
11929                 "Layout generation on $file2 does not change"
11930
11931         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11932         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11933 }
11934 run_test 184a "Basic layout swap"
11935
11936 test_184b() {
11937         check_swap_layouts_support && return 0
11938
11939         dir0=$DIR/$tdir/$testnum
11940         mkdir -p $dir0 || error "creating dir $dir0"
11941         file1=$dir0/f1
11942         file2=$dir0/f2
11943         file3=$dir0/f3
11944         dir1=$dir0/d1
11945         dir2=$dir0/d2
11946         mkdir $dir1 $dir2
11947         $SETSTRIPE -c1 $file1
11948         $SETSTRIPE -c2 $file2
11949         $SETSTRIPE -c1 $file3
11950         chown $RUNAS_ID $file3
11951         gen1=$($GETSTRIPE -g $file1)
11952         gen2=$($GETSTRIPE -g $file2)
11953
11954         $LFS swap_layouts $dir1 $dir2 &&
11955                 error "swap of directories layouts should fail"
11956         $LFS swap_layouts $dir1 $file1 &&
11957                 error "swap of directory and file layouts should fail"
11958         $RUNAS $LFS swap_layouts $file1 $file2 &&
11959                 error "swap of file we cannot write should fail"
11960         $LFS swap_layouts $file1 $file3 &&
11961                 error "swap of file with different owner should fail"
11962         /bin/true # to clear error code
11963 }
11964 run_test 184b "Forbidden layout swap (will generate errors)"
11965
11966 test_184c() {
11967         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
11968         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n" && return
11969         check_swap_layouts_support && return 0
11970
11971         local dir0=$DIR/$tdir/$testnum
11972         mkdir -p $dir0 || error "creating dir $dir0"
11973
11974         local ref1=$dir0/ref1
11975         local ref2=$dir0/ref2
11976         local file1=$dir0/file1
11977         local file2=$dir0/file2
11978         # create a file large enough for the concurrent test
11979         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
11980         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
11981         echo "ref file size: ref1($(stat -c %s $ref1))," \
11982              "ref2($(stat -c %s $ref2))"
11983
11984         cp $ref2 $file2
11985         dd if=$ref1 of=$file1 bs=16k &
11986         local DD_PID=$!
11987
11988         # Make sure dd starts to copy file
11989         while [ ! -f $file1 ]; do sleep 0.1; done
11990
11991         $LFS swap_layouts $file1 $file2
11992         local rc=$?
11993         wait $DD_PID
11994         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
11995         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
11996
11997         # how many bytes copied before swapping layout
11998         local copied=$(stat -c %s $file2)
11999         local remaining=$(stat -c %s $ref1)
12000         remaining=$((remaining - copied))
12001         echo "Copied $copied bytes before swapping layout..."
12002
12003         cmp -n $copied $file1 $ref2 | grep differ &&
12004                 error "Content mismatch [0, $copied) of ref2 and file1"
12005         cmp -n $copied $file2 $ref1 ||
12006                 error "Content mismatch [0, $copied) of ref1 and file2"
12007         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
12008                 error "Content mismatch [$copied, EOF) of ref1 and file1"
12009
12010         # clean up
12011         rm -f $ref1 $ref2 $file1 $file2
12012 }
12013 run_test 184c "Concurrent write and layout swap"
12014
12015 test_184d() {
12016         check_swap_layouts_support && return 0
12017         [ -z "$(which getfattr 2>/dev/null)" ] &&
12018                 skip "no getfattr command" && return 0
12019
12020         local file1=$DIR/$tdir/$tfile-1
12021         local file2=$DIR/$tdir/$tfile-2
12022         local file3=$DIR/$tdir/$tfile-3
12023         local lovea1
12024         local lovea2
12025
12026         mkdir -p $DIR/$tdir
12027         touch $file1 || error "create $file1 failed"
12028         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12029                 error "create $file2 failed"
12030         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12031                 error "create $file3 failed"
12032         lovea1=$(get_layout_param $file1)
12033
12034         $LFS swap_layouts $file2 $file3 ||
12035                 error "swap $file2 $file3 layouts failed"
12036         $LFS swap_layouts $file1 $file2 ||
12037                 error "swap $file1 $file2 layouts failed"
12038
12039         lovea2=$(get_layout_param $file2)
12040         echo "$lovea1"
12041         echo "$lovea2"
12042         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
12043
12044         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12045         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
12046 }
12047 run_test 184d "allow stripeless layouts swap"
12048
12049 test_184e() {
12050         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
12051                 { skip "Need MDS version at least 2.6.94"; return 0; }
12052         check_swap_layouts_support && return 0
12053         [ -z "$(which getfattr 2>/dev/null)" ] &&
12054                 skip "no getfattr command" && return 0
12055
12056         local file1=$DIR/$tdir/$tfile-1
12057         local file2=$DIR/$tdir/$tfile-2
12058         local file3=$DIR/$tdir/$tfile-3
12059         local lovea
12060
12061         mkdir -p $DIR/$tdir
12062         touch $file1 || error "create $file1 failed"
12063         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12064                 error "create $file2 failed"
12065         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12066                 error "create $file3 failed"
12067
12068         $LFS swap_layouts $file1 $file2 ||
12069                 error "swap $file1 $file2 layouts failed"
12070
12071         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12072         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
12073
12074         echo 123 > $file1 || error "Should be able to write into $file1"
12075
12076         $LFS swap_layouts $file1 $file3 ||
12077                 error "swap $file1 $file3 layouts failed"
12078
12079         echo 123 > $file1 || error "Should be able to write into $file1"
12080
12081         rm -rf $file1 $file2 $file3
12082 }
12083 run_test 184e "Recreate layout after stripeless layout swaps"
12084
12085 test_185() { # LU-2441
12086         # LU-3553 - no volatile file support in old servers
12087         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
12088                 { skip "Need MDS version at least 2.3.60"; return 0; }
12089
12090         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12091         touch $DIR/$tdir/spoo
12092         local mtime1=$(stat -c "%Y" $DIR/$tdir)
12093         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
12094                 error "cannot create/write a volatile file"
12095         [ "$FILESET" == "" ] &&
12096         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
12097                 error "FID is still valid after close"
12098
12099         multiop_bg_pause $DIR/$tdir vVw4096_c
12100         local multi_pid=$!
12101
12102         local OLD_IFS=$IFS
12103         IFS=":"
12104         local fidv=($fid)
12105         IFS=$OLD_IFS
12106         # assume that the next FID for this client is sequential, since stdout
12107         # is unfortunately eaten by multiop_bg_pause
12108         local n=$((${fidv[1]} + 1))
12109         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
12110         if [ "$FILESET" == "" ]; then
12111                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
12112                         error "FID is missing before close"
12113         fi
12114         kill -USR1 $multi_pid
12115         # 1 second delay, so if mtime change we will see it
12116         sleep 1
12117         local mtime2=$(stat -c "%Y" $DIR/$tdir)
12118         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
12119 }
12120 run_test 185 "Volatile file support"
12121
12122 test_187a() {
12123         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12124         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12125                 skip "Need MDS version at least 2.3.0" && return
12126
12127         local dir0=$DIR/$tdir/$testnum
12128         mkdir -p $dir0 || error "creating dir $dir0"
12129
12130         local file=$dir0/file1
12131         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
12132         local dv1=$($LFS data_version $file)
12133         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
12134         local dv2=$($LFS data_version $file)
12135         [[ $dv1 != $dv2 ]] ||
12136                 error "data version did not change on write $dv1 == $dv2"
12137
12138         # clean up
12139         rm -f $file1
12140 }
12141 run_test 187a "Test data version change"
12142
12143 test_187b() {
12144         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12145         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12146                 skip "Need MDS version at least 2.3.0" && return
12147
12148         local dir0=$DIR/$tdir/$testnum
12149         mkdir -p $dir0 || error "creating dir $dir0"
12150
12151         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
12152         [[ ${DV[0]} != ${DV[1]} ]] ||
12153                 error "data version did not change on write"\
12154                       " ${DV[0]} == ${DV[1]}"
12155
12156         # clean up
12157         rm -f $file1
12158 }
12159 run_test 187b "Test data version change on volatile file"
12160
12161 test_200() {
12162         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12163         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12164         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
12165
12166         local POOL=${POOL:-cea1}
12167         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
12168         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
12169         # Pool OST targets
12170         local first_ost=0
12171         local last_ost=$(($OSTCOUNT - 1))
12172         local ost_step=2
12173         local ost_list=$(seq $first_ost $ost_step $last_ost)
12174         local ost_range="$first_ost $last_ost $ost_step"
12175         local test_path=$POOL_ROOT/$POOL_DIR_NAME
12176         local file_dir=$POOL_ROOT/file_tst
12177         local subdir=$test_path/subdir
12178
12179         local rc=0
12180         while : ; do
12181                 # former test_200a test_200b
12182                 pool_add $POOL                          || { rc=$? ; break; }
12183                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
12184                 # former test_200c test_200d
12185                 mkdir -p $test_path
12186                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
12187                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
12188                 mkdir -p $subdir
12189                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
12190                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
12191                                                         || { rc=$? ; break; }
12192                 # former test_200e test_200f
12193                 local files=$((OSTCOUNT*3))
12194                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
12195                                                         || { rc=$? ; break; }
12196                 pool_create_files $POOL $file_dir $files "$ost_list" \
12197                                                         || { rc=$? ; break; }
12198                 # former test_200g test_200h
12199                 pool_lfs_df $POOL                       || { rc=$? ; break; }
12200                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
12201
12202                 # former test_201a test_201b test_201c
12203                 pool_remove_first_target $POOL          || { rc=$? ; break; }
12204
12205                 local f=$test_path/$tfile
12206                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
12207                 pool_remove $POOL $f                    || { rc=$? ; break; }
12208                 break
12209         done
12210
12211         destroy_test_pools
12212         return $rc
12213 }
12214 run_test 200 "OST pools"
12215
12216 # usage: default_attr <count | size | offset>
12217 default_attr() {
12218         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
12219 }
12220
12221 # usage: check_default_stripe_attr
12222 check_default_stripe_attr() {
12223         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
12224         case $1 in
12225         --stripe-count|-c)
12226                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
12227         --stripe-size|-S)
12228                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
12229         --stripe-index|-i)
12230                 EXPECTED=-1;;
12231         *)
12232                 error "unknown getstripe attr '$1'"
12233         esac
12234
12235         [ $ACTUAL != $EXPECTED ] &&
12236                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
12237 }
12238
12239 test_204a() {
12240         test_mkdir -p $DIR/$tdir
12241         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
12242
12243         check_default_stripe_attr --stripe-count
12244         check_default_stripe_attr --stripe-size
12245         check_default_stripe_attr --stripe-index
12246
12247         return 0
12248 }
12249 run_test 204a "Print default stripe attributes ================="
12250
12251 test_204b() {
12252         test_mkdir -p $DIR/$tdir
12253         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12254
12255         check_default_stripe_attr --stripe-size
12256         check_default_stripe_attr --stripe-index
12257
12258         return 0
12259 }
12260 run_test 204b "Print default stripe size and offset  ==========="
12261
12262 test_204c() {
12263         test_mkdir -p $DIR/$tdir
12264         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12265
12266         check_default_stripe_attr --stripe-count
12267         check_default_stripe_attr --stripe-index
12268
12269         return 0
12270 }
12271 run_test 204c "Print default stripe count and offset ==========="
12272
12273 test_204d() {
12274         test_mkdir -p $DIR/$tdir
12275         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12276
12277         check_default_stripe_attr --stripe-count
12278         check_default_stripe_attr --stripe-size
12279
12280         return 0
12281 }
12282 run_test 204d "Print default stripe count and size ============="
12283
12284 test_204e() {
12285         test_mkdir -p $DIR/$tdir
12286         $SETSTRIPE -d $DIR/$tdir
12287
12288         check_default_stripe_attr --stripe-count --raw
12289         check_default_stripe_attr --stripe-size --raw
12290         check_default_stripe_attr --stripe-index --raw
12291
12292         return 0
12293 }
12294 run_test 204e "Print raw stripe attributes ================="
12295
12296 test_204f() {
12297         test_mkdir -p $DIR/$tdir
12298         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12299
12300         check_default_stripe_attr --stripe-size --raw
12301         check_default_stripe_attr --stripe-index --raw
12302
12303         return 0
12304 }
12305 run_test 204f "Print raw stripe size and offset  ==========="
12306
12307 test_204g() {
12308         test_mkdir -p $DIR/$tdir
12309         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12310
12311         check_default_stripe_attr --stripe-count --raw
12312         check_default_stripe_attr --stripe-index --raw
12313
12314         return 0
12315 }
12316 run_test 204g "Print raw stripe count and offset ==========="
12317
12318 test_204h() {
12319         test_mkdir -p $DIR/$tdir
12320         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12321
12322         check_default_stripe_attr --stripe-count --raw
12323         check_default_stripe_attr --stripe-size --raw
12324
12325         return 0
12326 }
12327 run_test 204h "Print raw stripe count and size ============="
12328
12329 # Figure out which job scheduler is being used, if any,
12330 # or use a fake one
12331 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
12332         JOBENV=SLURM_JOB_ID
12333 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
12334         JOBENV=LSB_JOBID
12335 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
12336         JOBENV=PBS_JOBID
12337 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
12338         JOBENV=LOADL_STEP_ID
12339 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
12340         JOBENV=JOB_ID
12341 else
12342         $LCTL list_param jobid_name > /dev/null 2>&1
12343         if [ $? -eq 0 ]; then
12344                 JOBENV=nodelocal
12345         else
12346                 JOBENV=FAKE_JOBID
12347         fi
12348 fi
12349
12350 verify_jobstats() {
12351         local cmd=($1)
12352         shift
12353         local facets="$@"
12354
12355 # we don't really need to clear the stats for this test to work, since each
12356 # command has a unique jobid, but it makes debugging easier if needed.
12357 #       for facet in $facets; do
12358 #               local dev=$(convert_facet2label $facet)
12359 #               # clear old jobstats
12360 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
12361 #       done
12362
12363         # use a new JobID for each test, or we might see an old one
12364         [ "$JOBENV" = "FAKE_JOBID" ] &&
12365                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12366
12367         JOBVAL=${!JOBENV}
12368
12369         [ "$JOBENV" = "nodelocal" ] && {
12370                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12371                 $LCTL set_param jobid_name=$FAKE_JOBID
12372                 JOBVAL=$FAKE_JOBID
12373         }
12374
12375         log "Test: ${cmd[*]}"
12376         log "Using JobID environment variable $JOBENV=$JOBVAL"
12377
12378         if [ $JOBENV = "FAKE_JOBID" ]; then
12379                 FAKE_JOBID=$JOBVAL ${cmd[*]}
12380         else
12381                 ${cmd[*]}
12382         fi
12383
12384         # all files are created on OST0000
12385         for facet in $facets; do
12386                 local stats="*.$(convert_facet2label $facet).job_stats"
12387                 if [ $(do_facet $facet lctl get_param $stats |
12388                        grep -c $JOBVAL) -ne 1 ]; then
12389                         do_facet $facet lctl get_param $stats
12390                         error "No jobstats for $JOBVAL found on $facet::$stats"
12391                 fi
12392         done
12393 }
12394
12395 jobstats_set() {
12396         trap 0
12397         NEW_JOBENV=${1:-$OLD_JOBENV}
12398         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
12399         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
12400 }
12401
12402 cleanup_205() {
12403         trap 0
12404         do_facet $SINGLEMDS \
12405                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
12406         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
12407         cleanup_changelog
12408 }
12409
12410 test_205() { # Job stats
12411         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.1) ]] ||
12412                 { skip "Need MDS version with at least 2.7.1"; return 0; }
12413
12414         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12415         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12416         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12417         remote_ost_nodsh && skip "remote OST with nodsh" && return
12418
12419         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
12420                 skip "Server doesn't support jobstats" && return 0
12421         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
12422
12423         OLD_JOBENV=$($LCTL get_param -n jobid_var)
12424         if [ $OLD_JOBENV != $JOBENV ]; then
12425                 jobstats_set $JOBENV
12426                 trap cleanup_205 EXIT
12427         fi
12428
12429         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
12430         echo "Registered as changelog user $CL_USER"
12431
12432         OLD_INTERVAL=$(do_facet $SINGLEMDS \
12433                        lctl get_param -n mdt.*.job_cleanup_interval)
12434         local interval_new=5
12435         do_facet $SINGLEMDS \
12436                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
12437         local start=$SECONDS
12438
12439         local cmd
12440         # mkdir
12441         cmd="mkdir $DIR/$tdir"
12442         verify_jobstats "$cmd" "$SINGLEMDS"
12443         # rmdir
12444         cmd="rmdir $DIR/$tdir"
12445         verify_jobstats "$cmd" "$SINGLEMDS"
12446         # mkdir on secondary MDT
12447         if [ $MDSCOUNT -gt 1 ]; then
12448                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
12449                 verify_jobstats "$cmd" "mds2"
12450         fi
12451         # mknod
12452         cmd="mknod $DIR/$tfile c 1 3"
12453         verify_jobstats "$cmd" "$SINGLEMDS"
12454         # unlink
12455         cmd="rm -f $DIR/$tfile"
12456         verify_jobstats "$cmd" "$SINGLEMDS"
12457         # create all files on OST0000 so verify_jobstats can find OST stats
12458         # open & close
12459         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
12460         verify_jobstats "$cmd" "$SINGLEMDS"
12461         # setattr
12462         cmd="touch $DIR/$tfile"
12463         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12464         # write
12465         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
12466         verify_jobstats "$cmd" "ost1"
12467         # read
12468         cancel_lru_locks osc
12469         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
12470         verify_jobstats "$cmd" "ost1"
12471         # truncate
12472         cmd="$TRUNCATE $DIR/$tfile 0"
12473         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12474         # rename
12475         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
12476         verify_jobstats "$cmd" "$SINGLEMDS"
12477         # jobstats expiry - sleep until old stats should be expired
12478         local left=$((interval_new + 5 - (SECONDS - start)))
12479         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
12480                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
12481                         "0" $left
12482         cmd="mkdir $DIR/$tdir.expire"
12483         verify_jobstats "$cmd" "$SINGLEMDS"
12484         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
12485             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
12486
12487         # Ensure that jobid are present in changelog (if supported by MDS)
12488         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
12489         then
12490                 $LFS changelog $MDT0 | tail -9
12491                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
12492                 [ $jobids -eq 9 ] ||
12493                         error "Wrong changelog jobid count $jobids != 9"
12494
12495                 # LU-5862
12496                 JOBENV="disable"
12497                 jobstats_set $JOBENV
12498                 touch $DIR/$tfile
12499                 $LFS changelog $MDT0 | tail -1
12500                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
12501                 [ $jobids -eq 0 ] ||
12502                         error "Unexpected jobids when jobid_var=$JOBENV"
12503         fi
12504
12505         cleanup_205
12506 }
12507 run_test 205 "Verify job stats"
12508
12509 # LU-1480, LU-1773 and LU-1657
12510 test_206() {
12511         mkdir -p $DIR/$tdir
12512         $SETSTRIPE -c -1 $DIR/$tdir
12513 #define OBD_FAIL_LOV_INIT 0x1403
12514         $LCTL set_param fail_loc=0xa0001403
12515         $LCTL set_param fail_val=1
12516         touch $DIR/$tdir/$tfile || true
12517 }
12518 run_test 206 "fail lov_init_raid0() doesn't lbug"
12519
12520 test_207a() {
12521         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12522         local fsz=`stat -c %s $DIR/$tfile`
12523         cancel_lru_locks mdc
12524
12525         # do not return layout in getattr intent
12526 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
12527         $LCTL set_param fail_loc=0x170
12528         local sz=`stat -c %s $DIR/$tfile`
12529
12530         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
12531
12532         rm -rf $DIR/$tfile
12533 }
12534 run_test 207a "can refresh layout at glimpse"
12535
12536 test_207b() {
12537         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12538         local cksum=`md5sum $DIR/$tfile`
12539         local fsz=`stat -c %s $DIR/$tfile`
12540         cancel_lru_locks mdc
12541         cancel_lru_locks osc
12542
12543         # do not return layout in getattr intent
12544 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
12545         $LCTL set_param fail_loc=0x171
12546
12547         # it will refresh layout after the file is opened but before read issues
12548         echo checksum is "$cksum"
12549         echo "$cksum" |md5sum -c --quiet || error "file differs"
12550
12551         rm -rf $DIR/$tfile
12552 }
12553 run_test 207b "can refresh layout at open"
12554
12555 test_208() {
12556         # FIXME: in this test suite, only RD lease is used. This is okay
12557         # for now as only exclusive open is supported. After generic lease
12558         # is done, this test suite should be revised. - Jinshan
12559
12560         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12561         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
12562                 { skip "Need MDS version at least 2.4.52"; return 0; }
12563
12564         echo "==== test 1: verify get lease work"
12565         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
12566
12567         echo "==== test 2: verify lease can be broken by upcoming open"
12568         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12569         local PID=$!
12570         sleep 1
12571
12572         $MULTIOP $DIR/$tfile oO_RDONLY:c
12573         kill -USR1 $PID && wait $PID || error "break lease error"
12574
12575         echo "==== test 3: verify lease can't be granted if an open already exists"
12576         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
12577         local PID=$!
12578         sleep 1
12579
12580         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
12581         kill -USR1 $PID && wait $PID || error "open file error"
12582
12583         echo "==== test 4: lease can sustain over recovery"
12584         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
12585         PID=$!
12586         sleep 1
12587
12588         fail mds1
12589
12590         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
12591
12592         echo "==== test 5: lease broken can't be regained by replay"
12593         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12594         PID=$!
12595         sleep 1
12596
12597         # open file to break lease and then recovery
12598         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
12599         fail mds1
12600
12601         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
12602
12603         rm -f $DIR/$tfile
12604 }
12605 run_test 208 "Exclusive open"
12606
12607 test_209() {
12608         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
12609                 skip_env "must have disp_stripe" && return
12610
12611         touch $DIR/$tfile
12612         sync; sleep 5; sync;
12613
12614         echo 3 > /proc/sys/vm/drop_caches
12615         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12616
12617         # open/close 500 times
12618         for i in $(seq 500); do
12619                 cat $DIR/$tfile
12620         done
12621
12622         echo 3 > /proc/sys/vm/drop_caches
12623         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12624
12625         echo "before: $req_before, after: $req_after"
12626         [ $((req_after - req_before)) -ge 300 ] &&
12627                 error "open/close requests are not freed"
12628         return 0
12629 }
12630 run_test 209 "read-only open/close requests should be freed promptly"
12631
12632 test_212() {
12633         size=`date +%s`
12634         size=$((size % 8192 + 1))
12635         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
12636         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
12637         rm -f $DIR/f212 $DIR/f212.xyz
12638 }
12639 run_test 212 "Sendfile test ============================================"
12640
12641 test_213() {
12642         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
12643         cancel_lru_locks osc
12644         lctl set_param fail_loc=0x8000040f
12645         # generate a read lock
12646         cat $DIR/$tfile > /dev/null
12647         # write to the file, it will try to cancel the above read lock.
12648         cat /etc/hosts >> $DIR/$tfile
12649 }
12650 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
12651
12652 test_214() { # for bug 20133
12653         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
12654         for (( i=0; i < 340; i++ )) ; do
12655                 touch $DIR/$tdir/d214c/a$i
12656         done
12657
12658         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
12659         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
12660         ls $DIR/d214c || error "ls $DIR/d214c failed"
12661         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
12662         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
12663 }
12664 run_test 214 "hash-indexed directory test - bug 20133"
12665
12666 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
12667 create_lnet_proc_files() {
12668         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
12669         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
12670
12671         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
12672         rm -f "$TMP/lnet_$1.sys_tmp"
12673 }
12674
12675 # counterpart of create_lnet_proc_files
12676 remove_lnet_proc_files() {
12677         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
12678 }
12679
12680 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12681 # 3rd arg as regexp for body
12682 check_lnet_proc_stats() {
12683         local l=$(cat "$TMP/lnet_$1" |wc -l)
12684         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
12685
12686         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
12687 }
12688
12689 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12690 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
12691 # optional and can be regexp for 2nd line (lnet.routes case)
12692 check_lnet_proc_entry() {
12693         local blp=2          # blp stands for 'position of 1st line of body'
12694         [ -z "$5" ] || blp=3 # lnet.routes case
12695
12696         local l=$(cat "$TMP/lnet_$1" |wc -l)
12697         # subtracting one from $blp because the body can be empty
12698         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
12699
12700         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
12701                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
12702
12703         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
12704                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
12705
12706         # bail out if any unexpected line happened
12707         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
12708         [ "$?" != 0 ] || error "$2 misformatted"
12709 }
12710
12711 test_215() { # for bugs 18102, 21079, 21517
12712         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12713         local N='(0|[1-9][0-9]*)'       # non-negative numeric
12714         local P='[1-9][0-9]*'           # positive numeric
12715         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
12716         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
12717         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
12718         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
12719
12720         local L1 # regexp for 1st line
12721         local L2 # regexp for 2nd line (optional)
12722         local BR # regexp for the rest (body)
12723
12724         # lnet.stats should look as 11 space-separated non-negative numerics
12725         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
12726         create_lnet_proc_files "stats"
12727         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
12728         remove_lnet_proc_files "stats"
12729
12730         # lnet.routes should look like this:
12731         # Routing disabled/enabled
12732         # net hops priority state router
12733         # where net is a string like tcp0, hops > 0, priority >= 0,
12734         # state is up/down,
12735         # router is a string like 192.168.1.1@tcp2
12736         L1="^Routing (disabled|enabled)$"
12737         L2="^net +hops +priority +state +router$"
12738         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
12739         create_lnet_proc_files "routes"
12740         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
12741         remove_lnet_proc_files "routes"
12742
12743         # lnet.routers should look like this:
12744         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
12745         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
12746         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
12747         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
12748         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
12749         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
12750         create_lnet_proc_files "routers"
12751         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
12752         remove_lnet_proc_files "routers"
12753
12754         # lnet.peers should look like this:
12755         # nid refs state last max rtr min tx min queue
12756         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
12757         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
12758         # numeric (0 or >0 or <0), queue >= 0.
12759         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
12760         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
12761         create_lnet_proc_files "peers"
12762         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
12763         remove_lnet_proc_files "peers"
12764
12765         # lnet.buffers  should look like this:
12766         # pages count credits min
12767         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
12768         L1="^pages +count +credits +min$"
12769         BR="^ +$N +$N +$I +$I$"
12770         create_lnet_proc_files "buffers"
12771         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
12772         remove_lnet_proc_files "buffers"
12773
12774         # lnet.nis should look like this:
12775         # nid status alive refs peer rtr max tx min
12776         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
12777         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
12778         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
12779         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
12780         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
12781         create_lnet_proc_files "nis"
12782         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
12783         remove_lnet_proc_files "nis"
12784
12785         # can we successfully write to lnet.stats?
12786         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
12787         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
12788 }
12789 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
12790
12791 test_216() { # bug 20317
12792         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12793         remote_ost_nodsh && skip "remote OST with nodsh" && return
12794
12795         local node
12796         local facets=$(get_facets OST)
12797         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
12798
12799         save_lustre_params client "osc.*.contention_seconds" > $p
12800         save_lustre_params $facets \
12801                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
12802         save_lustre_params $facets \
12803                 "ldlm.namespaces.filter-*.contended_locks" >> $p
12804         save_lustre_params $facets \
12805                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
12806         clear_stats osc.*.osc_stats
12807
12808         # agressive lockless i/o settings
12809         do_nodes $(comma_list $(osts_nodes)) \
12810                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
12811                         ldlm.namespaces.filter-*.contended_locks=0 \
12812                         ldlm.namespaces.filter-*.contention_seconds=60"
12813         lctl set_param -n osc.*.contention_seconds=60
12814
12815         $DIRECTIO write $DIR/$tfile 0 10 4096
12816         $CHECKSTAT -s 40960 $DIR/$tfile
12817
12818         # disable lockless i/o
12819         do_nodes $(comma_list $(osts_nodes)) \
12820                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
12821                         ldlm.namespaces.filter-*.contended_locks=32 \
12822                         ldlm.namespaces.filter-*.contention_seconds=0"
12823         lctl set_param -n osc.*.contention_seconds=0
12824         clear_stats osc.*.osc_stats
12825
12826         dd if=/dev/zero of=$DIR/$tfile count=0
12827         $CHECKSTAT -s 0 $DIR/$tfile
12828
12829         restore_lustre_params <$p
12830         rm -f $p
12831         rm $DIR/$tfile
12832 }
12833 run_test 216 "check lockless direct write updates file size and kms correctly"
12834
12835 test_217() { # bug 22430
12836         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12837         local node
12838         local nid
12839
12840         for node in $(nodes_list); do
12841                 nid=$(host_nids_address $node $NETTYPE)
12842                 if [[ $nid = *-* ]] ; then
12843                         echo "lctl ping $(h2nettype $nid)"
12844                         lctl ping $(h2nettype $nid)
12845                 else
12846                         echo "skipping $node (no hyphen detected)"
12847                 fi
12848         done
12849 }
12850 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
12851
12852 test_218() {
12853        # do directio so as not to populate the page cache
12854        log "creating a 10 Mb file"
12855        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12856        log "starting reads"
12857        dd if=$DIR/$tfile of=/dev/null bs=4096 &
12858        log "truncating the file"
12859        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12860        log "killing dd"
12861        kill %+ || true # reads might have finished
12862        echo "wait until dd is finished"
12863        wait
12864        log "removing the temporary file"
12865        rm -rf $DIR/$tfile || error "tmp file removal failed"
12866 }
12867 run_test 218 "parallel read and truncate should not deadlock ======================="
12868
12869 test_219() {
12870         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12871         # write one partial page
12872         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
12873         # set no grant so vvp_io_commit_write will do sync write
12874         $LCTL set_param fail_loc=0x411
12875         # write a full page at the end of file
12876         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
12877
12878         $LCTL set_param fail_loc=0
12879         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
12880         $LCTL set_param fail_loc=0x411
12881         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
12882
12883         # LU-4201
12884         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
12885         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
12886 }
12887 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
12888
12889 test_220() { #LU-325
12890         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12891         remote_ost_nodsh && skip "remote OST with nodsh" && return
12892         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12893         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12894         local OSTIDX=0
12895
12896         # create on MDT0000 so the last_id and next_id are correct
12897         mkdir $DIR/$tdir
12898         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
12899         OST=${OST%_UUID}
12900
12901         # on the mdt's osc
12902         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
12903         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
12904                         osc.$mdtosc_proc1.prealloc_last_id)
12905         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
12906                         osc.$mdtosc_proc1.prealloc_next_id)
12907
12908         $LFS df -i
12909
12910         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
12911         #define OBD_FAIL_OST_ENOINO              0x229
12912         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
12913         create_pool $FSNAME.$TESTNAME || return 1
12914         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
12915
12916         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
12917
12918         MDSOBJS=$((last_id - next_id))
12919         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
12920
12921         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
12922         echo "OST still has $count kbytes free"
12923
12924         echo "create $MDSOBJS files @next_id..."
12925         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
12926
12927         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12928                         osc.$mdtosc_proc1.prealloc_last_id)
12929         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12930                         osc.$mdtosc_proc1.prealloc_next_id)
12931
12932         echo "after creation, last_id=$last_id2, next_id=$next_id2"
12933         $LFS df -i
12934
12935         echo "cleanup..."
12936
12937         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
12938         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
12939
12940         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
12941         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
12942         echo "unlink $MDSOBJS files @$next_id..."
12943         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
12944 }
12945 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
12946
12947 test_221() {
12948         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12949         dd if=`which date` of=$MOUNT/date oflag=sync
12950         chmod +x $MOUNT/date
12951
12952         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
12953         $LCTL set_param fail_loc=0x80001401
12954
12955         $MOUNT/date > /dev/null
12956         rm -f $MOUNT/date
12957 }
12958 run_test 221 "make sure fault and truncate race to not cause OOM"
12959
12960 test_222a () {
12961         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12962        rm -rf $DIR/$tdir
12963        test_mkdir -p $DIR/$tdir
12964        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12965        createmany -o $DIR/$tdir/$tfile 10
12966        cancel_lru_locks mdc
12967        cancel_lru_locks osc
12968        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12969        $LCTL set_param fail_loc=0x31a
12970        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
12971        $LCTL set_param fail_loc=0
12972        rm -r $DIR/$tdir
12973 }
12974 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
12975
12976 test_222b () {
12977         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12978         rm -rf $DIR/$tdir
12979         test_mkdir -p $DIR/$tdir
12980         $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12981         createmany -o $DIR/$tdir/$tfile 10
12982         cancel_lru_locks mdc
12983         cancel_lru_locks osc
12984         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12985         $LCTL set_param fail_loc=0x31a
12986         rm -r $DIR/$tdir || error "AGL for rmdir failed"
12987         $LCTL set_param fail_loc=0
12988 }
12989 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
12990
12991 test_223 () {
12992         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12993        rm -rf $DIR/$tdir
12994        test_mkdir -p $DIR/$tdir
12995        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12996        createmany -o $DIR/$tdir/$tfile 10
12997        cancel_lru_locks mdc
12998        cancel_lru_locks osc
12999        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
13000        $LCTL set_param fail_loc=0x31b
13001        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
13002        $LCTL set_param fail_loc=0
13003        rm -r $DIR/$tdir
13004 }
13005 run_test 223 "osc reenqueue if without AGL lock granted ======================="
13006
13007 test_224a() { # LU-1039, MRP-303
13008         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13009         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
13010         $LCTL set_param fail_loc=0x508
13011         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
13012         $LCTL set_param fail_loc=0
13013         df $DIR
13014 }
13015 run_test 224a "Don't panic on bulk IO failure"
13016
13017 test_224b() { # LU-1039, MRP-303
13018         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13019         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
13020         cancel_lru_locks osc
13021         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
13022         $LCTL set_param fail_loc=0x515
13023         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
13024         $LCTL set_param fail_loc=0
13025         df $DIR
13026 }
13027 run_test 224b "Don't panic on bulk IO failure"
13028
13029 test_224c() { # LU-6441
13030         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13031         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13032
13033         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13034         save_writethrough $p
13035         set_cache writethrough on
13036
13037         local pages_per_rpc=$($LCTL get_param \
13038                                 osc.*.max_pages_per_rpc)
13039         local at_max=$($LCTL get_param -n at_max)
13040         local timeout=$($LCTL get_param -n timeout)
13041         local test_at="$LCTL get_param -n at_max"
13042         local param_at="$FSNAME.sys.at_max"
13043         local test_timeout="$LCTL get_param -n timeout"
13044         local param_timeout="$FSNAME.sys.timeout"
13045
13046         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
13047
13048         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
13049                 error "conf_param at_max=0 failed"
13050         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
13051                 error "conf_param timeout=5 failed"
13052
13053         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
13054         do_facet ost1 $LCTL set_param fail_loc=0x520
13055         $LFS setstripe -c 1 -i 0 $DIR/$tfile
13056         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
13057         sync
13058         do_facet ost1 $LCTL set_param fail_loc=0
13059
13060         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
13061                 error "conf_param at_max=$at_max failed"
13062         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
13063                 $timeout || error "conf_param timeout=$timeout failed"
13064
13065         $LCTL set_param -n $pages_per_rpc
13066         restore_lustre_params < $p
13067         rm -f $p
13068 }
13069 run_test 224c "Don't hang if one of md lost during large bulk RPC"
13070
13071 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
13072 test_225a () {
13073         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13074         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13075         if [ -z ${MDSSURVEY} ]; then
13076               skip_env "mds-survey not found" && return
13077         fi
13078
13079         [ $MDSCOUNT -ge 2 ] &&
13080                 skip "skipping now for more than one MDT" && return
13081
13082        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13083             { skip "Need MDS version at least 2.2.51"; return; }
13084
13085        local mds=$(facet_host $SINGLEMDS)
13086        local target=$(do_nodes $mds 'lctl dl' | \
13087                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13088
13089        local cmd1="file_count=1000 thrhi=4"
13090        local cmd2="dir_count=2 layer=mdd stripe_count=0"
13091        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13092        local cmd="$cmd1 $cmd2 $cmd3"
13093
13094        rm -f ${TMP}/mds_survey*
13095        echo + $cmd
13096        eval $cmd || error "mds-survey with zero-stripe failed"
13097        cat ${TMP}/mds_survey*
13098        rm -f ${TMP}/mds_survey*
13099 }
13100 run_test 225a "Metadata survey sanity with zero-stripe"
13101
13102 test_225b () {
13103         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13104         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13105         if [ -z ${MDSSURVEY} ]; then
13106               skip_env "mds-survey not found" && return
13107         fi
13108         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13109             { skip "Need MDS version at least 2.2.51"; return; }
13110
13111         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
13112               skip_env "Need to mount OST to test" && return
13113         fi
13114
13115         [ $MDSCOUNT -ge 2 ] &&
13116                 skip "skipping now for more than one MDT" && return
13117        local mds=$(facet_host $SINGLEMDS)
13118        local target=$(do_nodes $mds 'lctl dl' | \
13119                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13120
13121        local cmd1="file_count=1000 thrhi=4"
13122        local cmd2="dir_count=2 layer=mdd stripe_count=1"
13123        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13124        local cmd="$cmd1 $cmd2 $cmd3"
13125
13126        rm -f ${TMP}/mds_survey*
13127        echo + $cmd
13128        eval $cmd || error "mds-survey with stripe_count failed"
13129        cat ${TMP}/mds_survey*
13130        rm -f ${TMP}/mds_survey*
13131 }
13132 run_test 225b "Metadata survey sanity with stripe_count = 1"
13133
13134 mcreate_path2fid () {
13135         local mode=$1
13136         local major=$2
13137         local minor=$3
13138         local name=$4
13139         local desc=$5
13140         local path=$DIR/$tdir/$name
13141         local fid
13142         local rc
13143         local fid_path
13144
13145         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
13146                 error "cannot create $desc"
13147
13148         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
13149         rc=$?
13150         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
13151
13152         fid_path=$($LFS fid2path $MOUNT $fid)
13153         rc=$?
13154         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
13155
13156         [ "$path" == "$fid_path" ] ||
13157                 error "fid2path returned $fid_path, expected $path"
13158
13159         echo "pass with $path and $fid"
13160 }
13161
13162 test_226a () {
13163         rm -rf $DIR/$tdir
13164         mkdir -p $DIR/$tdir
13165
13166         mcreate_path2fid 0010666 0 0 fifo "FIFO"
13167         mcreate_path2fid 0020666 1 3 null "character special file (null)"
13168         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
13169         mcreate_path2fid 0040666 0 0 dir "directory"
13170         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
13171         mcreate_path2fid 0100666 0 0 file "regular file"
13172         mcreate_path2fid 0120666 0 0 link "symbolic link"
13173         mcreate_path2fid 0140666 0 0 sock "socket"
13174 }
13175 run_test 226a "call path2fid and fid2path on files of all type"
13176
13177 test_226b () {
13178         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13179         rm -rf $DIR/$tdir
13180         local MDTIDX=1
13181
13182         mkdir -p $DIR/$tdir
13183         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
13184                 error "create remote directory failed"
13185         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
13186         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
13187                                 "character special file (null)"
13188         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
13189                                 "character special file (no device)"
13190         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
13191         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
13192                                 "block special file (loop)"
13193         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
13194         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
13195         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
13196 }
13197 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
13198
13199 # LU-1299 Executing or running ldd on a truncated executable does not
13200 # cause an out-of-memory condition.
13201 test_227() {
13202         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13203         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
13204         dd if=$(which date) of=$MOUNT/date bs=1k count=1
13205         chmod +x $MOUNT/date
13206
13207         $MOUNT/date > /dev/null
13208         ldd $MOUNT/date > /dev/null
13209         rm -f $MOUNT/date
13210 }
13211 run_test 227 "running truncated executable does not cause OOM"
13212
13213 # LU-1512 try to reuse idle OI blocks
13214 test_228a() {
13215         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13216         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13217         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13218                 skip "ldiskfs only test" && return
13219
13220         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13221         local myDIR=$DIR/$tdir
13222
13223         mkdir -p $myDIR
13224         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13225         $LCTL set_param fail_loc=0x80001002
13226         createmany -o $myDIR/t- 10000
13227         $LCTL set_param fail_loc=0
13228         # The guard is current the largest FID holder
13229         touch $myDIR/guard
13230         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13231                     tr -d '[')
13232         local IDX=$(($SEQ % 64))
13233
13234         do_facet $SINGLEMDS sync
13235         # Make sure journal flushed.
13236         sleep 6
13237         local blk1=$(do_facet $SINGLEMDS \
13238                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13239                      grep Blockcount | awk '{print $4}')
13240
13241         # Remove old files, some OI blocks will become idle.
13242         unlinkmany $myDIR/t- 10000
13243         # Create new files, idle OI blocks should be reused.
13244         createmany -o $myDIR/t- 2000
13245         do_facet $SINGLEMDS sync
13246         # Make sure journal flushed.
13247         sleep 6
13248         local blk2=$(do_facet $SINGLEMDS \
13249                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13250                      grep Blockcount | awk '{print $4}')
13251
13252         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13253 }
13254 run_test 228a "try to reuse idle OI blocks"
13255
13256 test_228b() {
13257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13258         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13259         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13260                 skip "ldiskfs only test" && return
13261
13262         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13263         local myDIR=$DIR/$tdir
13264
13265         mkdir -p $myDIR
13266         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13267         $LCTL set_param fail_loc=0x80001002
13268         createmany -o $myDIR/t- 10000
13269         $LCTL set_param fail_loc=0
13270         # The guard is current the largest FID holder
13271         touch $myDIR/guard
13272         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13273                     tr -d '[')
13274         local IDX=$(($SEQ % 64))
13275
13276         do_facet $SINGLEMDS sync
13277         # Make sure journal flushed.
13278         sleep 6
13279         local blk1=$(do_facet $SINGLEMDS \
13280                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13281                      grep Blockcount | awk '{print $4}')
13282
13283         # Remove old files, some OI blocks will become idle.
13284         unlinkmany $myDIR/t- 10000
13285
13286         # stop the MDT
13287         stop $SINGLEMDS || error "Fail to stop MDT."
13288         # remount the MDT
13289         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
13290
13291         df $MOUNT || error "Fail to df."
13292         # Create new files, idle OI blocks should be reused.
13293         createmany -o $myDIR/t- 2000
13294         do_facet $SINGLEMDS sync
13295         # Make sure journal flushed.
13296         sleep 6
13297         local blk2=$(do_facet $SINGLEMDS \
13298                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13299                      grep Blockcount | awk '{print $4}')
13300
13301         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13302 }
13303 run_test 228b "idle OI blocks can be reused after MDT restart"
13304
13305 #LU-1881
13306 test_228c() {
13307         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13308         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13309         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13310                 skip "ldiskfs only test" && return
13311
13312         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13313         local myDIR=$DIR/$tdir
13314
13315         mkdir -p $myDIR
13316         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13317         $LCTL set_param fail_loc=0x80001002
13318         # 20000 files can guarantee there are index nodes in the OI file
13319         createmany -o $myDIR/t- 20000
13320         $LCTL set_param fail_loc=0
13321         # The guard is current the largest FID holder
13322         touch $myDIR/guard
13323         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13324                     tr -d '[')
13325         local IDX=$(($SEQ % 64))
13326
13327         do_facet $SINGLEMDS sync
13328         # Make sure journal flushed.
13329         sleep 6
13330         local blk1=$(do_facet $SINGLEMDS \
13331                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13332                      grep Blockcount | awk '{print $4}')
13333
13334         # Remove old files, some OI blocks will become idle.
13335         unlinkmany $myDIR/t- 20000
13336         rm -f $myDIR/guard
13337         # The OI file should become empty now
13338
13339         # Create new files, idle OI blocks should be reused.
13340         createmany -o $myDIR/t- 2000
13341         do_facet $SINGLEMDS sync
13342         # Make sure journal flushed.
13343         sleep 6
13344         local blk2=$(do_facet $SINGLEMDS \
13345                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13346                      grep Blockcount | awk '{print $4}')
13347
13348         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13349 }
13350 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
13351
13352 test_229() { # LU-2482, LU-3448
13353         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
13354                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
13355                 return
13356         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13357         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
13358
13359         rm -f $DIR/$tfile
13360
13361         # Create a file with a released layout and stripe count 2.
13362         $MULTIOP $DIR/$tfile H2c ||
13363                 error "failed to create file with released layout"
13364
13365         $GETSTRIPE -v $DIR/$tfile
13366
13367         local pattern=$($GETSTRIPE -L $DIR/$tfile)
13368         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
13369
13370         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
13371         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
13372         stat $DIR/$tfile || error "failed to stat released file"
13373
13374         chown $RUNAS_ID $DIR/$tfile ||
13375                 error "chown $RUNAS_ID $DIR/$tfile failed"
13376
13377         chgrp $RUNAS_ID $DIR/$tfile ||
13378                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
13379
13380         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
13381         rm $DIR/$tfile || error "failed to remove released file"
13382 }
13383 run_test 229 "getstripe/stat/rm/attr changes work on released files"
13384
13385 test_230a() {
13386         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13387         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13388         local MDTIDX=1
13389
13390         test_mkdir $DIR/$tdir
13391         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
13392         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
13393         [ $mdt_idx -ne 0 ] &&
13394                 error "create local directory on wrong MDT $mdt_idx"
13395
13396         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
13397                         error "create remote directory failed"
13398         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
13399         [ $mdt_idx -ne $MDTIDX ] &&
13400                 error "create remote directory on wrong MDT $mdt_idx"
13401
13402         createmany -o $DIR/$tdir/test_230/t- 10 ||
13403                 error "create files on remote directory failed"
13404         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
13405         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
13406         rm -r $DIR/$tdir || error "unlink remote directory failed"
13407 }
13408 run_test 230a "Create remote directory and files under the remote directory"
13409
13410 test_230b() {
13411         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13412         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13413         local MDTIDX=1
13414         local mdt_index
13415         local i
13416         local file
13417         local pid
13418         local stripe_count
13419         local migrate_dir=$DIR/$tdir/migrate_dir
13420         local other_dir=$DIR/$tdir/other_dir
13421
13422         test_mkdir $DIR/$tdir
13423         test_mkdir -i0 -c1 $migrate_dir
13424         test_mkdir -i0 -c1 $other_dir
13425         for ((i=0; i<10; i++)); do
13426                 mkdir -p $migrate_dir/dir_${i}
13427                 createmany -o $migrate_dir/dir_${i}/f 10 ||
13428                         error "create files under remote dir failed $i"
13429         done
13430
13431         cp /etc/passwd $migrate_dir/$tfile
13432         cp /etc/passwd $other_dir/$tfile
13433         chattr +SAD $migrate_dir
13434         chattr +SAD $migrate_dir/$tfile
13435
13436         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13437         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13438         local old_dir_mode=$(stat -c%f $migrate_dir)
13439         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
13440
13441         mkdir -p $migrate_dir/dir_default_stripe2
13442         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
13443         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
13444
13445         mkdir -p $other_dir
13446         ln $migrate_dir/$tfile $other_dir/luna
13447         ln $migrate_dir/$tfile $migrate_dir/sofia
13448         ln $other_dir/$tfile $migrate_dir/david
13449         ln -s $migrate_dir/$tfile $other_dir/zachary
13450         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
13451         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
13452
13453         $LFS migrate -m $MDTIDX $migrate_dir ||
13454                 error "fails on migrating remote dir to MDT1"
13455
13456         echo "migratate to MDT1, then checking.."
13457         for ((i = 0; i < 10; i++)); do
13458                 for file in $(find $migrate_dir/dir_${i}); do
13459                         mdt_index=$($LFS getstripe -M $file)
13460                         [ $mdt_index == $MDTIDX ] ||
13461                                 error "$file is not on MDT${MDTIDX}"
13462                 done
13463         done
13464
13465         # the multiple link file should still in MDT0
13466         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
13467         [ $mdt_index == 0 ] ||
13468                 error "$file is not on MDT${MDTIDX}"
13469
13470         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13471         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13472                 error " expect $old_dir_flag get $new_dir_flag"
13473
13474         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13475         [ "$old_file_flag" = "$new_file_flag" ] ||
13476                 error " expect $old_file_flag get $new_file_flag"
13477
13478         local new_dir_mode=$(stat -c%f $migrate_dir)
13479         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13480                 error "expect mode $old_dir_mode get $new_dir_mode"
13481
13482         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13483         [ "$old_file_mode" = "$new_file_mode" ] ||
13484                 error "expect mode $old_file_mode get $new_file_mode"
13485
13486         diff /etc/passwd $migrate_dir/$tfile ||
13487                 error "$tfile different after migration"
13488
13489         diff /etc/passwd $other_dir/luna ||
13490                 error "luna different after migration"
13491
13492         diff /etc/passwd $migrate_dir/sofia ||
13493                 error "sofia different after migration"
13494
13495         diff /etc/passwd $migrate_dir/david ||
13496                 error "david different after migration"
13497
13498         diff /etc/passwd $other_dir/zachary ||
13499                 error "zachary different after migration"
13500
13501         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13502                 error "${tfile}_ln different after migration"
13503
13504         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13505                 error "${tfile}_ln_other different after migration"
13506
13507         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
13508         [ $stripe_count = 2 ] ||
13509                 error "dir strpe_count $d != 2 after migration."
13510
13511         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
13512         [ $stripe_count = 2 ] ||
13513                 error "file strpe_count $d != 2 after migration."
13514
13515         #migrate back to MDT0
13516         MDTIDX=0
13517
13518         $LFS migrate -m $MDTIDX $migrate_dir ||
13519                 error "fails on migrating remote dir to MDT0"
13520
13521         echo "migrate back to MDT0, checking.."
13522         for file in $(find $migrate_dir); do
13523                 mdt_index=$($LFS getstripe -M $file)
13524                 [ $mdt_index == $MDTIDX ] ||
13525                         error "$file is not on MDT${MDTIDX}"
13526         done
13527
13528         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13529         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13530                 error " expect $old_dir_flag get $new_dir_flag"
13531
13532         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13533         [ "$old_file_flag" = "$new_file_flag" ] ||
13534                 error " expect $old_file_flag get $new_file_flag"
13535
13536         local new_dir_mode=$(stat -c%f $migrate_dir)
13537         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13538                 error "expect mode $old_dir_mode get $new_dir_mode"
13539
13540         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13541         [ "$old_file_mode" = "$new_file_mode" ] ||
13542                 error "expect mode $old_file_mode get $new_file_mode"
13543
13544         diff /etc/passwd ${migrate_dir}/$tfile ||
13545                 error "$tfile different after migration"
13546
13547         diff /etc/passwd ${other_dir}/luna ||
13548                 error "luna different after migration"
13549
13550         diff /etc/passwd ${migrate_dir}/sofia ||
13551                 error "sofia different after migration"
13552
13553         diff /etc/passwd ${other_dir}/zachary ||
13554                 error "zachary different after migration"
13555
13556         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13557                 error "${tfile}_ln different after migration"
13558
13559         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13560                 error "${tfile}_ln_other different after migration"
13561
13562         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
13563         [ $stripe_count = 2 ] ||
13564                 error "dir strpe_count $d != 2 after migration."
13565
13566         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
13567         [ $stripe_count = 2 ] ||
13568                 error "file strpe_count $d != 2 after migration."
13569
13570         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13571 }
13572 run_test 230b "migrate directory"
13573
13574 test_230c() {
13575         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13576         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13577         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13578         local MDTIDX=1
13579         local mdt_index
13580         local file
13581         local migrate_dir=$DIR/$tdir/migrate_dir
13582
13583         #If migrating directory fails in the middle, all entries of
13584         #the directory is still accessiable.
13585         test_mkdir $DIR/$tdir
13586         test_mkdir -i0 -c1 $migrate_dir
13587         stat $migrate_dir
13588         createmany -o $migrate_dir/f 10 ||
13589                 error "create files under ${migrate_dir} failed"
13590
13591         #failed after migrating 5 entries
13592         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
13593         do_facet mds1 lctl set_param fail_loc=0x20001801
13594         do_facet mds1 lctl  set_param fail_val=5
13595         local t=$(ls $migrate_dir | wc -l)
13596         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
13597                 error "migrate should fail after 5 entries"
13598
13599         mkdir $migrate_dir/dir &&
13600                 error "mkdir succeeds under migrating directory"
13601         touch $migrate_dir/file &&
13602                 error "touch file succeeds under migrating directory"
13603
13604         local u=$(ls $migrate_dir | wc -l)
13605         [ "$u" == "$t" ] || error "$u != $t during migration"
13606
13607         for file in $(find $migrate_dir); do
13608                 stat $file || error "stat $file failed"
13609         done
13610
13611         do_facet mds1 lctl set_param fail_loc=0
13612         do_facet mds1 lctl set_param fail_val=0
13613
13614         $LFS migrate -m $MDTIDX $migrate_dir ||
13615                 error "migrate open files should failed with open files"
13616
13617         echo "Finish migration, then checking.."
13618         for file in $(find $migrate_dir); do
13619                 mdt_index=$($LFS getstripe -M $file)
13620                 [ $mdt_index == $MDTIDX ] ||
13621                         error "$file is not on MDT${MDTIDX}"
13622         done
13623
13624         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13625 }
13626 run_test 230c "check directory accessiblity if migration is failed"
13627
13628 test_230d() {
13629         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13630         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13631         local MDTIDX=1
13632         local mdt_index
13633         local migrate_dir=$DIR/$tdir/migrate_dir
13634         local i
13635         local j
13636
13637         test_mkdir $DIR/$tdir
13638         test_mkdir -i0 -c1 $migrate_dir
13639
13640         for ((i=0; i<100; i++)); do
13641                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
13642                 createmany -o $migrate_dir/dir_${i}/f 100 ||
13643                         error "create files under remote dir failed $i"
13644         done
13645
13646         $LFS migrate -m $MDTIDX $migrate_dir ||
13647                 error "migrate remote dir error"
13648
13649         echo "Finish migration, then checking.."
13650         for file in $(find $migrate_dir); do
13651                 mdt_index=$($LFS getstripe -M $file)
13652                 [ $mdt_index == $MDTIDX ] ||
13653                         error "$file is not on MDT${MDTIDX}"
13654         done
13655
13656         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13657 }
13658 run_test 230d "check migrate big directory"
13659
13660 test_230e() {
13661         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13662         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13663         local i
13664         local j
13665         local a_fid
13666         local b_fid
13667
13668         mkdir -p $DIR/$tdir
13669         mkdir $DIR/$tdir/migrate_dir
13670         mkdir $DIR/$tdir/other_dir
13671         touch $DIR/$tdir/migrate_dir/a
13672         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
13673         ls $DIR/$tdir/other_dir
13674
13675         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13676                 error "migrate dir fails"
13677
13678         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13679         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13680
13681         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13682         [ $mdt_index == 0 ] || error "a is not on MDT0"
13683
13684         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
13685                 error "migrate dir fails"
13686
13687         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
13688         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
13689
13690         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13691         [ $mdt_index == 1 ] || error "a is not on MDT1"
13692
13693         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
13694         [ $mdt_index == 1 ] || error "b is not on MDT1"
13695
13696         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13697         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
13698
13699         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
13700
13701         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13702 }
13703 run_test 230e "migrate mulitple local link files"
13704
13705 test_230f() {
13706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13707         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13708         local a_fid
13709         local ln_fid
13710
13711         mkdir -p $DIR/$tdir
13712         mkdir $DIR/$tdir/migrate_dir
13713         $LFS mkdir -i1 $DIR/$tdir/other_dir
13714         touch $DIR/$tdir/migrate_dir/a
13715         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
13716         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
13717         ls $DIR/$tdir/other_dir
13718
13719         # a should be migrated to MDT1, since no other links on MDT0
13720         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13721                 error "#1 migrate dir fails"
13722         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13723         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13724         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13725         [ $mdt_index == 1 ] || error "a is not on MDT1"
13726
13727         # a should stay on MDT1, because it is a mulitple link file
13728         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13729                 error "#2 migrate dir fails"
13730         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13731         [ $mdt_index == 1 ] || error "a is not on MDT1"
13732
13733         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13734                 error "#3 migrate dir fails"
13735
13736         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13737         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
13738         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
13739
13740         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
13741         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
13742
13743         # a should be migrated to MDT0, since no other links on MDT1
13744         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13745                 error "#4 migrate dir fails"
13746         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13747         [ $mdt_index == 0 ] || error "a is not on MDT0"
13748
13749         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13750 }
13751 run_test 230f "migrate mulitple remote link files"
13752
13753 test_230g() {
13754         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13755         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13756
13757         mkdir -p $DIR/$tdir/migrate_dir
13758
13759         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
13760                 error "migrating dir to non-exist MDT succeeds"
13761         true
13762 }
13763 run_test 230g "migrate dir to non-exist MDT"
13764
13765 test_230h() {
13766         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13767         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13768         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
13769                 skip "Need MDS version at least 2.7.64" && return
13770         local mdt_index
13771
13772         mkdir -p $DIR/$tdir/migrate_dir
13773
13774         $LFS migrate -m1 $DIR &&
13775                 error "migrating mountpoint1 should fail"
13776
13777         $LFS migrate -m1 $DIR/$tdir/.. &&
13778                 error "migrating mountpoint2 should fail"
13779
13780         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
13781                 error "migrating $tdir fail"
13782
13783         mdt_index=$($LFS getstripe -M $DIR/$tdir)
13784         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13785
13786         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13787         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13788
13789 }
13790 run_test 230h "migrate .. and root"
13791
13792 test_230i() {
13793         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13794         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13795
13796         mkdir -p $DIR/$tdir/migrate_dir
13797
13798         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
13799                 error "migration fails with a tailing slash"
13800
13801         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
13802                 error "migration fails with two tailing slashes"
13803 }
13804 run_test 230i "lfs migrate -m tolerates trailing slashes"
13805
13806 test_231a()
13807 {
13808         # For simplicity this test assumes that max_pages_per_rpc
13809         # is the same across all OSCs
13810         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
13811         local bulk_size=$((max_pages * 4096))
13812         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
13813                                        head -n 1)
13814
13815         mkdir -p $DIR/$tdir
13816         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
13817                 error "failed to set stripe with -S ${brw_size}M option"
13818
13819         # clear the OSC stats
13820         $LCTL set_param osc.*.stats=0 &>/dev/null
13821         stop_writeback
13822
13823         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
13824         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
13825                 oflag=direct &>/dev/null || error "dd failed"
13826
13827         sync; sleep 1; sync # just to be safe
13828         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
13829         if [ x$nrpcs != "x1" ]; then
13830                 $LCTL get_param osc.*.stats
13831                 error "found $nrpcs ost_write RPCs, not 1 as expected"
13832         fi
13833
13834         start_writeback
13835         # Drop the OSC cache, otherwise we will read from it
13836         cancel_lru_locks osc
13837
13838         # clear the OSC stats
13839         $LCTL set_param osc.*.stats=0 &>/dev/null
13840
13841         # Client reads $bulk_size.
13842         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
13843                 iflag=direct &>/dev/null || error "dd failed"
13844
13845         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
13846         if [ x$nrpcs != "x1" ]; then
13847                 $LCTL get_param osc.*.stats
13848                 error "found $nrpcs ost_read RPCs, not 1 as expected"
13849         fi
13850 }
13851 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
13852
13853 test_231b() {
13854         mkdir -p $DIR/$tdir
13855         local i
13856         for i in {0..1023}; do
13857                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
13858                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
13859                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
13860         done
13861         sync
13862 }
13863 run_test 231b "must not assert on fully utilized OST request buffer"
13864
13865 test_232() {
13866         mkdir -p $DIR/$tdir
13867         #define OBD_FAIL_LDLM_OST_LVB            0x31c
13868         $LCTL set_param fail_loc=0x31c
13869
13870         # ignore dd failure
13871         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
13872
13873         $LCTL set_param fail_loc=0
13874         umount_client $MOUNT || error "umount failed"
13875         mount_client $MOUNT || error "mount failed"
13876 }
13877 run_test 232 "failed lock should not block umount"
13878
13879 test_233a() {
13880         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
13881         { skip "Need MDS version at least 2.3.64"; return; }
13882         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13883
13884         local fid=$($LFS path2fid $MOUNT)
13885         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13886                 error "cannot access $MOUNT using its FID '$fid'"
13887 }
13888 run_test 233a "checking that OBF of the FS root succeeds"
13889
13890 test_233b() {
13891         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
13892         { skip "Need MDS version at least 2.5.90"; return; }
13893         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13894
13895         local fid=$($LFS path2fid $MOUNT/.lustre)
13896         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13897                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
13898
13899         fid=$($LFS path2fid $MOUNT/.lustre/fid)
13900         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13901                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
13902 }
13903 run_test 233b "checking that OBF of the FS .lustre succeeds"
13904
13905 test_234() {
13906         local p="$TMP/sanityN-$TESTNAME.parameters"
13907         save_lustre_params client "llite.*.xattr_cache" > $p
13908         lctl set_param llite.*.xattr_cache 1 ||
13909                 { skip "xattr cache is not supported"; return 0; }
13910
13911         mkdir -p $DIR/$tdir || error "mkdir failed"
13912         touch $DIR/$tdir/$tfile || error "touch failed"
13913         # OBD_FAIL_LLITE_XATTR_ENOMEM
13914         $LCTL set_param fail_loc=0x1405
13915         # output of the form: attr 2 4 44 3 fc13 x86_64
13916         V=($(IFS=".-" rpm -q attr))
13917         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
13918               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
13919                 # attr pre-2.4.44-7 had a bug with rc
13920                 # LU-3703 - SLES 11 and FC13 clients have older attr
13921                 getfattr -n user.attr $DIR/$tdir/$tfile &&
13922                         error "getfattr should have failed with ENOMEM"
13923         else
13924                 skip "LU-3703: attr version $(getfattr --version) too old"
13925         fi
13926         $LCTL set_param fail_loc=0x0
13927         rm -rf $DIR/$tdir
13928
13929         restore_lustre_params < $p
13930         rm -f $p
13931 }
13932 run_test 234 "xattr cache should not crash on ENOMEM"
13933
13934 test_235() {
13935         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
13936                 skip "Need MDS version at least 2.4.52" && return
13937         flock_deadlock $DIR/$tfile
13938         local RC=$?
13939         case $RC in
13940                 0)
13941                 ;;
13942                 124) error "process hangs on a deadlock"
13943                 ;;
13944                 *) error "error executing flock_deadlock $DIR/$tfile"
13945                 ;;
13946         esac
13947 }
13948 run_test 235 "LU-1715: flock deadlock detection does not work properly"
13949
13950 #LU-2935
13951 test_236() {
13952         check_swap_layouts_support && return 0
13953         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
13954
13955         local ref1=/etc/passwd
13956         local ref2=/etc/group
13957         local file1=$DIR/$tdir/f1
13958         local file2=$DIR/$tdir/f2
13959
13960         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
13961         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
13962         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
13963         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
13964         local fd=$(free_fd)
13965         local cmd="exec $fd<>$file2"
13966         eval $cmd
13967         rm $file2
13968         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
13969                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
13970         cmd="exec $fd>&-"
13971         eval $cmd
13972         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
13973
13974         #cleanup
13975         rm -rf $DIR/$tdir
13976 }
13977 run_test 236 "Layout swap on open unlinked file"
13978
13979 # test to verify file handle related system calls
13980 # (name_to_handle_at/open_by_handle_at)
13981 # The new system calls are supported in glibc >= 2.14.
13982
13983 test_237() {
13984         echo "Test file_handle syscalls" > $DIR/$tfile ||
13985                 error "write failed"
13986         check_fhandle_syscalls $DIR/$tfile ||
13987                 error "check_fhandle_syscalls failed"
13988 }
13989 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
13990
13991 # LU-4659 linkea consistency
13992 test_238() {
13993         local server_version=$(lustre_version_code $SINGLEMDS)
13994
13995         [[ $server_version -gt $(version_code 2.5.57) ]] ||
13996                 [[ $server_version -gt $(version_code 2.5.1) &&
13997                    $server_version -lt $(version_code 2.5.50) ]] ||
13998                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
13999
14000         touch $DIR/$tfile
14001         ln $DIR/$tfile $DIR/$tfile.lnk
14002         touch $DIR/$tfile.new
14003         mv $DIR/$tfile.new $DIR/$tfile
14004         local fid1=$($LFS path2fid $DIR/$tfile)
14005         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
14006         local path1=$($LFS fid2path $FSNAME "$fid1")
14007         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
14008         local path2=$($LFS fid2path $FSNAME "$fid2")
14009         [ $tfile.lnk == $path2 ] ||
14010                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
14011         rm -f $DIR/$tfile*
14012 }
14013 run_test 238 "Verify linkea consistency"
14014
14015 test_239() {
14016         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
14017                 skip "Need MDS version at least 2.5.60" && return
14018         local list=$(comma_list $(mdts_nodes))
14019
14020         mkdir -p $DIR/$tdir
14021         createmany -o $DIR/$tdir/f- 5000
14022         unlinkmany $DIR/$tdir/f- 5000
14023         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
14024         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
14025                         osc.*MDT*.sync_in_flight" | calc_sum)
14026         [ "$changes" -eq 0 ] || error "$changes not synced"
14027 }
14028 run_test 239 "osp_sync test"
14029
14030 test_239a() { #LU-5297
14031         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14032         touch $DIR/$tfile
14033         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
14034         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
14035         chgrp $RUNAS_GID $DIR/$tfile
14036         wait_delete_completed
14037 }
14038 run_test 239a "process invalid osp sync record correctly"
14039
14040 test_239b() { #LU-5297
14041         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14042         touch $DIR/$tfile1
14043         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
14044         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
14045         chgrp $RUNAS_GID $DIR/$tfile1
14046         wait_delete_completed
14047         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
14048         touch $DIR/$tfile2
14049         chgrp $RUNAS_GID $DIR/$tfile2
14050         wait_delete_completed
14051 }
14052 run_test 239b "process osp sync record with ENOMEM error correctly"
14053
14054 test_240() {
14055         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14056         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14057
14058         mkdir -p $DIR/$tdir
14059
14060         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
14061                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
14062         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
14063                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
14064
14065         umount_client $MOUNT || error "umount failed"
14066         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
14067         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
14068         mount_client $MOUNT || error "failed to mount client"
14069
14070         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
14071         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
14072 }
14073 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
14074
14075 test_241_bio() {
14076         for LOOP in $(seq $1); do
14077                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
14078                 cancel_lru_locks osc || true
14079         done
14080 }
14081
14082 test_241_dio() {
14083         for LOOP in $(seq $1); do
14084                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
14085                                                 iflag=direct 2>/dev/null
14086         done
14087 }
14088
14089 test_241a() { # was test_241
14090         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14091         ls -la $DIR/$tfile
14092         cancel_lru_locks osc
14093         test_241_bio 1000 &
14094         PID=$!
14095         test_241_dio 1000
14096         wait $PID
14097 }
14098 run_test 241a "bio vs dio"
14099
14100 test_241b() {
14101         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14102         ls -la $DIR/$tfile
14103         test_241_dio 1000 &
14104         PID=$!
14105         test_241_dio 1000
14106         wait $PID
14107 }
14108 run_test 241b "dio vs dio"
14109
14110 test_242() {
14111         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14112         mkdir -p $DIR/$tdir
14113         touch $DIR/$tdir/$tfile
14114
14115         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
14116         do_facet mds1 lctl set_param fail_loc=0x105
14117         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
14118
14119         do_facet mds1 lctl set_param fail_loc=0
14120         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
14121 }
14122 run_test 242 "mdt_readpage failure should not cause directory unreadable"
14123
14124 test_243()
14125 {
14126         test_mkdir -p $DIR/$tdir
14127         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
14128 }
14129 run_test 243 "various group lock tests"
14130
14131 test_244()
14132 {
14133         test_mkdir -p $DIR/$tdir
14134         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
14135         sendfile_grouplock $DIR/$tdir/$tfile || \
14136                 error "sendfile+grouplock failed"
14137         rm -rf $DIR/$tdir
14138 }
14139 run_test 244 "sendfile with group lock tests"
14140
14141 test_245() {
14142         local flagname="multi_mod_rpcs"
14143         local connect_data_name="max_mod_rpcs"
14144         local out
14145
14146         # check if multiple modify RPCs flag is set
14147         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
14148                 grep "connect_flags:")
14149         echo "$out"
14150
14151         echo "$out" | grep -qw $flagname
14152         if [ $? -ne 0 ]; then
14153                 echo "connect flag $flagname is not set"
14154                 return
14155         fi
14156
14157         # check if multiple modify RPCs data is set
14158         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
14159         echo "$out"
14160
14161         echo "$out" | grep -qw $connect_data_name ||
14162                 error "import should have connect data $connect_data_name"
14163 }
14164 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
14165
14166 test_246() { # LU-7371
14167         remote_ost_nodsh && skip "remote OST with nodsh" && return
14168         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
14169                 skip "Need OST version >= 2.7.62" && return 0
14170         do_facet ost1 $LCTL set_param fail_val=4095
14171 #define OBD_FAIL_OST_READ_SIZE          0x234
14172         do_facet ost1 $LCTL set_param fail_loc=0x234
14173         $LFS setstripe $DIR/$tfile -i 0 -c 1
14174         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
14175         cancel_lru_locks $FSNAME-OST0000
14176         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
14177 }
14178 run_test 246 "Read file of size 4095 should return right length"
14179
14180 test_247a() {
14181         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14182                 grep -q subtree ||
14183                 { skip "Fileset feature is not supported"; return; }
14184
14185         local submount=${MOUNT}_$tdir
14186
14187         mkdir $MOUNT/$tdir
14188         mkdir -p $submount || error "mkdir $submount failed"
14189         FILESET="$FILESET/$tdir" mount_client $submount ||
14190                 error "mount $submount failed"
14191         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
14192         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
14193                 error "read $MOUNT/$tdir/$tfile failed"
14194         umount_client $submount || error "umount $submount failed"
14195         rmdir $submount
14196 }
14197 run_test 247a "mount subdir as fileset"
14198
14199 test_247b() {
14200         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14201                 { skip "Fileset feature is not supported"; return; }
14202
14203         local submount=${MOUNT}_$tdir
14204
14205         rm -rf $MOUNT/$tdir
14206         mkdir -p $submount || error "mkdir $submount failed"
14207         SKIP_FILESET=1
14208         FILESET="$FILESET/$tdir" mount_client $submount &&
14209                 error "mount $submount should fail"
14210         rmdir $submount
14211 }
14212 run_test 247b "mount subdir that dose not exist"
14213
14214 test_247c() {
14215         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14216                 { skip "Fileset feature is not supported"; return; }
14217
14218         local submount=${MOUNT}_$tdir
14219
14220         mkdir -p $MOUNT/$tdir/dir1
14221         mkdir -p $submount || error "mkdir $submount failed"
14222         FILESET="$FILESET/$tdir" mount_client $submount ||
14223                 error "mount $submount failed"
14224         local fid=$($LFS path2fid $MOUNT/)
14225         $LFS fid2path $submount $fid && error "fid2path should fail"
14226         umount_client $submount || error "umount $submount failed"
14227         rmdir $submount
14228 }
14229 run_test 247c "running fid2path outside root"
14230
14231 test_247d() {
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 $submount/dir1)
14242         $LFS fid2path $submount $fid || error "fid2path should succeed"
14243         umount_client $submount || error "umount $submount failed"
14244         rmdir $submount
14245 }
14246 run_test 247d "running fid2path inside root"
14247
14248 # LU-8037
14249 test_247e() {
14250         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14251                 grep -q subtree ||
14252                 { skip "Fileset feature is not supported"; return; }
14253
14254         local submount=${MOUNT}_$tdir
14255
14256         mkdir $MOUNT/$tdir
14257         mkdir -p $submount || error "mkdir $submount failed"
14258         FILESET="$FILESET/.." mount_client $submount &&
14259                 error "mount $submount should fail"
14260         rmdir $submount
14261 }
14262 run_test 247e "mount .. as fileset"
14263
14264 test_248() {
14265         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
14266         [ -z "$fast_read_sav" ] && skip "no fast read support" && return
14267
14268         # create a large file for fast read verification
14269         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
14270
14271         # make sure the file is created correctly
14272         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
14273                 { rm -f $DIR/$tfile; skip "file creation error" && return; }
14274
14275         echo "Test 1: verify that fast read is 4 times faster on cache read"
14276
14277         # small read with fast read enabled
14278         $LCTL set_param -n llite.*.fast_read=1
14279         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14280                 awk '/copied/ { print $6 }')
14281
14282         # small read with fast read disabled
14283         $LCTL set_param -n llite.*.fast_read=0
14284         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14285                 awk '/copied/ { print $6 }')
14286
14287         # verify that fast read is 4 times faster for cache read
14288         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
14289                 error_not_in_vm "fast read was not 4 times faster: " \
14290                            "$t_fast vs $t_slow"
14291
14292         echo "Test 2: verify the performance between big and small read"
14293         $LCTL set_param -n llite.*.fast_read=1
14294
14295         # 1k non-cache read
14296         cancel_lru_locks osc
14297         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14298                 awk '/copied/ { print $6 }')
14299
14300         # 1M non-cache read
14301         cancel_lru_locks osc
14302         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14303                 awk '/copied/ { print $6 }')
14304
14305         # verify that big IO is not 4 times faster than small IO
14306         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
14307                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
14308
14309         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
14310         rm -f $DIR/$tfile
14311 }
14312 run_test 248 "fast read verification"
14313
14314 test_249() { # LU-7890
14315         rm -f $DIR/$tfile
14316         $SETSTRIPE -c 1 $DIR/$tfile
14317
14318         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
14319         skip "Need at least version 2.8.54"
14320
14321         # Offset 2T == 4k * 512M
14322         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
14323                 error "dd to 2T offset failed"
14324 }
14325 run_test 249 "Write above 2T file size"
14326
14327 test_250() {
14328         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
14329          && skip "no 16TB file size limit on ZFS" && return
14330
14331         $SETSTRIPE -c 1 $DIR/$tfile
14332         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
14333         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
14334         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
14335         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
14336                 conv=notrunc,fsync && error "append succeeded"
14337         return 0
14338 }
14339 run_test 250 "Write above 16T limit"
14340
14341 test_251() {
14342         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
14343
14344         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
14345         #Skip once - writing the first stripe will succeed
14346         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14347         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
14348                 error "short write happened"
14349
14350         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14351         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
14352                 error "short read happened"
14353
14354         rm -f $DIR/$tfile
14355 }
14356 run_test 251 "Handling short read and write correctly"
14357
14358 test_252() {
14359         local tgt
14360         local dev
14361         local out
14362         local uuid
14363         local num
14364         local gen
14365
14366         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14367         remote_ost_nodsh && skip "remote OST with nodsh" && return
14368         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
14369              "$(facet_fstype mds1)" != "ldiskfs" ]; then
14370                 skip "ldiskfs only test"
14371                 return
14372         fi
14373
14374         # check lr_reader on OST0000
14375         tgt=ost1
14376         dev=$(facet_device $tgt)
14377         out=$(do_facet $tgt $LR_READER $dev)
14378         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14379         echo "$out"
14380         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
14381         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
14382                 error "Invalid uuid returned by $LR_READER on target $tgt"
14383         echo -e "uuid returned by $LR_READER is '$uuid'\n"
14384
14385         # check lr_reader -c on MDT0000
14386         tgt=mds1
14387         dev=$(facet_device $tgt)
14388         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
14389                 echo "$LR_READER does not support additional options"
14390                 return 0
14391         fi
14392         out=$(do_facet $tgt $LR_READER -c $dev)
14393         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14394         echo "$out"
14395         num=$(echo "$out" | grep -c "mdtlov")
14396         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
14397                 error "Invalid number of mdtlov clients returned by $LR_READER"
14398         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
14399
14400         # check lr_reader -cr on MDT0000
14401         out=$(do_facet $tgt $LR_READER -cr $dev)
14402         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14403         echo "$out"
14404         echo "$out" | grep -q "^reply_data:$" ||
14405                 error "$LR_READER should have returned 'reply_data' section"
14406         num=$(echo "$out" | grep -c "client_generation")
14407         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
14408 }
14409 run_test 252 "check lr_reader tool"
14410
14411 test_253_fill_ost() {
14412         local size_mb #how many MB should we write to pass watermark
14413         local lwm=$3  #low watermark
14414         local free_10mb #10% of free space
14415
14416         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14417         size_mb=$((free_kb / 1024 - lwm))
14418         free_10mb=$((free_kb / 10240))
14419         #If 10% of free space cross low watermark use it
14420         if (( free_10mb > size_mb )); then
14421                 size_mb=$free_10mb
14422         else
14423                 #At least we need to store 1.1 of difference between
14424                 #free space and low watermark
14425                 size_mb=$((size_mb + size_mb / 10))
14426         fi
14427         if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
14428                 dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
14429                          oflag=append conv=notrunc
14430         fi
14431
14432         sleep_maxage
14433
14434         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14435         echo "OST still has $((free_kb / 1024)) mbytes free"
14436 }
14437
14438 test_253() {
14439         local ostidx=0
14440         local rc=0
14441
14442         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14443         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14444         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
14445
14446         local ost_name=$($LFS osts |
14447                 sed -n 's/^'$ostidx': \(.*\)_UUID .*/\1/p')
14448         # on the mdt's osc
14449         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
14450         do_facet $SINGLEMDS $LCTL get_param -n \
14451                 osp.$mdtosc_proc1.reserved_mb_high ||
14452                 { skip  "remote MDS does not support reserved_mb_high" &&
14453                   return; }
14454
14455         rm -rf $DIR/$tdir
14456         wait_mds_ost_sync
14457         wait_delete_completed
14458         mkdir $DIR/$tdir
14459
14460         local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
14461                         osp.$mdtosc_proc1.reserved_mb_high)
14462         local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
14463                         osp.$mdtosc_proc1.reserved_mb_low)
14464         echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
14465
14466         create_pool $FSNAME.$TESTNAME || error "Pool creation failed"
14467         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
14468                 error "Adding $ost_name to pool failed"
14469
14470         # Wait for client to see a OST at pool
14471         wait_update $HOSTNAME "$LCTL get_param -n
14472                 lov.$FSNAME-*.pools.$TESTNAME | sort -u |
14473                 grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
14474                 error "Client can not see the pool"
14475         $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
14476                 error "Setstripe failed"
14477
14478         dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
14479         local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
14480         echo "OST still has $((blocks/1024)) mbytes free"
14481
14482         local new_lwm=$((blocks/1024-10))
14483         do_facet $SINGLEMDS $LCTL set_param \
14484                         osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
14485         do_facet $SINGLEMDS $LCTL set_param \
14486                         osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
14487
14488         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14489
14490         #First enospc could execute orphan deletion so repeat.
14491         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14492
14493         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14494                         osp.$mdtosc_proc1.prealloc_status)
14495         echo "prealloc_status $oa_status"
14496
14497         dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
14498                 error "File creation should fail"
14499         #object allocation was stopped, but we still able to append files
14500         dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
14501                 error "Append failed"
14502         rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
14503
14504         wait_delete_completed
14505
14506         sleep_maxage
14507
14508         for i in $(seq 10 12); do
14509                 dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
14510                         error "File creation failed after rm";
14511         done
14512
14513         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14514                         osp.$mdtosc_proc1.prealloc_status)
14515         echo "prealloc_status $oa_status"
14516
14517         if (( oa_status != 0 )); then
14518                 error "Object allocation still disable after rm"
14519         fi
14520         do_facet $SINGLEMDS $LCTL set_param \
14521                         osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
14522         do_facet $SINGLEMDS $LCTL set_param \
14523                         osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
14524
14525
14526         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
14527                 error "Remove $ost_name from pool failed"
14528         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
14529                 error "Pool destroy fialed"
14530 }
14531 run_test 253 "Check object allocation limit"
14532
14533 test_254() {
14534         local cl_user
14535
14536         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14537         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14538         do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
14539                 { skip "MDS does not support changelog_size" && return; }
14540
14541         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
14542         echo "Registered as changelog user $cl_user"
14543
14544         $LFS changelog_clear $MDT0 $cl_user 0
14545
14546         local size1=$(do_facet mds1 \
14547                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14548         echo "Changelog size $size1"
14549
14550         rm -rf $DIR/$tdir
14551         $LFS mkdir -i 0 $DIR/$tdir
14552         # change something
14553         mkdir -p $DIR/$tdir/pics/2008/zachy
14554         touch $DIR/$tdir/pics/2008/zachy/timestamp
14555         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
14556         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
14557         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
14558         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
14559         rm $DIR/$tdir/pics/desktop.jpg
14560
14561         local size2=$(do_facet mds1 \
14562                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14563         echo "Changelog size after work $size2"
14564
14565         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
14566
14567         if (( size2 <= size1 )); then
14568                 error "Changelog size after work should be greater than original"
14569         fi
14570         return 0
14571 }
14572 run_test 254 "Check changelog size"
14573
14574 ladvise_no_type()
14575 {
14576         local type=$1
14577         local file=$2
14578
14579         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
14580                 awk -F: '{print $2}' | grep $type > /dev/null
14581         if [ $? -ne 0 ]; then
14582                 return 0
14583         fi
14584         return 1
14585 }
14586
14587 ladvise_no_ioctl()
14588 {
14589         local file=$1
14590
14591         lfs ladvise -a willread $file > /dev/null 2>&1
14592         if [ $? -eq 0 ]; then
14593                 return 1
14594         fi
14595
14596         lfs ladvise -a willread $file 2>&1 |
14597                 grep "Inappropriate ioctl for device" > /dev/null
14598         if [ $? -eq 0 ]; then
14599                 return 0
14600         fi
14601         return 1
14602 }
14603
14604 percent() {
14605         bc <<<"scale=2; ($1 - $2) * 100 / $2"
14606 }
14607
14608 # run a random read IO workload
14609 # usage: random_read_iops <filename> <filesize> <iosize>
14610 random_read_iops() {
14611         local file=$1
14612         local fsize=$2
14613         local iosize=${3:-4096}
14614
14615         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
14616                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
14617 }
14618
14619 drop_file_oss_cache() {
14620         local file="$1"
14621         local nodes="$2"
14622
14623         $LFS ladvise -a dontneed $file 2>/dev/null ||
14624                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
14625 }
14626
14627 ladvise_willread_performance()
14628 {
14629         local repeat=10
14630         local average_origin=0
14631         local average_cache=0
14632         local average_ladvise=0
14633
14634         for ((i = 1; i <= $repeat; i++)); do
14635                 echo "Iter $i/$repeat: reading without willread hint"
14636                 cancel_lru_locks osc
14637                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
14638                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
14639                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
14640                 average_origin=$(bc <<<"$average_origin + $speed_origin")
14641
14642                 cancel_lru_locks osc
14643                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
14644                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
14645                 average_cache=$(bc <<<"$average_cache + $speed_cache")
14646
14647                 cancel_lru_locks osc
14648                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
14649                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
14650                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
14651                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
14652                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
14653         done
14654         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
14655         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
14656         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
14657
14658         speedup_cache=$(percent $average_cache $average_origin)
14659         speedup_ladvise=$(percent $average_ladvise $average_origin)
14660
14661         echo "Average uncached read: $average_origin"
14662         echo "Average speedup with OSS cached read: " \
14663                 "$average_cache = +$speedup_cache%"
14664         echo "Average speedup with ladvise willread: " \
14665                 "$average_ladvise = +$speedup_ladvise%"
14666
14667         local lowest_speedup=20
14668         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
14669                 echo "Speedup with OSS cached read less than $lowest_speedup%, "
14670                         "got $average_cache%. Skipping ladvise willread check."
14671                 return 0
14672         fi
14673
14674         # the test won't work on ZFS until it supports 'ladvise dontneed', but
14675         # it is still good to run until then to exercise 'ladvise willread'
14676         ! $LFS ladvise -a dontneed $DIR/$tfile &&
14677                 [ "$(facet_fstype ost1)" = "zfs" ] &&
14678                 echo "osd-zfs does not support dontneed or drop_caches" &&
14679                 return 0
14680
14681         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
14682         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
14683                 error_not_in_vm "Speedup with willread is less than " \
14684                         "$lowest_speedup%, got $average_ladvise%"
14685 }
14686
14687 test_255a() {
14688         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
14689                 skip "lustre < 2.8.54 does not support ladvise " && return
14690         remote_ost_nodsh && skip "remote OST with nodsh" && return
14691
14692         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
14693
14694         ladvise_no_type willread $DIR/$tfile &&
14695                 skip "willread ladvise is not supported" && return
14696
14697         ladvise_no_ioctl $DIR/$tfile &&
14698                 skip "ladvise ioctl is not supported" && return
14699
14700         local size_mb=100
14701         local size=$((size_mb * 1048576))
14702         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
14703                 error "dd to $DIR/$tfile failed"
14704
14705         lfs ladvise -a willread $DIR/$tfile ||
14706                 error "Ladvise failed with no range argument"
14707
14708         lfs ladvise -a willread -s 0 $DIR/$tfile ||
14709                 error "Ladvise failed with no -l or -e argument"
14710
14711         lfs ladvise -a willread -e 1 $DIR/$tfile ||
14712                 error "Ladvise failed with only -e argument"
14713
14714         lfs ladvise -a willread -l 1 $DIR/$tfile ||
14715                 error "Ladvise failed with only -l argument"
14716
14717         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
14718                 error "End offset should not be smaller than start offset"
14719
14720         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
14721                 error "End offset should not be equal to start offset"
14722
14723         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
14724                 error "Ladvise failed with overflowing -s argument"
14725
14726         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
14727                 error "Ladvise failed with overflowing -e argument"
14728
14729         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
14730                 error "Ladvise failed with overflowing -l argument"
14731
14732         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
14733                 error "Ladvise succeeded with conflicting -l and -e arguments"
14734
14735         echo "Synchronous ladvise should wait"
14736         local delay=4
14737 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
14738         do_nodes $(comma_list $(osts_nodes)) \
14739                 $LCTL set_param fail_val=$delay fail_loc=0x237
14740
14741         local start_ts=$SECONDS
14742         lfs ladvise -a willread $DIR/$tfile ||
14743                 error "Ladvise failed with no range argument"
14744         local end_ts=$SECONDS
14745         local inteval_ts=$((end_ts - start_ts))
14746
14747         if [ $inteval_ts -lt $(($delay - 1)) ]; then
14748                 error "Synchronous advice didn't wait reply"
14749         fi
14750
14751         echo "Asynchronous ladvise shouldn't wait"
14752         local start_ts=$SECONDS
14753         lfs ladvise -a willread -b $DIR/$tfile ||
14754                 error "Ladvise failed with no range argument"
14755         local end_ts=$SECONDS
14756         local inteval_ts=$((end_ts - start_ts))
14757
14758         if [ $inteval_ts -gt $(($delay / 2)) ]; then
14759                 error "Asynchronous advice blocked"
14760         fi
14761
14762         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
14763         ladvise_willread_performance
14764 }
14765 run_test 255a "check 'lfs ladvise -a willread'"
14766
14767 facet_meminfo() {
14768         local facet=$1
14769         local info=$2
14770
14771         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
14772 }
14773
14774 test_255b() {
14775         remote_ost_nodsh && skip "remote OST with nodsh" && return
14776
14777         lfs setstripe -c 1 -i 0 $DIR/$tfile
14778
14779         ladvise_no_type dontneed $DIR/$tfile &&
14780                 skip "dontneed ladvise is not supported" && return
14781
14782         ladvise_no_ioctl $DIR/$tfile &&
14783                 skip "ladvise ioctl is not supported" && return
14784
14785         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
14786                 skip "lustre < 2.8.54 does not support ladvise" && return
14787
14788         ! $LFS ladvise -a dontneed $DIR/$tfile &&
14789                 [ "$(facet_fstype ost1)" = "zfs" ] &&
14790                 skip "zfs-osd does not support 'ladvise dontneed'" && return
14791
14792         local size_mb=100
14793         local size=$((size_mb * 1048576))
14794         # In order to prevent disturbance of other processes, only check 3/4
14795         # of the memory usage
14796         local kibibytes=$((size_mb * 1024 * 3 / 4))
14797
14798         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
14799                 error "dd to $DIR/$tfile failed"
14800
14801         local total=$(facet_meminfo ost1 MemTotal)
14802         echo "Total memory: $total KiB"
14803
14804         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
14805         local before_read=$(facet_meminfo ost1 Cached)
14806         echo "Cache used before read: $before_read KiB"
14807
14808         lfs ladvise -a willread $DIR/$tfile ||
14809                 error "Ladvise willread failed"
14810         local after_read=$(facet_meminfo ost1 Cached)
14811         echo "Cache used after read: $after_read KiB"
14812
14813         lfs ladvise -a dontneed $DIR/$tfile ||
14814                 error "Ladvise dontneed again failed"
14815         local no_read=$(facet_meminfo ost1 Cached)
14816         echo "Cache used after dontneed ladvise: $no_read KiB"
14817
14818         if [ $total -lt $((before_read + kibibytes)) ]; then
14819                 echo "Memory is too small, abort checking"
14820                 return 0
14821         fi
14822
14823         if [ $((before_read + kibibytes)) -gt $after_read ]; then
14824                 error "Ladvise willread should use more memory" \
14825                         "than $kibibytes KiB"
14826         fi
14827
14828         if [ $((no_read + kibibytes)) -gt $after_read ]; then
14829                 error "Ladvise dontneed should release more memory" \
14830                         "than $kibibytes KiB"
14831         fi
14832 }
14833 run_test 255b "check 'lfs ladvise -a dontneed'"
14834
14835 test_256() {
14836         local cl_user
14837         local cat_sl
14838         local mdt_dev
14839
14840         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14841         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14842         [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
14843                 skip "ldiskfs only test" && return
14844
14845         mdt_dev=$(mdsdevname 1)
14846         echo $mdt_dev
14847         cl_user=$(do_facet mds1 \
14848         "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
14849         if [[ -n $cl_user ]]; then
14850                 skip "active changelog user"
14851                 return
14852         fi
14853
14854         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
14855         echo "Registered as changelog user $cl_user"
14856
14857         rm -rf $DIR/$tdir
14858         mkdir -p $DIR/$tdir
14859
14860         $LFS changelog_clear $MDT0 $cl_user 0
14861
14862         # change something
14863         touch $DIR/$tdir/{1..10}
14864
14865         # stop the MDT
14866         stop mds1 || error "Fail to stop MDT."
14867
14868         # remount the MDT
14869         start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
14870
14871         #after mount new plainllog is used
14872         touch $DIR/$tdir/{11..19}
14873         local TEMP256FILE=$(mktemp TEMP256XXXXXX)
14874         cat_sl=$(do_facet mds1 \
14875         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
14876          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
14877         rm $TEMP256FILE
14878
14879         if (( cat_sl != 2 )); then
14880                 do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
14881                 error "Changelog catalog has wrong number of slots $cat_sl"
14882         fi
14883
14884         $LFS changelog_clear $MDT0 $cl_user 0
14885
14886         TEMP256FILE=$(mktemp TEMP256XXXXXX)
14887         cat_sl=$(do_facet mds1 \
14888         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
14889          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
14890         rm $TEMP256FILE
14891
14892         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
14893
14894         if (( cat_sl == 2 )); then
14895                 error "Empty plain llog was not deleted from changelog catalog"
14896         fi
14897         if (( cat_sl != 1 )); then
14898                 error "Active plain llog shouldn\`t be deleted from catalog"
14899         fi
14900 }
14901 run_test 256 "Check llog delete for empty and not full state"
14902
14903 test_257() {
14904         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14905         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
14906                 skip "Need MDS version at least 2.8.55" && return
14907
14908         test_mkdir -p $DIR/$tdir
14909
14910         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
14911                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
14912         stat $DIR/$tdir
14913
14914 #define OBD_FAIL_MDS_XATTR_REP                  0x161
14915         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
14916         local facet=mds$((mdtidx + 1))
14917         set_nodes_failloc $(facet_active_host $facet) 0x80000161
14918         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
14919
14920         stop $facet || error "stop MDS failed"
14921         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
14922                 error "start MDS fail"
14923 }
14924 run_test 257 "xattr locks are not lost"
14925
14926 # Verify we take the i_mutex when security requires it
14927 test_258a() {
14928 #define OBD_FAIL_IMUTEX_SEC 0x141c
14929         $LCTL set_param fail_loc=0x141c
14930         touch $DIR/$tfile
14931         chmod u+s $DIR/$tfile
14932         chmod a+rwx $DIR/$tfile
14933         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
14934         RC=$?
14935         if [ $RC -ne 0 ]; then
14936                 error "error, failed to take i_mutex, rc=$?"
14937         fi
14938         rm -f $DIR/$tfile
14939 }
14940 run_test 258a
14941
14942 # Verify we do NOT take the i_mutex in the normal case
14943 test_258b() {
14944 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
14945         $LCTL set_param fail_loc=0x141d
14946         touch $DIR/$tfile
14947         chmod a+rwx $DIR
14948         chmod a+rw $DIR/$tfile
14949         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
14950         RC=$?
14951         if [ $RC -ne 0 ]; then
14952                 error "error, took i_mutex unnecessarily, rc=$?"
14953         fi
14954         rm -f $DIR/$tfile
14955
14956 }
14957 run_test 258b "verify i_mutex security behavior"
14958
14959 test_260() {
14960 #define OBD_FAIL_MDC_CLOSE               0x806
14961         $LCTL set_param fail_loc=0x80000806
14962         touch $DIR/$tfile
14963
14964 }
14965 run_test 260 "Check mdc_close fail"
14966
14967 cleanup_test_300() {
14968         trap 0
14969         umask $SAVE_UMASK
14970 }
14971 test_striped_dir() {
14972         local mdt_index=$1
14973         local stripe_count
14974         local stripe_index
14975
14976         mkdir -p $DIR/$tdir
14977
14978         SAVE_UMASK=$(umask)
14979         trap cleanup_test_300 RETURN EXIT
14980
14981         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
14982                                                 $DIR/$tdir/striped_dir ||
14983                 error "set striped dir error"
14984
14985         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
14986         [ "$mode" = "755" ] || error "expect 755 got $mode"
14987
14988         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
14989                 error "getdirstripe failed"
14990         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
14991         if [ "$stripe_count" != "2" ]; then
14992                 error "1:stripe_count is $stripe_count, expect 2"
14993         fi
14994         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
14995         if [ "$stripe_count" != "2" ]; then
14996                 error "2:stripe_count is $stripe_count, expect 2"
14997         fi
14998
14999         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
15000         if [ "$stripe_index" != "$mdt_index" ]; then
15001                 error "stripe_index is $stripe_index, expect $mdt_index"
15002         fi
15003
15004         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15005                 error "nlink error after create striped dir"
15006
15007         mkdir $DIR/$tdir/striped_dir/a
15008         mkdir $DIR/$tdir/striped_dir/b
15009
15010         stat $DIR/$tdir/striped_dir/a ||
15011                 error "create dir under striped dir failed"
15012         stat $DIR/$tdir/striped_dir/b ||
15013                 error "create dir under striped dir failed"
15014
15015         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
15016                 error "nlink error after mkdir"
15017
15018         rmdir $DIR/$tdir/striped_dir/a
15019         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
15020                 error "nlink error after rmdir"
15021
15022         rmdir $DIR/$tdir/striped_dir/b
15023         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15024                 error "nlink error after rmdir"
15025
15026         chattr +i $DIR/$tdir/striped_dir
15027         createmany -o $DIR/$tdir/striped_dir/f 10 &&
15028                 error "immutable flags not working under striped dir!"
15029         chattr -i $DIR/$tdir/striped_dir
15030
15031         rmdir $DIR/$tdir/striped_dir ||
15032                 error "rmdir striped dir error"
15033
15034         cleanup_test_300
15035
15036         true
15037 }
15038
15039 test_300a() {
15040         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15041                 skip "skipped for lustre < 2.7.0" && return
15042         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15043         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15044
15045         test_striped_dir 0 || error "failed on striped dir on MDT0"
15046         test_striped_dir 1 || error "failed on striped dir on MDT0"
15047 }
15048 run_test 300a "basic striped dir sanity test"
15049
15050 test_300b() {
15051         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15052                 skip "skipped for lustre < 2.7.0" && return
15053         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15054         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15055         local i
15056         local mtime1
15057         local mtime2
15058         local mtime3
15059
15060         test_mkdir $DIR/$tdir || error "mkdir fail"
15061         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15062                 error "set striped dir error"
15063         for ((i=0; i<10; i++)); do
15064                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
15065                 sleep 1
15066                 touch $DIR/$tdir/striped_dir/file_$i ||
15067                                         error "touch error $i"
15068                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
15069                 [ $mtime1 -eq $mtime2 ] &&
15070                         error "mtime not change after create"
15071                 sleep 1
15072                 rm -f $DIR/$tdir/striped_dir/file_$i ||
15073                                         error "unlink error $i"
15074                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
15075                 [ $mtime2 -eq $mtime3 ] &&
15076                         error "mtime did not change after unlink"
15077         done
15078         true
15079 }
15080 run_test 300b "check ctime/mtime for striped dir"
15081
15082 test_300c() {
15083         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15084                 skip "skipped for lustre < 2.7.0" && return
15085         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15086         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15087         local file_count
15088
15089         mkdir -p $DIR/$tdir
15090         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
15091                 error "set striped dir error"
15092
15093         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
15094                 error "chown striped dir failed"
15095
15096         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
15097                 error "create 5k files failed"
15098
15099         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
15100
15101         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
15102
15103         rm -rf $DIR/$tdir
15104 }
15105 run_test 300c "chown && check ls under striped directory"
15106
15107 test_300d() {
15108         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15109                 skip "skipped for lustre < 2.7.0" && return
15110         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15111         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15112         local stripe_count
15113         local file
15114
15115         mkdir -p $DIR/$tdir
15116         $SETSTRIPE -c 2 $DIR/$tdir
15117
15118         #local striped directory
15119         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15120                 error "set striped dir error"
15121         createmany -o $DIR/$tdir/striped_dir/f 10 ||
15122                 error "create 10 files failed"
15123
15124         #remote striped directory
15125         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
15126                 error "set striped dir error"
15127         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
15128                 error "create 10 files failed"
15129
15130         for file in $(find $DIR/$tdir); do
15131                 stripe_count=$($GETSTRIPE -c $file)
15132                 [ $stripe_count -eq 2 ] ||
15133                         error "wrong stripe $stripe_count for $file"
15134         done
15135
15136         rm -rf $DIR/$tdir
15137 }
15138 run_test 300d "check default stripe under striped directory"
15139
15140 test_300e() {
15141         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15142                 skip "Need MDS version at least 2.7.55" && return
15143         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15144         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15145         local stripe_count
15146         local file
15147
15148         mkdir -p $DIR/$tdir
15149
15150         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15151                 error "set striped dir error"
15152
15153         touch $DIR/$tdir/striped_dir/a
15154         touch $DIR/$tdir/striped_dir/b
15155         touch $DIR/$tdir/striped_dir/c
15156
15157         mkdir $DIR/$tdir/striped_dir/dir_a
15158         mkdir $DIR/$tdir/striped_dir/dir_b
15159         mkdir $DIR/$tdir/striped_dir/dir_c
15160
15161         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
15162                 error "set striped adir under striped dir error"
15163
15164         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
15165                 error "set striped bdir under striped dir error"
15166
15167         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
15168                 error "set striped cdir under striped dir error"
15169
15170         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
15171                 error "rename dir under striped dir fails"
15172
15173         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
15174                 error "rename dir under different stripes fails"
15175
15176         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
15177                 error "rename file under striped dir should succeed"
15178
15179         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
15180                 error "rename dir under striped dir should succeed"
15181
15182         rm -rf $DIR/$tdir
15183 }
15184 run_test 300e "check rename under striped directory"
15185
15186 test_300f() {
15187         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15188                 skip "Need MDS version at least 2.7.55" && return
15189         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15190         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15191         local stripe_count
15192         local file
15193
15194         rm -rf $DIR/$tdir
15195         mkdir -p $DIR/$tdir
15196
15197         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15198                 error "set striped dir error"
15199
15200         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
15201                 error "set striped dir error"
15202
15203         touch $DIR/$tdir/striped_dir/a
15204         mkdir $DIR/$tdir/striped_dir/dir_a
15205         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
15206                 error "create striped dir under striped dir fails"
15207
15208         touch $DIR/$tdir/striped_dir1/b
15209         mkdir $DIR/$tdir/striped_dir1/dir_b
15210         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
15211                 error "create striped dir under striped dir fails"
15212
15213         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
15214                 error "rename dir under different striped dir should fail"
15215
15216         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
15217                 error "rename striped dir under diff striped dir should fail"
15218
15219         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
15220                 error "rename file under diff striped dirs fails"
15221
15222         rm -rf $DIR/$tdir
15223 }
15224 run_test 300f "check rename cross striped directory"
15225
15226 test_300_check_default_striped_dir()
15227 {
15228         local dirname=$1
15229         local default_count=$2
15230         local default_index=$3
15231         local stripe_count
15232         local stripe_index
15233         local dir_stripe_index
15234         local dir
15235
15236         echo "checking $dirname $default_count $default_index"
15237         $LFS setdirstripe -D -c $default_count -i $default_index \
15238                                 -t all_char $DIR/$tdir/$dirname ||
15239                 error "set default stripe on striped dir error"
15240         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
15241         [ $stripe_count -eq $default_count ] ||
15242                 error "expect $default_count get $stripe_count for $dirname"
15243
15244         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
15245         [ $stripe_index -eq $default_index ] ||
15246                 error "expect $default_index get $stripe_index for $dirname"
15247
15248         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
15249                                                 error "create dirs failed"
15250
15251         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
15252         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
15253         for dir in $(find $DIR/$tdir/$dirname/*); do
15254                 stripe_count=$($LFS getdirstripe -c $dir)
15255                 [ $stripe_count -eq $default_count ] ||
15256                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
15257                 error "stripe count $default_count != $stripe_count for $dir"
15258
15259                 stripe_index=$($LFS getdirstripe -i $dir)
15260                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
15261                         error "$stripe_index != $default_index for $dir"
15262
15263                 #check default stripe
15264                 stripe_count=$($LFS getdirstripe -D -c $dir)
15265                 [ $stripe_count -eq $default_count ] ||
15266                 error "default count $default_count != $stripe_count for $dir"
15267
15268                 stripe_index=$($LFS getdirstripe -D -i $dir)
15269                 [ $stripe_index -eq $default_index ] ||
15270                 error "default index $default_index != $stripe_index for $dir"
15271         done
15272         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
15273 }
15274
15275 test_300g() {
15276         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15277                 skip "Need MDS version at least 2.7.55" && return
15278         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15279         local dir
15280         local stripe_count
15281         local stripe_index
15282
15283         mkdir $DIR/$tdir
15284         mkdir $DIR/$tdir/normal_dir
15285
15286         #Checking when client cache stripe index
15287         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
15288         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
15289                 error "create striped_dir failed"
15290
15291         mkdir $DIR/$tdir/striped_dir/dir1 ||
15292                 error "create dir1 fails"
15293         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
15294         [ $stripe_index -eq 1 ] ||
15295                 error "dir1 expect 1 got $stripe_index"
15296
15297         $LFS setdirstripe -i2 $DIR/$tdir/striped_dir/dir2 ||
15298                 error "create dir2 fails"
15299         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir2)
15300         [ $stripe_index -eq 2 ] ||
15301                 error "dir2 expect 2 got $stripe_index"
15302
15303         #check default stripe count/stripe index
15304         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
15305         test_300_check_default_striped_dir normal_dir 1 0
15306         test_300_check_default_striped_dir normal_dir 2 1
15307         test_300_check_default_striped_dir normal_dir 2 -1
15308
15309         #delete default stripe information
15310         echo "delete default stripeEA"
15311         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
15312                 error "set default stripe on striped dir error"
15313
15314         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
15315         for dir in $(find $DIR/$tdir/normal_dir/*); do
15316                 stripe_count=$($LFS getdirstripe -c $dir)
15317                 [ $stripe_count -eq 0 ] ||
15318                         error "expect 1 get $stripe_count for $dir"
15319                 stripe_index=$($LFS getdirstripe -i $dir)
15320                 [ $stripe_index -eq 0 ] ||
15321                         error "expect 0 get $stripe_index for $dir"
15322         done
15323 }
15324 run_test 300g "check default striped directory for normal directory"
15325
15326 test_300h() {
15327         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15328                 skip "Need MDS version at least 2.7.55" && return
15329         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15330         local dir
15331         local stripe_count
15332
15333         mkdir $DIR/$tdir
15334         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
15335                                         $DIR/$tdir/striped_dir ||
15336                 error "set striped dir error"
15337
15338         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
15339         test_300_check_default_striped_dir striped_dir 1 0
15340         test_300_check_default_striped_dir striped_dir 2 1
15341         test_300_check_default_striped_dir striped_dir 2 -1
15342
15343         #delete default stripe information
15344         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
15345                 error "set default stripe on striped dir error"
15346
15347         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
15348         for dir in $(find $DIR/$tdir/striped_dir/*); do
15349                 stripe_count=$($LFS getdirstripe -c $dir)
15350                 [ $stripe_count -eq 0 ] ||
15351                         error "expect 1 get $stripe_count for $dir"
15352         done
15353 }
15354 run_test 300h "check default striped directory for striped directory"
15355
15356 test_300i() {
15357         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15358                 skip "Need MDS version at least 2.7.55" && return
15359         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15360         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15361         local stripe_count
15362         local file
15363
15364         mkdir $DIR/$tdir
15365
15366         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15367                 error "set striped dir error"
15368
15369         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15370                 error "create files under striped dir failed"
15371
15372         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
15373                 error "set striped hashdir error"
15374
15375         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
15376                 error "create dir0 under hash dir failed"
15377         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
15378                 error "create dir1 under hash dir failed"
15379
15380         # unfortunately, we need to umount to clear dir layout cache for now
15381         # once we fully implement dir layout, we can drop this
15382         umount_client $MOUNT || error "umount failed"
15383         mount_client $MOUNT || error "mount failed"
15384
15385         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
15386         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
15387         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
15388
15389         #set the stripe to be unknown hash type
15390         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
15391         $LCTL set_param fail_loc=0x1901
15392         for ((i = 0; i < 10; i++)); do
15393                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
15394                         error "stat f-$i failed"
15395                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
15396         done
15397
15398         touch $DIR/$tdir/striped_dir/f0 &&
15399                 error "create under striped dir with unknown hash should fail"
15400
15401         $LCTL set_param fail_loc=0
15402
15403         umount_client $MOUNT || error "umount failed"
15404         mount_client $MOUNT || error "mount failed"
15405
15406         return 0
15407 }
15408 run_test 300i "client handle unknown hash type striped directory"
15409
15410 test_300j() {
15411         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15412         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15413                 skip "Need MDS version at least 2.7.55" && return
15414         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15415         local stripe_count
15416         local file
15417
15418         mkdir $DIR/$tdir
15419
15420         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
15421         $LCTL set_param fail_loc=0x1702
15422         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15423                 error "set striped dir error"
15424
15425         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15426                 error "create files under striped dir failed"
15427
15428         $LCTL set_param fail_loc=0
15429
15430         rm -rf $DIR/$tdir || error "unlink striped dir fails"
15431
15432         return 0
15433 }
15434 run_test 300j "test large update record"
15435
15436 test_300k() {
15437         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15438                 skip "Need MDS version at least 2.7.55" && return
15439         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15440         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15441         local stripe_count
15442         local file
15443
15444         mkdir $DIR/$tdir
15445
15446         #define OBD_FAIL_LARGE_STRIPE   0x1703
15447         $LCTL set_param fail_loc=0x1703
15448         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
15449                 error "set striped dir error"
15450         $LCTL set_param fail_loc=0
15451
15452         $LFS getdirstripe $DIR/$tdir/striped_dir ||
15453                 error "getstripeddir fails"
15454         rm -rf $DIR/$tdir/striped_dir ||
15455                 error "unlink striped dir fails"
15456
15457         return 0
15458 }
15459 run_test 300k "test large striped directory"
15460
15461 test_300l() {
15462         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15463                 skip "Need MDS version at least 2.7.55" && return
15464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15465         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15466         local stripe_index
15467
15468         test_mkdir -p $DIR/$tdir/striped_dir
15469         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
15470                         error "chown $RUNAS_ID failed"
15471         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
15472                 error "set default striped dir failed"
15473
15474         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
15475         $LCTL set_param fail_loc=0x80000158
15476         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
15477
15478         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
15479         [ $stripe_index -eq 1 ] ||
15480                 error "expect 1 get $stripe_index for $dir"
15481 }
15482 run_test 300l "non-root user to create dir under striped dir with stale layout"
15483
15484 test_300m() {
15485         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15486                 skip "Need MDS version at least 2.7.55" && return
15487         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15488         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
15489
15490         mkdir -p $DIR/$tdir/striped_dir
15491         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
15492                 error "set default stripes dir error"
15493
15494         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
15495
15496         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
15497         [ $stripe_count -eq 0 ] ||
15498                         error "expect 0 get $stripe_count for a"
15499
15500         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
15501                 error "set default stripes dir error"
15502
15503         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
15504
15505         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
15506         [ $stripe_count -eq 0 ] ||
15507                         error "expect 0 get $stripe_count for b"
15508
15509         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
15510                 error "set default stripes dir error"
15511
15512         mkdir $DIR/$tdir/striped_dir/c &&
15513                 error "default stripe_index is invalid, mkdir c should fails"
15514
15515         rm -rf $DIR/$tdir || error "rmdir fails"
15516 }
15517 run_test 300m "setstriped directory on single MDT FS"
15518
15519 cleanup_300n() {
15520         local list=$(comma_list $(mdts_nodes))
15521
15522         trap 0
15523         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15524 }
15525
15526 test_300n() {
15527         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15528                 skip "Need MDS version at least 2.7.55" && return
15529         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15530         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15531         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15532
15533         local stripe_index
15534         local list=$(comma_list $(mdts_nodes))
15535
15536         trap cleanup_300n RETURN EXIT
15537         mkdir -p $DIR/$tdir
15538         chmod 777 $DIR/$tdir
15539         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
15540                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
15541                 error "create striped dir succeeds with gid=0"
15542
15543         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
15544         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
15545                 error "create striped dir fails with gid=-1"
15546
15547         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15548         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
15549                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
15550                 error "set default striped dir succeeds with gid=0"
15551
15552
15553         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
15554         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
15555                 error "set default striped dir fails with gid=-1"
15556
15557
15558         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15559         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
15560                                         error "create test_dir fails"
15561         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
15562                                         error "create test_dir1 fails"
15563         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
15564                                         error "create test_dir2 fails"
15565         cleanup_300n
15566 }
15567 run_test 300n "non-root user to create dir under striped dir with default EA"
15568
15569 test_300o() {
15570         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15571                 skip "Need MDS version at least 2.7.55" && return
15572         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15573         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15574         local numfree1
15575         local numfree2
15576
15577         mkdir -p $DIR/$tdir
15578
15579         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
15580         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
15581         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
15582                 skip "not enough free inodes $numfree1 $numfree2"
15583                 return
15584         fi
15585
15586         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
15587         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
15588         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
15589                 skip "not enough free space $numfree1 $numfree2"
15590                 return
15591         fi
15592
15593         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
15594                 error "setdirstripe fails"
15595
15596         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
15597                 error "create dirs fails"
15598
15599         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
15600         ls $DIR/$tdir/striped_dir > /dev/null ||
15601                 error "ls striped dir fails"
15602         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
15603                 error "unlink big striped dir fails"
15604 }
15605 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
15606
15607 test_300p() {
15608         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15609         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15610         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15611
15612         mkdir -p $DIR/$tdir
15613
15614         #define OBD_FAIL_OUT_ENOSPC     0x1704
15615         do_facet mds2 lctl set_param fail_loc=0x80001704
15616         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
15617                         error "create striped directory should fail"
15618
15619         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
15620
15621         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
15622         true
15623 }
15624 run_test 300p "create striped directory without space"
15625
15626 test_300q() {
15627         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15628         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15629
15630         local fd=$(free_fd)
15631         local cmd="exec $fd<$tdir"
15632         cd $DIR
15633         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
15634         eval $cmd
15635         cmd="exec $fd<&-"
15636         trap "eval $cmd" EXIT
15637         cd $tdir || error "cd $tdir fails"
15638         rmdir  ../$tdir || error "rmdir $tdir fails"
15639         mkdir local_dir && error "create dir succeeds"
15640         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
15641         eval $cmd
15642         return 0
15643 }
15644 run_test 300q "create remote directory under orphan directory"
15645
15646 prepare_remote_file() {
15647         mkdir $DIR/$tdir/src_dir ||
15648                 error "create remote source failed"
15649
15650         cp /etc/hosts $DIR/$tdir/src_dir/a || error
15651         touch $DIR/$tdir/src_dir/a
15652
15653         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
15654                 error "create remote target dir failed"
15655
15656         touch $DIR/$tdir/tgt_dir/b
15657
15658         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
15659                 error "rename dir cross MDT failed!"
15660
15661         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
15662                 error "src_child still exists after rename"
15663
15664         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
15665                 error "missing file(a) after rename"
15666
15667         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
15668                 error "diff after rename"
15669 }
15670
15671 test_310a() {
15672         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
15673         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15674         local remote_file=$DIR/$tdir/tgt_dir/b
15675
15676         mkdir -p $DIR/$tdir
15677
15678         prepare_remote_file || error "prepare remote file failed"
15679
15680         #open-unlink file
15681         $OPENUNLINK $remote_file $remote_file || error
15682         $CHECKSTAT -a $remote_file || error
15683 }
15684 run_test 310a "open unlink remote file"
15685
15686 test_310b() {
15687         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
15688         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15689         local remote_file=$DIR/$tdir/tgt_dir/b
15690
15691         mkdir -p $DIR/$tdir
15692
15693         prepare_remote_file || error "prepare remote file failed"
15694
15695         ln $remote_file $DIR/$tfile || error "link failed for remote file"
15696         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
15697         $CHECKSTAT -t file $remote_file || error "check file failed"
15698 }
15699 run_test 310b "unlink remote file with multiple links while open"
15700
15701 test_310c() {
15702         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
15703         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15704         local remote_file=$DIR/$tdir/tgt_dir/b
15705
15706         mkdir -p $DIR/$tdir
15707
15708         prepare_remote_file || error "prepare remote file failed"
15709
15710         ln $remote_file $DIR/$tfile || error "link failed for remote file"
15711         multiop_bg_pause $remote_file O_uc ||
15712                         error "mulitop failed for remote file"
15713         MULTIPID=$!
15714         $MULTIOP $DIR/$tfile Ouc
15715         kill -USR1 $MULTIPID
15716         wait $MULTIPID
15717 }
15718 run_test 310c "open-unlink remote file with multiple links"
15719
15720 #LU-4825
15721 test_311() {
15722         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.54) ] &&
15723                 skip "lustre < 2.8.54 does not contain LU-4825 fix" && return
15724         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15725         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15726
15727         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
15728
15729         mkdir -p $DIR/$tdir
15730         $SETSTRIPE -i 0 -c 1 $DIR/$tdir
15731         createmany -o $DIR/$tdir/$tfile. 1000
15732
15733         # statfs data is not real time, let's just calculate it
15734         old_iused=$((old_iused + 1000))
15735
15736         local count=$(do_facet $SINGLEMDS "lctl get_param -n \
15737                         osp.*OST0000*MDT0000.create_count")
15738         local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
15739                                 osp.*OST0000*MDT0000.max_create_count")
15740         for idx in $(seq $MDSCOUNT); do
15741                 do_facet mds$idx "lctl set_param -n \
15742                         osp.*OST0000*MDT000?.max_create_count=0"
15743         done
15744
15745         $SETSTRIPE -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
15746         local index=$($GETSTRIPE -i $DIR/$tdir/$tfile)
15747         [ $index -ne 0 ] || error "$tfile stripe index is 0"
15748
15749         unlinkmany $DIR/$tdir/$tfile. 1000
15750
15751         for idx in $(seq $MDSCOUNT); do
15752                 do_facet mds$idx "lctl set_param -n \
15753                         osp.*OST0000*MDT000?.max_create_count=$max_count"
15754                 do_facet mds$idx "lctl set_param -n \
15755                         osp.*OST0000*MDT000?.create_count=$count"
15756         done
15757
15758         local new_iused
15759         for i in $(seq 120); do
15760                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
15761                 # system may be too busy to destroy all objs in time, use
15762                 # a somewhat small value to not fail autotest
15763                 [ $((old_iused - new_iused)) -gt 400 ] && break
15764                 sleep 1
15765         done
15766
15767         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
15768         [ $((old_iused - new_iused)) -gt 400 ] ||
15769                 error "objs not destroyed after unlink"
15770 }
15771 run_test 311 "disable OSP precreate, and unlink should destroy objs"
15772
15773 zfs_oid_to_objid()
15774 {
15775         local ost=$1
15776         local objid=$2
15777
15778         local vdevdir=$(dirname $(facet_vdevice $ost))
15779         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
15780         local zfs_zapid=$(do_facet $ost $cmd |
15781                           grep -w "/O/0/d$((objid%32))" -C 5 |
15782                           awk '/Object/{getline; print $1}')
15783         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
15784                           awk "/$objid = /"'{printf $3}')
15785
15786         echo $zfs_objid
15787 }
15788
15789 zfs_object_blksz() {
15790         local ost=$1
15791         local objid=$2
15792
15793         local vdevdir=$(dirname $(facet_vdevice $ost))
15794         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
15795         local blksz=$(do_facet $ost $cmd $objid |
15796                       awk '/dblk/{getline; printf $4}')
15797
15798         case "${blksz: -1}" in
15799                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
15800                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
15801                 *) ;;
15802         esac
15803
15804         echo $blksz
15805 }
15806
15807 test_312() { # LU-4856
15808         remote_ost_nodsh && skip "remote OST with nodsh" && return
15809
15810         [ $(facet_fstype ost1) = "zfs" ] ||
15811                 { skip "the test only applies to zfs" && return; }
15812
15813         local max_blksz=$(do_facet ost1 \
15814                           $ZFS get -p recordsize $(facet_device ost1) |
15815                           awk '!/VALUE/{print $3}')
15816         local min_blksz=$(getconf PAGE_SIZE)
15817
15818         # to make life a little bit easier
15819         $LFS mkdir -c 1 -i 0 $DIR/$tdir
15820         $LFS setstripe -c 1 -i 0 $DIR/$tdir
15821
15822         local tf=$DIR/$tdir/$tfile
15823         touch $tf
15824         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
15825
15826         # Get ZFS object id
15827         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
15828
15829         # block size change by sequential over write
15830         local blksz
15831         for ((bs=$min_blksz; bs <= max_blksz; bs <<= 2)); do
15832                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
15833
15834                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
15835                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
15836         done
15837         rm -f $tf
15838
15839         # block size change by sequential append write
15840         dd if=/dev/zero of=$tf bs=$min_blksz count=1 oflag=sync conv=notrunc
15841         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
15842         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
15843
15844         for ((count = 1; count < $((max_blksz / min_blksz)); count *= 2)); do
15845                 dd if=/dev/zero of=$tf bs=$min_blksz count=$count seek=$count \
15846                         oflag=sync conv=notrunc
15847
15848                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
15849                 [ $blksz -eq $((2 * count * min_blksz)) ] ||
15850                         error "blksz error, actual $blksz, "    \
15851                                 "expected: 2 * $count * $min_blksz"
15852         done
15853         rm -f $tf
15854
15855         # random write
15856         touch $tf
15857         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
15858         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
15859
15860         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
15861         blksz=$(zfs_object_blksz ost1 $zfs_objid)
15862         [ $blksz -eq $min_blksz ] ||
15863                 error "blksz error: $blksz, expected: $min_blksz"
15864
15865         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
15866         blksz=$(zfs_object_blksz ost1 $zfs_objid)
15867         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
15868
15869         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
15870         blksz=$(zfs_object_blksz ost1 $zfs_objid)
15871         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
15872 }
15873 run_test 312 "make sure ZFS adjusts its block size by write pattern"
15874
15875 test_313() {
15876         remote_ost_nodsh && skip "remote OST with nodsh" && return
15877
15878         local file=$DIR/$tfile
15879         rm -f $file
15880         $SETSTRIPE -c 1 -i 0 $file || error "setstripe failed"
15881
15882         # define OBD_FAIL_TGT_RCVD_EIO           0x720
15883         do_facet ost1 "$LCTL set_param fail_loc=0x720"
15884         dd if=/dev/zero of=$file bs=4096 oflag=direct count=1 &&
15885                 error "write should failed"
15886         do_facet ost1 "$LCTL set_param fail_loc=0"
15887         rm -f $file
15888 }
15889 run_test 313 "io should fail after last_rcvd update fail"
15890
15891 test_fake_rw() {
15892         local read_write=$1
15893         if [ "$read_write" = "write" ]; then
15894                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
15895         elif [ "$read_write" = "read" ]; then
15896                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
15897         else
15898                 error "argument error"
15899         fi
15900
15901         # turn off debug for performance testing
15902         local saved_debug=$($LCTL get_param -n debug)
15903         $LCTL set_param debug=0
15904
15905         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
15906
15907         # get ost1 size - lustre-OST0000
15908         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
15909         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
15910         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
15911
15912         if [ "$read_write" = "read" ]; then
15913                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
15914         fi
15915
15916         local start_time=$(date +%s.%N)
15917         $dd_cmd bs=1M count=$blocks oflag=sync ||
15918                 error "real dd $read_write error"
15919         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
15920
15921         if [ "$read_write" = "write" ]; then
15922                 rm -f $DIR/$tfile
15923         fi
15924
15925         # define OBD_FAIL_OST_FAKE_RW           0x238
15926         do_facet ost1 $LCTL set_param fail_loc=0x238
15927
15928         local start_time=$(date +%s.%N)
15929         $dd_cmd bs=1M count=$blocks oflag=sync ||
15930                 error "fake dd $read_write error"
15931         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
15932
15933         if [ "$read_write" = "write" ]; then
15934                 # verify file size
15935                 cancel_lru_locks osc
15936                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
15937                         error "$tfile size not $blocks MB"
15938         fi
15939         do_facet ost1 $LCTL set_param fail_loc=0
15940
15941         echo "fake $read_write $duration_fake vs. normal $read_write" \
15942                 "$duration in seconds"
15943         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
15944                 error_not_in_vm "fake write is slower"
15945
15946         $LCTL set_param -n debug="$saved_debug"
15947         rm -f $DIR/$tfile
15948 }
15949 test_399a() { # LU-7655 for OST fake write
15950         remote_ost_nodsh && skip "remote OST with nodsh" && return
15951
15952         test_fake_rw write
15953 }
15954 run_test 399a "fake write should not be slower than normal write"
15955
15956 test_399b() { # LU-8726 for OST fake read
15957         remote_ost_nodsh && skip "remote OST with nodsh" && return
15958
15959         if [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
15960                 skip "ldiskfs only test" && return 0
15961         fi
15962         test_fake_rw read
15963 }
15964 run_test 399b "fake read should not be slower than normal read"
15965
15966 test_400a() { # LU-1606, was conf-sanity test_74
15967         local extra_flags=''
15968         local out=$TMP/$tfile
15969         local prefix=/usr/include/lustre
15970         local prog
15971
15972         if ! which $CC > /dev/null 2>&1; then
15973                 skip_env "$CC is not installed"
15974                 return 0
15975         fi
15976
15977         if ! [[ -d $prefix ]]; then
15978                 # Assume we're running in tree and fixup the include path.
15979                 extra_flags+=" -I$LUSTRE/include"
15980                 extra_flags+=" -L$LUSTRE/utils"
15981         fi
15982
15983         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
15984                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
15985                         error "client api broken"
15986         done
15987         rm -f $out
15988 }
15989 run_test 400a "Lustre client api program can compile and link"
15990
15991 test_400b() { # LU-1606, LU-5011
15992         local header
15993         local out=$TMP/$tfile
15994         local prefix=/usr/include/linux/lustre
15995
15996         # We use a hard coded prefix so that this test will not fail
15997         # when run in tree. There are headers in lustre/include/lustre/
15998         # that are not packaged (like lustre_idl.h) and have more
15999         # complicated include dependencies (like config.h and lnet/types.h).
16000         # Since this test about correct packaging we just skip them when
16001         # they don't exist (see below) rather than try to fixup cppflags.
16002
16003         if ! which $CC > /dev/null 2>&1; then
16004                 skip_env "$CC is not installed"
16005                 return 0
16006         fi
16007
16008         for header in $prefix/*.h; do
16009                 if ! [[ -f "$header" ]]; then
16010                         continue
16011                 fi
16012
16013                 if [[ "$(basename $header)" == lustre_ioctl.h ]]; then
16014                         continue # lustre_ioctl.h is internal header
16015                 fi
16016
16017                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
16018                         error "cannot compile '$header'"
16019         done
16020         rm -f $out
16021 }
16022 run_test 400b "packaged headers can be compiled"
16023
16024 test_401a() { #LU-7437
16025         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
16026         [ -n "$printf_arg" ] && skip_env "find does not support -printf" &&
16027                 return
16028         #count the number of parameters by "list_param -R"
16029         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
16030         #count the number of parameters by listing proc files
16031         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
16032         echo "proc_dirs='$proc_dirs'"
16033         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
16034         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
16035                       sort -u | wc -l)
16036
16037         [ $params -eq $procs ] ||
16038                 error "found $params parameters vs. $procs proc files"
16039
16040         # test the list_param -D option only returns directories
16041         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
16042         #count the number of parameters by listing proc directories
16043         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
16044                 sort -u | wc -l)
16045
16046         [ $params -eq $procs ] ||
16047                 error "found $params parameters vs. $procs proc files"
16048 }
16049 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
16050
16051 test_401b() {
16052         local save=$($LCTL get_param -n jobid_var)
16053         local tmp=testing
16054
16055         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
16056                 error "no error returned when setting bad parameters"
16057
16058         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
16059         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
16060
16061         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
16062         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
16063         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
16064 }
16065 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
16066
16067 test_401c() {
16068         local jobid_var_old=$($LCTL get_param -n jobid_var)
16069         local jobid_var_new
16070
16071         $LCTL set_param jobid_var= &&
16072                 error "no error returned for 'set_param a='"
16073
16074         jobid_var_new=$($LCTL get_param -n jobid_var)
16075         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16076                 error "jobid_var was changed by setting without value"
16077
16078         $LCTL set_param jobid_var &&
16079                 error "no error returned for 'set_param a'"
16080
16081         jobid_var_new=$($LCTL get_param -n jobid_var)
16082         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16083                 error "jobid_var was changed by setting without value"
16084 }
16085 run_test 401c "Verify 'lctl set_param' without value fails in either format."
16086
16087 test_401d() {
16088         local jobid_var_old=$($LCTL get_param -n jobid_var)
16089         local jobid_var_new
16090         local new_value="foo=bar"
16091
16092         $LCTL set_param jobid_var=$new_value ||
16093                 error "'set_param a=b' did not accept a value containing '='"
16094
16095         jobid_var_new=$($LCTL get_param -n jobid_var)
16096         [[ "$jobid_var_new" == "$new_value" ]] ||
16097                 error "'set_param a=b' failed on a value containing '='"
16098
16099         # Reset the jobid_var to test the other format
16100         $LCTL set_param jobid_var=$jobid_var_old
16101         jobid_var_new=$($LCTL get_param -n jobid_var)
16102         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16103                 error "failed to reset jobid_var"
16104
16105         $LCTL set_param jobid_var $new_value ||
16106                 error "'set_param a b' did not accept a value containing '='"
16107
16108         jobid_var_new=$($LCTL get_param -n jobid_var)
16109         [[ "$jobid_var_new" == "$new_value" ]] ||
16110                 error "'set_param a b' failed on a value containing '='"
16111
16112         $LCTL set_param jobid_var $jobid_var_old
16113         jobid_var_new=$($LCTL get_param -n jobid_var)
16114         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16115                 error "failed to reset jobid_var"
16116 }
16117 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
16118
16119 test_402() {
16120         local server_version=$(lustre_version_code $SINGLEMDS)
16121         [[ $server_version -ge $(version_code 2.7.66) ]] ||
16122         [[ $server_version -ge $(version_code 2.7.18.4) &&
16123                 $server_version -lt $(version_code 2.7.50) ]] ||
16124         [[ $server_version -ge $(version_code 2.7.2) &&
16125                 $server_version -lt $(version_code 2.7.11) ]] ||
16126                 { skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+";
16127                         return; }
16128         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16129         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
16130 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
16131         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
16132         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
16133                 echo "Touch failed - OK"
16134 }
16135 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
16136
16137 test_403() {
16138         local file1=$DIR/$tfile.1
16139         local file2=$DIR/$tfile.2
16140         local tfile=$TMP/$tfile
16141
16142         rm -f $file1 $file2 $tfile
16143
16144         touch $file1
16145         ln $file1 $file2
16146
16147         # 30 sec OBD_TIMEOUT in ll_getattr()
16148         # right before populating st_nlink
16149         $LCTL set_param fail_loc=0x80001409
16150         stat -c %h $file1 > $tfile &
16151
16152         # create an alias, drop all locks and reclaim the dentry
16153         < $file2
16154         cancel_lru_locks mdc
16155         cancel_lru_locks osc
16156         sysctl -w vm.drop_caches=2
16157
16158         wait
16159
16160         [ `cat $tfile` -gt 0 ] || error "wrong nlink count: `cat $tfile`"
16161
16162         rm -f $tfile $file1 $file2
16163 }
16164 run_test 403 "i_nlink should not drop to zero due to aliasing"
16165
16166 test_404() { # LU-6601
16167         local server_version=$(lustre_version_code $SINGLEMDS)
16168         [[ $server_version -ge $(version_code 2.8.53) ]] ||
16169                 { skip "Need server version newer than 2.8.52"; return 0; }
16170
16171         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16172         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
16173                 awk '/osp .*-osc-MDT/ { print $4}')
16174
16175         local osp
16176         for osp in $mosps; do
16177                 echo "Deactivate: " $osp
16178                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
16179                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16180                         awk -vp=$osp '$4 == p { print $2 }')
16181                 [ $stat = IN ] || {
16182                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16183                         error "deactivate error"
16184                 }
16185                 echo "Activate: " $osp
16186                 do_facet $SINGLEMDS $LCTL --device %$osp activate
16187                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16188                         awk -vp=$osp '$4 == p { print $2 }')
16189                 [ $stat = UP ] || {
16190                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16191                         error "activate error"
16192                 }
16193         done
16194 }
16195 run_test 404 "validate manual {de}activated works properly for OSPs"
16196
16197 test_405() {
16198         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
16199                 skip "Layout swap lock is not supported" && return
16200
16201         check_swap_layouts_support && return 0
16202
16203         test_mkdir -p $DIR/$tdir
16204         swap_lock_test -d $DIR/$tdir ||
16205                 error "One layout swap locked test failed"
16206 }
16207 run_test 405 "Various layout swap lock tests"
16208
16209 test_406() {
16210         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16211         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
16212         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
16213         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16214         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.50) ] &&
16215                 skip "Need MDS version at least 2.8.50" && return
16216
16217         local def_stripenr=$($GETSTRIPE -c $MOUNT)
16218         local def_stripe_size=$($GETSTRIPE -S $MOUNT)
16219         local def_stripe_offset=$($GETSTRIPE -i $MOUNT)
16220         local def_pool=$($GETSTRIPE -p $MOUNT)
16221
16222         local test_pool=$TESTNAME
16223         pool_add $test_pool || error "pool_add failed"
16224         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
16225                 error "pool_add_targets failed"
16226
16227         # parent set default stripe count only, child will stripe from both
16228         # parent and fs default
16229         $SETSTRIPE -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
16230                 error "setstripe $MOUNT failed"
16231         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
16232         $SETSTRIPE -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
16233         for i in $(seq 10); do
16234                 local f=$DIR/$tdir/$tfile.$i
16235                 touch $f || error "touch failed"
16236                 local count=$($GETSTRIPE -c $f)
16237                 [ $count -eq $OSTCOUNT ] ||
16238                         error "$f stripe count $count != $OSTCOUNT"
16239                 local offset=$($GETSTRIPE -i $f)
16240                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
16241                 local size=$($GETSTRIPE -S $f)
16242                 [ $size -eq $((def_stripe_size * 2)) ] ||
16243                         error "$f stripe size $size != $((def_stripe_size * 2))"
16244                 local pool=$($GETSTRIPE -p $f)
16245                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
16246         done
16247
16248         # change fs default striping, delete parent default striping, now child
16249         # will stripe from new fs default striping only
16250         $SETSTRIPE -c 1 -S $def_stripe_size -i 0 $MOUNT ||
16251                 error "change $MOUNT default stripe failed"
16252         $SETSTRIPE -c 0 $DIR/$tdir || error "delete $tdir default stripe failed"
16253         for i in $(seq 11 20); do
16254                 local f=$DIR/$tdir/$tfile.$i
16255                 touch $f || error "touch $f failed"
16256                 local count=$($GETSTRIPE -c $f)
16257                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
16258                 local offset=$($GETSTRIPE -i $f)
16259                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
16260                 local size=$($GETSTRIPE -S $f)
16261                 [ $size -eq $def_stripe_size ] ||
16262                         error "$f stripe size $size != $def_stripe_size"
16263                 local pool=$($GETSTRIPE -p $f)
16264                 [ "#$pool" == "#" ] || error "$f pool $pool is set"
16265
16266         done
16267
16268         unlinkmany $DIR/$tdir/$tfile. 1 20
16269
16270         # restore FS default striping
16271         if [ -z $def_pool ]; then
16272                 $SETSTRIPE -c $def_stripenr -S $def_stripe_size \
16273                         -i $def_stripe_offset $MOUNT ||
16274                         error "restore default striping failed"
16275         else
16276                 $SETSTRIPE -c $def_stripenr -S $def_stripe_size -p $def_pool \
16277                         -i $def_stripe_offset $MOUNT ||
16278                         error "restore default striping with $def_pool failed"
16279         fi
16280
16281         local f=$DIR/$tdir/$tfile
16282         pool_remove_all_targets $test_pool $f
16283         pool_remove $test_pool $f
16284 }
16285 run_test 406 "DNE support fs default striping"
16286
16287 test_407() {
16288         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16289         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
16290                 skip "Need MDS version at least 2.8.55" && return
16291         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16292
16293         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
16294                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
16295         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
16296                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
16297         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
16298
16299         #define OBD_FAIL_DT_TXN_STOP    0x2019
16300         for idx in $(seq $MDSCOUNT); do
16301                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
16302         done
16303         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
16304         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
16305                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
16306         true
16307 }
16308 run_test 407 "transaction fail should cause operation fail"
16309
16310 test_408() {
16311         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
16312
16313         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
16314         lctl set_param fail_loc=0x8000040a
16315         # let ll_prepare_partial_page() fail
16316         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
16317
16318         rm -f $DIR/$tfile
16319
16320         # create at least 100 unused inodes so that
16321         # shrink_icache_memory(0) should not return 0
16322         touch $DIR/$tfile-{0..100}
16323         rm -f $DIR/$tfile-{0..100}
16324         sync
16325
16326         echo 2 > /proc/sys/vm/drop_caches
16327 }
16328 run_test 408 "drop_caches should not hang due to page leaks"
16329
16330 test_409()
16331 {
16332         [ $MDSCOUNT -lt 2 ] &&
16333                 skip "We need at least 2 MDTs for this test" && return
16334
16335         check_mount_and_prep
16336
16337         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
16338         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
16339         touch $DIR/$tdir/guard || error "(2) Fail to create"
16340
16341         local PREFIX=$(str_repeat 'A' 128)
16342         echo "Create 1K hard links start at $(date)"
16343         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16344                 error "(3) Fail to hard link"
16345
16346         echo "Links count should be right although linkEA overflow"
16347         stat $DIR/$tdir/guard || error "(4) Fail to stat"
16348         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
16349         [ $linkcount -eq 1001 ] ||
16350                 error "(5) Unexpected hard links count: $linkcount"
16351
16352         echo "List all links start at $(date)"
16353         ls -l $DIR/$tdir/foo > /dev/null ||
16354                 error "(6) Fail to list $DIR/$tdir/foo"
16355
16356         echo "Unlink hard links start at $(date)"
16357         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16358                 error "(7) Fail to unlink"
16359 }
16360 run_test 409 "Large amount of cross-MDTs hard links on the same file"
16361
16362 test_410()
16363 {
16364         # Create a file, and stat it from the kernel
16365         local testfile=$DIR/$tfile
16366         touch $testfile
16367
16368         local run_id=$RANDOM
16369         local my_ino=$(stat --format "%i" $testfile)
16370
16371         # Try to insert the module. This will always fail as the
16372         # module is designed to not be inserted.
16373         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
16374             &> /dev/null
16375
16376         # Anything but success is a test failure
16377         dmesg | grep -q \
16378             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
16379             error "no inode match"
16380 }
16381 run_test 410 "Test inode number returned from kernel thread"
16382
16383 prep_801() {
16384         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
16385         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
16386                 skip "Need server version at least 2.9.55" & exit 0
16387         start_full_debug_logging
16388 }
16389
16390 post_801() {
16391         stop_full_debug_logging
16392 }
16393
16394 barrier_stat() {
16395         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16396                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16397                            awk '/The barrier for/ { print $7 }')
16398                 echo $st
16399         else
16400                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
16401                 echo \'$st\'
16402         fi
16403 }
16404
16405 barrier_expired() {
16406         local expired
16407
16408         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16409                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16410                           awk '/will be expired/ { print $7 }')
16411         else
16412                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
16413         fi
16414
16415         echo $expired
16416 }
16417
16418 test_801a() {
16419         prep_801
16420
16421         echo "Start barrier_freeze at: $(date)"
16422         #define OBD_FAIL_BARRIER_DELAY          0x2202
16423         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
16424         do_facet mgs $LCTL barrier_freeze $FSNAME 10 &
16425
16426         sleep 2
16427         local b_status=$(barrier_stat)
16428         echo "Got barrier status at: $(date)"
16429         [ "$b_status" = "'freezing_p1'" ] ||
16430                 error "(1) unexpected barrier status $b_status"
16431
16432         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
16433         wait
16434         b_status=$(barrier_stat)
16435         [ "$b_status" = "'frozen'" ] ||
16436                 error "(2) unexpected barrier status $b_status"
16437
16438         local expired=$(barrier_expired)
16439         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
16440         sleep $((expired + 3))
16441
16442         b_status=$(barrier_stat)
16443         [ "$b_status" = "'expired'" ] ||
16444                 error "(3) unexpected barrier status $b_status"
16445
16446         do_facet mgs $LCTL barrier_freeze $FSNAME 10 ||
16447                 error "(4) fail to freeze barrier"
16448
16449         b_status=$(barrier_stat)
16450         [ "$b_status" = "'frozen'" ] ||
16451                 error "(5) unexpected barrier status $b_status"
16452
16453         echo "Start barrier_thaw at: $(date)"
16454         #define OBD_FAIL_BARRIER_DELAY          0x2202
16455         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
16456         do_facet mgs $LCTL barrier_thaw $FSNAME &
16457
16458         sleep 2
16459         b_status=$(barrier_stat)
16460         echo "Got barrier status at: $(date)"
16461         [ "$b_status" = "'thawing'" ] ||
16462                 error "(6) unexpected barrier status $b_status"
16463
16464         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
16465         wait
16466         b_status=$(barrier_stat)
16467         [ "$b_status" = "'thawed'" ] ||
16468                 error "(7) unexpected barrier status $b_status"
16469
16470         #define OBD_FAIL_BARRIER_FAILURE        0x2203
16471         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
16472         do_facet mgs $LCTL barrier_freeze $FSNAME
16473
16474         b_status=$(barrier_stat)
16475         [ "$b_status" = "'failed'" ] ||
16476                 error "(8) unexpected barrier status $b_status"
16477
16478         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
16479         do_facet mgs $LCTL barrier_thaw $FSNAME
16480
16481         post_801
16482 }
16483 run_test 801a "write barrier user interfaces and stat machine"
16484
16485 test_801b() {
16486         prep_801
16487
16488         mkdir $DIR/$tdir || error "(1) fail to mkdir"
16489         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
16490         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
16491         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
16492         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
16493
16494         cancel_lru_locks mdc
16495
16496         # 180 seconds should be long enough
16497         do_facet mgs $LCTL barrier_freeze $FSNAME 180
16498
16499         local b_status=$(barrier_stat)
16500         [ "$b_status" = "'frozen'" ] ||
16501                 error "(6) unexpected barrier status $b_status"
16502
16503         mkdir $DIR/$tdir/d0/d10 &
16504         mkdir_pid=$!
16505
16506         touch $DIR/$tdir/d1/f13 &
16507         touch_pid=$!
16508
16509         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
16510         ln_pid=$!
16511
16512         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
16513         mv_pid=$!
16514
16515         rm -f $DIR/$tdir/d4/f12 &
16516         rm_pid=$!
16517
16518         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
16519
16520         # To guarantee taht the 'stat' is not blocked
16521         b_status=$(barrier_stat)
16522         [ "$b_status" = "'frozen'" ] ||
16523                 error "(8) unexpected barrier status $b_status"
16524
16525         # let above commands to run at background
16526         sleep 5
16527
16528         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
16529         ps -p $touch_pid || error "(10) touch should be blocked"
16530         ps -p $ln_pid || error "(11) link should be blocked"
16531         ps -p $mv_pid || error "(12) rename should be blocked"
16532         ps -p $rm_pid || error "(13) unlink should be blocked"
16533
16534         b_status=$(barrier_stat)
16535         [ "$b_status" = "'frozen'" ] ||
16536                 error "(14) unexpected barrier status $b_status"
16537
16538         do_facet mgs $LCTL barrier_thaw $FSNAME
16539         b_status=$(barrier_stat)
16540         [ "$b_status" = "'thawed'" ] ||
16541                 error "(15) unexpected barrier status $b_status"
16542
16543         wait $mkdir_pid || error "(16) mkdir should succeed"
16544         wait $touch_pid || error "(17) touch should succeed"
16545         wait $ln_pid || error "(18) link should succeed"
16546         wait $mv_pid || error "(19) rename should succeed"
16547         wait $rm_pid || error "(20) unlink should succeed"
16548
16549         post_801
16550 }
16551 run_test 801b "modification will be blocked by write barrier"
16552
16553 test_801c() {
16554         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
16555
16556         prep_801
16557
16558         stop mds2 || error "(1) Fail to stop mds2"
16559
16560         do_facet mgs $LCTL barrier_freeze $FSNAME 30
16561
16562         local b_status=$(barrier_stat)
16563         [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || {
16564                 do_facet mgs $LCTL barrier_thaw $FSNAME
16565                 error "(2) unexpected barrier status $b_status"
16566         }
16567
16568         do_facet mgs $LCTL barrier_rescan $FSNAME ||
16569                 error "(3) Fail to rescan barrier bitmap"
16570
16571         do_facet mgs $LCTL barrier_freeze $FSNAME 10
16572
16573         b_status=$(barrier_stat)
16574         [ "$b_status" = "'frozen'" ] ||
16575                 error "(4) unexpected barrier status $b_status"
16576
16577         do_facet mgs $LCTL barrier_thaw $FSNAME
16578         b_status=$(barrier_stat)
16579         [ "$b_status" = "'thawed'" ] ||
16580                 error "(5) unexpected barrier status $b_status"
16581
16582         local devname=$(mdsdevname 2)
16583
16584         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
16585
16586         do_facet mgs $LCTL barrier_rescan $FSNAME ||
16587                 error "(7) Fail to rescan barrier bitmap"
16588
16589         post_801
16590 }
16591 run_test 801c "rescan barrier bitmap"
16592
16593 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
16594 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
16595 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
16596
16597 cleanup_802() {
16598         trap 0
16599
16600         stopall
16601         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
16602         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
16603         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
16604         setupall
16605 }
16606
16607 test_802() {
16608
16609         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
16610         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
16611                 skip "Need server version at least 2.9.55" & exit 0
16612
16613         mkdir $DIR/$tdir || error "(1) fail to mkdir"
16614
16615         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
16616                 error "(2) Fail to copy"
16617
16618         trap cleanup_802 EXIT
16619
16620         # sync by force before remount as readonly
16621         sync; sync_all_data; sleep 3; sync_all_data
16622
16623         stopall
16624
16625         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
16626         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
16627         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
16628
16629         echo "Mount the server as read only"
16630         setupall server_only || error "(3) Fail to start servers"
16631
16632         echo "Mount client without ro should fail"
16633         mount_client $MOUNT &&
16634                 error "(4) Mount client without 'ro' should fail"
16635
16636         echo "Mount client with ro should succeed"
16637         mount_client $MOUNT ro ||
16638                 error "(5) Mount client with 'ro' should succeed"
16639
16640         echo "Modify should be refused"
16641         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
16642
16643         echo "Read should be allowed"
16644         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
16645                 error "(7) Read should succeed under ro mode"
16646
16647         cleanup_802
16648 }
16649 run_test 802 "simulate readonly device"
16650
16651 #
16652 # tests that do cleanup/setup should be run at the end
16653 #
16654
16655 test_900() {
16656         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16657         local ls
16658         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
16659         $LCTL set_param fail_loc=0x903
16660
16661         cancel_lru_locks MGC
16662
16663         FAIL_ON_ERROR=true cleanup
16664         FAIL_ON_ERROR=true setup
16665 }
16666 run_test 900 "umount should not race with any mgc requeue thread"
16667
16668 complete $SECONDS
16669 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
16670 check_and_cleanup_lustre
16671 if [ "$I_MOUNTED" != "yes" ]; then
16672         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
16673 fi
16674 exit_status