Whamcloud - gitweb
LU-8998 test: Test 'lfs find' composite file options
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 8; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: LU-9693 LU-6493 LU-9693 3561 5188
12 ALWAYS_EXCEPT="                42a    42b      42c     45   68b $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # skipped tests: LU-8411 LU-9096 LU-9054 LU-10199
16 ALWAYS_EXCEPT="  407     253     312     56xb     $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 OSC=${OSC:-"osc"}
44
45 CC=${CC:-cc}
46 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
47 CREATETEST=${CREATETEST:-createtest}
48 LFS=${LFS:-lfs}
49 LFIND=${LFIND:-"$LFS find"}
50 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
51 LCTL=${LCTL:-lctl}
52 OPENFILE=${OPENFILE:-openfile}
53 OPENUNLINK=${OPENUNLINK:-openunlink}
54 export MULTIOP=${MULTIOP:-multiop}
55 READS=${READS:-"reads"}
56 MUNLINK=${MUNLINK:-munlink}
57 SOCKETSERVER=${SOCKETSERVER:-socketserver}
58 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
59 MEMHOG=${MEMHOG:-memhog}
60 DIRECTIO=${DIRECTIO:-directio}
61 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
62 STRIPES_PER_OBJ=-1
63 CHECK_GRANT=${CHECK_GRANT:-"yes"}
64 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
65 export PARALLEL=${PARALLEL:-"no"}
66
67 export NAME=${NAME:-local}
68
69 SAVE_PWD=$PWD
70
71 CLEANUP=${CLEANUP:-:}
72 SETUP=${SETUP:-:}
73 TRACE=${TRACE:-""}
74 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
75 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
76 . $LUSTRE/tests/test-framework.sh
77 init_test_env $@
78 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
79 init_logging
80
81 #                                  5          12          (min)"
82 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 300o"
83
84 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
85         # bug number for skipped test: LU-1957
86         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  180"
87         #                                               13    (min)"
88         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
89 fi
90
91 FAIL_ON_ERROR=false
92
93 cleanup() {
94         echo -n "cln.."
95         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
96         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
97 }
98 setup() {
99         echo -n "mnt.."
100         load_modules
101         setupall || exit 10
102         echo "done"
103 }
104
105 check_swap_layouts_support()
106 {
107         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
108                 { skip "Does not support layout lock."; return 0; }
109         return 1
110 }
111
112 check_and_setup_lustre
113 DIR=${DIR:-$MOUNT}
114 assert_DIR
115
116 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
117         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
118 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
119
120 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
121 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
122 rm -rf $DIR/[Rdfs][0-9]*
123
124 # $RUNAS_ID may get set incorrectly somewhere else
125 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
126
127 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
128
129 build_test_filter
130
131 if [ "${ONLY}" = "MOUNT" ] ; then
132         echo "Lustre is up, please go on"
133         exit
134 fi
135
136 echo "preparing for tests involving mounts"
137 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
138 touch $EXT2_DEV
139 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
140 echo # add a newline after mke2fs.
141
142 umask 077
143
144 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
145 lctl set_param debug=-1 2> /dev/null || true
146 test_0a() {
147         touch $DIR/$tfile
148         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
149         rm $DIR/$tfile
150         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
151 }
152 run_test 0a "touch; rm ====================="
153
154 test_0b() {
155         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
156         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
157 }
158 run_test 0b "chmod 0755 $DIR ============================="
159
160 test_0c() {
161         $LCTL get_param mdc.*.import | grep "state: FULL" ||
162                 error "import not FULL"
163         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
164                 error "bad target"
165 }
166 run_test 0c "check import proc"
167
168 test_1() {
169         test_mkdir $DIR/$tdir
170         test_mkdir $DIR/$tdir/d2
171         mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
172         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
173         rmdir $DIR/$tdir/d2
174         rmdir $DIR/$tdir
175         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
176 }
177 run_test 1 "mkdir; remkdir; rmdir"
178
179 test_2() {
180         test_mkdir $DIR/$tdir
181         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
182         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
183         rm -r $DIR/$tdir
184         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
185 }
186 run_test 2 "mkdir; touch; rmdir; check file"
187
188 test_3() {
189         test_mkdir $DIR/$tdir
190         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
191         touch $DIR/$tdir/$tfile
192         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
193         rm -r $DIR/$tdir
194         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
195 }
196 run_test 3 "mkdir; touch; rmdir; check dir"
197
198 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
199 test_4() {
200         test_mkdir -i 1 $DIR/$tdir
201
202         touch $DIR/$tdir/$tfile ||
203                 error "Create file under remote directory failed"
204
205         rmdir $DIR/$tdir &&
206                 error "Expect error removing in-use dir $DIR/$tdir"
207
208         test -d $DIR/$tdir || error "Remote directory disappeared"
209
210         rm -rf $DIR/$tdir || error "remove remote dir error"
211 }
212 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
213
214 test_5() {
215         test_mkdir $DIR/$tdir
216         test_mkdir $DIR/$tdir/d2
217         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
218         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
219         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
220 }
221 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2"
222
223 test_6a() {
224         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
225         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
226         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
227                 error "$tfile does not have perm 0666 or UID $UID"
228         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
229         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
230                 error "$tfile should be 0666 and owned by UID $UID"
231 }
232 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
233
234 test_6c() {
235         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
236         touch $DIR/$tfile
237         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
238         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
239                 error "$tfile should be owned by UID $RUNAS_ID"
240         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
241         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
242                 error "$tfile should be owned by UID $RUNAS_ID"
243 }
244 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
245
246 test_6e() {
247         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
248         touch $DIR/$tfile
249         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
250         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
251                 error "$tfile should be owned by GID $UID"
252         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
253         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
254                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
255 }
256 run_test 6e "touch+chgrp $tfile; $RUNAS chgrp $tfile (should return error)"
257
258 test_6g() {
259         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
260         test_mkdir $DIR/$tdir
261         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
262         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
263         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
264         test_mkdir $DIR/$tdir/d/subdir
265         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
266                 error "$tdir/d/subdir should be GID $RUNAS_GID"
267         if [[ $MDSCOUNT -gt 1 ]]; then
268                 # check remote dir sgid inherite
269                 $LFS mkdir -i 0 $DIR/$tdir.local ||
270                         error "mkdir $tdir.local failed"
271                 chmod g+s $DIR/$tdir.local ||
272                         error "chmod $tdir.local failed"
273                 chgrp $RUNAS_GID $DIR/$tdir.local ||
274                         error "chgrp $tdir.local failed"
275                 $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
276                         error "mkdir $tdir.remote failed"
277                 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
278                         error "$tdir.remote should be owned by $UID.$RUNAS_ID"
279                 $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
280                         error "$tdir.remote should be mode 02755"
281         fi
282 }
283 run_test 6g "verify new dir in sgid dir inherits group"
284
285 test_6h() { # bug 7331
286         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
287         touch $DIR/$tfile || error "touch failed"
288         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
289         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
290                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
291         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
292                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
293 }
294 run_test 6h "$RUNAS chown RUNAS_ID.0 .../$tfile (should return error)"
295
296 test_7a() {
297         test_mkdir $DIR/$tdir
298         $MCREATE $DIR/$tdir/$tfile
299         chmod 0666 $DIR/$tdir/$tfile
300         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
301                 error "$tdir/$tfile should be mode 0666"
302 }
303 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
304
305 test_7b() {
306         if [ ! -d $DIR/$tdir ]; then
307                 test_mkdir $DIR/$tdir
308         fi
309         $MCREATE $DIR/$tdir/$tfile
310         echo -n foo > $DIR/$tdir/$tfile
311         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
312         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
313 }
314 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
315
316 test_8() {
317         test_mkdir $DIR/$tdir
318         touch $DIR/$tdir/$tfile
319         chmod 0666 $DIR/$tdir/$tfile
320         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
321                 error "$tfile mode not 0666"
322 }
323 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
324
325 test_9() {
326         test_mkdir $DIR/$tdir
327         test_mkdir $DIR/$tdir/d2
328         test_mkdir $DIR/$tdir/d2/d3
329         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
330 }
331 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
332
333 test_10() {
334         test_mkdir $DIR/$tdir
335         test_mkdir $DIR/$tdir/d2
336         touch $DIR/$tdir/d2/$tfile
337         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
338                 error "$tdir/d2/$tfile not a file"
339 }
340 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
341
342 test_11() {
343         test_mkdir $DIR/$tdir
344         test_mkdir $DIR/$tdir/d2
345         chmod 0666 $DIR/$tdir/d2
346         chmod 0705 $DIR/$tdir/d2
347         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
348                 error "$tdir/d2 mode not 0705"
349 }
350 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
351
352 test_12() {
353         test_mkdir $DIR/$tdir
354         touch $DIR/$tdir/$tfile
355         chmod 0666 $DIR/$tdir/$tfile
356         chmod 0654 $DIR/$tdir/$tfile
357         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
358                 error "$tdir/d2 mode not 0654"
359 }
360 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
361
362 test_13() {
363         test_mkdir $DIR/$tdir
364         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
365         >  $DIR/$tdir/$tfile
366         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
367                 error "$tdir/$tfile size not 0 after truncate"
368 }
369 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
370
371 test_14() {
372         test_mkdir $DIR/$tdir
373         touch $DIR/$tdir/$tfile
374         rm $DIR/$tdir/$tfile
375         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
376 }
377 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
378
379 test_15() {
380         test_mkdir $DIR/$tdir
381         touch $DIR/$tdir/$tfile
382         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
383         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
384                 error "$tdir/${tfile_2} not a file after rename"
385         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
386 }
387 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
388
389 test_16() {
390         test_mkdir $DIR/$tdir
391         touch $DIR/$tdir/$tfile
392         rm -rf $DIR/$tdir/$tfile
393         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
394 }
395 run_test 16 "touch .../d16/f; rm -rf .../d16/f"
396
397 test_17a() {
398         test_mkdir $DIR/$tdir
399         touch $DIR/$tdir/$tfile
400         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
401         ls -l $DIR/$tdir
402         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
403                 error "$tdir/l-exist not a symlink"
404         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
405                 error "$tdir/l-exist not referencing a file"
406         rm -f $DIR/$tdir/l-exist
407         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
408 }
409 run_test 17a "symlinks: create, remove (real)"
410
411 test_17b() {
412         test_mkdir $DIR/$tdir
413         ln -s no-such-file $DIR/$tdir/l-dangle
414         ls -l $DIR/$tdir
415         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
416                 error "$tdir/l-dangle not referencing no-such-file"
417         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
418                 error "$tdir/l-dangle not referencing non-existent file"
419         rm -f $DIR/$tdir/l-dangle
420         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
421 }
422 run_test 17b "symlinks: create, remove (dangling)"
423
424 test_17c() { # bug 3440 - don't save failed open RPC for replay
425         test_mkdir $DIR/$tdir
426         ln -s foo $DIR/$tdir/$tfile
427         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
428 }
429 run_test 17c "symlinks: open dangling (should return error)"
430
431 test_17d() {
432         test_mkdir $DIR/$tdir
433         ln -s foo $DIR/$tdir/$tfile
434         touch $DIR/$tdir/$tfile || error "creating to new symlink"
435 }
436 run_test 17d "symlinks: create dangling"
437
438 test_17e() {
439         test_mkdir $DIR/$tdir
440         local foo=$DIR/$tdir/$tfile
441         ln -s $foo $foo || error "create symlink failed"
442         ls -l $foo || error "ls -l failed"
443         ls $foo && error "ls not failed" || true
444 }
445 run_test 17e "symlinks: create recursive symlink (should return error)"
446
447 test_17f() {
448         test_mkdir $DIR/$tdir
449         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
450         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
451         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
452         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
453         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
454         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
455         ls -l  $DIR/$tdir
456 }
457 run_test 17f "symlinks: long and very long symlink name"
458
459 # str_repeat(S, N) generate a string that is string S repeated N times
460 str_repeat() {
461         local s=$1
462         local n=$2
463         local ret=''
464         while [ $((n -= 1)) -ge 0 ]; do
465                 ret=$ret$s
466         done
467         echo $ret
468 }
469
470 # Long symlinks and LU-2241
471 test_17g() {
472         test_mkdir $DIR/$tdir
473         local TESTS="59 60 61 4094 4095"
474
475         # Fix for inode size boundary in 2.1.4
476         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
477                 TESTS="4094 4095"
478
479         # Patch not applied to 2.2 or 2.3 branches
480         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
481         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
482                 TESTS="4094 4095"
483
484         # skip long symlink name for rhel6.5.
485         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
486         grep -q '6.5' /etc/redhat-release &>/dev/null &&
487                 TESTS="59 60 61 4062 4063"
488
489         for i in $TESTS; do
490                 local SYMNAME=$(str_repeat 'x' $i)
491                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
492                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
493         done
494 }
495 run_test 17g "symlinks: really long symlink name and inode boundaries"
496
497 test_17h() { #bug 17378
498         remote_mds_nodsh && skip "remote MDS with nodsh" && return
499         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
500         local mdt_idx
501         test_mkdir $DIR/$tdir
502         if [[ $MDSCOUNT -gt 1 ]]; then
503                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
504         else
505                 mdt_idx=0
506         fi
507         $LFS setstripe -c -1 $DIR/$tdir
508         #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
509         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
510         touch $DIR/$tdir/$tfile || true
511 }
512 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
513
514 test_17i() { #bug 20018
515         remote_mds_nodsh && skip "remote MDS with nodsh" && return
516         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
517         test_mkdir -c1 $DIR/$tdir
518         local foo=$DIR/$tdir/$tfile
519         local mdt_idx
520         if [[ $MDSCOUNT -gt 1 ]]; then
521                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
522         else
523                 mdt_idx=0
524         fi
525         ln -s $foo $foo || error "create symlink failed"
526 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
527         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
528         ls -l $foo && error "error not detected"
529         return 0
530 }
531 run_test 17i "don't panic on short symlink"
532
533 test_17k() { #bug 22301
534         [[ -z "$(which rsync 2>/dev/null)" ]] &&
535                 skip "no rsync command" && return 0
536         rsync --help | grep -q xattr ||
537                 skip_env "$(rsync --version | head -n1) does not support xattrs"
538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
539         test_mkdir $DIR/$tdir
540         test_mkdir $DIR/$tdir.new
541         touch $DIR/$tdir/$tfile
542         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
543         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
544                 error "rsync failed with xattrs enabled"
545 }
546 run_test 17k "symlinks: rsync with xattrs enabled"
547
548 test_17l() { # LU-279
549         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
550                 skip "no getfattr command" && return 0
551         test_mkdir $DIR/$tdir
552         touch $DIR/$tdir/$tfile
553         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
554         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
555                 # -h to not follow symlinks. -m '' to list all the xattrs.
556                 # grep to remove first line: '# file: $path'.
557                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
558                 do
559                         lgetxattr_size_check $path $xattr ||
560                                 error "lgetxattr_size_check $path $xattr failed"
561                 done
562         done
563 }
564 run_test 17l "Ensure lgetxattr's returned xattr size is consistent"
565
566 # LU-1540
567 test_17m() {
568         local short_sym="0123456789"
569         local wdir=$DIR/$tdir
570         local i
571
572         remote_mds_nodsh && skip "remote MDS with nodsh" && return
573         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
574         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
575                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
576
577         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
578                 skip "ldiskfs only test" && return 0
579
580         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
581
582         test_mkdir $wdir
583         long_sym=$short_sym
584         # create a long symlink file
585         for ((i = 0; i < 4; ++i)); do
586                 long_sym=${long_sym}${long_sym}
587         done
588
589         echo "create 512 short and long symlink files under $wdir"
590         for ((i = 0; i < 256; ++i)); do
591                 ln -sf ${long_sym}"a5a5" $wdir/long-$i
592                 ln -sf ${short_sym}"a5a5" $wdir/short-$i
593         done
594
595         echo "erase them"
596         rm -f $wdir/*
597         sync
598         wait_delete_completed
599
600         echo "recreate the 512 symlink files with a shorter string"
601         for ((i = 0; i < 512; ++i)); do
602                 # rewrite the symlink file with a shorter string
603                 ln -sf ${long_sym} $wdir/long-$i || error "long_sym failed"
604                 ln -sf ${short_sym} $wdir/short-$i || error "short_sym failed"
605         done
606
607         local mds_index=$(($($LFS getstripe -M $wdir) + 1))
608         local devname=$(mdsdevname $mds_index)
609
610         echo "stop and checking mds${mds_index}:"
611         # e2fsck should not return error
612         stop mds${mds_index}
613         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
614         rc=$?
615
616         start mds${mds_index} $devname $MDS_MOUNT_OPTS ||
617                 error "start mds${mds_index} failed"
618         df $MOUNT > /dev/null 2>&1
619         [ $rc -eq 0 ] ||
620                 error "e2fsck detected error for short/long symlink: rc=$rc"
621 }
622 run_test 17m "run e2fsck against MDT which contains short/long symlink"
623
624 check_fs_consistency_17n() {
625         local mdt_index
626         local rc=0
627
628         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
629         # so it only check MDT1/MDT2 instead of all of MDTs.
630         for mdt_index in 1 2; do
631                 local devname=$(mdsdevname $mdt_index)
632                 # e2fsck should not return error
633                 stop mds${mdt_index}
634                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
635                         rc=$((rc + $?))
636
637                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
638                         error "mount mds$mdt_index failed"
639                 df $MOUNT > /dev/null 2>&1
640         done
641         return $rc
642 }
643
644 test_17n() {
645         local i
646
647         remote_mds_nodsh && skip "remote MDS with nodsh" && return
648         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
649         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
650                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
651
652         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
653                 skip "ldiskfs only test" && return 0
654
655         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
656
657         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
658
659         test_mkdir $DIR/$tdir
660         for ((i=0; i<10; i++)); do
661                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
662                         error "create remote dir error $i"
663                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
664                         error "create files under remote dir failed $i"
665         done
666
667         check_fs_consistency_17n ||
668                 error "e2fsck report error after create files under remote dir"
669
670         for ((i = 0; i < 10; i++)); do
671                 rm -rf $DIR/$tdir/remote_dir_${i} ||
672                         error "destroy remote dir error $i"
673         done
674
675         check_fs_consistency_17n ||
676                 error "e2fsck report error after unlink files under remote dir"
677
678         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
679                 skip "lustre < 2.4.50 does not support migrate mv " && return
680
681         for ((i = 0; i < 10; i++)); do
682                 mkdir -p $DIR/$tdir/remote_dir_${i}
683                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
684                         error "create files under remote dir failed $i"
685                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
686                         error "migrate remote dir error $i"
687         done
688         check_fs_consistency_17n || error "e2fsck report error after migration"
689
690         for ((i = 0; i < 10; i++)); do
691                 rm -rf $DIR/$tdir/remote_dir_${i} ||
692                         error "destroy remote dir error $i"
693         done
694
695         check_fs_consistency_17n || error "e2fsck report error after unlink"
696 }
697 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
698
699 test_17o() {
700         remote_mds_nodsh && skip "remote MDS with nodsh" && return
701         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
702                 skip "Need MDS version at least 2.3.64" && return
703
704         local wdir=$DIR/${tdir}o
705         local mdt_index
706         local rc=0
707
708         test_mkdir $wdir
709         touch $wdir/$tfile
710         mdt_index=$($LFS getstripe -M $wdir/$tfile)
711         mdt_index=$((mdt_index + 1))
712
713         cancel_lru_locks mdc
714         #fail mds will wait the failover finish then set
715         #following fail_loc to avoid interfer the recovery process.
716         fail mds${mdt_index}
717
718         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
719         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
720         ls -l $wdir/$tfile && rc=1
721         do_facet mds${mdt_index} lctl set_param fail_loc=0
722         [[ $rc -eq 0 ]] || error "stat file should fail"
723 }
724 run_test 17o "stat file with incompat LMA feature"
725
726 test_18() {
727         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
728         ls $DIR || error "Failed to ls $DIR: $?"
729 }
730 run_test 18 "touch .../f ; ls ... =============================="
731
732 test_19a() {
733         touch $DIR/$tfile
734         ls -l $DIR
735         rm $DIR/$tfile
736         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
737 }
738 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
739
740 test_19b() {
741         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
742 }
743 run_test 19b "ls -l .../f19 (should return error) =============="
744
745 test_19c() {
746         [ $RUNAS_ID -eq $UID ] &&
747                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
748         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
749 }
750 run_test 19c "$RUNAS touch .../f19 (should return error) =="
751
752 test_19d() {
753         cat $DIR/f19 && error || true
754 }
755 run_test 19d "cat .../f19 (should return error) =============="
756
757 test_20() {
758         touch $DIR/$tfile
759         rm $DIR/$tfile
760         touch $DIR/$tfile
761         rm $DIR/$tfile
762         touch $DIR/$tfile
763         rm $DIR/$tfile
764         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
765 }
766 run_test 20 "touch .../f ; ls -l ..."
767
768 test_21() {
769         test_mkdir $DIR/$tdir
770         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
771         ln -s dangle $DIR/$tdir/link
772         echo foo >> $DIR/$tdir/link
773         cat $DIR/$tdir/dangle
774         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
775         $CHECKSTAT -f -t file $DIR/$tdir/link ||
776                 error "$tdir/link not linked to a file"
777 }
778 run_test 21 "write to dangling link"
779
780 test_22() {
781         local wdir=$DIR/$tdir
782         test_mkdir $wdir
783         chown $RUNAS_ID:$RUNAS_GID $wdir
784         (cd $wdir || error "cd $wdir failed";
785                 $RUNAS tar cf - /etc/hosts /etc/sysconfig/network |
786                 $RUNAS tar xf -)
787         ls -lR $wdir/etc || error "ls -lR $wdir/etc failed"
788         $CHECKSTAT -t dir $wdir/etc || error "checkstat -t dir failed"
789         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $wdir/etc ||
790                 error "checkstat -u failed"
791 }
792 run_test 22 "unpack tar archive as non-root user"
793
794 # was test_23
795 test_23a() {
796         test_mkdir $DIR/$tdir
797         local file=$DIR/$tdir/$tfile
798
799         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
800         openfile -f O_CREAT:O_EXCL $file &&
801                 error "$file recreate succeeded" || true
802 }
803 run_test 23a "O_CREAT|O_EXCL in subdir"
804
805 test_23b() { # bug 18988
806         test_mkdir $DIR/$tdir
807         local file=$DIR/$tdir/$tfile
808
809         rm -f $file
810         echo foo > $file || error "write filed"
811         echo bar >> $file || error "append filed"
812         $CHECKSTAT -s 8 $file || error "wrong size"
813         rm $file
814 }
815 run_test 23b "O_APPEND check"
816
817 # rename sanity
818 test_24a() {
819         echo '-- same directory rename'
820         test_mkdir $DIR/$tdir
821         touch $DIR/$tdir/$tfile.1
822         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
823         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
824 }
825 run_test 24a "rename file to non-existent target"
826
827 test_24b() {
828         test_mkdir $DIR/$tdir
829         touch $DIR/$tdir/$tfile.{1,2}
830         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
831         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
832         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
833 }
834 run_test 24b "rename file to existing target"
835
836 test_24c() {
837         test_mkdir $DIR/$tdir
838         test_mkdir $DIR/$tdir/d$testnum.1
839         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
840         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
841         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
842 }
843 run_test 24c "rename directory to non-existent target"
844
845 test_24d() {
846         test_mkdir -c1 $DIR/$tdir
847         test_mkdir -c1 $DIR/$tdir/d$testnum.1
848         test_mkdir -c1 $DIR/$tdir/d$testnum.2
849         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
850         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
851         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
852 }
853 run_test 24d "rename directory to existing target"
854
855 test_24e() {
856         echo '-- cross directory renames --'
857         test_mkdir $DIR/R5a
858         test_mkdir $DIR/R5b
859         touch $DIR/R5a/f
860         mv $DIR/R5a/f $DIR/R5b/g
861         $CHECKSTAT -a $DIR/R5a/f || error
862         $CHECKSTAT -t file $DIR/R5b/g || error
863 }
864 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
865
866 test_24f() {
867         test_mkdir $DIR/R6a
868         test_mkdir $DIR/R6b
869         touch $DIR/R6a/f $DIR/R6b/g
870         mv $DIR/R6a/f $DIR/R6b/g
871         $CHECKSTAT -a $DIR/R6a/f || error
872         $CHECKSTAT -t file $DIR/R6b/g || error
873 }
874 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
875
876 test_24g() {
877         test_mkdir $DIR/R7a
878         test_mkdir $DIR/R7b
879         test_mkdir $DIR/R7a/d
880         mv $DIR/R7a/d $DIR/R7b/e
881         $CHECKSTAT -a $DIR/R7a/d || error
882         $CHECKSTAT -t dir $DIR/R7b/e || error
883 }
884 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
885
886 test_24h() {
887         test_mkdir -c1 $DIR/R8a
888         test_mkdir -c1 $DIR/R8b
889         test_mkdir -c1 $DIR/R8a/d
890         test_mkdir -c1 $DIR/R8b/e
891         mrename $DIR/R8a/d $DIR/R8b/e
892         $CHECKSTAT -a $DIR/R8a/d || error
893         $CHECKSTAT -t dir $DIR/R8b/e || error
894 }
895 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
896
897 test_24i() {
898         echo "-- rename error cases"
899         test_mkdir $DIR/R9
900         test_mkdir $DIR/R9/a
901         touch $DIR/R9/f
902         mrename $DIR/R9/f $DIR/R9/a
903         $CHECKSTAT -t file $DIR/R9/f || error
904         $CHECKSTAT -t dir  $DIR/R9/a || error
905         $CHECKSTAT -a $DIR/R9/a/f || error
906 }
907 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
908
909 test_24j() {
910         test_mkdir $DIR/R10
911         mrename $DIR/R10/f $DIR/R10/g
912         $CHECKSTAT -t dir $DIR/R10 || error
913         $CHECKSTAT -a $DIR/R10/f || error
914         $CHECKSTAT -a $DIR/R10/g || error
915 }
916 run_test 24j "source does not exist ============================"
917
918 test_24k() {
919         test_mkdir $DIR/R11a
920         test_mkdir $DIR/R11a/d
921         touch $DIR/R11a/f
922         mv $DIR/R11a/f $DIR/R11a/d
923         $CHECKSTAT -a $DIR/R11a/f || error
924         $CHECKSTAT -t file $DIR/R11a/d/f || error
925 }
926 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
927
928 # bug 2429 - rename foo foo foo creates invalid file
929 test_24l() {
930         f="$DIR/f24l"
931         $MULTIOP $f OcNs || error
932 }
933 run_test 24l "Renaming a file to itself ========================"
934
935 test_24m() {
936         f="$DIR/f24m"
937         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
938         # on ext3 this does not remove either the source or target files
939         # though the "expected" operation would be to remove the source
940         $CHECKSTAT -t file ${f} || error "${f} missing"
941         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
942 }
943 run_test 24m "Renaming a file to a hard link to itself ========="
944
945 test_24n() {
946     f="$DIR/f24n"
947     # this stats the old file after it was renamed, so it should fail
948     touch ${f}
949     $CHECKSTAT ${f}
950     mv ${f} ${f}.rename
951     $CHECKSTAT ${f}.rename
952     $CHECKSTAT -a ${f}
953 }
954 run_test 24n "Statting the old file after renaming (Posix rename 2)"
955
956 test_24o() {
957         test_mkdir $DIR/$tdir
958         rename_many -s random -v -n 10 $DIR/$tdir
959 }
960 run_test 24o "rename of files during htree split"
961
962 test_24p() {
963         test_mkdir $DIR/R12a
964         test_mkdir $DIR/R12b
965         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
966         mrename $DIR/R12a $DIR/R12b
967         $CHECKSTAT -a $DIR/R12a || error
968         $CHECKSTAT -t dir $DIR/R12b || error
969         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
970         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
971 }
972 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
973
974 cleanup_multiop_pause() {
975         trap 0
976         kill -USR1 $MULTIPID
977 }
978
979 test_24q() {
980         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
981         test_mkdir $DIR/R13a
982         test_mkdir $DIR/R13b
983         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
984         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
985         MULTIPID=$!
986
987         trap cleanup_multiop_pause EXIT
988         mrename $DIR/R13a $DIR/R13b
989         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
990         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
991         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
992         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
993         cleanup_multiop_pause
994         wait $MULTIPID || error "multiop close failed"
995 }
996 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
997
998 test_24r() { #bug 3789
999         test_mkdir $DIR/R14a
1000         test_mkdir $DIR/R14a/b
1001         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1002         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1003         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1004 }
1005 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1006
1007 test_24s() {
1008         test_mkdir $DIR/R15a
1009         test_mkdir $DIR/R15a/b
1010         test_mkdir $DIR/R15a/b/c
1011         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1012         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1013         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1014 }
1015 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1016 test_24t() {
1017         test_mkdir $DIR/R16a
1018         test_mkdir $DIR/R16a/b
1019         test_mkdir $DIR/R16a/b/c
1020         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1021         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1022         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1023 }
1024 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1025
1026 test_24u() { # bug12192
1027         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1028         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1029 }
1030 run_test 24u "create stripe file"
1031
1032 page_size() {
1033         local size
1034         size=$(getconf PAGE_SIZE 2>/dev/null)
1035         echo -n ${size:-4096}
1036 }
1037
1038 simple_cleanup_common() {
1039         local rc=0
1040         trap 0
1041         [ -z "$DIR" -o -z "$tdir" ] && return 0
1042
1043         local start=$SECONDS
1044         rm -rf $DIR/$tdir
1045         rc=$?
1046         wait_delete_completed
1047         echo "cleanup time $((SECONDS - start))"
1048         return $rc
1049 }
1050
1051 max_pages_per_rpc() {
1052         local mdtname="$(printf "MDT%04x" ${1:-0})"
1053         $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
1054 }
1055
1056 test_24v() {
1057         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1058         local nrfiles=${COUNT:-100000}
1059         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1060         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && nrfiles=${COUNT:-10000}
1061
1062         local fname="$DIR/$tdir/$tfile"
1063         test_mkdir "$(dirname $fname)"
1064         # assume MDT0000 has the fewest inodes
1065         local stripes=$($LFS getdirstripe -c $(dirname $fname))
1066         local free_inodes=$(($(mdt_free_inodes 0) * stripes))
1067         [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
1068
1069         trap simple_cleanup_common EXIT
1070
1071         createmany -m "$fname" $nrfiles
1072
1073         cancel_lru_locks mdc
1074         lctl set_param mdc.*.stats clear
1075
1076         # was previously test_24D: LU-6101
1077         # readdir() returns correct number of entries after cursor reload
1078         local num_ls=$(ls $DIR/$tdir | wc -l)
1079         local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
1080         local num_all=$(ls -a $DIR/$tdir | wc -l)
1081         if [ $num_ls -ne $nrfiles -o $num_uniq -ne $nrfiles -o \
1082              $num_all -ne $((nrfiles + 2)) ]; then
1083                 error "Expected $nrfiles files, got $num_ls " \
1084                         "($num_uniq unique $num_all .&..)"
1085         fi
1086         # LU-5 large readdir
1087         # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
1088         #               N bytes for name (len($nrfiles) rounded to 8 bytes) +
1089         #               8 bytes for luda_type (4 bytes rounded to 8 bytes)
1090         # take into account of overhead in lu_dirpage header and end mark in
1091         # each page, plus one in rpc_num calculation.
1092         local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
1093         local page_entries=$((($(page_size) - 24) / dirent_size))
1094         local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
1095         local rpc_pages=$(max_pages_per_rpc $mdt_idx)
1096         local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
1097         local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
1098         echo "readpages: $mds_readpage rpc_max: $rpc_max"
1099         (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
1100                 error "large readdir doesn't take effect: " \
1101                       "$mds_readpage should be about $rpc_max"
1102
1103         simple_cleanup_common
1104 }
1105 run_test 24v "list large directory (test hash collision, b=17560)"
1106
1107 test_24w() { # bug21506
1108         SZ1=234852
1109         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1110         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1111         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1112         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1113         [[ "$SZ1" -eq "$SZ2" ]] ||
1114                 error "Error reading at the end of the file $tfile"
1115 }
1116 run_test 24w "Reading a file larger than 4Gb"
1117
1118 test_24x() {
1119         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1120
1121         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1122                 skip "Need MDS version at least 2.7.56" && return
1123
1124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1125         local MDTIDX=1
1126         local remote_dir=$DIR/$tdir/remote_dir
1127
1128         test_mkdir $DIR/$tdir
1129         $LFS mkdir -i $MDTIDX $remote_dir ||
1130                 error "create remote directory failed"
1131
1132         test_mkdir $DIR/$tdir/src_dir
1133         touch $DIR/$tdir/src_file
1134         test_mkdir $remote_dir/tgt_dir
1135         touch $remote_dir/tgt_file
1136
1137         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1138                 error "rename dir cross MDT failed!"
1139
1140         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1141                 error "rename file cross MDT failed!"
1142
1143         touch $DIR/$tdir/ln_file
1144         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1145                 error "ln file cross MDT failed"
1146
1147         rm -rf $DIR/$tdir || error "Can not delete directories"
1148 }
1149 run_test 24x "cross MDT rename/link"
1150
1151 test_24y() {
1152         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1153         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1154         local remote_dir=$DIR/$tdir/remote_dir
1155         local mdtidx=1
1156
1157         test_mkdir $DIR/$tdir
1158         $LFS mkdir -i $mdtidx $remote_dir ||
1159                    error "create remote directory failed"
1160
1161         test_mkdir $remote_dir/src_dir
1162         touch $remote_dir/src_file
1163         test_mkdir $remote_dir/tgt_dir
1164         touch $remote_dir/tgt_file
1165
1166         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1167                 error "rename subdir in the same remote dir failed!"
1168
1169         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1170                 error "rename files in the same remote dir failed!"
1171
1172         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1173                 error "link files in the same remote dir failed!"
1174
1175         rm -rf $DIR/$tdir || error "Can not delete directories"
1176 }
1177 run_test 24y "rename/link on the same dir should succeed"
1178
1179 test_24A() { # LU-3182
1180         local NFILES=5000
1181
1182         rm -rf $DIR/$tdir
1183         test_mkdir $DIR/$tdir
1184         trap simple_cleanup_common EXIT
1185         createmany -m $DIR/$tdir/$tfile $NFILES
1186         local t=$(ls $DIR/$tdir | wc -l)
1187         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1188         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1189         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1190                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1191         fi
1192
1193         simple_cleanup_common || error "Can not delete directories"
1194 }
1195 run_test 24A "readdir() returns correct number of entries."
1196
1197 test_24B() { # LU-4805
1198         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1199         local count
1200
1201         test_mkdir $DIR/$tdir
1202         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1203                 error "create striped dir failed"
1204
1205         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1206         [ $count -eq 2 ] || error "Expected 2, got $count"
1207
1208         touch $DIR/$tdir/striped_dir/a
1209
1210         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1211         [ $count -eq 3 ] || error "Expected 3, got $count"
1212
1213         touch $DIR/$tdir/striped_dir/.f
1214
1215         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1216         [ $count -eq 4 ] || error "Expected 4, got $count"
1217
1218         rm -rf $DIR/$tdir || error "Can not delete directories"
1219 }
1220 run_test 24B "readdir for striped dir return correct number of entries"
1221
1222 test_24C() {
1223         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1224
1225         mkdir $DIR/$tdir
1226         mkdir $DIR/$tdir/d0
1227         mkdir $DIR/$tdir/d1
1228
1229         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1230                 error "create striped dir failed"
1231
1232         cd $DIR/$tdir/d0/striped_dir
1233
1234         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1235         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1236         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1237
1238         [ "$d0_ino" = "$parent_ino" ] ||
1239                 error ".. wrong, expect $d0_ino, get $parent_ino"
1240
1241         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1242                 error "mv striped dir failed"
1243
1244         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1245
1246         [ "$d1_ino" = "$parent_ino" ] ||
1247                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1248 }
1249 run_test 24C "check .. in striped dir"
1250
1251 test_24E() {
1252         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1253         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1254
1255         mkdir -p $DIR/$tdir
1256         mkdir $DIR/$tdir/src_dir
1257         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1258                 error "create remote source failed"
1259
1260         touch $DIR/$tdir/src_dir/src_child/a
1261
1262         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1263                 error "create remote target dir failed"
1264
1265         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1266                 error "create remote target child failed"
1267
1268         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1269                 error "rename dir cross MDT failed!"
1270
1271         find $DIR/$tdir
1272
1273         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1274                 error "src_child still exists after rename"
1275
1276         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1277                 error "missing file(a) after rename"
1278
1279         rm -rf $DIR/$tdir || error "Can not delete directories"
1280 }
1281 run_test 24E "cross MDT rename/link"
1282
1283 test_25a() {
1284         echo '== symlink sanity ============================================='
1285
1286         test_mkdir $DIR/d25
1287         ln -s d25 $DIR/s25
1288         touch $DIR/s25/foo || error
1289 }
1290 run_test 25a "create file in symlinked directory ==============="
1291
1292 test_25b() {
1293         [ ! -d $DIR/d25 ] && test_25a
1294         $CHECKSTAT -t file $DIR/s25/foo || error
1295 }
1296 run_test 25b "lookup file in symlinked directory ==============="
1297
1298 test_26a() {
1299         test_mkdir $DIR/d26
1300         test_mkdir $DIR/d26/d26-2
1301         ln -s d26/d26-2 $DIR/s26
1302         touch $DIR/s26/foo || error
1303 }
1304 run_test 26a "multiple component symlink ======================="
1305
1306 test_26b() {
1307         test_mkdir -p $DIR/$tdir/d26-2
1308         ln -s $tdir/d26-2/foo $DIR/s26-2
1309         touch $DIR/s26-2 || error
1310 }
1311 run_test 26b "multiple component symlink at end of lookup ======"
1312
1313 test_26c() {
1314         test_mkdir $DIR/d26.2
1315         touch $DIR/d26.2/foo
1316         ln -s d26.2 $DIR/s26.2-1
1317         ln -s s26.2-1 $DIR/s26.2-2
1318         ln -s s26.2-2 $DIR/s26.2-3
1319         chmod 0666 $DIR/s26.2-3/foo
1320 }
1321 run_test 26c "chain of symlinks"
1322
1323 # recursive symlinks (bug 439)
1324 test_26d() {
1325         ln -s d26-3/foo $DIR/d26-3
1326 }
1327 run_test 26d "create multiple component recursive symlink"
1328
1329 test_26e() {
1330         [ ! -h $DIR/d26-3 ] && test_26d
1331         rm $DIR/d26-3
1332 }
1333 run_test 26e "unlink multiple component recursive symlink"
1334
1335 # recursive symlinks (bug 7022)
1336 test_26f() {
1337         test_mkdir $DIR/$tdir
1338         test_mkdir $DIR/$tdir/$tfile
1339         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1340         test_mkdir -p lndir/bar1
1341         test_mkdir $DIR/$tdir/$tfile/$tfile
1342         cd $tfile                || error "cd $tfile failed"
1343         ln -s .. dotdot          || error "ln dotdot failed"
1344         ln -s dotdot/lndir lndir || error "ln lndir failed"
1345         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1346         output=`ls $tfile/$tfile/lndir/bar1`
1347         [ "$output" = bar1 ] && error "unexpected output"
1348         rm -r $tfile             || error "rm $tfile failed"
1349         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1350 }
1351 run_test 26f "rm -r of a directory which has recursive symlink"
1352
1353 test_27a() {
1354         test_mkdir $DIR/$tdir
1355         $LFS getstripe $DIR/$tdir
1356         $LFS setstripe -c 1 $DIR/$tdir/$tfile || error "setstripe failed"
1357         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1358         cp /etc/hosts $DIR/$tdir/$tfile || error
1359 }
1360 run_test 27a "one stripe file"
1361
1362 test_27b() {
1363         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1364         test_mkdir $DIR/$tdir
1365         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1366         $LFS getstripe -c $DIR/$tdir/$tfile
1367         [ $($LFS getstripe -c $DIR/$tdir/$tfile) -eq 2 ] ||
1368                 error "two-stripe file doesn't have two stripes"
1369
1370         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1371 }
1372 run_test 27b "create and write to two stripe file"
1373
1374 test_27d() {
1375         test_mkdir $DIR/$tdir
1376         $LFS setstripe -c 0 -i -1 -S 0 $DIR/$tdir/$tfile ||
1377                 error "setstripe failed"
1378         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1379         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
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 $DIR/$tdir
1388         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1389         $LFS setstripe -c 2 $DIR/$tdir/$tfile && error "setstripe worked twice"
1390         $CHECKSTAT -t file $DIR/$tdir/$tfile || 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 $DIR/$tdir
1407         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1408         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "no stripe info" ||
1409                 error "$DIR/$tdir/$tfile 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 $DIR/$tdir
1423         $LFS setstripe -i $OSTCOUNT $DIR/$tdir/$tfile &&
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 $DIR/$tdir
1430         local file=$DIR/$tdir/$tfile
1431         local ll_max_blksize=$((4 * 1024 * 1024))
1432         $LFS setstripe -S 67108864 $file || error "setstripe failed"
1433         local blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1434         [ $blksize -le $ll_max_blksize ] || error "1:$blksize > $ll_max_blksize"
1435         dd if=/dev/zero of=$file bs=4k count=1
1436         blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1437         [ $blksize -le $ll_max_blksize ] || error "2:$blksize > $ll_max_blksize"
1438 }
1439 run_test 27k "limit i_blksize for broken user apps"
1440
1441 test_27l() {
1442         mcreate $DIR/$tfile || error "creating file"
1443         $RUNAS $LFS setstripe -c 1 $DIR/$tfile &&
1444                 error "setstripe should have failed" || true
1445 }
1446 run_test 27l "check setstripe permissions (should return error)"
1447
1448 test_27m() {
1449         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1450
1451         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1452                    head -n1)
1453         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1454                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1455                 return
1456         fi
1457         trap simple_cleanup_common EXIT
1458         test_mkdir $DIR/$tdir
1459         $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.1
1460         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1024 count=$MAXFREE &&
1461                 error "dd should fill OST0"
1462         i=2
1463         while $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.$i; do
1464                 i=$((i + 1))
1465                 [ $i -gt 256 ] && break
1466         done
1467         i=$((i + 1))
1468         touch $DIR/$tdir/$tfile.$i
1469         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1470             awk '{print $1}'| grep -w "0") ] &&
1471                 error "OST0 was full but new created file still use it"
1472         i=$((i + 1))
1473         touch $DIR/$tdir/$tfile.$i
1474         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1475             awk '{print $1}'| grep -w "0") ] &&
1476                 error "OST0 was full but new created file still use it"
1477         simple_cleanup_common
1478 }
1479 run_test 27m "create file while OST0 was full"
1480
1481 sleep_maxage() {
1482         local delay=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
1483                       head -n 1 | awk '{ print $1 * 2 }')
1484         sleep $delay
1485 }
1486
1487 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1488 # if the OST isn't full anymore.
1489 reset_enospc() {
1490         local OSTIDX=${1:-""}
1491
1492         local list=$(comma_list $(osts_nodes))
1493         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1494
1495         do_nodes $list lctl set_param fail_loc=0
1496         sync    # initiate all OST_DESTROYs from MDS to OST
1497         sleep_maxage
1498 }
1499
1500 exhaust_precreations() {
1501         local OSTIDX=$1
1502         local FAILLOC=$2
1503         local FAILIDX=${3:-$OSTIDX}
1504         local ofacet=ost$((OSTIDX + 1))
1505
1506         test_mkdir -p -c1 $DIR/$tdir
1507         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1508         local mfacet=mds$((mdtidx + 1))
1509         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1510
1511         local OST=$(ostname_from_index $OSTIDX)
1512
1513         # on the mdt's osc
1514         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1515         local last_id=$(do_facet $mfacet lctl get_param -n \
1516                         osc.$mdtosc_proc1.prealloc_last_id)
1517         local next_id=$(do_facet $mfacet lctl get_param -n \
1518                         osc.$mdtosc_proc1.prealloc_next_id)
1519
1520         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1521         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1522
1523         test_mkdir -p $DIR/$tdir/${OST}
1524         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1525 #define OBD_FAIL_OST_ENOSPC              0x215
1526         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1527         echo "Creating to objid $last_id on ost $OST..."
1528         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1529         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1530         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1531         sleep_maxage
1532 }
1533
1534 exhaust_all_precreations() {
1535         local i
1536         for (( i=0; i < OSTCOUNT; i++ )) ; do
1537                 exhaust_precreations $i $1 -1
1538         done
1539 }
1540
1541 test_27n() {
1542         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1544         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1545         remote_ost_nodsh && skip "remote OST with nodsh" && return
1546
1547         reset_enospc
1548         rm -f $DIR/$tdir/$tfile
1549         exhaust_precreations 0 0x80000215
1550         $LFS setstripe -c -1 $DIR/$tdir
1551         touch $DIR/$tdir/$tfile || error
1552         $LFS getstripe $DIR/$tdir/$tfile
1553         reset_enospc
1554 }
1555 run_test 27n "create file with some full OSTs"
1556
1557 test_27o() {
1558         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1560         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1561         remote_ost_nodsh && skip "remote OST with nodsh" && return
1562
1563         reset_enospc
1564         rm -f $DIR/$tdir/$tfile
1565         exhaust_all_precreations 0x215
1566
1567         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1568
1569         reset_enospc
1570         rm -rf $DIR/$tdir/*
1571 }
1572 run_test 27o "create file with all full OSTs (should error)"
1573
1574 test_27p() {
1575         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1576         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1577         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1578         remote_ost_nodsh && skip "remote OST with nodsh" && return
1579
1580         reset_enospc
1581         rm -f $DIR/$tdir/$tfile
1582         test_mkdir $DIR/$tdir
1583
1584         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1585         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1586         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1587
1588         exhaust_precreations 0 0x80000215
1589         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1590         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1591         $LFS getstripe $DIR/$tdir/$tfile
1592
1593         reset_enospc
1594 }
1595 run_test 27p "append to a truncated file with some full OSTs"
1596
1597 test_27q() {
1598         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1599         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1600         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1601         remote_ost_nodsh && skip "remote OST with nodsh" && return
1602
1603         reset_enospc
1604         rm -f $DIR/$tdir/$tfile
1605
1606         test_mkdir $DIR/$tdir
1607         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1608         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||
1609                 error "truncate $DIR/$tdir/$tfile failed"
1610         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1611
1612         exhaust_all_precreations 0x215
1613
1614         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1615         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1616
1617         reset_enospc
1618 }
1619 run_test 27q "append to truncated file with all OSTs full (should error)"
1620
1621 test_27r() {
1622         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1623         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1624         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1625         remote_ost_nodsh && skip "remote OST with nodsh" && return
1626
1627         reset_enospc
1628         rm -f $DIR/$tdir/$tfile
1629         exhaust_precreations 0 0x80000215
1630
1631         $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile # && error
1632
1633         reset_enospc
1634 }
1635 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1636
1637 test_27s() { # bug 10725
1638         test_mkdir $DIR/$tdir
1639         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1640         local stripe_count=0
1641         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1642         $LFS setstripe -S $stripe_size -c $stripe_count $DIR/$tdir &&
1643                 error "stripe width >= 2^32 succeeded" || true
1644
1645 }
1646 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1647
1648 test_27t() { # bug 10864
1649         WDIR=$(pwd)
1650         WLFS=$(which lfs)
1651         cd $DIR
1652         touch $tfile
1653         $WLFS getstripe $tfile
1654         cd $WDIR
1655 }
1656 run_test 27t "check that utils parse path correctly"
1657
1658 test_27u() { # bug 4900
1659         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1660         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1661         local index
1662         local list=$(comma_list $(mdts_nodes))
1663
1664 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1665         do_nodes $list $LCTL set_param fail_loc=0x139
1666         test_mkdir -p $DIR/$tdir
1667         trap simple_cleanup_common EXIT
1668         createmany -o $DIR/$tdir/t- 1000
1669         do_nodes $list $LCTL set_param fail_loc=0
1670
1671         TLOG=$TMP/$tfile.getstripe
1672         $LFS getstripe $DIR/$tdir > $TLOG
1673         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1674         unlinkmany $DIR/$tdir/t- 1000
1675         trap 0
1676         [[ $OBJS -gt 0 ]] &&
1677                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1678 }
1679 run_test 27u "skip object creation on OSC w/o objects"
1680
1681 test_27v() { # bug 4900
1682         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1683         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1684         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1685         remote_ost_nodsh && skip "remote OST with nodsh" && return
1686
1687         exhaust_all_precreations 0x215
1688         reset_enospc
1689
1690         $LFS setstripe -c 1 $DIR/$tdir         # 1 stripe / file
1691
1692         touch $DIR/$tdir/$tfile
1693         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1694         # all except ost1
1695         for (( i=1; i < OSTCOUNT; i++ )); do
1696                 do_facet ost$i lctl set_param fail_loc=0x705
1697         done
1698         local START=`date +%s`
1699         createmany -o $DIR/$tdir/$tfile 32
1700
1701         local FINISH=`date +%s`
1702         local TIMEOUT=`lctl get_param -n timeout`
1703         local PROCESS=$((FINISH - START))
1704         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1705                error "$FINISH - $START >= $TIMEOUT / 2"
1706         sleep $((TIMEOUT / 2 - PROCESS))
1707         reset_enospc
1708 }
1709 run_test 27v "skip object creation on slow OST"
1710
1711 test_27w() { # bug 10997
1712         test_mkdir $DIR/$tdir
1713         $LFS setstripe -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1714         [ $($LFS getstripe -S $DIR/$tdir/f0) -ne 65536 ] &&
1715                 error "stripe size $size != 65536" || true
1716         [ $($LFS getstripe -d $DIR/$tdir | grep -c "stripe_count") -eq 0 ] &&
1717                 error "$LFS getstripe -d $DIR/$tdir no 'stripe_count'" || true
1718 }
1719 run_test 27w "check $LFS setstripe -S and getstrip -d options"
1720
1721 test_27wa() {
1722         [[ $OSTCOUNT -lt 2 ]] &&
1723                 skip_env "skipping multiple stripe count/offset test" && return
1724
1725         test_mkdir $DIR/$tdir
1726         for i in $(seq 1 $OSTCOUNT); do
1727                 offset=$((i - 1))
1728                 $LFS setstripe -c $i -i $offset $DIR/$tdir/f$i ||
1729                         error "setstripe -c $i -i $offset failed"
1730                 count=$($LFS getstripe -c $DIR/$tdir/f$i)
1731                 index=$($LFS getstripe -i $DIR/$tdir/f$i)
1732                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1733                 [ $index -ne $offset ] &&
1734                         error "stripe offset $index != $offset" || true
1735         done
1736 }
1737 run_test 27wa "check $LFS setstripe -c -i options"
1738
1739 test_27x() {
1740         remote_ost_nodsh && skip "remote OST with nodsh" && return
1741         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1742         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1743         OFFSET=$(($OSTCOUNT - 1))
1744         OSTIDX=0
1745         local OST=$(ostname_from_index $OSTIDX)
1746
1747         test_mkdir $DIR/$tdir
1748         $LFS setstripe -c 1 $DIR/$tdir  # 1 stripe per file
1749         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1750         sleep_maxage
1751         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1752         for i in $(seq 0 $OFFSET); do
1753                 [ $($LFS getstripe $DIR/$tdir/$tfile$i | grep -A 10 obdidx |
1754                         awk '{print $1}' | grep -w "$OSTIDX") ] &&
1755                 error "OST0 was degraded but new created file still use it"
1756         done
1757         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1758 }
1759 run_test 27x "create files while OST0 is degraded"
1760
1761 test_27y() {
1762         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1763         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1764         remote_ost_nodsh && skip "remote OST with nodsh" && return
1765         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1766
1767         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1768         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1769                 osc.$mdtosc.prealloc_last_id)
1770         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1771                 osc.$mdtosc.prealloc_next_id)
1772         local fcount=$((last_id - next_id))
1773         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1774         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1775
1776         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1777                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1778         local OST_DEACTIVE_IDX=-1
1779         local OSC
1780         local OSTIDX
1781         local OST
1782
1783         for OSC in $MDS_OSCS; do
1784                 OST=$(osc_to_ost $OSC)
1785                 OSTIDX=$(index_from_ostuuid $OST)
1786                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1787                         OST_DEACTIVE_IDX=$OSTIDX
1788                 fi
1789                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1790                         echo $OSC "is Deactivated:"
1791                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1792                 fi
1793         done
1794
1795         OSTIDX=$(index_from_ostuuid $OST)
1796         test_mkdir $DIR/$tdir
1797         $LFS setstripe -c 1 $DIR/$tdir      # 1 stripe / file
1798
1799         for OSC in $MDS_OSCS; do
1800                 OST=$(osc_to_ost $OSC)
1801                 OSTIDX=$(index_from_ostuuid $OST)
1802                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1803                         echo $OST "is degraded:"
1804                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1805                                                 obdfilter.$OST.degraded=1
1806                 fi
1807         done
1808
1809         sleep_maxage
1810         createmany -o $DIR/$tdir/$tfile $fcount
1811
1812         for OSC in $MDS_OSCS; do
1813                 OST=$(osc_to_ost $OSC)
1814                 OSTIDX=$(index_from_ostuuid $OST)
1815                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1816                         echo $OST "is recovered from degraded:"
1817                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1818                                                 obdfilter.$OST.degraded=0
1819                 else
1820                         do_facet $SINGLEMDS lctl --device %$OSC activate
1821                 fi
1822         done
1823
1824         # all osp devices get activated, hence -1 stripe count restored
1825         local stripe_count=0
1826
1827         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1828         # devices get activated.
1829         sleep_maxage
1830         $LFS setstripe -c -1 $DIR/$tfile
1831         stripe_count=$($LFS getstripe -c $DIR/$tfile)
1832         rm -f $DIR/$tfile
1833         [ $stripe_count -ne $OSTCOUNT ] &&
1834                 error "Of $OSTCOUNT OSTs, only $stripe_count is available"
1835         return 0
1836 }
1837 run_test 27y "create files while OST0 is degraded and the rest inactive"
1838
1839 check_seq_oid()
1840 {
1841         log "check file $1"
1842
1843         lmm_count=$($GETSTRIPE -c $1)
1844         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1845         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1846
1847         local old_ifs="$IFS"
1848         IFS=$'[:]'
1849         fid=($($LFS path2fid $1))
1850         IFS="$old_ifs"
1851
1852         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1853         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1854
1855         # compare lmm_seq and lu_fid->f_seq
1856         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1857         # compare lmm_object_id and lu_fid->oid
1858         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1859
1860         # check the trusted.fid attribute of the OST objects of the file
1861         local have_obdidx=false
1862         local stripe_nr=0
1863         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1864                 # skip lines up to and including "obdidx"
1865                 [ -z "$obdidx" ] && break
1866                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1867                 $have_obdidx || continue
1868
1869                 local ost=$((obdidx + 1))
1870                 local dev=$(ostdevname $ost)
1871                 local oid_hex
1872
1873                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1874
1875                 seq=$(echo $seq | sed -e "s/^0x//g")
1876                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1877                         oid_hex=$(echo $oid)
1878                 else
1879                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1880                 fi
1881                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1882
1883                 local ff=""
1884                 #
1885                 # Don't unmount/remount the OSTs if we don't need to do that.
1886                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1887                 # update too, until that use mount/ll_decode_filter_fid/mount.
1888                 # Re-enable when debugfs will understand new filter_fid.
1889                 #
1890                 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
1891                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1892                                 $dev 2>/dev/null" | grep "parent=")
1893                 fi
1894                 if [ -z "$ff" ]; then
1895                         stop ost$ost
1896                         mount_fstype ost$ost
1897                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1898                                 $(facet_mntpt ost$ost)/$obj_file)
1899                         unmount_fstype ost$ost
1900                         start ost$ost $dev $OST_MOUNT_OPTS
1901                         clients_up
1902                 fi
1903
1904                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1905
1906                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1907
1908                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1909                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1910                 #
1911                 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
1912                 #       stripe_size=1048576 component_id=1 component_start=0 \
1913                 #       component_end=33554432
1914                 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
1915                 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
1916                 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
1917                 local ff_pstripe
1918                 if grep -q 'stripe=' <<<$ff; then
1919                         ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
1920                 else
1921                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1922                         # into f_ver in this case.  See comment on ff_parent.
1923                         ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
1924                 fi
1925
1926                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1927                 [ $ff_pseq = $lmm_seq ] ||
1928                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1929                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1930                 [ $ff_poid = $lmm_oid ] ||
1931                         error "FF parent OID $ff_poid != $lmm_oid"
1932                 (($ff_pstripe == $stripe_nr)) ||
1933                         error "FF stripe $ff_pstripe != $stripe_nr"
1934
1935                 stripe_nr=$((stripe_nr + 1))
1936                 [ $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
1937                         continue
1938                 if grep -q 'stripe_count=' <<<$ff; then
1939                         local ff_scnt=$(sed -e 's/.*stripe_count=//' \
1940                                             -e 's/ .*//' <<<$ff)
1941                         [ $lmm_count = $ff_scnt ] ||
1942                                 error "FF stripe count $lmm_count != $ff_scnt"
1943                 fi
1944         done
1945 }
1946
1947 test_27z() {
1948         remote_ost_nodsh && skip "remote OST with nodsh" && return
1949         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1950         test_mkdir $DIR/$tdir
1951
1952         $LFS setstripe -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1953                 { error "setstripe -c -1 failed"; return 1; }
1954         # We need to send a write to every object to get parent FID info set.
1955         # This _should_ also work for setattr, but does not currently.
1956         # touch $DIR/$tdir/$tfile-1 ||
1957         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1958                 { error "dd $tfile-1 failed"; return 2; }
1959         $LFS setstripe -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1960                 { error "setstripe -c -1 failed"; return 3; }
1961         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1962                 { error "dd $tfile-2 failed"; return 4; }
1963
1964         # make sure write RPCs have been sent to OSTs
1965         sync; sleep 5; sync
1966
1967         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1968         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1969 }
1970 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1971
1972 test_27A() { # b=19102
1973         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1974         local restore_size=$($GETSTRIPE -S $MOUNT)
1975         local restore_count=$($GETSTRIPE -c $MOUNT)
1976         local restore_offset=$($GETSTRIPE -i $MOUNT)
1977         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1978         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1979                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1980         local default_size=$($GETSTRIPE -S $MOUNT)
1981         local default_offset=$($GETSTRIPE -i $MOUNT)
1982         local dsize=$((1024 * 1024))
1983         [ $default_size -eq $dsize ] ||
1984                 error "stripe size $default_size != $dsize"
1985         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1986         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1987 }
1988 run_test 27A "check filesystem-wide default LOV EA values"
1989
1990 test_27B() { # LU-2523
1991         test_mkdir $DIR/$tdir
1992         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1993         touch $DIR/$tdir/f0
1994         # open f1 with O_LOV_DELAY_CREATE
1995         # rename f0 onto f1
1996         # call setstripe ioctl on open file descriptor for f1
1997         # close
1998         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1999                 $DIR/$tdir/f0
2000
2001         rm -f $DIR/$tdir/f1
2002         # open f1 with O_LOV_DELAY_CREATE
2003         # unlink f1
2004         # call setstripe ioctl on open file descriptor for f1
2005         # close
2006         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
2007
2008         # Allow multiop to fail in imitation of NFS's busted semantics.
2009         true
2010 }
2011 run_test 27B "call setstripe on open unlinked file/rename victim"
2012
2013 test_27C() { #LU-2871
2014         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
2015
2016         declare -a ost_idx
2017         local index
2018         local found
2019         local i
2020         local j
2021
2022         test_mkdir $DIR/$tdir
2023         cd $DIR/$tdir
2024         for i in $(seq 0 $((OSTCOUNT - 1))); do
2025                 # set stripe across all OSTs starting from OST$i
2026                 $SETSTRIPE -i $i -c -1 $tfile$i
2027                 # get striping information
2028                 ost_idx=($($GETSTRIPE $tfile$i |
2029                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2030                 echo ${ost_idx[@]}
2031
2032                 # check the layout
2033                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2034                         error "${#ost_idx[@]} != $OSTCOUNT"
2035
2036                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2037                         found=0
2038                         for j in $(echo ${ost_idx[@]}); do
2039                                 if [ $index -eq $j ]; then
2040                                         found=1
2041                                         break
2042                                 fi
2043                         done
2044                         [ $found = 1 ] ||
2045                                 error "Can not find $index in ${ost_idx[@]}"
2046                 done
2047         done
2048 }
2049 run_test 27C "check full striping across all OSTs"
2050
2051 test_27D() {
2052         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2053         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
2054         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2055         local POOL=${POOL:-testpool}
2056         local first_ost=0
2057         local last_ost=$(($OSTCOUNT - 1))
2058         local ost_step=1
2059         local ost_list=$(seq $first_ost $ost_step $last_ost)
2060         local ost_range="$first_ost $last_ost $ost_step"
2061
2062         test_mkdir $DIR/$tdir
2063         pool_add $POOL || error "pool_add failed"
2064         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2065
2066         local skip27D
2067         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ] &&
2068                 skip27D += "-s 29"
2069         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.55) -o \
2070           $(lustre_version_code client) -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 $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 $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         rm -fr $DIR/$tdir
2499         test_mkdir -p $DIR/$tdir/tmp
2500         local tmp_dir=$DIR/$tdir/tmp
2501         ln -s $DIR/$tdir $tmp_dir/symlink11
2502         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
2503         $CHECKSTAT -t link $DIR/$tdir/tmp/symlink11 || error "symlink11 bad"
2504         $CHECKSTAT -t link $DIR/$tdir/symlink01 || error "symlink01 bad"
2505 }
2506 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir"
2507
2508 test_32f() {
2509         rm -fr $DIR/$tdir
2510         test_mkdir -p $DIR/$tdir/tmp
2511         local tmp_dir=$DIR/$tdir/tmp
2512         ln -s $DIR/$tdir $tmp_dir/symlink11
2513         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
2514         ls $DIR/$tdir/tmp/symlink11  || error "symlink11 bad"
2515         ls $DIR/$tdir/symlink01 || error "symlink01 bad"
2516 }
2517 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir"
2518
2519 test_32g() {
2520         local tmp_dir=$DIR/$tdir/tmp
2521         test_mkdir -p $tmp_dir
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 "symlink12 not a link"
2526         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error "symlink02 not a link"
2527         $CHECKSTAT -t dir -f $tmp_dir/symlink12 || error "symlink12 not a dir"
2528         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error "symlink12 not a dir"
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 $tmp_dir
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 "listing symlink12"
2540         ls $DIR/$tdir/symlink02  || error "listing symlink02"
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/$tdir
2689         test_mkdir $DIR/$tdir
2690         chown $RUNAS_ID $DIR/$tdir
2691         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile ||
2692                 error "$RUNAS create $tdir/$tfile failed"
2693         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile &&
2694                 error "open RDWR" || true
2695 }
2696 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2697
2698 test_33b() {
2699         rm -fr $DIR/$tdir
2700         test_mkdir $DIR/$tdir
2701         chown $RUNAS_ID $DIR/$tdir
2702         $RUNAS $OPENFILE -f 1286739555 $DIR/$tdir/$tfile || true
2703 }
2704 run_test 33b "test open file with malformed flags (No panic)"
2705
2706 test_33c() {
2707         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2708         local ostnum
2709         local ostname
2710         local write_bytes
2711         local all_zeros
2712
2713         remote_ost_nodsh && skip "remote OST with nodsh" && return
2714         all_zeros=:
2715         rm -fr $DIR/$tdir
2716         test_mkdir $DIR/$tdir
2717         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2718
2719         sync
2720         for ostnum in $(seq $OSTCOUNT); do
2721                 # test-framework's OST numbering is one-based, while Lustre's
2722                 # is zero-based
2723                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2724                 # Parsing llobdstat's output sucks; we could grep the /proc
2725                 # path, but that's likely to not be as portable as using the
2726                 # llobdstat utility.  So we parse lctl output instead.
2727                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2728                         obdfilter/$ostname/stats |
2729                         awk '/^write_bytes/ {print $7}' )
2730                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2731                 if (( ${write_bytes:-0} > 0 ))
2732                 then
2733                         all_zeros=false
2734                         break;
2735                 fi
2736         done
2737
2738         $all_zeros || return 0
2739
2740         # Write four bytes
2741         echo foo > $DIR/$tdir/bar
2742         # Really write them
2743         sync
2744
2745         # Total up write_bytes after writing.  We'd better find non-zeros.
2746         for ostnum in $(seq $OSTCOUNT); do
2747                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2748                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2749                         obdfilter/$ostname/stats |
2750                         awk '/^write_bytes/ {print $7}' )
2751                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2752                 if (( ${write_bytes:-0} > 0 ))
2753                 then
2754                         all_zeros=false
2755                         break;
2756                 fi
2757         done
2758
2759         if $all_zeros
2760         then
2761                 for ostnum in $(seq $OSTCOUNT); do
2762                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2763                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2764                         do_facet ost$ostnum lctl get_param -n \
2765                                 obdfilter/$ostname/stats
2766                 done
2767                 error "OST not keeping write_bytes stats (b22312)"
2768         fi
2769 }
2770 run_test 33c "test llobdstat and write_bytes"
2771
2772 test_33d() {
2773         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2775         local MDTIDX=1
2776         local remote_dir=$DIR/$tdir/remote_dir
2777
2778         test_mkdir $DIR/$tdir
2779         $LFS mkdir -i $MDTIDX $remote_dir ||
2780                 error "create remote directory failed"
2781
2782         touch $remote_dir/$tfile
2783         chmod 444 $remote_dir/$tfile
2784         chown $RUNAS_ID $remote_dir/$tfile
2785
2786         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2787
2788         chown $RUNAS_ID $remote_dir
2789         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2790                                         error "create" || true
2791         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2792                                     error "open RDWR" || true
2793         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2794 }
2795 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2796
2797 test_33e() {
2798         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2799
2800         mkdir $DIR/$tdir
2801
2802         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2803         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2804         mkdir $DIR/$tdir/local_dir
2805
2806         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2807         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2808         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2809
2810         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2811                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2812
2813         rmdir $DIR/$tdir/* || error "rmdir failed"
2814
2815         umask 777
2816         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2817         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2818         mkdir $DIR/$tdir/local_dir
2819
2820         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2821         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2822         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2823
2824         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2825                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2826
2827         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2828
2829         umask 000
2830         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2831         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2832         mkdir $DIR/$tdir/local_dir
2833
2834         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2835         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2836         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2837
2838         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2839                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2840 }
2841 run_test 33e "mkdir and striped directory should have same mode"
2842
2843 cleanup_33f() {
2844         trap 0
2845         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2846 }
2847
2848 test_33f() {
2849         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2850         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2851
2852         mkdir $DIR/$tdir
2853         chmod go+rwx $DIR/$tdir
2854         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2855         trap cleanup_33f EXIT
2856
2857         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2858                 error "cannot create striped directory"
2859
2860         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2861                 error "cannot create files in striped directory"
2862
2863         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2864                 error "cannot remove files in striped directory"
2865
2866         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2867                 error "cannot remove striped directory"
2868
2869         cleanup_33f
2870 }
2871 run_test 33f "nonroot user can create, access, and remove a striped directory"
2872
2873 test_33g() {
2874         mkdir -p $DIR/$tdir/dir2
2875
2876         local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
2877         echo $err
2878         [[ $err =~ "exists" ]] || error "Not exists error"
2879 }
2880 run_test 33g "nonroot user create already existing root created file"
2881
2882 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2883 test_34a() {
2884         rm -f $DIR/f34
2885         $MCREATE $DIR/f34 || error
2886         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2887         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2888         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2889         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2890 }
2891 run_test 34a "truncate file that has not been opened ==========="
2892
2893 test_34b() {
2894         [ ! -f $DIR/f34 ] && test_34a
2895         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2896         $OPENFILE -f O_RDONLY $DIR/f34
2897         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2898         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2899 }
2900 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2901
2902 test_34c() {
2903         [ ! -f $DIR/f34 ] && test_34a
2904         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2905         $OPENFILE -f O_RDWR $DIR/f34
2906         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2907         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2908 }
2909 run_test 34c "O_RDWR opening file-with-size works =============="
2910
2911 test_34d() {
2912         [ ! -f $DIR/f34 ] && test_34a
2913         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2914         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2915         rm $DIR/f34
2916 }
2917 run_test 34d "write to sparse file ============================="
2918
2919 test_34e() {
2920         rm -f $DIR/f34e
2921         $MCREATE $DIR/f34e || error
2922         $TRUNCATE $DIR/f34e 1000 || error
2923         $CHECKSTAT -s 1000 $DIR/f34e || error
2924         $OPENFILE -f O_RDWR $DIR/f34e
2925         $CHECKSTAT -s 1000 $DIR/f34e || error
2926 }
2927 run_test 34e "create objects, some with size and some without =="
2928
2929 test_34f() { # bug 6242, 6243
2930         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2931         SIZE34F=48000
2932         rm -f $DIR/f34f
2933         $MCREATE $DIR/f34f || error
2934         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2935         dd if=$DIR/f34f of=$TMP/f34f
2936         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2937         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2938         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2939         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2940         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2941 }
2942 run_test 34f "read from a file with no objects until EOF ======="
2943
2944 test_34g() {
2945         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2946         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2947         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2948         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2949         cancel_lru_locks osc
2950         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2951                 error "wrong size after lock cancel"
2952
2953         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2954         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2955                 error "expanding truncate failed"
2956         cancel_lru_locks osc
2957         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2958                 error "wrong expanded size after lock cancel"
2959 }
2960 run_test 34g "truncate long file ==============================="
2961
2962 test_34h() {
2963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2964         local gid=10
2965         local sz=1000
2966
2967         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2968         sync # Flush the cache so that multiop below does not block on cache
2969              # flush when getting the group lock
2970         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2971         MULTIPID=$!
2972
2973         # Since just timed wait is not good enough, let's do a sync write
2974         # that way we are sure enough time for a roundtrip + processing
2975         # passed + 2 seconds of extra margin.
2976         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2977         rm $DIR/${tfile}-1
2978         sleep 2
2979
2980         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2981                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2982                 kill -9 $MULTIPID
2983         fi
2984         wait $MULTIPID
2985         local nsz=`stat -c %s $DIR/$tfile`
2986         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2987 }
2988 run_test 34h "ftruncate file under grouplock should not block"
2989
2990 test_35a() {
2991         cp /bin/sh $DIR/f35a
2992         chmod 444 $DIR/f35a
2993         chown $RUNAS_ID $DIR/f35a
2994         $RUNAS $DIR/f35a && error || true
2995         rm $DIR/f35a
2996 }
2997 run_test 35a "exec file with mode 444 (should return and not leak)"
2998
2999 test_36a() {
3000         rm -f $DIR/f36
3001         utime $DIR/f36 || error
3002 }
3003 run_test 36a "MDS utime check (mknod, utime)"
3004
3005 test_36b() {
3006         echo "" > $DIR/f36
3007         utime $DIR/f36 || error
3008 }
3009 run_test 36b "OST utime check (open, utime)"
3010
3011 test_36c() {
3012         rm -f $DIR/d36/f36
3013         test_mkdir $DIR/d36
3014         chown $RUNAS_ID $DIR/d36
3015         $RUNAS utime $DIR/d36/f36 || error
3016 }
3017 run_test 36c "non-root MDS utime check (mknod, utime)"
3018
3019 test_36d() {
3020         [ ! -d $DIR/d36 ] && test_36c
3021         echo "" > $DIR/d36/f36
3022         $RUNAS utime $DIR/d36/f36 || error
3023 }
3024 run_test 36d "non-root OST utime check (open, utime)"
3025
3026 test_36e() {
3027         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3028         test_mkdir $DIR/$tdir
3029         touch $DIR/$tdir/$tfile
3030         $RUNAS utime $DIR/$tdir/$tfile &&
3031                 error "utime worked, expected failure" || true
3032 }
3033 run_test 36e "utime on non-owned file (should return error)"
3034
3035 subr_36fh() {
3036         local fl="$1"
3037         local LANG_SAVE=$LANG
3038         local LC_LANG_SAVE=$LC_LANG
3039         export LANG=C LC_LANG=C # for date language
3040
3041         DATESTR="Dec 20  2000"
3042         test_mkdir $DIR/$tdir
3043         lctl set_param fail_loc=$fl
3044         date; date +%s
3045         cp /etc/hosts $DIR/$tdir/$tfile
3046         sync & # write RPC generated with "current" inode timestamp, but delayed
3047         sleep 1
3048         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
3049         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
3050         cancel_lru_locks osc
3051         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
3052         date; date +%s
3053         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
3054                 echo "BEFORE: $LS_BEFORE" && \
3055                 echo "AFTER : $LS_AFTER" && \
3056                 echo "WANT  : $DATESTR" && \
3057                 error "$DIR/$tdir/$tfile timestamps changed" || true
3058
3059         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
3060 }
3061
3062 test_36f() {
3063         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3064         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3065         subr_36fh "0x80000214"
3066 }
3067 run_test 36f "utime on file racing with OST BRW write =========="
3068
3069 test_36g() {
3070         remote_ost_nodsh && skip "remote OST with nodsh" && return
3071         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3072         local fmd_max_age
3073         local fmd_before
3074         local fmd_after
3075
3076         test_mkdir $DIR/$tdir
3077         fmd_max_age=$(do_facet ost1 \
3078                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
3079                 head -n 1")
3080
3081         fmd_before=$(do_facet ost1 \
3082                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3083         touch $DIR/$tdir/$tfile
3084         sleep $((fmd_max_age + 12))
3085         fmd_after=$(do_facet ost1 \
3086                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3087
3088         echo "fmd_before: $fmd_before"
3089         echo "fmd_after: $fmd_after"
3090         [[ $fmd_after -gt $fmd_before ]] &&
3091                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
3092                 error "fmd didn't expire after ping" || true
3093 }
3094 run_test 36g "filter mod data cache expiry ====================="
3095
3096 test_36h() {
3097         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3098         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3099         subr_36fh "0x80000227"
3100 }
3101 run_test 36h "utime on file racing with OST BRW write =========="
3102
3103 test_36i() {
3104         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3105
3106         test_mkdir $DIR/$tdir
3107         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3108
3109         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3110         local new_mtime=$((mtime + 200))
3111
3112         #change Modify time of striped dir
3113         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3114                         error "change mtime failed"
3115
3116         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3117
3118         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3119 }
3120 run_test 36i "change mtime on striped directory"
3121
3122 # test_37 - duplicate with tests 32q 32r
3123
3124 test_38() {
3125         local file=$DIR/$tfile
3126         touch $file
3127         openfile -f O_DIRECTORY $file
3128         local RC=$?
3129         local ENOTDIR=20
3130         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3131         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3132 }
3133 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3134
3135 test_39a() { # was test_39
3136         touch $DIR/$tfile
3137         touch $DIR/${tfile}2
3138 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3139 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3140 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3141         sleep 2
3142         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3143         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3144                 echo "mtime"
3145                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3146                 echo "atime"
3147                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3148                 echo "ctime"
3149                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3150                 error "O_TRUNC didn't change timestamps"
3151         fi
3152 }
3153 run_test 39a "mtime changed on create"
3154
3155 test_39b() {
3156         test_mkdir -c1 $DIR/$tdir
3157         cp -p /etc/passwd $DIR/$tdir/fopen
3158         cp -p /etc/passwd $DIR/$tdir/flink
3159         cp -p /etc/passwd $DIR/$tdir/funlink
3160         cp -p /etc/passwd $DIR/$tdir/frename
3161         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3162
3163         sleep 1
3164         echo "aaaaaa" >> $DIR/$tdir/fopen
3165         echo "aaaaaa" >> $DIR/$tdir/flink
3166         echo "aaaaaa" >> $DIR/$tdir/funlink
3167         echo "aaaaaa" >> $DIR/$tdir/frename
3168
3169         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3170         local link_new=`stat -c %Y $DIR/$tdir/flink`
3171         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3172         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3173
3174         cat $DIR/$tdir/fopen > /dev/null
3175         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3176         rm -f $DIR/$tdir/funlink2
3177         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3178
3179         for (( i=0; i < 2; i++ )) ; do
3180                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3181                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3182                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3183                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3184
3185                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3186                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3187                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3188                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3189
3190                 cancel_lru_locks osc
3191                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3192         done
3193 }
3194 run_test 39b "mtime change on open, link, unlink, rename  ======"
3195
3196 # this should be set to past
3197 TEST_39_MTIME=`date -d "1 year ago" +%s`
3198
3199 # bug 11063
3200 test_39c() {
3201         touch $DIR1/$tfile
3202         sleep 2
3203         local mtime0=`stat -c %Y $DIR1/$tfile`
3204
3205         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3206         local mtime1=`stat -c %Y $DIR1/$tfile`
3207         [ "$mtime1" = $TEST_39_MTIME ] || \
3208                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3209
3210         local d1=`date +%s`
3211         echo hello >> $DIR1/$tfile
3212         local d2=`date +%s`
3213         local mtime2=`stat -c %Y $DIR1/$tfile`
3214         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3215                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3216
3217         mv $DIR1/$tfile $DIR1/$tfile-1
3218
3219         for (( i=0; i < 2; i++ )) ; do
3220                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3221                 [ "$mtime2" = "$mtime3" ] || \
3222                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3223
3224                 cancel_lru_locks osc
3225                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3226         done
3227 }
3228 run_test 39c "mtime change on rename ==========================="
3229
3230 # bug 21114
3231 test_39d() {
3232         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3233         touch $DIR1/$tfile
3234
3235         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3236
3237         for (( i=0; i < 2; i++ )) ; do
3238                 local mtime=`stat -c %Y $DIR1/$tfile`
3239                 [ $mtime = $TEST_39_MTIME ] || \
3240                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3241
3242                 cancel_lru_locks osc
3243                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3244         done
3245 }
3246 run_test 39d "create, utime, stat =============================="
3247
3248 # bug 21114
3249 test_39e() {
3250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3251         touch $DIR1/$tfile
3252         local mtime1=`stat -c %Y $DIR1/$tfile`
3253
3254         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3255
3256         for (( i=0; i < 2; i++ )) ; do
3257                 local mtime2=`stat -c %Y $DIR1/$tfile`
3258                 [ $mtime2 = $TEST_39_MTIME ] || \
3259                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3260
3261                 cancel_lru_locks osc
3262                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3263         done
3264 }
3265 run_test 39e "create, stat, utime, stat ========================"
3266
3267 # bug 21114
3268 test_39f() {
3269         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3270         touch $DIR1/$tfile
3271         mtime1=`stat -c %Y $DIR1/$tfile`
3272
3273         sleep 2
3274         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3275
3276         for (( i=0; i < 2; i++ )) ; do
3277                 local mtime2=`stat -c %Y $DIR1/$tfile`
3278                 [ $mtime2 = $TEST_39_MTIME ] || \
3279                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3280
3281                 cancel_lru_locks osc
3282                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3283         done
3284 }
3285 run_test 39f "create, stat, sleep, utime, stat ================="
3286
3287 # bug 11063
3288 test_39g() {
3289         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3290         echo hello >> $DIR1/$tfile
3291         local mtime1=`stat -c %Y $DIR1/$tfile`
3292
3293         sleep 2
3294         chmod o+r $DIR1/$tfile
3295
3296         for (( i=0; i < 2; i++ )) ; do
3297                 local mtime2=`stat -c %Y $DIR1/$tfile`
3298                 [ "$mtime1" = "$mtime2" ] || \
3299                         error "lost mtime: $mtime2, should be $mtime1"
3300
3301                 cancel_lru_locks osc
3302                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3303         done
3304 }
3305 run_test 39g "write, chmod, stat ==============================="
3306
3307 # bug 11063
3308 test_39h() {
3309         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3310         touch $DIR1/$tfile
3311         sleep 1
3312
3313         local d1=`date`
3314         echo hello >> $DIR1/$tfile
3315         local mtime1=`stat -c %Y $DIR1/$tfile`
3316
3317         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3318         local d2=`date`
3319         if [ "$d1" != "$d2" ]; then
3320                 echo "write and touch not within one second"
3321         else
3322                 for (( i=0; i < 2; i++ )) ; do
3323                         local mtime2=`stat -c %Y $DIR1/$tfile`
3324                         [ "$mtime2" = $TEST_39_MTIME ] || \
3325                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3326
3327                         cancel_lru_locks osc
3328                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3329                 done
3330         fi
3331 }
3332 run_test 39h "write, utime within one second, stat ============="
3333
3334 test_39i() {
3335         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3336         touch $DIR1/$tfile
3337         sleep 1
3338
3339         echo hello >> $DIR1/$tfile
3340         local mtime1=`stat -c %Y $DIR1/$tfile`
3341
3342         mv $DIR1/$tfile $DIR1/$tfile-1
3343
3344         for (( i=0; i < 2; i++ )) ; do
3345                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3346
3347                 [ "$mtime1" = "$mtime2" ] || \
3348                         error "lost mtime: $mtime2, should be $mtime1"
3349
3350                 cancel_lru_locks osc
3351                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3352         done
3353 }
3354 run_test 39i "write, rename, stat =============================="
3355
3356 test_39j() {
3357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3358         start_full_debug_logging
3359         touch $DIR1/$tfile
3360         sleep 1
3361
3362         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3363         lctl set_param fail_loc=0x80000412
3364         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3365                 error "multiop failed"
3366         local multipid=$!
3367         local mtime1=`stat -c %Y $DIR1/$tfile`
3368
3369         mv $DIR1/$tfile $DIR1/$tfile-1
3370
3371         kill -USR1 $multipid
3372         wait $multipid || error "multiop close failed"
3373
3374         for (( i=0; i < 2; i++ )) ; do
3375                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3376                 [ "$mtime1" = "$mtime2" ] ||
3377                         error "mtime is lost on close: $mtime2, " \
3378                               "should be $mtime1"
3379
3380                 cancel_lru_locks osc
3381                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3382         done
3383         lctl set_param fail_loc=0
3384         stop_full_debug_logging
3385 }
3386 run_test 39j "write, rename, close, stat ======================="
3387
3388 test_39k() {
3389         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3390         touch $DIR1/$tfile
3391         sleep 1
3392
3393         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3394         local multipid=$!
3395         local mtime1=`stat -c %Y $DIR1/$tfile`
3396
3397         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3398
3399         kill -USR1 $multipid
3400         wait $multipid || error "multiop close failed"
3401
3402         for (( i=0; i < 2; i++ )) ; do
3403                 local mtime2=`stat -c %Y $DIR1/$tfile`
3404
3405                 [ "$mtime2" = $TEST_39_MTIME ] || \
3406                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3407
3408                 cancel_lru_locks osc
3409                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3410         done
3411 }
3412 run_test 39k "write, utime, close, stat ========================"
3413
3414 # this should be set to future
3415 TEST_39_ATIME=`date -d "1 year" +%s`
3416
3417 test_39l() {
3418         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3419         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3420         local atime_diff=$(do_facet $SINGLEMDS \
3421                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3422         rm -rf $DIR/$tdir
3423         mkdir -p $DIR/$tdir
3424
3425         # test setting directory atime to future
3426         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3427         local atime=$(stat -c %X $DIR/$tdir)
3428         [ "$atime" = $TEST_39_ATIME ] ||
3429                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3430
3431         # test setting directory atime from future to now
3432         local now=$(date +%s)
3433         touch -a -d @$now $DIR/$tdir
3434
3435         atime=$(stat -c %X $DIR/$tdir)
3436         [ "$atime" -eq "$now"  ] ||
3437                 error "atime is not updated from future: $atime, $now"
3438
3439         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3440         sleep 3
3441
3442         # test setting directory atime when now > dir atime + atime_diff
3443         local d1=$(date +%s)
3444         ls $DIR/$tdir
3445         local d2=$(date +%s)
3446         cancel_lru_locks mdc
3447         atime=$(stat -c %X $DIR/$tdir)
3448         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3449                 error "atime is not updated  : $atime, should be $d2"
3450
3451         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3452         sleep 3
3453
3454         # test not setting directory atime when now < dir atime + atime_diff
3455         ls $DIR/$tdir
3456         cancel_lru_locks mdc
3457         atime=$(stat -c %X $DIR/$tdir)
3458         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3459                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3460
3461         do_facet $SINGLEMDS \
3462                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3463 }
3464 run_test 39l "directory atime update ==========================="
3465
3466 test_39m() {
3467         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3468         touch $DIR1/$tfile
3469         sleep 2
3470         local far_past_mtime=$(date -d "May 29 1953" +%s)
3471         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3472
3473         touch -m -d @$far_past_mtime $DIR1/$tfile
3474         touch -a -d @$far_past_atime $DIR1/$tfile
3475
3476         for (( i=0; i < 2; i++ )) ; do
3477                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3478                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3479                         error "atime or mtime set incorrectly"
3480
3481                 cancel_lru_locks osc
3482                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3483         done
3484 }
3485 run_test 39m "test atime and mtime before 1970"
3486
3487 test_39n() { # LU-3832
3488         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3489         local atime_diff=$(do_facet $SINGLEMDS \
3490                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3491         local atime0
3492         local atime1
3493         local atime2
3494
3495         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3496
3497         rm -rf $DIR/$tfile
3498         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3499         atime0=$(stat -c %X $DIR/$tfile)
3500
3501         sleep 5
3502         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3503         atime1=$(stat -c %X $DIR/$tfile)
3504
3505         sleep 5
3506         cancel_lru_locks mdc
3507         cancel_lru_locks osc
3508         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3509         atime2=$(stat -c %X $DIR/$tfile)
3510
3511         do_facet $SINGLEMDS \
3512                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3513
3514         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3515         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3516 }
3517 run_test 39n "check that O_NOATIME is honored"
3518
3519 test_39o() {
3520         TESTDIR=$DIR/$tdir/$tfile
3521         [ -e $TESTDIR ] && rm -rf $TESTDIR
3522         mkdir -p $TESTDIR
3523         cd $TESTDIR
3524         links1=2
3525         ls
3526         mkdir a b
3527         ls
3528         links2=$(stat -c %h .)
3529         [ $(($links1 + 2)) != $links2 ] &&
3530                 error "wrong links count $(($links1 + 2)) != $links2"
3531         rmdir b
3532         links3=$(stat -c %h .)
3533         [ $(($links1 + 1)) != $links3 ] &&
3534                 error "wrong links count $links1 != $links3"
3535         return 0
3536 }
3537 run_test 39o "directory cached attributes updated after create"
3538
3539 test_39p() {
3540         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3541         local MDTIDX=1
3542         TESTDIR=$DIR/$tdir/$tdir
3543         [ -e $TESTDIR ] && rm -rf $TESTDIR
3544         test_mkdir -p $TESTDIR
3545         cd $TESTDIR
3546         links1=2
3547         ls
3548         test_mkdir -i $MDTIDX $TESTDIR/remote_dir1
3549         test_mkdir -i $MDTIDX $TESTDIR/remote_dir2
3550         ls
3551         links2=$(stat -c %h .)
3552         [ $(($links1 + 2)) != $links2 ] &&
3553                 error "wrong links count $(($links1 + 2)) != $links2"
3554         rmdir remote_dir2
3555         links3=$(stat -c %h .)
3556         [ $(($links1 + 1)) != $links3 ] &&
3557                 error "wrong links count $links1 != $links3"
3558         return 0
3559 }
3560 run_test 39p "remote directory cached attributes updated after create ========"
3561
3562
3563 test_39q() { # LU-8041
3564         local testdir=$DIR/$tdir
3565         mkdir -p $testdir
3566         multiop_bg_pause $testdir D_c || error "multiop failed"
3567         local multipid=$!
3568         cancel_lru_locks mdc
3569         kill -USR1 $multipid
3570         local atime=$(stat -c %X $testdir)
3571         [ "$atime" -ne 0 ] || error "atime is zero"
3572 }
3573 run_test 39q "close won't zero out atime"
3574
3575 test_40() {
3576         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3577         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3578                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3579         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3580                 error "$tfile is not 4096 bytes in size"
3581 }
3582 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3583
3584 test_41() {
3585         # bug 1553
3586         small_write $DIR/f41 18
3587 }
3588 run_test 41 "test small file write + fstat ====================="
3589
3590 count_ost_writes() {
3591         lctl get_param -n ${OSC}.*.stats |
3592                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3593                         END { printf("%0.0f", writes) }'
3594 }
3595
3596 # decent default
3597 WRITEBACK_SAVE=500
3598 DIRTY_RATIO_SAVE=40
3599 MAX_DIRTY_RATIO=50
3600 BG_DIRTY_RATIO_SAVE=10
3601 MAX_BG_DIRTY_RATIO=25
3602
3603 start_writeback() {
3604         trap 0
3605         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3606         # dirty_ratio, dirty_background_ratio
3607         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3608                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3609                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3610                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3611         else
3612                 # if file not here, we are a 2.4 kernel
3613                 kill -CONT `pidof kupdated`
3614         fi
3615 }
3616
3617 stop_writeback() {
3618         # setup the trap first, so someone cannot exit the test at the
3619         # exact wrong time and mess up a machine
3620         trap start_writeback EXIT
3621         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3622         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3623                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3624                 sysctl -w vm.dirty_writeback_centisecs=0
3625                 sysctl -w vm.dirty_writeback_centisecs=0
3626                 # save and increase /proc/sys/vm/dirty_ratio
3627                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3628                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3629                 # save and increase /proc/sys/vm/dirty_background_ratio
3630                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3631                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3632         else
3633                 # if file not here, we are a 2.4 kernel
3634                 kill -STOP `pidof kupdated`
3635         fi
3636 }
3637
3638 # ensure that all stripes have some grant before we test client-side cache
3639 setup_test42() {
3640         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3641                 dd if=/dev/zero of=$i bs=4k count=1
3642                 rm $i
3643         done
3644 }
3645
3646 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3647 # file truncation, and file removal.
3648 test_42a() {
3649         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3650         setup_test42
3651         cancel_lru_locks $OSC
3652         stop_writeback
3653         sync; sleep 1; sync # just to be safe
3654         BEFOREWRITES=`count_ost_writes`
3655         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3656         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3657         AFTERWRITES=`count_ost_writes`
3658         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3659                 error "$BEFOREWRITES < $AFTERWRITES"
3660         start_writeback
3661 }
3662 run_test 42a "ensure that we don't flush on close"
3663
3664 test_42b() {
3665         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3666         setup_test42
3667         cancel_lru_locks $OSC
3668         stop_writeback
3669         sync
3670         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3671         BEFOREWRITES=$(count_ost_writes)
3672         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3673         AFTERWRITES=$(count_ost_writes)
3674         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3675                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3676         fi
3677         BEFOREWRITES=$(count_ost_writes)
3678         sync || error "sync: $?"
3679         AFTERWRITES=$(count_ost_writes)
3680         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3681                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3682         fi
3683         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3684         start_writeback
3685         return 0
3686 }
3687 run_test 42b "test destroy of file with cached dirty data ======"
3688
3689 # if these tests just want to test the effect of truncation,
3690 # they have to be very careful.  consider:
3691 # - the first open gets a {0,EOF}PR lock
3692 # - the first write conflicts and gets a {0, count-1}PW
3693 # - the rest of the writes are under {count,EOF}PW
3694 # - the open for truncate tries to match a {0,EOF}PR
3695 #   for the filesize and cancels the PWs.
3696 # any number of fixes (don't get {0,EOF} on open, match
3697 # composite locks, do smarter file size management) fix
3698 # this, but for now we want these tests to verify that
3699 # the cancellation with truncate intent works, so we
3700 # start the file with a full-file pw lock to match against
3701 # until the truncate.
3702 trunc_test() {
3703         test=$1
3704         file=$DIR/$test
3705         offset=$2
3706         cancel_lru_locks $OSC
3707         stop_writeback
3708         # prime the file with 0,EOF PW to match
3709         touch $file
3710         $TRUNCATE $file 0
3711         sync; sync
3712         # now the real test..
3713         dd if=/dev/zero of=$file bs=1024 count=100
3714         BEFOREWRITES=`count_ost_writes`
3715         $TRUNCATE $file $offset
3716         cancel_lru_locks $OSC
3717         AFTERWRITES=`count_ost_writes`
3718         start_writeback
3719 }
3720
3721 test_42c() {
3722         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3723         trunc_test 42c 1024
3724         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3725             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3726         rm $file
3727 }
3728 run_test 42c "test partial truncate of file with cached dirty data"
3729
3730 test_42d() {
3731         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3732         trunc_test 42d 0
3733         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3734             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3735         rm $file
3736 }
3737 run_test 42d "test complete truncate of file with cached dirty data"
3738
3739 test_42e() { # bug22074
3740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3741         local TDIR=$DIR/${tdir}e
3742         local pagesz=$(page_size)
3743         local pages=16 # hardcoded 16 pages, don't change it.
3744         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3745         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3746         local max_dirty_mb
3747         local warmup_files
3748
3749         test_mkdir $DIR/${tdir}e
3750         $SETSTRIPE -c 1 $TDIR
3751         createmany -o $TDIR/f $files
3752
3753         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3754
3755         # we assume that with $OSTCOUNT files, at least one of them will
3756         # be allocated on OST0.
3757         warmup_files=$((OSTCOUNT * max_dirty_mb))
3758         createmany -o $TDIR/w $warmup_files
3759
3760         # write a large amount of data into one file and sync, to get good
3761         # avail_grant number from OST.
3762         for ((i=0; i<$warmup_files; i++)); do
3763                 idx=$($GETSTRIPE -i $TDIR/w$i)
3764                 [ $idx -ne 0 ] && continue
3765                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3766                 break
3767         done
3768         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3769         sync
3770         $LCTL get_param $proc_osc0/cur_dirty_bytes
3771         $LCTL get_param $proc_osc0/cur_grant_bytes
3772
3773         # create as much dirty pages as we can while not to trigger the actual
3774         # RPCs directly. but depends on the env, VFS may trigger flush during this
3775         # period, hopefully we are good.
3776         for ((i=0; i<$warmup_files; i++)); do
3777                 idx=$($GETSTRIPE -i $TDIR/w$i)
3778                 [ $idx -ne 0 ] && continue
3779                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3780         done
3781         $LCTL get_param $proc_osc0/cur_dirty_bytes
3782         $LCTL get_param $proc_osc0/cur_grant_bytes
3783
3784         # perform the real test
3785         $LCTL set_param $proc_osc0/rpc_stats 0
3786         for ((;i<$files; i++)); do
3787                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3788                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3789         done
3790         sync
3791         $LCTL get_param $proc_osc0/rpc_stats
3792
3793         local percent=0
3794         local have_ppr=false
3795         $LCTL get_param $proc_osc0/rpc_stats |
3796                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3797                         # skip lines until we are at the RPC histogram data
3798                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3799                         $have_ppr || continue
3800
3801                         # we only want the percent stat for < 16 pages
3802                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3803
3804                         percent=$((percent + WPCT))
3805                         if [[ $percent -gt 15 ]]; then
3806                                 error "less than 16-pages write RPCs" \
3807                                       "$percent% > 15%"
3808                                 break
3809                         fi
3810                 done
3811         rm -rf $TDIR
3812 }
3813 run_test 42e "verify sub-RPC writes are not done synchronously"
3814
3815 test_43A() { # was test_43
3816         test_mkdir $DIR/$tdir
3817         cp -p /bin/ls $DIR/$tdir/$tfile
3818         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3819         pid=$!
3820         # give multiop a chance to open
3821         sleep 1
3822
3823         $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
3824         kill -USR1 $pid
3825 }
3826 run_test 43A "execution of file opened for write should return -ETXTBSY"
3827
3828 test_43a() {
3829         test_mkdir $DIR/$tdir
3830         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3831                 cp -p multiop $DIR/$tdir/multiop
3832         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3833                 error "multiop open $TMP/$tfile.junk failed"
3834         MULTIOP_PID=$!
3835         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3836         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3837         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3838 }
3839 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3840
3841 test_43b() {
3842         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3843         test_mkdir $DIR/$tdir
3844         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3845                 cp -p multiop $DIR/$tdir/multiop
3846         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3847                 error "multiop open $TMP/$tfile.junk failed"
3848         MULTIOP_PID=$!
3849         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3850         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3851         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3852 }
3853 run_test 43b "truncate of file being executed should return -ETXTBSY"
3854
3855 test_43c() {
3856         local testdir="$DIR/$tdir"
3857         test_mkdir $testdir
3858         cp $SHELL $testdir/
3859         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |
3860                 ( cd $testdir && md5sum -c )
3861 }
3862 run_test 43c "md5sum of copy into lustre"
3863
3864 test_44A() { # was test_44
3865         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
3866         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3867         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3868 }
3869 run_test 44A "zero length read from a sparse stripe"
3870
3871 test_44a() {
3872         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3873                 awk '{ print $2 }')
3874         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3875         [[ $nstripe -gt $OSTCOUNT ]] &&
3876             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3877             return
3878         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3879                 awk '{ print $2 }')
3880         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3881                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3882                         awk '{ print $2 }')
3883         fi
3884
3885         OFFSETS="0 $((stride/2)) $((stride-1))"
3886         for offset in $OFFSETS; do
3887                 for i in $(seq 0 $((nstripe-1))); do
3888                         local GLOBALOFFSETS=""
3889                         # size in Bytes
3890                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3891                         local myfn=$DIR/d44a-$size
3892                         echo "--------writing $myfn at $size"
3893                         ll_sparseness_write $myfn $size ||
3894                                 error "ll_sparseness_write"
3895                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3896                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3897                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3898
3899                         for j in $(seq 0 $((nstripe-1))); do
3900                                 # size in Bytes
3901                                 size=$((((j + $nstripe )*$stride + $offset)))
3902                                 ll_sparseness_write $myfn $size ||
3903                                         error "ll_sparseness_write"
3904                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3905                         done
3906                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3907                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3908                         rm -f $myfn
3909                 done
3910         done
3911 }
3912 run_test 44a "test sparse pwrite ==============================="
3913
3914 dirty_osc_total() {
3915         tot=0
3916         for d in `lctl get_param -n ${OSC}.*.cur_dirty_bytes`; do
3917                 tot=$(($tot + $d))
3918         done
3919         echo $tot
3920 }
3921 do_dirty_record() {
3922         before=`dirty_osc_total`
3923         echo executing "\"$*\""
3924         eval $*
3925         after=`dirty_osc_total`
3926         echo before $before, after $after
3927 }
3928 test_45() {
3929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3930         f="$DIR/f45"
3931         # Obtain grants from OST if it supports it
3932         echo blah > ${f}_grant
3933         stop_writeback
3934         sync
3935         do_dirty_record "echo blah > $f"
3936         [[ $before -eq $after ]] && error "write wasn't cached"
3937         do_dirty_record "> $f"
3938         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3939         do_dirty_record "echo blah > $f"
3940         [[ $before -eq $after ]] && error "write wasn't cached"
3941         do_dirty_record "sync"
3942         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3943         do_dirty_record "echo blah > $f"
3944         [[ $before -eq $after ]] && error "write wasn't cached"
3945         do_dirty_record "cancel_lru_locks osc"
3946         [[ $before -gt $after ]] ||
3947                 error "lock cancellation didn't lower dirty count"
3948         start_writeback
3949 }
3950 run_test 45 "osc io page accounting ============================"
3951
3952 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3953 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3954 # objects offset and an assert hit when an rpc was built with 1023's mapped
3955 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3956 test_46() {
3957         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3958         f="$DIR/f46"
3959         stop_writeback
3960         sync
3961         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3962         sync
3963         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3964         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3965         sync
3966         start_writeback
3967 }
3968 run_test 46 "dirtying a previously written page ================"
3969
3970 # test_47 is removed "Device nodes check" is moved to test_28
3971
3972 test_48a() { # bug 2399
3973         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3974         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3975                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3976                 return
3977         test_mkdir $DIR/$tdir
3978         cd $DIR/$tdir
3979         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3980         test_mkdir $DIR/$tdir
3981         touch foo || error "'touch foo' failed after recreating cwd"
3982         test_mkdir bar
3983         touch .foo || error "'touch .foo' failed after recreating cwd"
3984         test_mkdir .bar
3985         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3986         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3987         cd . || error "'cd .' failed after recreating cwd"
3988         mkdir . && error "'mkdir .' worked after recreating cwd"
3989         rmdir . && error "'rmdir .' worked after recreating cwd"
3990         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3991         cd .. || error "'cd ..' failed after recreating cwd"
3992 }
3993 run_test 48a "Access renamed working dir (should return errors)="
3994
3995 test_48b() { # bug 2399
3996         rm -rf $DIR/$tdir
3997         test_mkdir $DIR/$tdir
3998         cd $DIR/$tdir
3999         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
4000         touch foo && error "'touch foo' worked after removing cwd"
4001         mkdir foo && error "'mkdir foo' worked after removing cwd"
4002         touch .foo && error "'touch .foo' worked after removing cwd"
4003         mkdir .foo && error "'mkdir .foo' worked after removing cwd"
4004         ls . > /dev/null && error "'ls .' worked after removing cwd"
4005         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4006         mkdir . && error "'mkdir .' worked after removing cwd"
4007         rmdir . && error "'rmdir .' worked after removing cwd"
4008         ln -s . foo && error "'ln -s .' worked after removing cwd"
4009         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
4010 }
4011 run_test 48b "Access removed working dir (should return errors)="
4012
4013 test_48c() { # bug 2350
4014         #lctl set_param debug=-1
4015         #set -vx
4016         rm -rf $DIR/$tdir
4017         test_mkdir -p $DIR/$tdir/dir
4018         cd $DIR/$tdir/dir
4019         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4020         $TRACE touch foo && error "touch foo worked after removing cwd"
4021         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
4022         touch .foo && error "touch .foo worked after removing cwd"
4023         mkdir .foo && error "mkdir .foo worked after removing cwd"
4024         $TRACE ls . && error "'ls .' worked after removing cwd"
4025         $TRACE ls .. || error "'ls ..' failed after removing cwd"
4026         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
4027         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
4028         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
4029         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
4030 }
4031 run_test 48c "Access removed working subdir (should return errors)"
4032
4033 test_48d() { # bug 2350
4034         #lctl set_param debug=-1
4035         #set -vx
4036         rm -rf $DIR/$tdir
4037         test_mkdir -p $DIR/$tdir/dir
4038         cd $DIR/$tdir/dir
4039         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4040         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4041         $TRACE touch foo && error "'touch foo' worked after removing parent"
4042         $TRACE mkdir foo && error "mkdir foo worked after removing parent"
4043         touch .foo && error "'touch .foo' worked after removing parent"
4044         mkdir .foo && error "mkdir .foo worked after removing parent"
4045         $TRACE ls . && error "'ls .' worked after removing parent"
4046         $TRACE ls .. && error "'ls ..' worked after removing parent"
4047         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
4048         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
4049         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
4050         true
4051 }
4052 run_test 48d "Access removed parent subdir (should return errors)"
4053
4054 test_48e() { # bug 4134
4055         #lctl set_param debug=-1
4056         #set -vx
4057         rm -rf $DIR/$tdir
4058         test_mkdir -p $DIR/$tdir/dir
4059         cd $DIR/$tdir/dir
4060         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4061         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4062         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
4063         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
4064         # On a buggy kernel addition of "touch foo" after cd .. will
4065         # produce kernel oops in lookup_hash_it
4066         touch ../foo && error "'cd ..' worked after recreate parent"
4067         cd $DIR
4068         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
4069 }
4070 run_test 48e "Access to recreated parent subdir (should return errors)"
4071
4072 test_49() { # LU-1030
4073         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4074         remote_ost_nodsh && skip "remote OST with nodsh" && return
4075         # get ost1 size - lustre-OST0000
4076         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
4077                 awk '{ print $4 }')
4078         # write 800M at maximum
4079         [[ $ost1_size -lt 2 ]] && ost1_size=2
4080         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
4081
4082         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
4083         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
4084         local dd_pid=$!
4085
4086         # change max_pages_per_rpc while writing the file
4087         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
4088         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
4089         # loop until dd process exits
4090         while ps ax -opid | grep -wq $dd_pid; do
4091                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
4092                 sleep $((RANDOM % 5 + 1))
4093         done
4094         # restore original max_pages_per_rpc
4095         $LCTL set_param $osc1_mppc=$orig_mppc
4096         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
4097 }
4098 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4099
4100 test_50() {
4101         # bug 1485
4102         test_mkdir $DIR/$tdir
4103         cd $DIR/$tdir
4104         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4105 }
4106 run_test 50 "special situations: /proc symlinks  ==============="
4107
4108 test_51a() {    # was test_51
4109         # bug 1516 - create an empty entry right after ".." then split dir
4110         test_mkdir -c1 $DIR/$tdir
4111         touch $DIR/$tdir/foo
4112         $MCREATE $DIR/$tdir/bar
4113         rm $DIR/$tdir/foo
4114         createmany -m $DIR/$tdir/longfile 201
4115         FNUM=202
4116         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4117                 $MCREATE $DIR/$tdir/longfile$FNUM
4118                 FNUM=$(($FNUM + 1))
4119                 echo -n "+"
4120         done
4121         echo
4122         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4123 }
4124 run_test 51a "special situations: split htree with empty entry =="
4125
4126 cleanup_print_lfs_df () {
4127         trap 0
4128         $LFS df
4129         $LFS df -i
4130 }
4131
4132 test_51b() {
4133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4134         local dir=$DIR/$tdir
4135
4136         local nrdirs=$((65536 + 100))
4137
4138         # cleanup the directory
4139         rm -fr $dir
4140
4141         test_mkdir -c1 $dir
4142
4143         $LFS df
4144         $LFS df -i
4145         local mdtidx=$(printf "%04x" $($LFS getstripe -M $dir))
4146         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4147         [[ $numfree -lt $nrdirs ]] &&
4148                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4149                 return
4150
4151         # need to check free space for the directories as well
4152         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4153         numfree=$(( blkfree / $(fs_inode_ksize) ))
4154         [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)" &&
4155                 return
4156
4157         trap cleanup_print_lfs_df EXIT
4158
4159         # create files
4160         createmany -d $dir/d $nrdirs || {
4161                 unlinkmany $dir/d $nrdirs
4162                 error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
4163         }
4164
4165         # really created :
4166         nrdirs=$(ls -U $dir | wc -l)
4167
4168         # unlink all but 100 subdirectories, then check it still works
4169         local left=100
4170         local delete=$((nrdirs - left))
4171
4172         $LFS df
4173         $LFS df -i
4174
4175         # for ldiskfs the nlink count should be 1, but this is OSD specific
4176         # and so this is listed for informational purposes only
4177         echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
4178         unlinkmany -d $dir/d $delete ||
4179                 error "unlink of first $delete subdirs failed"
4180
4181         echo "nlink between: $(stat -c %h $dir)"
4182         local found=$(ls -U $dir | wc -l)
4183         [ $found -ne $left ] &&
4184                 error "can't find subdirs: found only $found, expected $left"
4185
4186         unlinkmany -d $dir/d $delete $left ||
4187                 error "unlink of second $left subdirs failed"
4188         # regardless of whether the backing filesystem tracks nlink accurately
4189         # or not, the nlink count shouldn't be more than "." and ".." here
4190         local after=$(stat -c %h $dir)
4191         [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
4192                 echo "nlink after: $after"
4193
4194         cleanup_print_lfs_df
4195 }
4196 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
4197
4198 test_51d() {
4199         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4200         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
4201         test_mkdir $DIR/$tdir
4202         createmany -o $DIR/$tdir/t- 1000
4203         $LFS getstripe $DIR/$tdir > $TMP/$tfile
4204         for N in $(seq 0 $((OSTCOUNT - 1))); do
4205                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4206                         END { printf("%0.0f", objs) }' $TMP/$tfile)
4207                 OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
4208                         '($1 == '$N') { objs += 1 } \
4209                         END { printf("%0.0f", objs) }')
4210                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4211         done
4212         unlinkmany $DIR/$tdir/t- 1000
4213
4214         NLAST=0
4215         for N in $(seq 1 $((OSTCOUNT - 1))); do
4216                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4217                         error "OST $N has less objects vs OST $NLAST" \
4218                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4219                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4220                         error "OST $N has less objects vs OST $NLAST" \
4221                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4222
4223                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4224                         error "OST $N has less #0 objects vs OST $NLAST" \
4225                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4226                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4227                         error "OST $N has less #0 objects vs OST $NLAST" \
4228                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4229                 NLAST=$N
4230         done
4231         rm -f $TMP/$tfile
4232 }
4233 run_test 51d "check object distribution"
4234
4235 test_51e() {
4236         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4237                 skip "ldiskfs only test"
4238                 return
4239         fi
4240
4241         test_mkdir -c1 $DIR/$tdir
4242         test_mkdir -c1 $DIR/$tdir/d0
4243
4244         touch $DIR/$tdir/d0/foo
4245         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4246                 error "file exceed 65000 nlink limit!"
4247         unlinkmany $DIR/$tdir/d0/f- 65001
4248         return 0
4249 }
4250 run_test 51e "check file nlink limit"
4251
4252 test_51f() {
4253         test_mkdir $DIR/$tdir
4254
4255         local max=100000
4256         local ulimit_old=$(ulimit -n)
4257         local spare=20 # number of spare fd's for scripts/libraries, etc.
4258         local mdt=$(lfs getstripe -M $DIR/$tdir)
4259         local numfree=$(lfs df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
4260
4261         echo "MDT$mdt numfree=$numfree, max=$max"
4262         [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
4263         if [ $((numfree + spare)) -gt $ulimit_old ]; then
4264                 while ! ulimit -n $((numfree + spare)); do
4265                         numfree=$((numfree * 3 / 4))
4266                 done
4267                 echo "changed ulimit from $ulimit_old to $((numfree + spare))"
4268         else
4269                 echo "left ulimit at $ulimit_old"
4270         fi
4271
4272         createmany -o -k -t 120 $DIR/$tdir/f $numfree || {
4273                 unlinkmany $DIR/$tdir/f $numfree
4274                 error "create+open $numfree files in $DIR/$tdir failed"
4275         }
4276         ulimit -n $ulimit_old
4277
4278         # if createmany exits at 120s there will be fewer than $numfree files
4279         unlinkmany $DIR/$tdir/f $numfree || true
4280 }
4281 run_test 51f "check many open files limit"
4282
4283 test_52a() {
4284         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4285         test_mkdir $DIR/$tdir
4286         touch $DIR/$tdir/foo
4287         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4288         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4289         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4290         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4291         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4292                                         error "link worked"
4293         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4294         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4295         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4296                                                      error "lsattr"
4297         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4298         cp -r $DIR/$tdir $TMP/
4299         rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
4300 }
4301 run_test 52a "append-only flag test (should return errors)"
4302
4303 test_52b() {
4304         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4305         test_mkdir $DIR/$tdir
4306         touch $DIR/$tdir/foo
4307         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4308         cat test > $DIR/$tdir/foo && error "cat test worked"
4309         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4310         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4311         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4312                                         error "link worked"
4313         echo foo >> $DIR/$tdir/foo && error "echo worked"
4314         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4315         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4316         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4317         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4318                                                         error "lsattr"
4319         chattr -i $DIR/$tdir/foo || error "chattr failed"
4320
4321         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4322 }
4323 run_test 52b "immutable flag test (should return errors) ======="
4324
4325 test_53() {
4326         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4327         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4328         remote_ost_nodsh && skip "remote OST with nodsh" && return
4329
4330         local param
4331         local param_seq
4332         local ostname
4333         local mds_last
4334         local mds_last_seq
4335         local ost_last
4336         local ost_last_seq
4337         local ost_last_id
4338         local ostnum
4339         local node
4340         local found=false
4341         local support_last_seq=true
4342
4343         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4344                 support_last_seq=false
4345
4346         # only test MDT0000
4347         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4348         local value
4349         for value in $(do_facet $SINGLEMDS \
4350                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4351                 param=$(echo ${value[0]} | cut -d "=" -f1)
4352                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4353
4354                 if $support_last_seq; then
4355                         param_seq=$(echo $param |
4356                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4357                         mds_last_seq=$(do_facet $SINGLEMDS \
4358                                        $LCTL get_param -n $param_seq)
4359                 fi
4360                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4361
4362                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4363                 node=$(facet_active_host ost$((ostnum+1)))
4364                 param="obdfilter.$ostname.last_id"
4365                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4366                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4367                         ost_last_id=$ost_last
4368
4369                         if $support_last_seq; then
4370                                 ost_last_id=$(echo $ost_last |
4371                                               awk -F':' '{print $2}' |
4372                                               sed -e "s/^0x//g")
4373                                 ost_last_seq=$(echo $ost_last |
4374                                                awk -F':' '{print $1}')
4375                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4376                         fi
4377
4378                         if [[ $ost_last_id != $mds_last ]]; then
4379                                 error "$ost_last_id != $mds_last"
4380                         else
4381                                 found=true
4382                                 break
4383                         fi
4384                 done
4385         done
4386         $found || error "can not match last_seq/last_id for $mdtosc"
4387         return 0
4388 }
4389 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4390
4391 test_54a() {
4392         perl -MSocket -e ';' || { skip "no Socket perl module installed" && return; }
4393
4394         $SOCKETSERVER $DIR/socket ||
4395                 error "$SOCKETSERVER $DIR/socket failed: $?"
4396         $SOCKETCLIENT $DIR/socket ||
4397                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4398         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4399 }
4400 run_test 54a "unix domain socket test =========================="
4401
4402 test_54b() {
4403         f="$DIR/f54b"
4404         mknod $f c 1 3
4405         chmod 0666 $f
4406         dd if=/dev/zero of=$f bs=$(page_size) count=1
4407 }
4408 run_test 54b "char device works in lustre ======================"
4409
4410 find_loop_dev() {
4411         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4412         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4413         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4414
4415         for i in $(seq 3 7); do
4416                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4417                 LOOPDEV=$LOOPBASE$i
4418                 LOOPNUM=$i
4419                 break
4420         done
4421 }
4422
4423 cleanup_54c() {
4424         local rc=0
4425         loopdev="$DIR/loop54c"
4426
4427         trap 0
4428         $UMOUNT $DIR/$tdir || rc=$?
4429         losetup -d $loopdev || true
4430         losetup -d $LOOPDEV || true
4431         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4432         return $rc
4433 }
4434
4435 test_54c() {
4436         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4437         loopdev="$DIR/loop54c"
4438
4439         find_loop_dev
4440         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4441         trap cleanup_54c EXIT
4442         mknod $loopdev b 7 $LOOPNUM
4443         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4444         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4445         losetup $loopdev $DIR/$tfile ||
4446                 error "can't set up $loopdev for $DIR/$tfile"
4447         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4448         test_mkdir $DIR/$tdir
4449         mount -t ext2 $loopdev $DIR/$tdir ||
4450                 error "error mounting $loopdev on $DIR/$tdir"
4451         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4452                 error "dd write"
4453         df $DIR/$tdir
4454         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4455                 error "dd read"
4456         cleanup_54c
4457 }
4458 run_test 54c "block device works in lustre ====================="
4459
4460 test_54d() {
4461         f="$DIR/f54d"
4462         string="aaaaaa"
4463         mknod $f p
4464         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4465 }
4466 run_test 54d "fifo device works in lustre ======================"
4467
4468 test_54e() {
4469         f="$DIR/f54e"
4470         string="aaaaaa"
4471         cp -aL /dev/console $f
4472         echo $string > $f || error "echo $string to $f failed"
4473 }
4474 run_test 54e "console/tty device works in lustre ======================"
4475
4476 #The test_55 used to be iopen test and it was removed by bz#24037.
4477 #run_test 55 "check iopen_connect_dentry() ======================"
4478
4479 test_56a() {    # was test_56
4480         rm -rf $DIR/$tdir
4481         $SETSTRIPE -d $DIR
4482         test_mkdir -p $DIR/$tdir/dir
4483         NUMFILES=3
4484         NUMFILESx2=$(($NUMFILES * 2))
4485         for i in $(seq 1 $NUMFILES); do
4486                 touch $DIR/$tdir/file$i
4487                 touch $DIR/$tdir/dir/file$i
4488         done
4489
4490         # test lfs getstripe with --recursive
4491         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4492         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4493                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4494         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4495         [[ $FILENUM -eq $NUMFILES ]] ||
4496                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4497         echo "$GETSTRIPE --recursive passed."
4498
4499         # test lfs getstripe with file instead of dir
4500         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4501         [[ $FILENUM -eq 1 ]] ||
4502                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4503         echo "$GETSTRIPE file1 passed."
4504
4505         #test lfs getstripe with --verbose
4506         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4507                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4508                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4509         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4510                 error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4511
4512         #test lfs getstripe with -v prints lmm_fid
4513         [[ $($GETSTRIPE -v $DIR/$tdir | grep -c lmm_fid) -eq $NUMFILES ]] ||
4514                 error "$GETSTRIPE -v $DIR/$tdir: want $NUMFILES lmm_fid: lines"
4515         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_fid) -eq 0 ]] ||
4516                 error "$GETSTRIPE $DIR/$tdir: showed lmm_fid"
4517         echo "$GETSTRIPE --verbose passed."
4518
4519         #check for FID information
4520         local fid1=$($GETSTRIPE --fid $DIR/$tdir/file1)
4521         local fid2=$($GETSTRIPE --verbose $DIR/$tdir/file1 |
4522                        awk '/lmm_fid: / { print $2 }')
4523         local fid3=$($LFS path2fid $DIR/$tdir/file1)
4524         [ "$fid1" != "$fid2" ] &&
4525                 error "getstripe --fid $fid1 != getstripe --verbose $fid2"
4526         [ "$fid1" != "$fid3" ] &&
4527                 error "getstripe --fid $fid1 != lfs path2fid $fid3"
4528         echo "$GETSTRIPE --fid passed."
4529
4530         #test lfs getstripe with --obd
4531         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4532                 grep -q "unknown obduuid" ||
4533                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4534
4535         [[ $OSTCOUNT -lt 2 ]] &&
4536                 skip_env "skipping other $GETSTRIPE --obd test" && return
4537
4538         OSTIDX=1
4539         OBDUUID=$(ostuuid_from_index $OSTIDX)
4540         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4541         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4542         [[ $FOUND -eq $FILENUM ]] ||
4543                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4544         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4545                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4546                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4547                 error "$GETSTRIPE --obd: should not show file on other obd"
4548         echo "$GETSTRIPE --obd passed"
4549 }
4550 run_test 56a "check $GETSTRIPE"
4551
4552 test_56b() {
4553         test_mkdir $DIR/$tdir
4554         NUMDIRS=3
4555         for i in $(seq 1 $NUMDIRS); do
4556                 test_mkdir $DIR/$tdir/dir$i
4557         done
4558
4559         # test lfs getdirstripe default mode is non-recursion, which is
4560         # different from lfs getstripe
4561         dircnt=$($LFS getdirstripe $DIR/$tdir | grep -c lmv_stripe_count)
4562         [[ $dircnt -eq 1 ]] ||
4563                 error "$LFS getdirstripe: found $dircnt, not 1"
4564         dircnt=$($LFS getdirstripe --recursive $DIR/$tdir |
4565                 grep -c lmv_stripe_count)
4566         [[ $dircnt -eq $((NUMDIRS + 1)) ]] ||
4567                 error "$LFS getdirstripe --recursive: found $dircnt, \
4568                         not $((NUMDIRS + 1))"
4569 }
4570 run_test 56b "check $LFS getdirstripe"
4571
4572 test_56c() {
4573         local ost_idx=0
4574         local ost_name=$(ostname_from_index $ost_idx)
4575
4576         local old_status=$(ost_dev_status $ost_idx)
4577         [[ -z "$old_status" ]] ||
4578                 { skip_env "OST $ost_name is in $old_status status"; return 0; }
4579
4580         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
4581         sleep_maxage
4582
4583         local new_status=$(ost_dev_status $ost_idx)
4584         [[ "$new_status" = "D" ]] ||
4585                 error "OST $ost_name is in status of '$new_status', not 'D'"
4586
4587         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
4588         sleep_maxage
4589
4590         new_status=$(ost_dev_status $ost_idx)
4591         [[ -z "$new_status" ]] ||
4592                 error "OST $ost_name is in status of '$new_status', not ''"
4593 }
4594 run_test 56c "check 'lfs df' showing device status"
4595
4596 NUMFILES=3
4597 NUMDIRS=3
4598 setup_56() {
4599         local LOCAL_NUMFILES="$1"
4600         local LOCAL_NUMDIRS="$2"
4601         local MKDIR_PARAMS="$3"
4602         local DIR_STRIPE_PARAMS="$4"
4603
4604         if [ ! -d "$TDIR" ] ; then
4605                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4606                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4607                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4608                         touch $TDIR/file$i
4609                 done
4610                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4611                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4612                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4613                                 touch $TDIR/dir$i/file$j
4614                         done
4615                 done
4616         fi
4617 }
4618
4619 setup_56_special() {
4620         LOCAL_NUMFILES=$1
4621         LOCAL_NUMDIRS=$2
4622         setup_56 $1 $2
4623         if [ ! -e "$TDIR/loop1b" ] ; then
4624                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4625                         mknod $TDIR/loop${i}b b 7 $i
4626                         mknod $TDIR/null${i}c c 1 3
4627                         ln -s $TDIR/file1 $TDIR/link${i}l
4628                 done
4629                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4630                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4631                         mknod $TDIR/dir$i/null${i}c c 1 3
4632                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4633                 done
4634         fi
4635 }
4636
4637 test_56g() {
4638         $SETSTRIPE -d $DIR
4639
4640         TDIR=$DIR/${tdir}g
4641         setup_56 $NUMFILES $NUMDIRS
4642
4643         EXPECTED=$(($NUMDIRS + 2))
4644         # test lfs find with -name
4645         for i in $(seq 1 $NUMFILES) ; do
4646                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4647                 [ $NUMS -eq $EXPECTED ] ||
4648                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4649                               "found $NUMS, expected $EXPECTED"
4650         done
4651 }
4652 run_test 56g "check lfs find -name ============================="
4653
4654 test_56h() {
4655         $SETSTRIPE -d $DIR
4656
4657         TDIR=$DIR/${tdir}g
4658         setup_56 $NUMFILES $NUMDIRS
4659
4660         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4661         # test lfs find with ! -name
4662         for i in $(seq 1 $NUMFILES) ; do
4663                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4664                 [ $NUMS -eq $EXPECTED ] ||
4665                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4666                               "found $NUMS, expected $EXPECTED"
4667         done
4668 }
4669 run_test 56h "check lfs find ! -name"
4670
4671 test_56i() {
4672         tdir=${tdir}i
4673         test_mkdir $DIR/$tdir
4674         UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4675         CMD="$LFIND -ost $UUID $DIR/$tdir"
4676         OUT=$($CMD)
4677         [ -z "$OUT" ] || error "'$CMD' returned directory '$OUT'"
4678 }
4679 run_test 56i "check 'lfs find -ost UUID' skips directories"
4680
4681 test_56j() {
4682         TDIR=$DIR/${tdir}g
4683         setup_56_special $NUMFILES $NUMDIRS
4684
4685         EXPECTED=$((NUMDIRS + 1))
4686         CMD="$LFIND -type d $TDIR"
4687         NUMS=$($CMD | wc -l)
4688         [ $NUMS -eq $EXPECTED ] ||
4689                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4690 }
4691 run_test 56j "check lfs find -type d ============================="
4692
4693 test_56k() {
4694         TDIR=$DIR/${tdir}g
4695         setup_56_special $NUMFILES $NUMDIRS
4696
4697         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4698         CMD="$LFIND -type f $TDIR"
4699         NUMS=$($CMD | wc -l)
4700         [ $NUMS -eq $EXPECTED ] ||
4701                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4702 }
4703 run_test 56k "check lfs find -type f ============================="
4704
4705 test_56l() {
4706         TDIR=$DIR/${tdir}g
4707         setup_56_special $NUMFILES $NUMDIRS
4708
4709         EXPECTED=$((NUMDIRS + NUMFILES))
4710         CMD="$LFIND -type b $TDIR"
4711         NUMS=$($CMD | wc -l)
4712         [ $NUMS -eq $EXPECTED ] ||
4713                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4714 }
4715 run_test 56l "check lfs find -type b ============================="
4716
4717 test_56m() {
4718         TDIR=$DIR/${tdir}g
4719         setup_56_special $NUMFILES $NUMDIRS
4720
4721         EXPECTED=$((NUMDIRS + NUMFILES))
4722         CMD="$LFIND -type c $TDIR"
4723         NUMS=$($CMD | wc -l)
4724         [ $NUMS -eq $EXPECTED ] ||
4725                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4726 }
4727 run_test 56m "check lfs find -type c ============================="
4728
4729 test_56n() {
4730         TDIR=$DIR/${tdir}g
4731         setup_56_special $NUMFILES $NUMDIRS
4732
4733         EXPECTED=$((NUMDIRS + NUMFILES))
4734         CMD="$LFIND -type l $TDIR"
4735         NUMS=$($CMD | wc -l)
4736         [ $NUMS -eq $EXPECTED ] ||
4737                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4738 }
4739 run_test 56n "check lfs find -type l ============================="
4740
4741 test_56o() {
4742         TDIR=$DIR/${tdir}o
4743         setup_56 $NUMFILES $NUMDIRS
4744         utime $TDIR/file1 > /dev/null || error "utime (1)"
4745         utime $TDIR/file2 > /dev/null || error "utime (2)"
4746         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4747         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4748         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4749         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4750
4751         EXPECTED=4
4752         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4753         [ $NUMS -eq $EXPECTED ] || \
4754                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4755
4756         EXPECTED=12
4757         CMD="$LFIND -mtime 0 $TDIR"
4758         NUMS=$($CMD | wc -l)
4759         [ $NUMS -eq $EXPECTED ] ||
4760                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4761 }
4762 run_test 56o "check lfs find -mtime for old files =========================="
4763
4764 test_56p() {
4765         [ $RUNAS_ID -eq $UID ] &&
4766                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4767
4768         TDIR=$DIR/${tdir}p
4769         setup_56 $NUMFILES $NUMDIRS
4770
4771         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4772         EXPECTED=$NUMFILES
4773         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4774         NUMS=$($CMD | wc -l)
4775         [ $NUMS -eq $EXPECTED ] || \
4776                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4777
4778         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4779         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4780         NUMS=$($CMD | wc -l)
4781         [ $NUMS -eq $EXPECTED ] || \
4782                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4783 }
4784 run_test 56p "check lfs find -uid and ! -uid ==============================="
4785
4786 test_56q() {
4787         [ $RUNAS_ID -eq $UID ] &&
4788                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4789
4790         TDIR=$DIR/${tdir}q
4791         setup_56 $NUMFILES $NUMDIRS
4792
4793         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4794
4795         EXPECTED=$NUMFILES
4796         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4797         NUMS=$($CMD | wc -l)
4798         [ $NUMS -eq $EXPECTED ] ||
4799                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4800
4801         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4802         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4803         NUMS=$($CMD | wc -l)
4804         [ $NUMS -eq $EXPECTED ] ||
4805                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4806 }
4807 run_test 56q "check lfs find -gid and ! -gid ==============================="
4808
4809 test_56r() {
4810         TDIR=$DIR/${tdir}r
4811         setup_56 $NUMFILES $NUMDIRS
4812
4813         EXPECTED=12
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         EXPECTED=0
4819         CMD="$LFIND ! -size 0 -type f $TDIR"
4820         NUMS=$($CMD | wc -l)
4821         [ $NUMS -eq $EXPECTED ] ||
4822                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4823         echo "test" > $TDIR/$tfile
4824         echo "test2" > $TDIR/$tfile.2 && sync
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=1
4831         CMD="$LFIND -size +5 -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 +0 -type f $TDIR"
4837         NUMS=$($CMD | wc -l)
4838         [ $NUMS -eq $EXPECTED ] ||
4839                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4840         EXPECTED=2
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         EXPECTED=12
4846         CMD="$LFIND -size -5 -type f $TDIR"
4847         NUMS=$($CMD | wc -l)
4848         [ $NUMS -eq $EXPECTED ] ||
4849                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4850 }
4851 run_test 56r "check lfs find -size works =========================="
4852
4853 test_56s() { # LU-611
4854         TDIR=$DIR/${tdir}s
4855
4856         #LU-9369
4857         setup_56 0 $NUMDIRS
4858         for i in $(seq 1 $NUMDIRS); do
4859                 $SETSTRIPE -c $((OSTCOUNT + 1)) $TDIR/dir$i/$tfile
4860         done
4861         EXPECTED=$NUMDIRS
4862         CMD="$LFIND -c $OSTCOUNT $TDIR"
4863         NUMS=$($CMD | wc -l)
4864         [ $NUMS -eq $EXPECTED ] || {
4865                 $GETSTRIPE -R $TDIR
4866                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4867         }
4868         rm -rf $TDIR
4869
4870         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4871         if [[ $OSTCOUNT -gt 1 ]]; then
4872                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4873                 ONESTRIPE=4
4874                 EXTRA=4
4875         else
4876                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4877                 EXTRA=0
4878         fi
4879
4880         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4881         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4882         NUMS=$($CMD | wc -l)
4883         [ $NUMS -eq $EXPECTED ] || {
4884                 $GETSTRIPE -R $TDIR
4885                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4886         }
4887
4888         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4889         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4890         NUMS=$($CMD | wc -l)
4891         [ $NUMS -eq $EXPECTED ] || {
4892                 $GETSTRIPE -R $TDIR
4893                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4894         }
4895
4896         EXPECTED=$ONESTRIPE
4897         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4898         NUMS=$($CMD | wc -l)
4899         [ $NUMS -eq $EXPECTED ] || {
4900                 $GETSTRIPE -R $TDIR
4901                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4902         }
4903
4904         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4905         NUMS=$($CMD | wc -l)
4906         [ $NUMS -eq $EXPECTED ] || {
4907                 $GETSTRIPE -R $TDIR
4908                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4909         }
4910
4911         EXPECTED=0
4912         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4913         NUMS=$($CMD | wc -l)
4914         [ $NUMS -eq $EXPECTED ] || {
4915                 $GETSTRIPE -R $TDIR
4916                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4917         }
4918 }
4919 run_test 56s "check lfs find -stripe-count works"
4920
4921 test_56t() { # LU-611
4922         TDIR=$DIR/${tdir}t
4923
4924         #LU-9369
4925         setup_56 0 $NUMDIRS
4926         for i in $(seq 1 $NUMDIRS); do
4927                 $SETSTRIPE -S 4M $TDIR/dir$i/$tfile
4928         done
4929         EXPECTED=$NUMDIRS
4930         CMD="$LFIND -S 4M $TDIR"
4931         NUMS=$($CMD | wc -l)
4932         [ $NUMS -eq $EXPECTED ] || {
4933                 $GETSTRIPE -R $TDIR
4934                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4935         }
4936         rm -rf $TDIR
4937
4938         setup_56 $NUMFILES $NUMDIRS "--stripe-size 512k"
4939
4940         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4941
4942         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4943         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4944         NUMS=$($CMD | wc -l)
4945         [ $NUMS -eq $EXPECTED ] ||
4946                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4947
4948         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4949         NUMS=$($CMD | wc -l)
4950         [ $NUMS -eq $EXPECTED ] ||
4951                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4952
4953         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4954         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4955         NUMS=$($CMD | wc -l)
4956         [ $NUMS -eq $EXPECTED ] ||
4957                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4958
4959         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4960         NUMS=$($CMD | wc -l)
4961         [ $NUMS -eq $EXPECTED ] ||
4962                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4963
4964         EXPECTED=4
4965         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4966         NUMS=$($CMD | wc -l)
4967         [ $NUMS -eq $EXPECTED ] ||
4968                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4969
4970         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4971         NUMS=$($CMD | wc -l)
4972         [ $NUMS -eq $EXPECTED ] ||
4973                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4974
4975         EXPECTED=0
4976         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4977         NUMS=$($CMD | wc -l)
4978         [ $NUMS -eq $EXPECTED ] ||
4979                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4980 }
4981 run_test 56t "check lfs find -stripe-size works"
4982
4983 test_56u() { # LU-611
4984         TDIR=$DIR/${tdir}u
4985         setup_56 $NUMFILES $NUMDIRS "-i 0"
4986
4987         if [[ $OSTCOUNT -gt 1 ]]; then
4988                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4989                 ONESTRIPE=4
4990         else
4991                 ONESTRIPE=0
4992         fi
4993
4994         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4995         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4996         NUMS=$($CMD | wc -l)
4997         [ $NUMS -eq $EXPECTED ] ||
4998                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4999
5000         EXPECTED=$ONESTRIPE
5001         CMD="$LFIND -stripe-index 1 -type f $TDIR"
5002         NUMS=$($CMD | wc -l)
5003         [ $NUMS -eq $EXPECTED ] ||
5004                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5005
5006         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
5007         NUMS=$($CMD | wc -l)
5008         [ $NUMS -eq $EXPECTED ] ||
5009                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5010
5011         EXPECTED=0
5012         # This should produce an error and not return any files
5013         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
5014         NUMS=$($CMD 2>/dev/null | wc -l)
5015         [ $NUMS -eq $EXPECTED ] ||
5016                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5017
5018         if [[ $OSTCOUNT -gt 1 ]]; then
5019                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
5020                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
5021                 NUMS=$($CMD | wc -l)
5022                 [ $NUMS -eq $EXPECTED ] ||
5023                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5024         fi
5025 }
5026 run_test 56u "check lfs find -stripe-index works"
5027
5028 test_56v() {
5029     local MDT_IDX=0
5030
5031     TDIR=$DIR/${tdir}v
5032     rm -rf $TDIR
5033     setup_56 $NUMFILES $NUMDIRS
5034
5035     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
5036     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
5037
5038     for file in $($LFIND -mdt $UUID $TDIR); do
5039         file_mdt_idx=$($GETSTRIPE -M $file)
5040         [ $file_mdt_idx -eq $MDT_IDX ] ||
5041             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
5042     done
5043 }
5044 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
5045
5046 test_56w() {
5047         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5048         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5049         TDIR=$DIR/${tdir}w
5050
5051         rm -rf $TDIR || error "remove $TDIR failed"
5052         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
5053
5054         local stripe_size
5055         stripe_size=$($GETSTRIPE -S -d $TDIR) ||
5056                 error "$GETSTRIPE -S -d $TDIR failed"
5057         stripe_size=${stripe_size%% *}
5058
5059         local file_size=$((stripe_size * OSTCOUNT))
5060         local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
5061         local required_space=$((file_num * file_size))
5062
5063         local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
5064                            head -n1)
5065         [[ $free_space -le $((required_space / 1024)) ]] &&
5066                 skip_env "need $required_space bytes, have $free_space KB" &&
5067                 return
5068
5069         local dd_bs=65536
5070         local dd_count=$((file_size / dd_bs))
5071
5072         # write data into the files
5073         local i
5074         local j
5075         local file
5076         for i in $(seq 1 $NUMFILES); do
5077                 file=$TDIR/file$i
5078                 yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5079                         error "write data into $file failed"
5080         done
5081         for i in $(seq 1 $NUMDIRS); do
5082                 for j in $(seq 1 $NUMFILES); do
5083                         file=$TDIR/dir$i/file$j
5084                         yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5085                                 error "write data into $file failed"
5086                 done
5087         done
5088
5089         # $LFS_MIGRATE will fail if hard link migration is unsupported
5090         if [[ $(lustre_version_code mds1) -gt $(version_code 2.5.55) ]]; then
5091                 createmany -l$TDIR/dir1/file1 $TDIR/dir1/link 200 ||
5092                         error "creating links to $TDIR/dir1/file1 failed"
5093         fi
5094
5095         local expected=-1
5096         [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
5097
5098         # lfs_migrate file
5099         local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
5100         echo "$cmd"
5101         eval $cmd || error "$cmd failed"
5102
5103         check_stripe_count $TDIR/file1 $expected
5104
5105         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
5106         then
5107                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
5108                 # OST 1 if it is on OST 0. This file is small enough to
5109                 # be on only one stripe.
5110                 file=$TDIR/migr_1_ost
5111                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
5112                         error "write data into $file failed"
5113                 local obdidx=$($LFS getstripe -i $file)
5114                 local oldmd5=$(md5sum $file)
5115                 local newobdidx=0
5116                 [[ $obdidx -eq 0 ]] && newobdidx=1
5117                 cmd="$LFS migrate -i $newobdidx $file"
5118                 echo $cmd
5119                 eval $cmd || error "$cmd failed"
5120                 local realobdix=$($LFS getstripe -i $file)
5121                 local newmd5=$(md5sum $file)
5122                 [[ $newobdidx -ne $realobdix ]] &&
5123                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
5124                 [[ "$oldmd5" != "$newmd5" ]] &&
5125                         error "md5sum differ: $oldmd5, $newmd5"
5126         fi
5127
5128     # lfs_migrate dir
5129     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
5130     echo "$cmd"
5131     eval $cmd || error "$cmd failed"
5132
5133     for j in $(seq 1 $NUMFILES); do
5134         check_stripe_count $TDIR/dir1/file$j $expected
5135     done
5136
5137     # lfs_migrate works with lfs find
5138     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
5139          $LFS_MIGRATE -y -c $expected"
5140     echo "$cmd"
5141     eval $cmd || error "$cmd failed"
5142
5143     for i in $(seq 2 $NUMFILES); do
5144         check_stripe_count $TDIR/file$i $expected
5145     done
5146     for i in $(seq 2 $NUMDIRS); do
5147         for j in $(seq 1 $NUMFILES); do
5148             check_stripe_count $TDIR/dir$i/file$j $expected
5149         done
5150     done
5151 }
5152 run_test 56w "check lfs_migrate -c stripe_count works"
5153
5154 test_56x() {
5155         check_swap_layouts_support && return 0
5156         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5157
5158         local dir0=$DIR/$tdir
5159         local ref1=/etc/passwd
5160         local file1=$dir0/file1
5161
5162         test_mkdir $dir0 || error "creating dir $dir0"
5163         $LFS setstripe -c 2 $file1
5164         cp $ref1 $file1
5165         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
5166         stripe=$($LFS getstripe -c $file1)
5167         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5168         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5169
5170         # clean up
5171         rm -f $file1
5172 }
5173 run_test 56x "lfs migration support"
5174
5175 test_56xa() {
5176         check_swap_layouts_support && return 0
5177         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5178
5179         local dir0=$DIR/$tdir/$testnum
5180         test_mkdir -p $dir0
5181
5182         local ref1=/etc/passwd
5183         local file1=$dir0/file1
5184
5185         $LFS setstripe -c 2 $file1
5186         cp $ref1 $file1
5187         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
5188         local stripe=$($LFS getstripe -c $file1)
5189         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5190         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5191
5192         # clean up
5193         rm -f $file1
5194 }
5195 run_test 56xa "lfs migration --block support"
5196
5197 check_migrate_links() {
5198         local dir="$1"
5199         local file1="$dir/file1"
5200         local begin="$2"
5201         local count="$3"
5202         local total_count=$(($begin + $count - 1))
5203         local symlink_count=10
5204         local uniq_count=10
5205
5206         if [ ! -f "$file1" ]; then
5207                 echo -n "creating initial file..."
5208                 $LFS setstripe -c 1 -S "512k" "$file1" ||
5209                         error "cannot setstripe initial file"
5210                 echo "done"
5211
5212                 echo -n "creating symlinks..."
5213                 for s in $(seq 1 $symlink_count); do
5214                         ln -s "$file1" "$dir/slink$s" ||
5215                                 error "cannot create symlinks"
5216                 done
5217                 echo "done"
5218
5219                 echo -n "creating nonlinked files..."
5220                 createmany -o "$dir/uniq" 1 10 &> /dev/null ||
5221                         error "cannot create nonlinked files"
5222                 echo "done"
5223         fi
5224
5225         # create hard links
5226         if [ ! -f "$dir/file$total_count" ]; then
5227                 echo -n "creating hard links $begin:$total_count..."
5228                 createmany -l"$file1" "$dir/file" "$begin" "$count" &>  \
5229                         /dev/null || error "cannot create hard links"
5230                 echo "done"
5231         fi
5232
5233         echo -n "checking number of hard links listed in xattrs..."
5234         local fid=$($LFS getstripe -F "$file1")
5235         local paths=($($LFS fid2path "$MOUNT" "$fid" 2> /dev/null))
5236
5237         echo "${#paths[*]}"
5238         if [ ${#paths[*]} -lt $total_count -a "$begin" -eq 2  ]; then
5239                         echo "hard link list has unexpected size, skipping test"
5240                         return 0
5241         fi
5242         if [ ${#paths[*]} -ge $total_count -a "$begin" -ne 2  ]; then
5243                         error "link names should exceed xattrs size"
5244         fi
5245
5246         echo -n "migrating files..."
5247         local migrate_out=$($LFS_MIGRATE -y -S '1m' $dir)
5248         local rc=$?
5249         [ $rc -eq 0 ] || error "migrate failed rc = $rc"
5250         echo "done"
5251
5252         # make sure all links have been properly migrated
5253         echo -n "verifying files..."
5254         fid=$($LFS getstripe -F "$file1") ||
5255                 error "cannot get fid for file $file1"
5256         for i in $(seq 2 $total_count); do
5257                 local fid2=$($LFS getstripe -F $dir/file$i)
5258                 [ "$fid2" == "$fid" ] ||
5259                         error "migrated hard link has mismatched FID"
5260         done
5261
5262         # make sure hard links were properly detected, and migration was
5263         # performed only once for the entire link set; nonlinked files should
5264         # also be migrated
5265         local actual=$(grep -c 'done migrate' <<< "$migrate_out")
5266         local expected=$(($uniq_count + 1))
5267         [ "$actual" -eq  "$expected" ] ||
5268                 error "hard links individually migrated ($actual != $expected)"
5269
5270         # make sure the correct number of hard links are present
5271         local hardlinks=$(stat -c '%h' "$file1")
5272         [ $hardlinks -eq $total_count ] ||
5273                 error "num hard links $hardlinks != $total_count"
5274         echo "done"
5275
5276         return 0
5277 }
5278
5279 test_56xb() {
5280         local dir0="$DIR/$tdir"
5281
5282         test_mkdir "$dir0" || error "cannot create dir $dir0"
5283
5284         echo "testing lfs migrate mode when all links fit within xattrs"
5285         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir0" 2 99
5286
5287         echo "testing rsync mode when all links fit within xattrs"
5288         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir0" 2 99
5289
5290         echo "testing lfs migrate mode when all links do not fit within xattrs"
5291         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir0" 101 100
5292
5293         echo "testing rsync mode when all links do not fit within xattrs"
5294         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir0" 101 100
5295
5296         # clean up
5297         rm -rf $dir0
5298 }
5299 run_test 56xb "lfs migration hard link support"
5300
5301 test_56y() {
5302         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
5303                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
5304                 return
5305
5306         local res=""
5307         local dir0=$DIR/$tdir/$testnum
5308         test_mkdir -p $dir0
5309         local f1=$dir0/file1
5310         local f2=$dir0/file2
5311
5312         touch $f1 || error "creating std file $f1"
5313         $MULTIOP $f2 H2c || error "creating released file $f2"
5314
5315         # a directory can be raid0, so ask only for files
5316         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
5317         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
5318
5319         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
5320         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
5321
5322         # only files can be released, so no need to force file search
5323         res=$($LFIND $dir0 -L released)
5324         [[ $res == $f2 ]] || error "search released: found $res != $f2"
5325
5326         res=$($LFIND $dir0 \! -L released)
5327         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
5328
5329 }
5330 run_test 56y "lfs find -L raid0|released"
5331
5332 test_56z() { # LU-4824
5333         # This checks to make sure 'lfs find' continues after errors
5334         # There are two classes of errors that should be caught:
5335         # - If multiple paths are provided, all should be searched even if one
5336         #   errors out
5337         # - If errors are encountered during the search, it should not terminate
5338         #   early
5339         local i
5340         test_mkdir $DIR/$tdir
5341         for i in d{0..9}; do
5342                 test_mkdir $DIR/$tdir/$i
5343         done
5344         touch $DIR/$tdir/d{0..9}/$tfile
5345         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5346                 error "$LFS find did not return an error"
5347         # Make a directory unsearchable. This should NOT be the last entry in
5348         # directory order.  Arbitrarily pick the 6th entry
5349         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5350         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5351         # The user should be able to see 10 directories and 9 files
5352         [ $count == 19 ] || error "$LFS find did not continue after error"
5353 }
5354 run_test 56z "lfs find should continue after an error"
5355
5356 test_56aa() { # LU-5937
5357         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5358
5359         mkdir $DIR/$tdir
5360         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5361
5362         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5363         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5364
5365         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5366 }
5367 run_test 56aa "lfs find --size under striped dir"
5368
5369 test_56ba() {
5370         # Create composite files with one component
5371         TDIR=$DIR/$tdir/1Mfiles
5372         setup_56 5 1 "--component-end 1M"
5373         # Create composite files with three components
5374         TDIR=$DIR/$tdir/2Mfiles
5375         setup_56 5 2 "-E 2M -E 4M -E 6M"
5376         TDIR=$DIR/$tdir
5377         # Create non-composite files
5378         createmany -o $TDIR/${tfile}- 10
5379
5380         local nfiles=$($LFIND --component-end 1M --type f $TDIR | wc -l)
5381         [[ $nfiles == 10 ]] ||
5382                 error "lfs find -E 1M found $nfiles != 10 files"
5383
5384         nfiles=$($LFIND ! -E 1M --type f $TDIR | wc -l)
5385         [[ $nfiles == 25 ]] ||
5386                 error "lfs find ! -E 1M found $nfiles != 25 files"
5387
5388         # All files have a component that starts at 0
5389         local nfiles=$($LFIND --component-start 0 --type f $TDIR | wc -l)
5390         [[ $nfiles == 35 ]] ||
5391                 error "lfs find --component-start 0 found $nfiles != 35 files"
5392
5393         nfiles=$($LFIND --component-start 2M --type f $TDIR | wc -l)
5394         [[ $nfiles == 15 ]] ||
5395                 error "$LFIND --component-start 2M found $nfiles != 15 files"
5396
5397         # All files created here have a componenet that does not starts at 2M
5398         nfiles=$($LFIND ! --component-start 2M --type f $TDIR | wc -l)
5399         [[ $nfiles == 35 ]] ||
5400                 error "$LFIND ! --component-start 2M found $nfiles != 35 files"
5401
5402         # Find files with a specified number of components
5403         local nfiles=$($LFIND --component-count 3 --type f $TDIR | wc -l)
5404         [[ $nfiles == 15 ]] ||
5405                 error "lfs find --component-count 3 found $nfiles != 15 files"
5406
5407         # Remember non-composite files have a component count of zero
5408         local nfiles=$($LFIND --component-count 0 --type f $TDIR | wc -l)
5409         [[ $nfiles == 10 ]] ||
5410                 error "lfs find --component-count 0 found $nfiles != 10 files"
5411
5412         nfiles=$($LFIND ! --component-count 3 --type f $TDIR | wc -l)
5413         [[ $nfiles == 20 ]] ||
5414                 error "$LFIND ! --component-count 3 found $nfiles != 20 files"
5415
5416         # All files have a flag called "init"
5417         local nfiles=$($LFIND --component-flags init --type f $TDIR | wc -l)
5418         [[ $nfiles == 35 ]] ||
5419                 error "$LFIND --component-flags init found $nfiles != 35 files"
5420
5421         # Multi-component files will have a component not initialized
5422         local nfiles=$($LFIND ! --component-flags init --type f $TDIR | wc -l)
5423         [[ $nfiles == 15 ]] ||
5424                 error "$LFIND !--component-flags init found $nfiles != 15 files"
5425
5426         rm -rf $TDIR
5427
5428 }
5429 run_test 56ba "test lfs find --component-end, -start, -count, and -flags"
5430
5431 test_57a() {
5432         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5433         # note test will not do anything if MDS is not local
5434         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5435                 skip "ldiskfs only test"
5436                 return
5437         fi
5438
5439         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5440         local MNTDEV="osd*.*MDT*.mntdev"
5441         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5442         [ -z "$DEV" ] && error "can't access $MNTDEV"
5443         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5444                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5445                         error "can't access $DEV"
5446                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5447                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5448                 rm $TMP/t57a.dump
5449         done
5450 }
5451 run_test 57a "verify MDS filesystem created with large inodes =="
5452
5453 test_57b() {
5454         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5455         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5456                 skip "ldiskfs only test"
5457                 return
5458         fi
5459
5460         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5461         local dir=$DIR/$tdir
5462
5463         local FILECOUNT=100
5464         local FILE1=$dir/f1
5465         local FILEN=$dir/f$FILECOUNT
5466
5467         rm -rf $dir || error "removing $dir"
5468         test_mkdir -c1 $dir
5469         local mdtidx=$($LFS getstripe -M $dir)
5470         local mdtname=MDT$(printf %04x $mdtidx)
5471         local facet=mds$((mdtidx + 1))
5472
5473         echo "mcreating $FILECOUNT files"
5474         createmany -m $dir/f 1 $FILECOUNT || \
5475                 error "creating files in $dir"
5476
5477         # verify that files do not have EAs yet
5478         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5479         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5480
5481         sync
5482         sleep 1
5483         df $dir  #make sure we get new statfs data
5484         local MDSFREE=$(do_facet $facet \
5485                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5486         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5487         echo "opening files to create objects/EAs"
5488         local FILE
5489         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5490                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5491         done
5492
5493         # verify that files have EAs now
5494         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5495         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5496
5497         sleep 1  #make sure we get new statfs data
5498         df $dir
5499         local MDSFREE2=$(do_facet $facet \
5500                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5501         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5502         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5503                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5504                         error "MDC before $MDCFREE != after $MDCFREE2"
5505                 else
5506                         echo "MDC before $MDCFREE != after $MDCFREE2"
5507                         echo "unable to confirm if MDS has large inodes"
5508                 fi
5509         fi
5510         rm -rf $dir
5511 }
5512 run_test 57b "default LOV EAs are stored inside large inodes ==="
5513
5514 test_58() {
5515         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5516         [ -z "$(which wiretest 2>/dev/null)" ] &&
5517                         skip_env "could not find wiretest" && return
5518         wiretest
5519 }
5520 run_test 58 "verify cross-platform wire constants =============="
5521
5522 test_59() {
5523         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5524         echo "touch 130 files"
5525         createmany -o $DIR/f59- 130
5526         echo "rm 130 files"
5527         unlinkmany $DIR/f59- 130
5528         sync
5529         # wait for commitment of removal
5530         wait_delete_completed
5531 }
5532 run_test 59 "verify cancellation of llog records async ========="
5533
5534 TEST60_HEAD="test_60 run $RANDOM"
5535 test_60a() {
5536         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5537         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5538         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5539                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5540                         skip_env "missing subtest run-llog.sh" && return
5541
5542         log "$TEST60_HEAD - from kernel mode"
5543         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5544         do_facet mgs "sh run-llog.sh" || error "run-llog.sh failed"
5545         do_facet mgs $LCTL dk > $TMP/$tfile
5546
5547         # LU-6388: test llog_reader
5548         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5549         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5550         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5551                         skip_env "missing llog_reader" && return
5552         local fstype=$(facet_fstype mgs)
5553         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5554                 skip_env "Only for ldiskfs or zfs type mgs" && return
5555
5556         local mntpt=$(facet_mntpt mgs)
5557         local mgsdev=$(mgsdevname 1)
5558         local fid_list
5559         local fid
5560         local rec_list
5561         local rec
5562         local rec_type
5563         local obj_file
5564         local path
5565         local seq
5566         local oid
5567         local pass=true
5568
5569         #get fid and record list
5570         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5571                 tail -n 4))
5572         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5573                 tail -n 4))
5574         #remount mgs as ldiskfs or zfs type
5575         stop mgs || error "stop mgs failed"
5576         mount_fstype mgs || error "remount mgs failed"
5577         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5578                 fid=${fid_list[i]}
5579                 rec=${rec_list[i]}
5580                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5581                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5582                 oid=$((16#$oid))
5583
5584                 case $fstype in
5585                         ldiskfs )
5586                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5587                         zfs )
5588                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5589                 esac
5590                 echo "obj_file is $obj_file"
5591                 do_facet mgs $llog_reader $obj_file
5592
5593                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5594                         awk '{ print $3 }' | sed -e "s/^type=//g")
5595                 if [ $rec_type != $rec ]; then
5596                         echo "FAILED test_60a wrong record type $rec_type," \
5597                               "should be $rec"
5598                         pass=false
5599                         break
5600                 fi
5601
5602                 #check obj path if record type is LLOG_LOGID_MAGIC
5603                 if [ "$rec" == "1064553b" ]; then
5604                         path=$(do_facet mgs $llog_reader $obj_file |
5605                                 grep "path=" | awk '{ print $NF }' |
5606                                 sed -e "s/^path=//g")
5607                         if [ $obj_file != $mntpt/$path ]; then
5608                                 echo "FAILED test_60a wrong obj path" \
5609                                       "$montpt/$path, should be $obj_file"
5610                                 pass=false
5611                                 break
5612                         fi
5613                 fi
5614         done
5615         rm -f $TMP/$tfile
5616         #restart mgs before "error", otherwise it will block the next test
5617         stop mgs || error "stop mgs failed"
5618         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5619         $pass || error "test failed, see FAILED test_60a messages for specifics"
5620 }
5621 run_test 60a "llog_test run from kernel module and test llog_reader"
5622
5623 test_60aa() {
5624         # test old logid format
5625         if [ $(lustre_version_code mgs) -le $(version_code 3.1.53) ]; then
5626                 do_facet mgs $LCTL dl | grep MGS
5627                 do_facet mgs "$LCTL --device %MGS llog_print \\\\\\\$$FSNAME-client" ||
5628                         error "old llog_print failed"
5629         fi
5630
5631         # test new logid format
5632         if [ $(lustre_version_code mgs) -ge $(version_code 2.9.53) ]; then
5633                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
5634                         error "new llog_print failed"
5635         fi
5636 }
5637 run_test 60aa "llog_print works with FIDs and simple names"
5638
5639 test_60b() { # bug 6411
5640         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5641         dmesg > $DIR/$tfile
5642         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
5643                                 /llog.test/ {
5644                                         if (marker)
5645                                                 from_marker++
5646                                         from_begin++
5647                                 }
5648                                 END {
5649                                         if (marker)
5650                                                 print from_marker
5651                                         else
5652                                                 print from_begin
5653                                 }")
5654         [[ $LLOG_COUNT -gt 100 ]] &&
5655                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5656 }
5657 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5658
5659 test_60c() {
5660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5661         echo "create 5000 files"
5662         createmany -o $DIR/f60c- 5000
5663 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5664         lctl set_param fail_loc=0x80000137
5665         unlinkmany $DIR/f60c- 5000
5666         lctl set_param fail_loc=0
5667 }
5668 run_test 60c "unlink file when mds full"
5669
5670 test_60d() {
5671         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5672         SAVEPRINTK=$(lctl get_param -n printk)
5673
5674         # verify "lctl mark" is even working"
5675         MESSAGE="test message ID $RANDOM $$"
5676         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5677         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5678
5679         lctl set_param printk=0 || error "set lnet.printk failed"
5680         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5681         MESSAGE="new test message ID $RANDOM $$"
5682         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5683         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5684         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5685
5686         lctl set_param -n printk="$SAVEPRINTK"
5687 }
5688 run_test 60d "test printk console message masking"
5689
5690 test_60e() {
5691         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5692         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5693         touch $DIR/$tfile
5694 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5695         do_facet mds1 lctl set_param fail_loc=0x15b
5696         rm $DIR/$tfile
5697 }
5698 run_test 60e "no space while new llog is being created"
5699
5700 test_61() {
5701         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5702         f="$DIR/f61"
5703         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5704         cancel_lru_locks osc
5705         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5706         sync
5707 }
5708 run_test 61 "mmap() writes don't make sync hang ================"
5709
5710 # bug 2330 - insufficient obd_match error checking causes LBUG
5711 test_62() {
5712         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5713         f="$DIR/f62"
5714         echo foo > $f
5715         cancel_lru_locks osc
5716         lctl set_param fail_loc=0x405
5717         cat $f && error "cat succeeded, expect -EIO"
5718         lctl set_param fail_loc=0
5719 }
5720 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5721 # match every page all of the time.
5722 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5723
5724 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5725 # Though this test is irrelevant anymore, it helped to reveal some
5726 # other grant bugs (LU-4482), let's keep it.
5727 test_63a() {   # was test_63
5728         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5729         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5730         for i in `seq 10` ; do
5731                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5732                 sleep 5
5733                 kill $!
5734                 sleep 1
5735         done
5736
5737         rm -f $DIR/f63 || true
5738 }
5739 run_test 63a "Verify oig_wait interruption does not crash ======="
5740
5741 # bug 2248 - async write errors didn't return to application on sync
5742 # bug 3677 - async write errors left page locked
5743 test_63b() {
5744         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5745         debugsave
5746         lctl set_param debug=-1
5747
5748         # ensure we have a grant to do async writes
5749         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5750         rm $DIR/$tfile
5751
5752         sync    # sync lest earlier test intercept the fail_loc
5753
5754         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5755         lctl set_param fail_loc=0x80000406
5756         $MULTIOP $DIR/$tfile Owy && \
5757                 error "sync didn't return ENOMEM"
5758         sync; sleep 2; sync     # do a real sync this time to flush page
5759         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5760                 error "locked page left in cache after async error" || true
5761         debugrestore
5762 }
5763 run_test 63b "async write errors should be returned to fsync ==="
5764
5765 test_64a () {
5766         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5767         df $DIR
5768         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5769 }
5770 run_test 64a "verify filter grant calculations (in kernel) ====="
5771
5772 test_64b () {
5773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5774         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5775 }
5776 run_test 64b "check out-of-space detection on client"
5777
5778 test_64c() {
5779         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5780 }
5781 run_test 64c "verify grant shrink"
5782
5783 # bug 1414 - set/get directories' stripe info
5784 test_65a() {
5785         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5786         test_mkdir $DIR/$tdir
5787         touch $DIR/$tdir/f1
5788         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5789 }
5790 run_test 65a "directory with no stripe info"
5791
5792 test_65b() {
5793         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5794         test_mkdir $DIR/$tdir
5795         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5796
5797         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5798                                                 error "setstripe"
5799         touch $DIR/$tdir/f2
5800         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5801 }
5802 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
5803
5804 test_65c() {
5805         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5806         [ $OSTCOUNT -lt 2 ] && skip "need at least 2 OSTs" && return
5807         test_mkdir $DIR/$tdir
5808         local stripesize=$($GETSTRIPE -S $DIR/$tdir)
5809
5810         $LFS setstripe -S $((stripesize * 4)) -i 1 \
5811                 -c $((OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5812         touch $DIR/$tdir/f3
5813         $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5814 }
5815 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
5816
5817 test_65d() {
5818         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5819         test_mkdir $DIR/$tdir
5820         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
5821         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5822
5823         if [[ $STRIPECOUNT -le 0 ]]; then
5824                 sc=1
5825         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5826 #LOV_MAX_STRIPE_COUNT is 2000
5827                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5828         else
5829                 sc=$(($STRIPECOUNT - 1))
5830         fi
5831         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5832         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5833         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5834                 error "lverify failed"
5835 }
5836 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
5837
5838 test_65e() {
5839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5840         test_mkdir $DIR/$tdir
5841
5842         $SETSTRIPE $DIR/$tdir || error "setstripe"
5843         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5844                                         error "no stripe info failed"
5845         touch $DIR/$tdir/f6
5846         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5847 }
5848 run_test 65e "directory setstripe defaults"
5849
5850 test_65f() {
5851         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5852         test_mkdir $DIR/${tdir}f
5853         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5854 }
5855 run_test 65f "dir setstripe permission (should return error) ==="
5856
5857 test_65g() {
5858         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5859         test_mkdir $DIR/$tdir
5860         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5861
5862         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5863                 error "setstripe -S failed"
5864         $LFS setstripe -d $DIR/$tdir || error "setstripe -d failed"
5865         $LFS getstripe -v $DIR/$tdir | grep "Default" ||
5866                 error "delete default stripe failed"
5867 }
5868 run_test 65g "directory setstripe -d"
5869
5870 test_65h() {
5871         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5872         test_mkdir $DIR/$tdir
5873         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5874
5875         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5876                 error "setstripe -S failed"
5877         test_mkdir $DIR/$tdir/dd1
5878         [ $($LFS getstripe -c $DIR/$tdir) = $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5879                 error "stripe info inherit failed"
5880 }
5881 run_test 65h "directory stripe info inherit ===================="
5882
5883 test_65i() { # bug6367
5884         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5885         $SETSTRIPE -S 65536 -c -1 $MOUNT
5886 }
5887 run_test 65i "set non-default striping on root directory (bug 6367)="
5888
5889 test_65ia() { # bug12836
5890         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5891         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5892 }
5893 run_test 65ia "getstripe on -1 default directory striping"
5894
5895 test_65ib() { # bug12836
5896         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5897         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5898 }
5899 run_test 65ib "getstripe -v on -1 default directory striping"
5900
5901 test_65ic() { # bug12836
5902         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5903         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5904 }
5905 run_test 65ic "new find on -1 default directory striping"
5906
5907 test_65j() { # bug6367
5908         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5909         sync; sleep 1
5910         # if we aren't already remounting for each test, do so for this test
5911         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5912                 cleanup || error "failed to unmount"
5913                 setup
5914         fi
5915         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5916 }
5917 run_test 65j "set default striping on root directory (bug 6367)="
5918
5919 test_65k() { # bug11679
5920         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5921         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5922         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5923
5924         local disable_precreate=true
5925         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.8.54) ] &&
5926                 disable_precreate=false
5927
5928         echo "Check OST status: "
5929         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
5930                 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
5931
5932         for OSC in $MDS_OSCS; do
5933                 echo $OSC "is active"
5934                 do_facet $SINGLEMDS lctl --device %$OSC activate
5935         done
5936
5937         for INACTIVE_OSC in $MDS_OSCS; do
5938                 local ost=$(osc_to_ost $INACTIVE_OSC)
5939                 local ostnum=$(do_facet $SINGLEMDS lctl get_param -n \
5940                                lov.*md*.target_obd |
5941                                awk -F: /$ost/'{ print $1 }' | head -n 1)
5942
5943                 mkdir -p $DIR/$tdir
5944                 $SETSTRIPE -i $ostnum -c 1 $DIR/$tdir
5945                 createmany -o $DIR/$tdir/$tfile.$ostnum. 1000
5946
5947                 echo "Deactivate: " $INACTIVE_OSC
5948                 do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5949
5950                 local count=$(do_facet $SINGLEMDS "lctl get_param -n \
5951                               osp.$ost*MDT0000.create_count")
5952                 local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
5953                                   osp.$ost*MDT0000.max_create_count")
5954                 $disable_precreate &&
5955                         do_facet $SINGLEMDS "lctl set_param -n \
5956                                 osp.$ost*MDT0000.max_create_count=0"
5957
5958                 for idx in $(seq 0 $((OSTCOUNT - 1))); do
5959                         [ -f $DIR/$tdir/$idx ] && continue
5960                         echo "$SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx"
5961                         $SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx ||
5962                                 error "setstripe $idx should succeed"
5963                         rm -f $DIR/$tdir/$idx || error "rm $idx failed"
5964                 done
5965                 unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
5966                 rmdir $DIR/$tdir
5967
5968                 do_facet $SINGLEMDS "lctl set_param -n \
5969                         osp.$ost*MDT0000.max_create_count=$max_count"
5970                 do_facet $SINGLEMDS "lctl set_param -n \
5971                         osp.$ost*MDT0000.create_count=$count"
5972                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5973                 echo $INACTIVE_OSC "is Activate"
5974
5975                 wait_osc_import_state mds ost$ostnum FULL
5976         done
5977 }
5978 run_test 65k "validate manual striping works properly with deactivated OSCs"
5979
5980 test_65l() { # bug 12836
5981         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5982         test_mkdir -p $DIR/$tdir/test_dir
5983         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5984         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5985 }
5986 run_test 65l "lfs find on -1 stripe dir ========================"
5987
5988 test_65m() {
5989         $RUNAS $SETSTRIPE -c 2 $MOUNT && error "setstripe should fail"
5990         true
5991 }
5992 run_test 65m "normal user can't set filesystem default stripe"
5993
5994 # bug 2543 - update blocks count on client
5995 test_66() {
5996         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5997         COUNT=${COUNT:-8}
5998         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5999         sync; sync_all_data; sync; sync_all_data
6000         cancel_lru_locks osc
6001         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
6002         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
6003 }
6004 run_test 66 "update inode blocks count on client ==============="
6005
6006 meminfo() {
6007         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
6008 }
6009
6010 swap_used() {
6011         swapon -s | awk '($1 == "'$1'") { print $4 }'
6012 }
6013
6014 # bug5265, obdfilter oa2dentry return -ENOENT
6015 # #define OBD_FAIL_SRV_ENOENT 0x217
6016 test_69() {
6017         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6018         remote_ost_nodsh && skip "remote OST with nodsh" && return
6019
6020         f="$DIR/$tfile"
6021         $SETSTRIPE -c 1 -i 0 $f
6022
6023         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
6024
6025         do_facet ost1 lctl set_param fail_loc=0x217
6026         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
6027         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
6028
6029         do_facet ost1 lctl set_param fail_loc=0
6030         $DIRECTIO write $f 0 2 || error "write error"
6031
6032         cancel_lru_locks osc
6033         $DIRECTIO read $f 0 1 || error "read error"
6034
6035         do_facet ost1 lctl set_param fail_loc=0x217
6036         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
6037
6038         do_facet ost1 lctl set_param fail_loc=0
6039         rm -f $f
6040 }
6041 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
6042
6043 test_71() {
6044         test_mkdir $DIR/$tdir
6045         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
6046         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
6047 }
6048 run_test 71 "Running dbench on lustre (don't segment fault) ===="
6049
6050 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
6051         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6052         [ "$RUNAS_ID" = "$UID" ] &&
6053                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6054
6055         # Check that testing environment is properly set up. Skip if not
6056         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
6057                 skip_env "User $RUNAS_ID does not exist - skipping"
6058                 return 0
6059         }
6060         touch $DIR/$tfile
6061         chmod 777 $DIR/$tfile
6062         chmod ug+s $DIR/$tfile
6063         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
6064                 error "$RUNAS dd $DIR/$tfile failed"
6065         # See if we are still setuid/sgid
6066         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6067                 error "S/gid is not dropped on write"
6068         # Now test that MDS is updated too
6069         cancel_lru_locks mdc
6070         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6071                 error "S/gid is not dropped on MDS"
6072         rm -f $DIR/$tfile
6073 }
6074 run_test 72a "Test that remove suid works properly (bug5695) ===="
6075
6076 test_72b() { # bug 24226 -- keep mode setting when size is not changing
6077         local perm
6078
6079         [ "$RUNAS_ID" = "$UID" ] && \
6080                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6081         [ "$RUNAS_ID" -eq 0 ] && \
6082                 skip_env "RUNAS_ID = 0 -- skipping" && return
6083
6084         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6085         # Check that testing environment is properly set up. Skip if not
6086         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
6087                 skip_env "User $RUNAS_ID does not exist - skipping"
6088                 return 0
6089         }
6090         touch $DIR/${tfile}-f{g,u}
6091         test_mkdir $DIR/${tfile}-dg
6092         test_mkdir $DIR/${tfile}-du
6093         chmod 770 $DIR/${tfile}-{f,d}{g,u}
6094         chmod g+s $DIR/${tfile}-{f,d}g
6095         chmod u+s $DIR/${tfile}-{f,d}u
6096         for perm in 777 2777 4777; do
6097                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
6098                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
6099                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
6100                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
6101         done
6102         true
6103 }
6104 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
6105
6106 # bug 3462 - multiple simultaneous MDC requests
6107 test_73() {
6108         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6109         test_mkdir $DIR/d73-1
6110         test_mkdir $DIR/d73-2
6111         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
6112         pid1=$!
6113
6114         lctl set_param fail_loc=0x80000129
6115         $MULTIOP $DIR/d73-1/f73-2 Oc &
6116         sleep 1
6117         lctl set_param fail_loc=0
6118
6119         $MULTIOP $DIR/d73-2/f73-3 Oc &
6120         pid3=$!
6121
6122         kill -USR1 $pid1
6123         wait $pid1 || return 1
6124
6125         sleep 25
6126
6127         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
6128         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
6129         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
6130
6131         rm -rf $DIR/d73-*
6132 }
6133 run_test 73 "multiple MDC requests (should not deadlock)"
6134
6135 test_74a() { # bug 6149, 6184
6136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6137         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6138         #
6139         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6140         # will spin in a tight reconnection loop
6141         touch $DIR/f74a
6142         $LCTL set_param fail_loc=0x8000030e
6143         # get any lock that won't be difficult - lookup works.
6144         ls $DIR/f74a
6145         $LCTL set_param fail_loc=0
6146         rm -f $DIR/f74a
6147         true
6148 }
6149 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
6150
6151 test_74b() { # bug 13310
6152         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6153         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6154         #
6155         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6156         # will spin in a tight reconnection loop
6157         $LCTL set_param fail_loc=0x8000030e
6158         # get a "difficult" lock
6159         touch $DIR/f74b
6160         $LCTL set_param fail_loc=0
6161         rm -f $DIR/f74b
6162         true
6163 }
6164 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
6165
6166 test_74c() {
6167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6168         #define OBD_FAIL_LDLM_NEW_LOCK
6169         $LCTL set_param fail_loc=0x319
6170         touch $DIR/$tfile && error "touch successful"
6171         $LCTL set_param fail_loc=0
6172         true
6173 }
6174 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
6175
6176 num_inodes() {
6177         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
6178 }
6179
6180 test_76() { # Now for bug 20433, added originally in bug 1443
6181         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6182         local CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
6183         cancel_lru_locks osc
6184         BEFORE_INODES=$(num_inodes)
6185         echo "before inodes: $BEFORE_INODES"
6186         local COUNT=1000
6187         [ "$SLOW" = "no" ] && COUNT=100
6188         for i in $(seq $COUNT); do
6189                 touch $DIR/$tfile
6190                 rm -f $DIR/$tfile
6191         done
6192         cancel_lru_locks osc
6193         AFTER_INODES=$(num_inodes)
6194         echo "after inodes: $AFTER_INODES"
6195         local wait=0
6196         while [[ $((AFTER_INODES-1*${CPUS:-1})) -gt $BEFORE_INODES ]]; do
6197                 sleep 2
6198                 AFTER_INODES=$(num_inodes)
6199                 wait=$((wait+2))
6200                 echo "wait $wait seconds inodes: $AFTER_INODES"
6201                 if [ $wait -gt 30 ]; then
6202                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
6203                 fi
6204         done
6205 }
6206 run_test 76 "confirm clients recycle inodes properly ===="
6207
6208
6209 export ORIG_CSUM=""
6210 set_checksums()
6211 {
6212         # Note: in sptlrpc modes which enable its own bulk checksum, the
6213         # original crc32_le bulk checksum will be automatically disabled,
6214         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
6215         # will be checked by sptlrpc code against sptlrpc bulk checksum.
6216         # In this case set_checksums() will not be no-op, because sptlrpc
6217         # bulk checksum will be enabled all through the test.
6218
6219         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
6220         lctl set_param -n osc.*.checksums $1
6221         return 0
6222 }
6223
6224 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
6225                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
6226 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
6227 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
6228 set_checksum_type()
6229 {
6230         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
6231         log "set checksum type to $1"
6232         return 0
6233 }
6234 F77_TMP=$TMP/f77-temp
6235 F77SZ=8
6236 setup_f77() {
6237         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
6238                 error "error writing to $F77_TMP"
6239 }
6240
6241 test_77a() { # bug 10889
6242         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6243         $GSS && skip "could not run with gss" && return
6244         [ ! -f $F77_TMP ] && setup_f77
6245         set_checksums 1
6246         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
6247         set_checksums 0
6248         rm -f $DIR/$tfile
6249 }
6250 run_test 77a "normal checksum read/write operation"
6251
6252 test_77b() { # bug 10889
6253         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6254         $GSS && skip "could not run with gss" && return
6255         [ ! -f $F77_TMP ] && setup_f77
6256         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6257         $LCTL set_param fail_loc=0x80000409
6258         set_checksums 1
6259
6260         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6261                 error "dd error: $?"
6262         $LCTL set_param fail_loc=0
6263
6264         for algo in $CKSUM_TYPES; do
6265                 cancel_lru_locks osc
6266                 set_checksum_type $algo
6267                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6268                 $LCTL set_param fail_loc=0x80000408
6269                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6270                 $LCTL set_param fail_loc=0
6271         done
6272         set_checksums 0
6273         set_checksum_type $ORIG_CSUM_TYPE
6274         rm -f $DIR/$tfile
6275 }
6276 run_test 77b "checksum error on client write, read"
6277
6278 cleanup_77c() {
6279         trap 0
6280         set_checksums 0
6281         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
6282         $check_ost &&
6283                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
6284         [ -n $osc_file_prefix ] && rm -f ${osc_file_prefix}*
6285         $check_ost && [ -n $ost_file_prefix ] &&
6286                 do_facet ost1 rm -f ${ost_file_prefix}\*
6287 }
6288
6289 test_77c() {
6290         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6291         $GSS && skip "could not run with gss" && return
6292
6293         local bad1
6294         local osc_file_prefix
6295         local osc_file
6296         local check_ost=false
6297         local ost_file_prefix
6298         local ost_file
6299         local orig_cksum
6300         local dump_cksum
6301         local fid
6302
6303         # ensure corruption will occur on first OSS/OST
6304         $LFS setstripe -i 0 $DIR/$tfile
6305
6306         [ ! -f $F77_TMP ] && setup_f77
6307         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6308                 error "dd write error: $?"
6309         fid=$($LFS path2fid $DIR/$tfile)
6310
6311         if [ $(lustre_version_code ost1) -ge $(version_code 2.9.57) ]
6312         then
6313                 check_ost=true
6314                 ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
6315                 ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
6316         else
6317                 echo "OSS do not support bulk pages dump upon error"
6318         fi
6319
6320         osc_file_prefix=$($LCTL get_param -n debug_path)
6321         osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
6322
6323         trap cleanup_77c EXIT
6324
6325         set_checksums 1
6326         # enable bulk pages dump upon error on Client
6327         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
6328         # enable bulk pages dump upon error on OSS
6329         $check_ost &&
6330                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
6331
6332         # flush Client cache to allow next read to reach OSS
6333         cancel_lru_locks osc
6334
6335         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
6336         $LCTL set_param fail_loc=0x80000408
6337         dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
6338         $LCTL set_param fail_loc=0
6339
6340         rm -f $DIR/$tfile
6341
6342         # check cksum dump on Client
6343         osc_file=$(ls ${osc_file_prefix}*)
6344         [ -n "$osc_file" ] || error "no checksum dump file on Client"
6345         # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
6346         bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
6347         [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
6348         orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
6349                      cksum)
6350         dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
6351         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6352                 error "dump content does not match on Client"
6353
6354         $check_ost || skip "No need to check cksum dump on OSS"
6355
6356         # check cksum dump on OSS
6357         ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
6358         [ -n "$ost_file" ] || error "no checksum dump file on OSS"
6359         orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
6360         dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
6361         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6362                 error "dump content does not match on OSS"
6363
6364         cleanup_77c
6365 }
6366 run_test 77c "checksum error on client read with debug"
6367
6368 test_77d() { # bug 10889
6369         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6370         $GSS && skip "could not run with gss" && return
6371         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6372         $LCTL set_param fail_loc=0x80000409
6373         set_checksums 1
6374         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6375                 error "direct write: rc=$?"
6376         $LCTL set_param fail_loc=0
6377         set_checksums 0
6378
6379         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6380         $LCTL set_param fail_loc=0x80000408
6381         set_checksums 1
6382         cancel_lru_locks osc
6383         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6384                 error "direct read: rc=$?"
6385         $LCTL set_param fail_loc=0
6386         set_checksums 0
6387 }
6388 run_test 77d "checksum error on OST direct write, read"
6389
6390 test_77f() { # bug 10889
6391         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6392         $GSS && skip "could not run with gss" && return
6393         set_checksums 1
6394         for algo in $CKSUM_TYPES; do
6395                 cancel_lru_locks osc
6396                 set_checksum_type $algo
6397                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6398                 $LCTL set_param fail_loc=0x409
6399                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
6400                         error "direct write succeeded"
6401                 $LCTL set_param fail_loc=0
6402         done
6403         set_checksum_type $ORIG_CSUM_TYPE
6404         set_checksums 0
6405 }
6406 run_test 77f "repeat checksum error on write (expect error)"
6407
6408 test_77g() { # bug 10889
6409         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6410         $GSS && skip "could not run with gss" && return
6411         remote_ost_nodsh && skip "remote OST with nodsh" && return
6412
6413         [ ! -f $F77_TMP ] && setup_f77
6414
6415         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
6416         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
6417         do_facet ost1 lctl set_param fail_loc=0x8000021a
6418         set_checksums 1
6419         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
6420                 error "write error: rc=$?"
6421         do_facet ost1 lctl set_param fail_loc=0
6422         set_checksums 0
6423
6424         cancel_lru_locks osc
6425         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
6426         do_facet ost1 lctl set_param fail_loc=0x8000021b
6427         set_checksums 1
6428         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6429         do_facet ost1 lctl set_param fail_loc=0
6430         set_checksums 0
6431 }
6432 run_test 77g "checksum error on OST write, read"
6433
6434 test_77j() { # bug 13805
6435         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6436         $GSS && skip "could not run with gss" && return
6437         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6438         lctl set_param fail_loc=0x40c
6439         remount_client $MOUNT
6440         lctl set_param fail_loc=0
6441         # wait async osc connect to finish and reflect updated state value
6442         local i
6443         for (( i=0; i < OSTCOUNT; i++ )) ; do
6444                 wait_osc_import_state client ost$((i+1)) FULL
6445         done
6446
6447         for VALUE in $(lctl get_param osc.*osc-[^mM]*.checksum_type); do
6448                 PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
6449                 algo=$(lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g')
6450                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6451         done
6452         remount_client $MOUNT
6453 }
6454 run_test 77j "client only supporting ADLER32"
6455
6456 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6457 rm -f $F77_TMP
6458 unset F77_TMP
6459
6460 cleanup_test_78() {
6461         trap 0
6462         rm -f $DIR/$tfile
6463 }
6464
6465 test_78() { # bug 10901
6466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6467         remote_ost || { skip_env "local OST" && return; }
6468
6469         NSEQ=5
6470         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6471         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6472         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6473         echo "MemTotal: $MEMTOTAL"
6474
6475         # reserve 256MB of memory for the kernel and other running processes,
6476         # and then take 1/2 of the remaining memory for the read/write buffers.
6477         if [ $MEMTOTAL -gt 512 ] ;then
6478                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6479         else
6480                 # for those poor memory-starved high-end clusters...
6481                 MEMTOTAL=$((MEMTOTAL / 2))
6482         fi
6483         echo "Mem to use for directio: $MEMTOTAL"
6484
6485         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6486         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6487         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6488         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6489                 head -n1)
6490         echo "Smallest OST: $SMALLESTOST"
6491         [[ $SMALLESTOST -lt 10240 ]] &&
6492                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6493
6494         trap cleanup_test_78 EXIT
6495
6496         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6497                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6498
6499         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6500         echo "File size: $F78SIZE"
6501         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6502         for i in $(seq 1 $NSEQ); do
6503                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6504                 echo directIO rdwr round $i of $NSEQ
6505                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6506         done
6507
6508         cleanup_test_78
6509 }
6510 run_test 78 "handle large O_DIRECT writes correctly ============"
6511
6512 test_79() { # bug 12743
6513         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6514         wait_delete_completed
6515
6516         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6517         BKFREE=$(calc_osc_kbytes kbytesfree)
6518         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6519
6520         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6521         DFTOTAL=`echo $STRING | cut -d, -f1`
6522         DFUSED=`echo $STRING  | cut -d, -f2`
6523         DFAVAIL=`echo $STRING | cut -d, -f3`
6524         DFFREE=$(($DFTOTAL - $DFUSED))
6525
6526         ALLOWANCE=$((64 * $OSTCOUNT))
6527
6528         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6529            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6530                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6531         fi
6532         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6533            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6534                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6535         fi
6536         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6537            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6538                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6539         fi
6540 }
6541 run_test 79 "df report consistency check ======================="
6542
6543 test_80() { # bug 10718
6544         remote_ost_nodsh && skip "remote OST with nodsh" && return
6545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6546         # relax strong synchronous semantics for slow backends like ZFS
6547         local soc="obdfilter.*.sync_on_lock_cancel"
6548         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6549         local hosts=
6550         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6551                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6552                           facet_active_host $host; done | sort -u)
6553                 do_nodes $hosts lctl set_param $soc=never
6554         fi
6555
6556         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6557         sync; sleep 1; sync
6558         local BEFORE=`date +%s`
6559         cancel_lru_locks osc
6560         local AFTER=`date +%s`
6561         local DIFF=$((AFTER-BEFORE))
6562         if [ $DIFF -gt 1 ] ; then
6563                 error "elapsed for 1M@1T = $DIFF"
6564         fi
6565
6566         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6567
6568         rm -f $DIR/$tfile
6569 }
6570 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6571
6572 test_81a() { # LU-456
6573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6574         remote_ost_nodsh && skip "remote OST with nodsh" && return
6575         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6576         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6577         do_facet ost1 lctl set_param fail_loc=0x80000228
6578
6579         # write should trigger a retry and success
6580         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6581         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6582         RC=$?
6583         if [ $RC -ne 0 ] ; then
6584                 error "write should success, but failed for $RC"
6585         fi
6586 }
6587 run_test 81a "OST should retry write when get -ENOSPC ==============="
6588
6589 test_81b() { # LU-456
6590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6591         remote_ost_nodsh && skip "remote OST with nodsh" && return
6592         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6593         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6594         do_facet ost1 lctl set_param fail_loc=0x228
6595
6596         # write should retry several times and return -ENOSPC finally
6597         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6598         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6599         RC=$?
6600         ENOSPC=28
6601         if [ $RC -ne $ENOSPC ] ; then
6602                 error "dd should fail for -ENOSPC, but succeed."
6603         fi
6604 }
6605 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6606
6607 test_82() { # LU-1031
6608         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6609         local gid1=14091995
6610         local gid2=16022000
6611
6612         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6613         local MULTIPID1=$!
6614         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6615         local MULTIPID2=$!
6616         kill -USR1 $MULTIPID2
6617         sleep 2
6618         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6619                 error "First grouplock does not block second one"
6620         else
6621                 echo "Second grouplock blocks first one"
6622         fi
6623         kill -USR1 $MULTIPID1
6624         wait $MULTIPID1
6625         wait $MULTIPID2
6626 }
6627 run_test 82 "Basic grouplock test"
6628
6629 test_83() {
6630         local sfile="/boot/System.map-$(uname -r)"
6631         # define OBD_FAIL_LLITE_PTASK_IO_FAIL 0x140d
6632         $LCTL set_param fail_loc=0x140d
6633         cp $sfile $DIR/$tfile || error "write failed"
6634         diff -c $sfile $DIR/$tfile || error "files are different"
6635         $LCTL set_param fail_loc=0
6636         rm -f $DIR/$tfile
6637 }
6638 run_test 83 "Short write in ptask ==============================="
6639
6640 test_99() {
6641         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6642                 return
6643         test_mkdir $DIR/$tdir.cvsroot
6644         chown $RUNAS_ID $DIR/$tdir.cvsroot
6645
6646         cd $TMP
6647         $RUNAS cvs -d $DIR/$tdir.cvsroot init || error "cvs init failed"
6648
6649         cd /etc/init.d
6650         # some versions of cvs import exit(1) when asked to import links or
6651         # files they can't read.  ignore those files.
6652         local toignore=$(find . -type l -printf '-I %f\n' -o \
6653                          ! -perm /4 -printf '-I %f\n')
6654         $RUNAS cvs -d $DIR/$tdir.cvsroot import -m "nomesg" $toignore \
6655                 $tdir.reposname vtag rtag
6656
6657         cd $DIR
6658         test_mkdir $DIR/$tdir.reposname
6659         chown $RUNAS_ID $DIR/$tdir.reposname
6660         $RUNAS cvs -d $DIR/$tdir.cvsroot co $tdir.reposname
6661
6662         cd $DIR/$tdir.reposname
6663         $RUNAS touch foo99
6664         $RUNAS cvs add -m 'addmsg' foo99
6665         $RUNAS cvs update
6666         $RUNAS cvs commit -m 'nomsg' foo99
6667         rm -fr $DIR/$tdir.cvsroot
6668 }
6669 run_test 99 "cvs strange file/directory operations"
6670
6671 test_100() {
6672         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6673         [[ "$NETTYPE" =~ tcp ]] ||
6674                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" &&
6675                         return ; }
6676
6677         remote_ost_nodsh && skip "remote OST with nodsh" && return
6678         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6679         remote_servers ||
6680                 { skip "useless for local single node setup" && return; }
6681
6682         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6683                 [ "$PROT" != "tcp" ] && continue
6684                 RPORT=$(echo $REMOTE | cut -d: -f2)
6685                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6686
6687                 rc=0
6688                 LPORT=`echo $LOCAL | cut -d: -f2`
6689                 if [ $LPORT -ge 1024 ]; then
6690                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6691                         netstat -tna
6692                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6693                 fi
6694         done
6695         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6696 }
6697 run_test 100 "check local port using privileged port ==========="
6698
6699 function get_named_value()
6700 {
6701     local tag
6702
6703     tag=$1
6704     while read ;do
6705         line=$REPLY
6706         case $line in
6707         $tag*)
6708             echo $line | sed "s/^$tag[ ]*//"
6709             break
6710             ;;
6711         esac
6712     done
6713 }
6714
6715 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6716                    awk '/^max_cached_mb/ { print $2 }')
6717
6718 cleanup_101a() {
6719         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6720         trap 0
6721 }
6722
6723 test_101a() {
6724         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6725         [ $MDSCOUNT -ge 2 ] && skip "needs < 2 MDTs" && return #LU-4322
6726         local s
6727         local discard
6728         local nreads=10000
6729         local cache_limit=32
6730
6731         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6732         trap cleanup_101a EXIT
6733         $LCTL set_param -n llite.*.read_ahead_stats 0
6734         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6735
6736         #
6737         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6738         #
6739         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6740         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6741
6742         discard=0
6743         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6744                 get_named_value 'read but discarded' | cut -d" " -f1); do
6745                         discard=$(($discard + $s))
6746         done
6747         cleanup_101a
6748
6749         if [[ $(($discard * 10)) -gt $nreads ]]; then
6750                 $LCTL get_param osc.*-osc*.rpc_stats
6751                 $LCTL get_param llite.*.read_ahead_stats
6752                 error "too many ($discard) discarded pages"
6753         fi
6754         rm -f $DIR/$tfile || true
6755 }
6756 run_test 101a "check read-ahead for random reads"
6757
6758 setup_test101bc() {
6759         test_mkdir $DIR/$tdir
6760         local STRIPE_SIZE=$1
6761         local FILE_LENGTH=$2
6762         STRIPE_OFFSET=0
6763
6764         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6765
6766         local list=$(comma_list $(osts_nodes))
6767         set_osd_param $list '' read_cache_enable 0
6768         set_osd_param $list '' writethrough_cache_enable 0
6769
6770         trap cleanup_test101bc EXIT
6771         # prepare the read-ahead file
6772         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6773
6774         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6775                                 count=$FILE_SIZE_MB 2> /dev/null
6776
6777 }
6778
6779 cleanup_test101bc() {
6780         trap 0
6781         rm -rf $DIR/$tdir
6782         rm -f $DIR/$tfile
6783
6784         local list=$(comma_list $(osts_nodes))
6785         set_osd_param $list '' read_cache_enable 1
6786         set_osd_param $list '' writethrough_cache_enable 1
6787 }
6788
6789 calc_total() {
6790         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6791 }
6792
6793 ra_check_101() {
6794         local READ_SIZE=$1
6795         local STRIPE_SIZE=$2
6796         local FILE_LENGTH=$3
6797         local RA_INC=1048576
6798         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6799         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6800                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6801         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6802                         get_named_value 'read but discarded' |
6803                         cut -d" " -f1 | calc_total)
6804         if [[ $DISCARD -gt $discard_limit ]]; then
6805                 $LCTL get_param llite.*.read_ahead_stats
6806                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6807         else
6808                 echo "Read-ahead success for size ${READ_SIZE}"
6809         fi
6810 }
6811
6812 test_101b() {
6813         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6814         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
6815         local STRIPE_SIZE=1048576
6816         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6817         if [ $SLOW == "yes" ]; then
6818                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6819         else
6820                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6821         fi
6822
6823         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6824
6825         # prepare the read-ahead file
6826         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6827         cancel_lru_locks osc
6828         for BIDX in 2 4 8 16 32 64 128 256
6829         do
6830                 local BSIZE=$((BIDX*4096))
6831                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6832                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6833                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6834                 $LCTL set_param -n llite.*.read_ahead_stats 0
6835                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6836                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6837                 cancel_lru_locks osc
6838                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6839         done
6840         cleanup_test101bc
6841         true
6842 }
6843 run_test 101b "check stride-io mode read-ahead ================="
6844
6845 test_101c() {
6846         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6847         local STRIPE_SIZE=1048576
6848         local FILE_LENGTH=$((STRIPE_SIZE*100))
6849         local nreads=10000
6850         local osc_rpc_stats
6851
6852         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6853
6854         cancel_lru_locks osc
6855         $LCTL set_param osc.*.rpc_stats 0
6856         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6857         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6858                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6859                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6860                 local size
6861
6862                 if [ $lines -le 20 ]; then
6863                         continue
6864                 fi
6865                 for size in 1 2 4 8; do
6866                         local rpc=$(echo "$stats" |
6867                                     awk '($1 == "'$size':") {print $2; exit; }')
6868                         [ $rpc != 0 ] &&
6869                                 error "Small $((size*4))k read IO $rpc !"
6870                 done
6871                 echo "$osc_rpc_stats check passed!"
6872         done
6873         cleanup_test101bc
6874         true
6875 }
6876 run_test 101c "check stripe_size aligned read-ahead ================="
6877
6878 set_read_ahead() {
6879         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6880         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6881 }
6882
6883 test_101d() {
6884         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6885         local file=$DIR/$tfile
6886         local sz_MB=${FILESIZE_101d:-500}
6887         local ra_MB=${READAHEAD_MB:-40}
6888
6889         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6890         [ $free_MB -lt $sz_MB ] &&
6891                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6892
6893         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6894         $SETSTRIPE -c -1 $file || error "setstripe failed"
6895
6896         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6897         echo Cancel LRU locks on lustre client to flush the client cache
6898         cancel_lru_locks osc
6899
6900         echo Disable read-ahead
6901         local old_READAHEAD=$(set_read_ahead 0)
6902
6903         echo Reading the test file $file with read-ahead disabled
6904         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6905
6906         echo Cancel LRU locks on lustre client to flush the client cache
6907         cancel_lru_locks osc
6908         echo Enable read-ahead with ${ra_MB}MB
6909         set_read_ahead $ra_MB
6910
6911         echo Reading the test file $file with read-ahead enabled
6912         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6913
6914         echo "read-ahead disabled time read $raOFF"
6915         echo "read-ahead enabled  time read $raON"
6916
6917         set_read_ahead $old_READAHEAD
6918         rm -f $file
6919         wait_delete_completed
6920
6921         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6922                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6923 }
6924 run_test 101d "file read with and without read-ahead enabled"
6925
6926 test_101e() {
6927         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6928         local file=$DIR/$tfile
6929         local size_KB=500  #KB
6930         local count=100
6931         local bsize=1024
6932
6933         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6934         local need_KB=$((count * size_KB))
6935         [[ $free_KB -le $need_KB ]] &&
6936                 skip_env "Need free space $need_KB, have $free_KB" && return
6937
6938         echo "Creating $count ${size_KB}K test files"
6939         for ((i = 0; i < $count; i++)); do
6940                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6941         done
6942
6943         echo "Cancel LRU locks on lustre client to flush the client cache"
6944         cancel_lru_locks $OSC
6945
6946         echo "Reset readahead stats"
6947         $LCTL set_param -n llite.*.read_ahead_stats 0
6948
6949         for ((i = 0; i < $count; i++)); do
6950                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6951         done
6952
6953         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6954                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6955
6956         for ((i = 0; i < $count; i++)); do
6957                 rm -rf $file.$i 2>/dev/null
6958         done
6959
6960         #10000 means 20% reads are missing in readahead
6961         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6962 }
6963 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6964
6965 test_101f() {
6966         which iozone || { skip "no iozone installed" && return; }
6967
6968         local old_debug=$($LCTL get_param debug)
6969         old_debug=${old_debug#*=}
6970         $LCTL set_param debug="reada mmap"
6971
6972         # create a test file
6973         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
6974
6975         echo Cancel LRU locks on lustre client to flush the client cache
6976         cancel_lru_locks osc
6977
6978         echo Reset readahead stats
6979         $LCTL set_param -n llite.*.read_ahead_stats 0
6980
6981         echo mmap read the file with small block size
6982         iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
6983                 > /dev/null 2>&1
6984
6985         echo checking missing pages
6986         $LCTL get_param llite.*.read_ahead_stats
6987         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6988                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
6989
6990         $LCTL set_param debug="$old_debug"
6991         [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
6992         rm -f $DIR/$tfile
6993 }
6994 run_test 101f "check mmap read performance"
6995
6996 test_101g_brw_size_test() {
6997         local mb=$1
6998         local pages=$((mb * 1048576 / $(page_size)))
6999
7000         $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
7001                 { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
7002         for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
7003                 [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
7004                         return 2
7005         done
7006
7007         $LCTL set_param -n osc.*.rpc_stats=0
7008
7009         # 10 RPCs should be enough for the test
7010         local count=10
7011         dd if=/dev/zero of=$DIR/$tfile bs=${mb}M count=$count ||
7012                 { error "dd write ${mb} MB blocks failed"; return 3; }
7013         cancel_lru_locks osc
7014         dd of=/dev/null if=$DIR/$tfile bs=${mb}M count=$count ||
7015                 { error "dd write ${mb} MB blocks failed"; return 4; }
7016
7017         # calculate number of full-sized read and write RPCs
7018         rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
7019                 sed -n '/pages per rpc/,/^$/p' |
7020                 awk '/'$pages':/ { reads += $2; writes += $6 }; \
7021                 END { print reads,writes }'))
7022         [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
7023                 return 5
7024         [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
7025                 return 6
7026
7027         return 0
7028 }
7029
7030 test_101g() {
7031         local rpcs
7032         local osts=$(get_facets OST)
7033         local list=$(comma_list $(osts_nodes))
7034         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
7035         local brw_size="obdfilter.*.brw_size"
7036
7037         $LFS setstripe -i 0 -c 1 $DIR/$tfile
7038
7039         local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
7040         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.52) -a \
7041              $(lustre_version_code client) -ge $(version_code 2.8.52) ]; then
7042                 [ $(lustre_version_code ost1) -ge $(version_code 2.9.52) ] &&
7043                         suffix="M"
7044                 if [[ $orig_mb -lt 16 ]]; then
7045                         save_lustre_params $osts "$brw_size" > $p
7046                         do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
7047                                 error "set 16MB RPC size failed"
7048
7049                         echo "remount client to enable new RPC size"
7050                         remount_client $MOUNT || error "remount_client failed"
7051                 fi
7052
7053                 test_101g_brw_size_test 16 || error "16MB RPC test failed"
7054                 # should be able to set brw_size=12, but no rpc_stats for that
7055                 test_101g_brw_size_test 8 || error "8MB RPC test failed"
7056         fi
7057
7058         test_101g_brw_size_test 4 || error "4MB RPC test failed"
7059
7060         if [[ $orig_mb -lt 16 ]]; then
7061                 restore_lustre_params < $p
7062                 remount_client $MOUNT || error "remount_client restore failed"
7063         fi
7064
7065         rm -f $p $DIR/$tfile
7066 }
7067 run_test 101g "Big bulk(4/16 MiB) readahead"
7068
7069 setup_test102() {
7070         test_mkdir $DIR/$tdir
7071         chown $RUNAS_ID $DIR/$tdir
7072         STRIPE_SIZE=65536
7073         STRIPE_OFFSET=1
7074         STRIPE_COUNT=$OSTCOUNT
7075         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
7076
7077         trap cleanup_test102 EXIT
7078         cd $DIR
7079         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
7080         cd $DIR/$tdir
7081         for num in 1 2 3 4; do
7082                 for count in $(seq 1 $STRIPE_COUNT); do
7083                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
7084                                 local size=`expr $STRIPE_SIZE \* $num`
7085                                 local file=file"$num-$idx-$count"
7086                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
7087                         done
7088                 done
7089         done
7090
7091         cd $DIR
7092         $1 tar cf $TMP/f102.tar $tdir --xattrs
7093 }
7094
7095 cleanup_test102() {
7096         trap 0
7097         rm -f $TMP/f102.tar
7098         rm -rf $DIR/d0.sanity/d102
7099 }
7100
7101 test_102a() {
7102         local testfile=$DIR/$tfile
7103
7104         touch $testfile
7105
7106         [ "$UID" != 0 ] && skip_env "must run as root" && return
7107         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
7108                 skip_env "must have user_xattr" && return
7109
7110         [ -z "$(which setfattr 2>/dev/null)" ] &&
7111                 skip_env "could not find setfattr" && return
7112
7113         echo "set/get xattr..."
7114         setfattr -n trusted.name1 -v value1 $testfile ||
7115                 error "setfattr -n trusted.name1=value1 $testfile failed"
7116         getfattr -n trusted.name1 $testfile 2> /dev/null |
7117           grep "trusted.name1=.value1" ||
7118                 error "$testfile missing trusted.name1=value1"
7119
7120         setfattr -n user.author1 -v author1 $testfile ||
7121                 error "setfattr -n user.author1=author1 $testfile failed"
7122         getfattr -n user.author1 $testfile 2> /dev/null |
7123           grep "user.author1=.author1" ||
7124                 error "$testfile missing trusted.author1=author1"
7125
7126         echo "listxattr..."
7127         setfattr -n trusted.name2 -v value2 $testfile ||
7128                 error "$testfile unable to set trusted.name2"
7129         setfattr -n trusted.name3 -v value3 $testfile ||
7130                 error "$testfile unable to set trusted.name3"
7131         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
7132             grep "trusted.name" | wc -l) -eq 3 ] ||
7133                 error "$testfile missing 3 trusted.name xattrs"
7134
7135         setfattr -n user.author2 -v author2 $testfile ||
7136                 error "$testfile unable to set user.author2"
7137         setfattr -n user.author3 -v author3 $testfile ||
7138                 error "$testfile unable to set user.author3"
7139         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
7140             grep "user.author" | wc -l) -eq 3 ] ||
7141                 error "$testfile missing 3 user.author xattrs"
7142
7143         echo "remove xattr..."
7144         setfattr -x trusted.name1 $testfile ||
7145                 error "$testfile error deleting trusted.name1"
7146         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
7147                 error "$testfile did not delete trusted.name1 xattr"
7148
7149         setfattr -x user.author1 $testfile ||
7150                 error "$testfile error deleting user.author1"
7151         echo "set lustre special xattr ..."
7152         $LFS setstripe -c1 $testfile
7153         local lovea=$(getfattr -n "trusted.lov" -e hex $testfile |
7154                 awk -F "=" '/trusted.lov/ { print $2 }' )
7155         setfattr -n "trusted.lov" -v $lovea $testfile ||
7156                 error "$testfile doesn't ignore setting trusted.lov again"
7157         setfattr -n "trusted.lov" -v "invalid_value" $testfile &&
7158                 error "$testfile allow setting invalid trusted.lov"
7159         rm -f $testfile
7160 }
7161 run_test 102a "user xattr test =================================="
7162
7163 test_102b() {
7164         [ -z "$(which setfattr 2>/dev/null)" ] &&
7165                 skip_env "could not find setfattr" && return
7166
7167         # b10930: get/set/list trusted.lov xattr
7168         echo "get/set/list trusted.lov xattr ..."
7169         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7170         local testfile=$DIR/$tfile
7171         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7172                 error "setstripe failed"
7173         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
7174                 error "getstripe failed"
7175         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
7176                 error "can't get trusted.lov from $testfile"
7177
7178         local testfile2=${testfile}2
7179         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
7180                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
7181
7182         $MCREATE $testfile2
7183         setfattr -n trusted.lov -v $value $testfile2
7184         local stripe_size=$($GETSTRIPE -S $testfile2)
7185         local stripe_count=$($GETSTRIPE -c $testfile2)
7186         [[ $stripe_size -eq 65536 ]] ||
7187                 error "stripe size $stripe_size != 65536"
7188         [[ $stripe_count -eq $STRIPECOUNT ]] ||
7189                 error "stripe count $stripe_count != $STRIPECOUNT"
7190         rm -f $DIR/$tfile
7191 }
7192 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
7193
7194 test_102c() {
7195         [ -z "$(which setfattr 2>/dev/null)" ] &&
7196                 skip_env "could not find setfattr" && return
7197
7198         # b10930: get/set/list lustre.lov xattr
7199         echo "get/set/list lustre.lov xattr ..."
7200         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7201         test_mkdir $DIR/$tdir
7202         chown $RUNAS_ID $DIR/$tdir
7203         local testfile=$DIR/$tdir/$tfile
7204         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7205                 error "setstripe failed"
7206         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
7207                 error "getstripe failed"
7208         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
7209         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
7210
7211         local testfile2=${testfile}2
7212         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
7213                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
7214
7215         $RUNAS $MCREATE $testfile2
7216         $RUNAS setfattr -n lustre.lov -v $value $testfile2
7217         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
7218         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
7219         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
7220         [ $stripe_count -eq $STRIPECOUNT ] ||
7221                 error "stripe count $stripe_count != $STRIPECOUNT"
7222 }
7223 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
7224
7225 compare_stripe_info1() {
7226         local stripe_index_all_zero=true
7227
7228         for num in 1 2 3 4; do
7229                 for count in $(seq 1 $STRIPE_COUNT); do
7230                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
7231                                 local size=$((STRIPE_SIZE * num))
7232                                 local file=file"$num-$offset-$count"
7233                                 stripe_size=$($LFS getstripe -S $PWD/$file)
7234                                 [[ $stripe_size -ne $size ]] &&
7235                                     error "$file: size $stripe_size != $size"
7236                                 stripe_count=$($LFS getstripe -c $PWD/$file)
7237                                 # allow fewer stripes to be created, ORI-601
7238                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
7239                                     error "$file: count $stripe_count != $count"
7240                                 stripe_index=$($LFS getstripe -i $PWD/$file)
7241                                 [[ $stripe_index -ne 0 ]] &&
7242                                         stripe_index_all_zero=false
7243                         done
7244                 done
7245         done
7246         $stripe_index_all_zero &&
7247                 error "all files are being extracted starting from OST index 0"
7248         return 0
7249 }
7250
7251 have_xattrs_include() {
7252         tar --help | grep -q xattrs-include &&
7253                 echo --xattrs-include="lustre.*"
7254 }
7255
7256 test_102d() {
7257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7258         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7259         XINC=$(have_xattrs_include)
7260         setup_test102
7261         tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
7262         cd $DIR/$tdir/$tdir
7263         compare_stripe_info1
7264 }
7265 run_test 102d "tar restore stripe info from tarfile,not keep osts"
7266
7267 test_102f() {
7268         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7269         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7270         XINC=$(have_xattrs_include)
7271         setup_test102
7272         test_mkdir $DIR/$tdir.restore
7273         cd $DIR
7274         tar cf - --xattrs $tdir | tar xf - \
7275                 -C $DIR/$tdir.restore --xattrs $XINC
7276         cd $DIR/$tdir.restore/$tdir
7277         compare_stripe_info1
7278 }
7279 run_test 102f "tar copy files, not keep osts"
7280
7281 grow_xattr() {
7282         local xsize=${1:-1024}  # in bytes
7283         local file=$DIR/$tfile
7284
7285         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
7286                 skip "must have user_xattr" && return 0
7287         [ -z "$(which setfattr 2>/dev/null)" ] &&
7288                 skip_env "could not find setfattr" && return 0
7289         [ -z "$(which getfattr 2>/dev/null)" ] &&
7290                 skip_env "could not find getfattr" && return 0
7291
7292         touch $file
7293
7294         local value="$(generate_string $xsize)"
7295
7296         local xbig=trusted.big
7297         log "save $xbig on $file"
7298         setfattr -n $xbig -v $value $file ||
7299                 error "saving $xbig on $file failed"
7300
7301         local orig=$(get_xattr_value $xbig $file)
7302         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
7303
7304         local xsml=trusted.sml
7305         log "save $xsml on $file"
7306         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
7307
7308         local new=$(get_xattr_value $xbig $file)
7309         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
7310
7311         log "grow $xsml on $file"
7312         setfattr -n $xsml -v "$value" $file ||
7313                 error "growing $xsml on $file failed"
7314
7315         new=$(get_xattr_value $xbig $file)
7316         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
7317         log "$xbig still valid after growing $xsml"
7318
7319         rm -f $file
7320 }
7321
7322 test_102h() { # bug 15777
7323         grow_xattr 1024
7324 }
7325 run_test 102h "grow xattr from inside inode to external block"
7326
7327 test_102ha() {
7328         large_xattr_enabled || { skip "large_xattr disabled" && return; }
7329         grow_xattr $(max_xattr_size)
7330 }
7331 run_test 102ha "grow xattr from inside inode to external inode"
7332
7333 test_102i() { # bug 17038
7334         [ -z "$(which getfattr 2>/dev/null)" ] &&
7335                 skip "could not find getfattr" && return
7336         touch $DIR/$tfile
7337         ln -s $DIR/$tfile $DIR/${tfile}link
7338         getfattr -n trusted.lov $DIR/$tfile ||
7339                 error "lgetxattr on $DIR/$tfile failed"
7340         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
7341                 grep -i "no such attr" ||
7342                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
7343         rm -f $DIR/$tfile $DIR/${tfile}link
7344 }
7345 run_test 102i "lgetxattr test on symbolic link ============"
7346
7347 test_102j() {
7348         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7349         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7350         XINC=$(have_xattrs_include)
7351         setup_test102 "$RUNAS"
7352         chown $RUNAS_ID $DIR/$tdir
7353         $RUNAS tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
7354         cd $DIR/$tdir/$tdir
7355         compare_stripe_info1 "$RUNAS"
7356 }
7357 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
7358
7359 test_102k() {
7360         [ -z "$(which setfattr 2>/dev/null)" ] &&
7361                 skip "could not find setfattr" && return
7362         touch $DIR/$tfile
7363         # b22187 just check that does not crash for regular file.
7364         setfattr -n trusted.lov $DIR/$tfile
7365         # b22187 'setfattr -n trusted.lov' should remove LOV EA for directories
7366         local test_kdir=$DIR/$tdir
7367         test_mkdir $test_kdir
7368         local default_size=$($LFS getstripe -S $test_kdir)
7369         local default_count=$($LFS getstripe -c $test_kdir)
7370         local default_offset=$($LFS getstripe -i $test_kdir)
7371         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
7372                 error 'dir setstripe failed'
7373         setfattr -n trusted.lov $test_kdir
7374         local stripe_size=$($LFS getstripe -S $test_kdir)
7375         local stripe_count=$($LFS getstripe -c $test_kdir)
7376         local stripe_offset=$($LFS getstripe -i $test_kdir)
7377         [ $stripe_size -eq $default_size ] ||
7378                 error "stripe size $stripe_size != $default_size"
7379         [ $stripe_count -eq $default_count ] ||
7380                 error "stripe count $stripe_count != $default_count"
7381         [ $stripe_offset -eq $default_offset ] ||
7382                 error "stripe offset $stripe_offset != $default_offset"
7383         rm -rf $DIR/$tfile $test_kdir
7384 }
7385 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
7386
7387 test_102l() {
7388         [ -z "$(which getfattr 2>/dev/null)" ] &&
7389                 skip "could not find getfattr" && return
7390
7391         # LU-532 trusted. xattr is invisible to non-root
7392         local testfile=$DIR/$tfile
7393
7394         touch $testfile
7395
7396         echo "listxattr as user..."
7397         chown $RUNAS_ID $testfile
7398         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
7399             grep -q "trusted" &&
7400                 error "$testfile trusted xattrs are user visible"
7401
7402         return 0;
7403 }
7404 run_test 102l "listxattr size test =================================="
7405
7406 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
7407         local path=$DIR/$tfile
7408         touch $path
7409
7410         listxattr_size_check $path || error "listattr_size_check $path failed"
7411 }
7412 run_test 102m "Ensure listxattr fails on small bufffer ========"
7413
7414 cleanup_test102
7415
7416 getxattr() { # getxattr path name
7417         # Return the base64 encoding of the value of xattr name on path.
7418         local path=$1
7419         local name=$2
7420
7421         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
7422         # file: $path
7423         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7424         #
7425         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7426
7427         getfattr --absolute-names --encoding=base64 --name=$name $path |
7428                 awk -F= -v name=$name '$1 == name {
7429                         print substr($0, index($0, "=") + 1);
7430         }'
7431 }
7432
7433 test_102n() { # LU-4101 mdt: protect internal xattrs
7434         [ -z "$(which setfattr 2>/dev/null)" ] &&
7435                 skip "could not find setfattr" && return
7436         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
7437         then
7438                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
7439                 return
7440         fi
7441
7442         local file0=$DIR/$tfile.0
7443         local file1=$DIR/$tfile.1
7444         local xattr0=$TMP/$tfile.0
7445         local xattr1=$TMP/$tfile.1
7446         local namelist="lov lma lmv link fid version som hsm"
7447         local name
7448         local value
7449
7450         rm -rf $file0 $file1 $xattr0 $xattr1
7451         touch $file0 $file1
7452
7453         # Get 'before' xattrs of $file1.
7454         getfattr --absolute-names --dump --match=- $file1 > $xattr0
7455
7456         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
7457                 namelist+=" lfsck_namespace"
7458         for name in $namelist; do
7459                 # Try to copy xattr from $file0 to $file1.
7460                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7461
7462                 setfattr --name=trusted.$name --value="$value" $file1 ||
7463                         error "setxattr 'trusted.$name' failed"
7464
7465                 # Try to set a garbage xattr.
7466                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7467
7468                 if [[ x$name == "xlov" ]]; then
7469                         setfattr --name=trusted.lov --value="$value" $file1 &&
7470                         error "setxattr invalid 'trusted.lov' success"
7471                 else
7472                         setfattr --name=trusted.$name --value="$value" $file1 ||
7473                                 error "setxattr invalid 'trusted.$name' failed"
7474                 fi
7475
7476                 # Try to remove the xattr from $file1. We don't care if this
7477                 # appears to succeed or fail, we just don't want there to be
7478                 # any changes or crashes.
7479                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7480         done
7481
7482         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
7483         then
7484                 name="lfsck_ns"
7485                 # Try to copy xattr from $file0 to $file1.
7486                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7487
7488                 setfattr --name=trusted.$name --value="$value" $file1 ||
7489                         error "setxattr 'trusted.$name' failed"
7490
7491                 # Try to set a garbage xattr.
7492                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7493
7494                 setfattr --name=trusted.$name --value="$value" $file1 ||
7495                         error "setxattr 'trusted.$name' failed"
7496
7497                 # Try to remove the xattr from $file1. We don't care if this
7498                 # appears to succeed or fail, we just don't want there to be
7499                 # any changes or crashes.
7500                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7501         fi
7502
7503         # Get 'after' xattrs of file1.
7504         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7505
7506         if ! diff $xattr0 $xattr1; then
7507                 error "before and after xattrs of '$file1' differ"
7508         fi
7509
7510         rm -rf $file0 $file1 $xattr0 $xattr1
7511
7512         return 0
7513 }
7514 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7515
7516 test_102p() { # LU-4703 setxattr did not check ownership
7517         local testfile=$DIR/$tfile
7518
7519         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7520                 skip "MDS needs to be at least 2.5.56" && return
7521
7522         touch $testfile
7523
7524         echo "setfacl as user..."
7525         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7526         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7527
7528         echo "setfattr as user..."
7529         setfacl -m "u:$RUNAS_ID:---" $testfile
7530         $RUNAS setfattr -x system.posix_acl_access $testfile
7531         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7532 }
7533 run_test 102p "check setxattr(2) correctly fails without permission"
7534
7535 test_102q() {
7536         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7537                 skip "MDS needs to be at least 2.6.92" && return
7538         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7539 }
7540 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7541
7542 test_102r() {
7543         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7544                 skip "MDS needs to be at least 2.6.93" && return
7545         touch $DIR/$tfile || error "touch"
7546         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7547         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7548         rm $DIR/$tfile || error "rm"
7549
7550         #normal directory
7551         mkdir -p $DIR/$tdir || error "mkdir"
7552         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7553         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7554         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7555                 error "$testfile error deleting user.author1"
7556         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7557                 grep "user.$(basename $tdir)" &&
7558                 error "$tdir did not delete user.$(basename $tdir)"
7559         rmdir $DIR/$tdir || error "rmdir"
7560
7561         #striped directory
7562         test_mkdir $DIR/$tdir
7563         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7564         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7565         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7566                 error "$testfile error deleting user.author1"
7567         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7568                 grep "user.$(basename $tdir)" &&
7569                 error "$tdir did not delete user.$(basename $tdir)"
7570         rmdir $DIR/$tdir || error "rm striped dir"
7571 }
7572 run_test 102r "set EAs with empty values"
7573
7574 run_acl_subtest()
7575 {
7576     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7577     return $?
7578 }
7579
7580 test_103a() {
7581         [ "$UID" != 0 ] && skip_env "must run as root" && return
7582         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7583                 skip "must have acl enabled" && return
7584         [ -z "$(which setfacl 2>/dev/null)" ] &&
7585                 skip_env "could not find setfacl" && return
7586         $GSS && skip "could not run under gss" && return
7587         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7588
7589         gpasswd -a daemon bin                           # LU-5641
7590         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7591
7592         declare -a identity_old
7593
7594         for num in $(seq $MDSCOUNT); do
7595                 switch_identity $num true || identity_old[$num]=$?
7596         done
7597
7598         SAVE_UMASK=$(umask)
7599         umask 0022
7600         mkdir -p $DIR/$tdir
7601         cd $DIR/$tdir
7602
7603         echo "performing cp ..."
7604         run_acl_subtest cp || error "run_acl_subtest cp failed"
7605         echo "performing getfacl-noacl..."
7606         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7607         echo "performing misc..."
7608         run_acl_subtest misc || error  "misc test failed"
7609         echo "performing permissions..."
7610         run_acl_subtest permissions || error "permissions failed"
7611         # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
7612         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.8.55) -o \
7613              \( $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6) -a \
7614              $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.29) \) ]
7615         then
7616                 echo "performing permissions xattr..."
7617                 run_acl_subtest permissions_xattr ||
7618                         error "permissions_xattr failed"
7619         fi
7620         echo "performing setfacl..."
7621         run_acl_subtest setfacl || error  "setfacl test failed"
7622
7623         # inheritance test got from HP
7624         echo "performing inheritance..."
7625         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7626         chmod +x make-tree || error "chmod +x failed"
7627         run_acl_subtest inheritance || error "inheritance test failed"
7628         rm -f make-tree
7629
7630         echo "LU-974 ignore umask when acl is enabled..."
7631         run_acl_subtest 974 || error "LU-974 umask test failed"
7632         if [ $MDSCOUNT -ge 2 ]; then
7633                 run_acl_subtest 974_remote ||
7634                         error "LU-974 umask test failed under remote dir"
7635         fi
7636
7637         echo "LU-2561 newly created file is same size as directory..."
7638         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7639                 run_acl_subtest 2561 || error "LU-2561 test failed"
7640         else
7641                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7642         fi
7643
7644         run_acl_subtest 4924 || error "LU-4924 test failed"
7645
7646         cd $SAVE_PWD
7647         umask $SAVE_UMASK
7648
7649         for num in $(seq $MDSCOUNT); do
7650                 if [ "${identity_old[$num]}" = 1 ]; then
7651                         switch_identity $num false || identity_old[$num]=$?
7652                 fi
7653         done
7654 }
7655 run_test 103a "acl test ========================================="
7656
7657 test_103c() {
7658         mkdir -p $DIR/$tdir
7659         cp -rp $DIR/$tdir $DIR/$tdir.bak
7660
7661         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7662                 error "$DIR/$tdir shouldn't contain default ACL"
7663         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7664                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7665         true
7666 }
7667 run_test 103c "'cp -rp' won't set empty acl"
7668
7669 test_104a() {
7670         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7671         touch $DIR/$tfile
7672         lfs df || error "lfs df failed"
7673         lfs df -ih || error "lfs df -ih failed"
7674         lfs df -h $DIR || error "lfs df -h $DIR failed"
7675         lfs df -i $DIR || error "lfs df -i $DIR failed"
7676         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7677         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7678
7679         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7680         lctl --device %$OSC deactivate
7681         lfs df || error "lfs df with deactivated OSC failed"
7682         lctl --device %$OSC activate
7683         # wait the osc back to normal
7684         wait_osc_import_state client ost FULL
7685
7686         lfs df || error "lfs df with reactivated OSC failed"
7687         rm -f $DIR/$tfile
7688 }
7689 run_test 104a "lfs df [-ih] [path] test ========================="
7690
7691 test_104b() {
7692         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7693         [ $RUNAS_ID -eq $UID ] &&
7694                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7695         chmod 666 /dev/obd
7696         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7697                         grep "Permission denied" | wc -l)))
7698         if [ $denied_cnt -ne 0 ]; then
7699                 error "lfs check servers test failed"
7700         fi
7701 }
7702 run_test 104b "$RUNAS lfs check servers test ===================="
7703
7704 test_105a() {
7705         # doesn't work on 2.4 kernels
7706         touch $DIR/$tfile
7707         if $(flock_is_enabled); then
7708                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7709         else
7710                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7711         fi
7712         rm -f $DIR/$tfile
7713 }
7714 run_test 105a "flock when mounted without -o flock test ========"
7715
7716 test_105b() {
7717         touch $DIR/$tfile
7718         if $(flock_is_enabled); then
7719                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7720         else
7721                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7722         fi
7723         rm -f $DIR/$tfile
7724 }
7725 run_test 105b "fcntl when mounted without -o flock test ========"
7726
7727 test_105c() {
7728         touch $DIR/$tfile
7729         if $(flock_is_enabled); then
7730                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7731         else
7732                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7733         fi
7734         rm -f $DIR/$tfile
7735 }
7736 run_test 105c "lockf when mounted without -o flock test"
7737
7738 test_105d() { # bug 15924
7739         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7740         test_mkdir $DIR/$tdir
7741         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7742         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7743         $LCTL set_param fail_loc=0x80000315
7744         flocks_test 2 $DIR/$tdir
7745 }
7746 run_test 105d "flock race (should not freeze) ========"
7747
7748 test_105e() { # bug 22660 && 22040
7749         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7750         touch $DIR/$tfile
7751         flocks_test 3 $DIR/$tfile
7752 }
7753 run_test 105e "Two conflicting flocks from same process"
7754
7755 test_106() { #bug 10921
7756         test_mkdir $DIR/$tdir
7757         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7758         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7759 }
7760 run_test 106 "attempt exec of dir followed by chown of that dir"
7761
7762 test_107() {
7763         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7764         CDIR=`pwd`
7765         cd $DIR
7766
7767         local file=core
7768         rm -f $file
7769
7770         local save_pattern=$(sysctl -n kernel.core_pattern)
7771         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7772         sysctl -w kernel.core_pattern=$file
7773         sysctl -w kernel.core_uses_pid=0
7774
7775         ulimit -c unlimited
7776         sleep 60 &
7777         SLEEPPID=$!
7778
7779         sleep 1
7780
7781         kill -s 11 $SLEEPPID
7782         wait $SLEEPPID
7783         if [ -e $file ]; then
7784                 size=`stat -c%s $file`
7785                 [ $size -eq 0 ] && error "Fail to create core file $file"
7786         else
7787                 error "Fail to create core file $file"
7788         fi
7789         rm -f $file
7790         sysctl -w kernel.core_pattern=$save_pattern
7791         sysctl -w kernel.core_uses_pid=$save_uses_pid
7792         cd $CDIR
7793 }
7794 run_test 107 "Coredump on SIG"
7795
7796 test_110() {
7797         test_mkdir $DIR/$tdir
7798         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255)
7799         $LFS mkdir -c $MDSCOUNT $DIR/$tdir/$(str_repeat 'b' 256) &&
7800                 error "mkdir with 256 char should fail, but did not"
7801         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7802                 error "create with 255 char failed"
7803         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7804                 error "create with 256 char should fail, but did not"
7805
7806         ls -l $DIR/$tdir
7807         rm -rf $DIR/$tdir
7808 }
7809 run_test 110 "filename length checking"
7810
7811 #
7812 # Purpose: To verify dynamic thread (OSS) creation.
7813 #
7814 test_115() {
7815         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7816         remote_ost_nodsh && skip "remote OST with nodsh" && return
7817
7818         # Lustre does not stop service threads once they are started.
7819         # Reset number of running threads to default.
7820         stopall
7821         setupall
7822
7823         local OSTIO_pre
7824         local save_params="$TMP/sanity-$TESTNAME.parameters"
7825
7826         # Get ll_ost_io count before I/O
7827         OSTIO_pre=$(do_facet ost1 \
7828                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
7829         # Exit if lustre is not running (ll_ost_io not running).
7830         [ -z "$OSTIO_pre" ] && error "no OSS threads"
7831
7832         echo "Starting with $OSTIO_pre threads"
7833         local thread_max=$((OSTIO_pre * 2))
7834         local rpc_in_flight=$((thread_max * 2))
7835         # Number of I/O Process proposed to be started.
7836         local nfiles
7837         local facets=$(get_facets OST)
7838
7839         save_lustre_params client "osc.*OST*.max_rpcs_in_flight" > $save_params
7840         save_lustre_params $facets "ost.OSS.ost_io.threads_max" >> $save_params
7841
7842         # Set in_flight to $rpc_in_flight
7843         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
7844                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
7845         nfiles=${rpc_in_flight}
7846         # Set ost thread_max to $thread_max
7847         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
7848
7849         # 5 Minutes should be sufficient for max number of OSS
7850         # threads(thread_max) to be created.
7851         local timeout=300
7852
7853         # Start I/O.
7854         local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
7855         test_mkdir $DIR/$tdir
7856         for i in $(seq $nfiles); do
7857                 local file=$DIR/$tdir/${tfile}-$i
7858                 $LFS setstripe -c -1 -i 0 $file
7859                 ($WTL $file $timeout)&
7860         done
7861
7862         # I/O Started - Wait for thread_started to reach thread_max or report
7863         # error if thread_started is more than thread_max.
7864         echo "Waiting for thread_started to reach thread_max"
7865         local thread_started=0
7866         local end_time=$((SECONDS + timeout))
7867
7868         while [ $SECONDS -le $end_time ] ; do
7869                 echo -n "."
7870                 # Get ost i/o thread_started count.
7871                 thread_started=$(do_facet ost1 \
7872                         "$LCTL get_param \
7873                         ost.OSS.ost_io.threads_started | cut -d= -f2")
7874                 # Break out if thread_started is equal/greater than thread_max
7875                 if [[ $thread_started -ge $thread_max ]]; then
7876                         echo ll_ost_io thread_started $thread_started, \
7877                                 equal/greater than thread_max $thread_max
7878                         break
7879                 fi
7880                 sleep 1
7881         done
7882
7883         # Cleanup - We have the numbers, Kill i/o jobs if running.
7884         jobcount=($(jobs -p))
7885         for i in $(seq 0 $((${#jobcount[@]}-1)))
7886         do
7887                 kill -9 ${jobcount[$i]}
7888                 if [ $? -ne 0 ] ; then
7889                         echo Warning: \
7890                         Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
7891                 fi
7892         done
7893
7894         # Cleanup files left by WTL binary.
7895         for i in $(seq $nfiles); do
7896                 local file=$DIR/$tdir/${tfile}-$i
7897                 rm -rf $file
7898                 if [ $? -ne 0 ] ; then
7899                         echo "Warning: Failed to delete file $file"
7900                 fi
7901         done
7902
7903         restore_lustre_params <$save_params
7904         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
7905
7906         # Error out if no new thread has started or Thread started is greater
7907         # than thread max.
7908         if [[ $thread_started -le $OSTIO_pre ||
7909                         $thread_started -gt $thread_max ]]; then
7910                 error "ll_ost_io: thread_started $thread_started" \
7911                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
7912                       "No new thread started or thread started greater " \
7913                       "than thread_max."
7914         fi
7915 }
7916 run_test 115 "verify dynamic thread creation===================="
7917
7918 free_min_max () {
7919         wait_delete_completed
7920         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7921         echo "OST kbytes available: ${AVAIL[@]}"
7922         MAXV=${AVAIL[0]}
7923         MAXI=0
7924         MINV=${AVAIL[0]}
7925         MINI=0
7926         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7927                 #echo OST $i: ${AVAIL[i]}kb
7928                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7929                         MAXV=${AVAIL[i]}
7930                         MAXI=$i
7931                 fi
7932                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7933                         MINV=${AVAIL[i]}
7934                         MINI=$i
7935                 fi
7936         done
7937         echo "Min free space: OST $MINI: $MINV"
7938         echo "Max free space: OST $MAXI: $MAXV"
7939 }
7940
7941 test_116a() { # was previously test_116()
7942         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7943         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7944
7945         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7946
7947         echo -n "Free space priority "
7948         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7949                 head -n1
7950         declare -a AVAIL
7951         free_min_max
7952
7953         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7954         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7955                 && return
7956         trap simple_cleanup_common EXIT
7957
7958
7959         # Check if we need to generate uneven OSTs
7960         test_mkdir -p $DIR/$tdir/OST${MINI}
7961         local FILL=$((MINV / 4))
7962         local DIFF=$((MAXV - MINV))
7963         local DIFF2=$((DIFF * 100 / MINV))
7964
7965         local threshold=$(do_facet $SINGLEMDS \
7966                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7967         threshold=${threshold%%%}
7968         echo -n "Check for uneven OSTs: "
7969         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7970
7971         if [[ $DIFF2 -gt $threshold ]]; then
7972                 echo "ok"
7973                 echo "Don't need to fill OST$MINI"
7974         else
7975                 # generate uneven OSTs. Write 2% over the QOS threshold value
7976                 echo "no"
7977                 DIFF=$((threshold - DIFF2 + 2))
7978                 DIFF2=$((MINV * DIFF / 100))
7979                 echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
7980                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7981                         error "setstripe failed"
7982                 DIFF=$((DIFF2 / 2048))
7983                 i=0
7984                 while [ $i -lt $DIFF ]; do
7985                         i=$((i + 1))
7986                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7987                                 bs=2M count=1 2>/dev/null
7988                         echo -n .
7989                 done
7990                 echo .
7991                 sync
7992                 sleep_maxage
7993                 free_min_max
7994         fi
7995
7996         DIFF=$((MAXV - MINV))
7997         DIFF2=$((DIFF * 100 / MINV))
7998         echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
7999         if [ $DIFF2 -gt $threshold ]; then
8000                 echo "ok"
8001         else
8002                 echo "failed - QOS mode won't be used"
8003                 skip "QOS imbalance criteria not met"
8004                 simple_cleanup_common
8005                 return
8006         fi
8007
8008         MINI1=$MINI
8009         MINV1=$MINV
8010         MAXI1=$MAXI
8011         MAXV1=$MAXV
8012
8013         # now fill using QOS
8014         $SETSTRIPE -c 1 $DIR/$tdir
8015         FILL=$((FILL / 200))
8016         if [ $FILL -gt 600 ]; then
8017                 FILL=600
8018         fi
8019         echo "writing $FILL files to QOS-assigned OSTs"
8020         i=0
8021         while [ $i -lt $FILL ]; do
8022                 i=$((i + 1))
8023                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
8024                         count=1 2>/dev/null
8025                 echo -n .
8026         done
8027         echo "wrote $i 200k files"
8028         sync
8029         sleep_maxage
8030
8031         echo "Note: free space may not be updated, so measurements might be off"
8032         free_min_max
8033         DIFF2=$((MAXV - MINV))
8034         echo "free space delta: orig $DIFF final $DIFF2"
8035         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
8036         DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
8037         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
8038         DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
8039         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
8040         if [[ $DIFF -gt 0 ]]; then
8041                 FILL=$((DIFF2 * 100 / DIFF - 100))
8042                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
8043         fi
8044
8045         # Figure out which files were written where
8046         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
8047                awk '/'$MINI1': / {print $2; exit}')
8048         echo $UUID
8049         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
8050         echo "$MINC files created on smaller OST $MINI1"
8051         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
8052                awk '/'$MAXI1': / {print $2; exit}')
8053         echo $UUID
8054         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
8055         echo "$MAXC files created on larger OST $MAXI1"
8056         if [[ $MINC -gt 0 ]]; then
8057                 FILL=$((MAXC * 100 / MINC - 100))
8058                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
8059         fi
8060         [[ $MAXC -gt $MINC ]] ||
8061                 error_ignore LU-9 "stripe QOS didn't balance free space"
8062         simple_cleanup_common
8063 }
8064 run_test 116a "stripe QOS: free space balance ==================="
8065
8066 test_116b() { # LU-2093
8067         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8068         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8069
8070 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
8071         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
8072                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
8073         [ -z "$old_rr" ] && skip "no QOS" && return 0
8074         do_facet $SINGLEMDS lctl set_param \
8075                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
8076         mkdir -p $DIR/$tdir
8077         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
8078         createmany -o $DIR/$tdir/f- 20 || error "can't create"
8079         do_facet $SINGLEMDS lctl set_param fail_loc=0
8080         rm -rf $DIR/$tdir
8081         do_facet $SINGLEMDS lctl set_param \
8082                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
8083 }
8084 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
8085
8086 test_117() # bug 10891
8087 {
8088         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8089         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
8090         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
8091         lctl set_param fail_loc=0x21e
8092         > $DIR/$tfile || error "truncate failed"
8093         lctl set_param fail_loc=0
8094         echo "Truncate succeeded."
8095         rm -f $DIR/$tfile
8096 }
8097 run_test 117 "verify osd extend =========="
8098
8099 NO_SLOW_RESENDCOUNT=4
8100 export OLD_RESENDCOUNT=""
8101 set_resend_count () {
8102         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
8103         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
8104         lctl set_param -n $PROC_RESENDCOUNT $1
8105         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
8106 }
8107
8108 # for reduce test_118* time (b=14842)
8109 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8110
8111 # Reset async IO behavior after error case
8112 reset_async() {
8113         FILE=$DIR/reset_async
8114
8115         # Ensure all OSCs are cleared
8116         $SETSTRIPE -c -1 $FILE
8117         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
8118         sync
8119         rm $FILE
8120 }
8121
8122 test_118a() #bug 11710
8123 {
8124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8125         reset_async
8126
8127         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8128         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8129         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8130
8131         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8132                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8133                 return 1;
8134         fi
8135         rm -f $DIR/$tfile
8136 }
8137 run_test 118a "verify O_SYNC works =========="
8138
8139 test_118b()
8140 {
8141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8142         remote_ost_nodsh && skip "remote OST with nodsh" && return
8143
8144         reset_async
8145
8146         #define OBD_FAIL_SRV_ENOENT 0x217
8147         set_nodes_failloc "$(osts_nodes)" 0x217
8148         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8149         RC=$?
8150         set_nodes_failloc "$(osts_nodes)" 0
8151         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8152         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8153                     grep -c writeback)
8154
8155         if [[ $RC -eq 0 ]]; then
8156                 error "Must return error due to dropped pages, rc=$RC"
8157                 return 1;
8158         fi
8159
8160         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8161                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8162                 return 1;
8163         fi
8164
8165         echo "Dirty pages not leaked on ENOENT"
8166
8167         # Due to the above error the OSC will issue all RPCs syncronously
8168         # until a subsequent RPC completes successfully without error.
8169         $MULTIOP $DIR/$tfile Ow4096yc
8170         rm -f $DIR/$tfile
8171
8172         return 0
8173 }
8174 run_test 118b "Reclaim dirty pages on fatal error =========="
8175
8176 test_118c()
8177 {
8178         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8179
8180         # for 118c, restore the original resend count, LU-1940
8181         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
8182                                 set_resend_count $OLD_RESENDCOUNT
8183         remote_ost_nodsh && skip "remote OST with nodsh" && return
8184
8185         reset_async
8186
8187         #define OBD_FAIL_OST_EROFS               0x216
8188         set_nodes_failloc "$(osts_nodes)" 0x216
8189
8190         # multiop should block due to fsync until pages are written
8191         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8192         MULTIPID=$!
8193         sleep 1
8194
8195         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8196                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8197         fi
8198
8199         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8200                     grep -c writeback)
8201         if [[ $WRITEBACK -eq 0 ]]; then
8202                 error "No page in writeback, writeback=$WRITEBACK"
8203         fi
8204
8205         set_nodes_failloc "$(osts_nodes)" 0
8206         wait $MULTIPID
8207         RC=$?
8208         if [[ $RC -ne 0 ]]; then
8209                 error "Multiop fsync failed, rc=$RC"
8210         fi
8211
8212         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8213         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8214                     grep -c writeback)
8215         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8216                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8217         fi
8218
8219         rm -f $DIR/$tfile
8220         echo "Dirty pages flushed via fsync on EROFS"
8221         return 0
8222 }
8223 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
8224
8225 # continue to use small resend count to reduce test_118* time (b=14842)
8226 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8227
8228 test_118d()
8229 {
8230         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8231         remote_ost_nodsh && skip "remote OST with nodsh" && return
8232
8233         reset_async
8234
8235         #define OBD_FAIL_OST_BRW_PAUSE_BULK
8236         set_nodes_failloc "$(osts_nodes)" 0x214
8237         # multiop should block due to fsync until pages are written
8238         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8239         MULTIPID=$!
8240         sleep 1
8241
8242         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8243                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8244         fi
8245
8246         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8247                     grep -c writeback)
8248         if [[ $WRITEBACK -eq 0 ]]; then
8249                 error "No page in writeback, writeback=$WRITEBACK"
8250         fi
8251
8252         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
8253         set_nodes_failloc "$(osts_nodes)" 0
8254
8255         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8256         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8257                     grep -c writeback)
8258         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8259                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8260         fi
8261
8262         rm -f $DIR/$tfile
8263         echo "Dirty pages gaurenteed flushed via fsync"
8264         return 0
8265 }
8266 run_test 118d "Fsync validation inject a delay of the bulk =========="
8267
8268 test_118f() {
8269         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8270         reset_async
8271
8272         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
8273         lctl set_param fail_loc=0x8000040a
8274
8275         # Should simulate EINVAL error which is fatal
8276         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8277         RC=$?
8278         if [[ $RC -eq 0 ]]; then
8279                 error "Must return error due to dropped pages, rc=$RC"
8280         fi
8281
8282         lctl set_param fail_loc=0x0
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 |
8287                     grep -c writeback)
8288         if [[ $LOCKED -ne 0 ]]; then
8289                 error "Locked pages remain in cache, locked=$LOCKED"
8290         fi
8291
8292         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8293                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8294         fi
8295
8296         rm -f $DIR/$tfile
8297         echo "No pages locked after fsync"
8298
8299         reset_async
8300         return 0
8301 }
8302 run_test 118f "Simulate unrecoverable OSC side error =========="
8303
8304 test_118g() {
8305         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8306         reset_async
8307
8308         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
8309         lctl set_param fail_loc=0x406
8310
8311         # simulate local -ENOMEM
8312         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8313         RC=$?
8314
8315         lctl set_param fail_loc=0
8316         if [[ $RC -eq 0 ]]; then
8317                 error "Must return error due to dropped pages, rc=$RC"
8318         fi
8319
8320         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8321         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8322         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8323                         grep -c writeback)
8324         if [[ $LOCKED -ne 0 ]]; then
8325                 error "Locked pages remain in cache, locked=$LOCKED"
8326         fi
8327
8328         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8329                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8330         fi
8331
8332         rm -f $DIR/$tfile
8333         echo "No pages locked after fsync"
8334
8335         reset_async
8336         return 0
8337 }
8338 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
8339
8340 test_118h() {
8341         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8342         remote_ost_nodsh && skip "remote OST with nodsh" && return
8343
8344         reset_async
8345
8346         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8347         set_nodes_failloc "$(osts_nodes)" 0x20e
8348         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8349         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8350         RC=$?
8351
8352         set_nodes_failloc "$(osts_nodes)" 0
8353         if [[ $RC -eq 0 ]]; then
8354                 error "Must return error due to dropped pages, rc=$RC"
8355         fi
8356
8357         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8358         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8359         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8360                     grep -c writeback)
8361         if [[ $LOCKED -ne 0 ]]; then
8362                 error "Locked pages remain in cache, locked=$LOCKED"
8363         fi
8364
8365         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8366                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8367         fi
8368
8369         rm -f $DIR/$tfile
8370         echo "No pages locked after fsync"
8371
8372         return 0
8373 }
8374 run_test 118h "Verify timeout in handling recoverables errors  =========="
8375
8376 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8377
8378 test_118i() {
8379         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8380         remote_ost_nodsh && skip "remote OST with nodsh" && return
8381
8382         reset_async
8383
8384         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8385         set_nodes_failloc "$(osts_nodes)" 0x20e
8386
8387         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8388         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8389         PID=$!
8390         sleep 5
8391         set_nodes_failloc "$(osts_nodes)" 0
8392
8393         wait $PID
8394         RC=$?
8395         if [[ $RC -ne 0 ]]; then
8396                 error "got error, but should be not, rc=$RC"
8397         fi
8398
8399         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8400         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8401         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8402         if [[ $LOCKED -ne 0 ]]; then
8403                 error "Locked pages remain in cache, locked=$LOCKED"
8404         fi
8405
8406         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8407                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8408         fi
8409
8410         rm -f $DIR/$tfile
8411         echo "No pages locked after fsync"
8412
8413         return 0
8414 }
8415 run_test 118i "Fix error before timeout in recoverable error  =========="
8416
8417 [ "$SLOW" = "no" ] && set_resend_count 4
8418
8419 test_118j() {
8420         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8421         remote_ost_nodsh && skip "remote OST with nodsh" && return
8422
8423         reset_async
8424
8425         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
8426         set_nodes_failloc "$(osts_nodes)" 0x220
8427
8428         # return -EIO from OST
8429         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8430         RC=$?
8431         set_nodes_failloc "$(osts_nodes)" 0x0
8432         if [[ $RC -eq 0 ]]; then
8433                 error "Must return error due to dropped pages, rc=$RC"
8434         fi
8435
8436         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8437         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8438         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8439         if [[ $LOCKED -ne 0 ]]; then
8440                 error "Locked pages remain in cache, locked=$LOCKED"
8441         fi
8442
8443         # in recoverable error on OST we want resend and stay until it finished
8444         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8445                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8446         fi
8447
8448         rm -f $DIR/$tfile
8449         echo "No pages locked after fsync"
8450
8451         return 0
8452 }
8453 run_test 118j "Simulate unrecoverable OST side error =========="
8454
8455 test_118k()
8456 {
8457         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8458         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
8459
8460         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8461         set_nodes_failloc "$(osts_nodes)" 0x20e
8462         test_mkdir $DIR/$tdir
8463
8464         for ((i=0;i<10;i++)); do
8465                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
8466                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
8467                 SLEEPPID=$!
8468                 sleep 0.500s
8469                 kill $SLEEPPID
8470                 wait $SLEEPPID
8471         done
8472
8473         set_nodes_failloc "$(osts_nodes)" 0
8474         rm -rf $DIR/$tdir
8475 }
8476 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
8477
8478 test_118l()
8479 {
8480         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8481         # LU-646
8482         test_mkdir $DIR/$tdir
8483         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
8484         rm -rf $DIR/$tdir
8485 }
8486 run_test 118l "fsync dir"
8487
8488 test_118m() # LU-3066
8489 {
8490         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8491         test_mkdir $DIR/$tdir
8492         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
8493         rm -rf $DIR/$tdir
8494 }
8495 run_test 118m "fdatasync dir ========="
8496
8497 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8498
8499 test_119a() # bug 11737
8500 {
8501         BSIZE=$((512 * 1024))
8502         directio write $DIR/$tfile 0 1 $BSIZE
8503         # We ask to read two blocks, which is more than a file size.
8504         # directio will indicate an error when requested and actual
8505         # sizes aren't equeal (a normal situation in this case) and
8506         # print actual read amount.
8507         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
8508         if [ "$NOB" != "$BSIZE" ]; then
8509                 error "read $NOB bytes instead of $BSIZE"
8510         fi
8511         rm -f $DIR/$tfile
8512 }
8513 run_test 119a "Short directIO read must return actual read amount"
8514
8515 test_119b() # bug 11737
8516 {
8517         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
8518
8519         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
8520         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
8521         sync
8522         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
8523                 error "direct read failed"
8524         rm -f $DIR/$tfile
8525 }
8526 run_test 119b "Sparse directIO read must return actual read amount"
8527
8528 test_119c() # bug 13099
8529 {
8530         BSIZE=1048576
8531         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
8532         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
8533         rm -f $DIR/$tfile
8534 }
8535 run_test 119c "Testing for direct read hitting hole"
8536
8537 test_119d() # bug 15950
8538 {
8539         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8540         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
8541         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
8542         BSIZE=1048576
8543         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
8544         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
8545         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
8546         lctl set_param fail_loc=0x40d
8547         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
8548         pid_dio=$!
8549         sleep 1
8550         cat $DIR/$tfile > /dev/null &
8551         lctl set_param fail_loc=0
8552         pid_reads=$!
8553         wait $pid_dio
8554         log "the DIO writes have completed, now wait for the reads (should not block very long)"
8555         sleep 2
8556         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8557         error "the read rpcs have not completed in 2s"
8558         rm -f $DIR/$tfile
8559         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8560 }
8561 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8562
8563 test_120a() {
8564         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8565         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8566         test_mkdir $DIR/$tdir
8567         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8568                 { skip "no early lock cancel on server"; return 0; }
8569
8570         lru_resize_disable mdc
8571         lru_resize_disable osc
8572         cancel_lru_locks mdc
8573         # asynchronous object destroy at MDT could cause bl ast to client
8574         cancel_lru_locks osc
8575
8576         stat $DIR/$tdir > /dev/null
8577         can1=$(do_facet $SINGLEMDS \
8578                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8579                awk '/ldlm_cancel/ {print $2}')
8580         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8581                awk '/ldlm_bl_callback/ {print $2}')
8582         test_mkdir -c1 $DIR/$tdir/d1
8583         can2=$(do_facet $SINGLEMDS \
8584                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8585                awk '/ldlm_cancel/ {print $2}')
8586         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8587                awk '/ldlm_bl_callback/ {print $2}')
8588         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8589         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8590         lru_resize_enable mdc
8591         lru_resize_enable osc
8592 }
8593 run_test 120a "Early Lock Cancel: mkdir test"
8594
8595 test_120b() {
8596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8597         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8598         test_mkdir $DIR/$tdir
8599         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8600                 { skip "no early lock cancel on server"; return 0; }
8601         lru_resize_disable mdc
8602         lru_resize_disable osc
8603         cancel_lru_locks mdc
8604         stat $DIR/$tdir > /dev/null
8605         can1=$(do_facet $SINGLEMDS \
8606                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8607                awk '/ldlm_cancel/ {print $2}')
8608         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8609                awk '/ldlm_bl_callback/ {print $2}')
8610         touch $DIR/$tdir/f1
8611         can2=$(do_facet $SINGLEMDS \
8612                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8613                awk '/ldlm_cancel/ {print $2}')
8614         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8615                awk '/ldlm_bl_callback/ {print $2}')
8616         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8617         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8618         lru_resize_enable mdc
8619         lru_resize_enable osc
8620 }
8621 run_test 120b "Early Lock Cancel: create test"
8622
8623 test_120c() {
8624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8625         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8626         test_mkdir -c1 $DIR/$tdir
8627         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8628                 { skip "no early lock cancel on server"; return 0; }
8629         lru_resize_disable mdc
8630         lru_resize_disable osc
8631         test_mkdir -c1 $DIR/$tdir/d1
8632         test_mkdir -c1 $DIR/$tdir/d2
8633         touch $DIR/$tdir/d1/f1
8634         cancel_lru_locks mdc
8635         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8636         can1=$(do_facet $SINGLEMDS \
8637                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8638                awk '/ldlm_cancel/ {print $2}')
8639         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8640                awk '/ldlm_bl_callback/ {print $2}')
8641         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8642         can2=$(do_facet $SINGLEMDS \
8643                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8644                awk '/ldlm_cancel/ {print $2}')
8645         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8646                awk '/ldlm_bl_callback/ {print $2}')
8647         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8648         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8649         lru_resize_enable mdc
8650         lru_resize_enable osc
8651 }
8652 run_test 120c "Early Lock Cancel: link test"
8653
8654 test_120d() {
8655         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8656         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8657         test_mkdir -c1 $DIR/$tdir
8658         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8659                 { skip "no early lock cancel on server"; return 0; }
8660         lru_resize_disable mdc
8661         lru_resize_disable osc
8662         touch $DIR/$tdir
8663         cancel_lru_locks mdc
8664         stat $DIR/$tdir > /dev/null
8665         can1=$(do_facet $SINGLEMDS \
8666                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8667                awk '/ldlm_cancel/ {print $2}')
8668         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8669                awk '/ldlm_bl_callback/ {print $2}')
8670         chmod a+x $DIR/$tdir
8671         can2=$(do_facet $SINGLEMDS \
8672                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8673                awk '/ldlm_cancel/ {print $2}')
8674         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8675                awk '/ldlm_bl_callback/ {print $2}')
8676         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8677         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8678         lru_resize_enable mdc
8679         lru_resize_enable osc
8680 }
8681 run_test 120d "Early Lock Cancel: setattr test"
8682
8683 test_120e() {
8684         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8685         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8686                 { skip "no early lock cancel on server"; return 0; }
8687         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8688         local dlmtrace_set=false
8689
8690         test_mkdir -c1 $DIR/$tdir
8691         lru_resize_disable mdc
8692         lru_resize_disable osc
8693         ! $LCTL get_param debug | grep -q dlmtrace &&
8694                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
8695         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8696         cancel_lru_locks mdc
8697         cancel_lru_locks osc
8698         dd if=$DIR/$tdir/f1 of=/dev/null
8699         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8700         # XXX client can not do early lock cancel of OST lock
8701         # during unlink (LU-4206), so cancel osc lock now.
8702         sleep 2
8703         cancel_lru_locks osc
8704         can1=$(do_facet $SINGLEMDS \
8705                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8706                awk '/ldlm_cancel/ {print $2}')
8707         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8708                awk '/ldlm_bl_callback/ {print $2}')
8709         unlink $DIR/$tdir/f1
8710         sleep 5
8711         can2=$(do_facet $SINGLEMDS \
8712                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8713                awk '/ldlm_cancel/ {print $2}')
8714         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8715                awk '/ldlm_bl_callback/ {print $2}')
8716         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
8717                 $LCTL dk $TMP/cancel.debug.txt
8718         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
8719                 $LCTL dk $TMP/blocking.debug.txt
8720         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
8721         lru_resize_enable mdc
8722         lru_resize_enable osc
8723 }
8724 run_test 120e "Early Lock Cancel: unlink test"
8725
8726 test_120f() {
8727         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8728         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8729                 { skip "no early lock cancel on server"; return 0; }
8730         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8731         test_mkdir -c1 $DIR/$tdir
8732         lru_resize_disable mdc
8733         lru_resize_disable osc
8734         test_mkdir -c1 $DIR/$tdir/d1
8735         test_mkdir -c1 $DIR/$tdir/d2
8736         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8737         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8738         cancel_lru_locks mdc
8739         cancel_lru_locks osc
8740         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8741         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8742         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8743         # XXX client can not do early lock cancel of OST lock
8744         # during rename (LU-4206), so cancel osc lock now.
8745         sleep 2
8746         cancel_lru_locks osc
8747         can1=$(do_facet $SINGLEMDS \
8748                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8749                awk '/ldlm_cancel/ {print $2}')
8750         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8751                awk '/ldlm_bl_callback/ {print $2}')
8752         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8753         sleep 5
8754         can2=$(do_facet $SINGLEMDS \
8755                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8756                awk '/ldlm_cancel/ {print $2}')
8757         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8758                awk '/ldlm_bl_callback/ {print $2}')
8759         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8760         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8761         lru_resize_enable mdc
8762         lru_resize_enable osc
8763 }
8764 run_test 120f "Early Lock Cancel: rename test"
8765
8766 test_120g() {
8767         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8768         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8769                 { skip "no early lock cancel on server"; return 0; }
8770         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8771         lru_resize_disable mdc
8772         lru_resize_disable osc
8773         count=10000
8774         echo create $count files
8775         test_mkdir $DIR/$tdir
8776         cancel_lru_locks mdc
8777         cancel_lru_locks osc
8778         t0=$(date +%s)
8779
8780         can0=$(do_facet $SINGLEMDS \
8781                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8782                awk '/ldlm_cancel/ {print $2}')
8783         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8784                awk '/ldlm_bl_callback/ {print $2}')
8785         createmany -o $DIR/$tdir/f $count
8786         sync
8787         can1=$(do_facet $SINGLEMDS \
8788                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8789                awk '/ldlm_cancel/ {print $2}')
8790         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8791                awk '/ldlm_bl_callback/ {print $2}')
8792         t1=$(date +%s)
8793         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8794         echo rm $count files
8795         rm -r $DIR/$tdir
8796         sync
8797         can2=$(do_facet $SINGLEMDS \
8798                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8799                awk '/ldlm_cancel/ {print $2}')
8800         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8801                awk '/ldlm_bl_callback/ {print $2}')
8802         t2=$(date +%s)
8803         echo total: $count removes in $((t2-t1))
8804         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8805         sleep 2
8806         # wait for commitment of removal
8807         lru_resize_enable mdc
8808         lru_resize_enable osc
8809 }
8810 run_test 120g "Early Lock Cancel: performance test"
8811
8812 test_121() { #bug #10589
8813         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8814         rm -rf $DIR/$tfile
8815         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8816 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8817         lctl set_param fail_loc=0x310
8818         cancel_lru_locks osc > /dev/null
8819         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8820         lctl set_param fail_loc=0
8821         [[ $reads -eq $writes ]] ||
8822                 error "read $reads blocks, must be $writes blocks"
8823 }
8824 run_test 121 "read cancel race ========="
8825
8826 test_123a() { # was test 123, statahead(bug 11401)
8827         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8828         SLOWOK=0
8829         if ! grep -q "processor.*: 1" /proc/cpuinfo; then
8830                 log "testing UP system. Performance may be lower than expected."
8831                 SLOWOK=1
8832         fi
8833
8834         rm -rf $DIR/$tdir
8835         test_mkdir $DIR/$tdir
8836         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8837         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8838         MULT=10
8839         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8840                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8841
8842                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8843                 lctl set_param -n llite.*.statahead_max 0
8844                 lctl get_param llite.*.statahead_max
8845                 cancel_lru_locks mdc
8846                 cancel_lru_locks osc
8847                 stime=`date +%s`
8848                 time ls -l $DIR/$tdir | wc -l
8849                 etime=`date +%s`
8850                 delta=$((etime - stime))
8851                 log "ls $i files without statahead: $delta sec"
8852                 lctl set_param llite.*.statahead_max=$max
8853
8854                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8855                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8856                 cancel_lru_locks mdc
8857                 cancel_lru_locks osc
8858                 stime=`date +%s`
8859                 time ls -l $DIR/$tdir | wc -l
8860                 etime=`date +%s`
8861                 delta_sa=$((etime - stime))
8862                 log "ls $i files with statahead: $delta_sa sec"
8863                 lctl get_param -n llite.*.statahead_stats
8864                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8865
8866                 [[ $swrong -lt $ewrong ]] &&
8867                         log "statahead was stopped, maybe too many locks held!"
8868                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8869
8870                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8871                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8872                     lctl set_param -n llite.*.statahead_max 0
8873                     lctl get_param llite.*.statahead_max
8874                     cancel_lru_locks mdc
8875                     cancel_lru_locks osc
8876                     stime=`date +%s`
8877                     time ls -l $DIR/$tdir | wc -l
8878                     etime=`date +%s`
8879                     delta=$((etime - stime))
8880                     log "ls $i files again without statahead: $delta sec"
8881                     lctl set_param llite.*.statahead_max=$max
8882                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8883                         if [  $SLOWOK -eq 0 ]; then
8884                                 error "ls $i files is slower with statahead!"
8885                         else
8886                                 log "ls $i files is slower with statahead!"
8887                         fi
8888                         break
8889                     fi
8890                 fi
8891
8892                 [ $delta -gt 20 ] && break
8893                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8894                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8895         done
8896         log "ls done"
8897
8898         stime=`date +%s`
8899         rm -r $DIR/$tdir
8900         sync
8901         etime=`date +%s`
8902         delta=$((etime - stime))
8903         log "rm -r $DIR/$tdir/: $delta seconds"
8904         log "rm done"
8905         lctl get_param -n llite.*.statahead_stats
8906 }
8907 run_test 123a "verify statahead work"
8908
8909 test_123b () { # statahead(bug 15027)
8910         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8911         test_mkdir $DIR/$tdir
8912         createmany -o $DIR/$tdir/$tfile-%d 1000
8913
8914         cancel_lru_locks mdc
8915         cancel_lru_locks osc
8916
8917 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8918         lctl set_param fail_loc=0x80000803
8919         ls -lR $DIR/$tdir > /dev/null
8920         log "ls done"
8921         lctl set_param fail_loc=0x0
8922         lctl get_param -n llite.*.statahead_stats
8923         rm -r $DIR/$tdir
8924         sync
8925
8926 }
8927 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8928
8929 test_124a() {
8930         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8931         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
8932                 { skip "no lru resize on server"; return 0; }
8933         local NR=2000
8934         test_mkdir $DIR/$tdir
8935
8936         log "create $NR files at $DIR/$tdir"
8937         createmany -o $DIR/$tdir/f $NR ||
8938                 error "failed to create $NR files in $DIR/$tdir"
8939
8940         cancel_lru_locks mdc
8941         ls -l $DIR/$tdir > /dev/null
8942
8943         local NSDIR=""
8944         local LRU_SIZE=0
8945         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8946                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8947                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8948                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8949                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8950                         log "NSDIR=$NSDIR"
8951                         log "NS=$(basename $NSDIR)"
8952                         break
8953                 fi
8954         done
8955
8956         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8957                 skip "Not enough cached locks created!"
8958                 return 0
8959         fi
8960         log "LRU=$LRU_SIZE"
8961
8962         local SLEEP=30
8963
8964         # We know that lru resize allows one client to hold $LIMIT locks
8965         # for 10h. After that locks begin to be killed by client.
8966         local MAX_HRS=10
8967         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8968         log "LIMIT=$LIMIT"
8969         if [ $LIMIT -lt $LRU_SIZE ]; then
8970             skip "Limit is too small $LIMIT"
8971             return 0
8972         fi
8973
8974         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8975         # killing locks. Some time was spent for creating locks. This means
8976         # that up to the moment of sleep finish we must have killed some of
8977         # them (10-100 locks). This depends on how fast ther were created.
8978         # Many of them were touched in almost the same moment and thus will
8979         # be killed in groups.
8980         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8981
8982         # Use $LRU_SIZE_B here to take into account real number of locks
8983         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8984         local LRU_SIZE_B=$LRU_SIZE
8985         log "LVF=$LVF"
8986         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8987         log "OLD_LVF=$OLD_LVF"
8988         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8989
8990         # Let's make sure that we really have some margin. Client checks
8991         # cached locks every 10 sec.
8992         SLEEP=$((SLEEP+20))
8993         log "Sleep ${SLEEP} sec"
8994         local SEC=0
8995         while ((SEC<$SLEEP)); do
8996                 echo -n "..."
8997                 sleep 5
8998                 SEC=$((SEC+5))
8999                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
9000                 echo -n "$LRU_SIZE"
9001         done
9002         echo ""
9003         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
9004         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
9005
9006         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
9007                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
9008                 unlinkmany $DIR/$tdir/f $NR
9009                 return
9010         }
9011
9012         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
9013         log "unlink $NR files at $DIR/$tdir"
9014         unlinkmany $DIR/$tdir/f $NR
9015 }
9016 run_test 124a "lru resize ======================================="
9017
9018 get_max_pool_limit()
9019 {
9020         local limit=$($LCTL get_param \
9021                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
9022         local max=0
9023         for l in $limit; do
9024                 if [[ $l -gt $max ]]; then
9025                         max=$l
9026                 fi
9027         done
9028         echo $max
9029 }
9030
9031 test_124b() {
9032         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9033         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
9034                 { skip "no lru resize on server"; return 0; }
9035
9036         LIMIT=$(get_max_pool_limit)
9037
9038         NR=$(($(default_lru_size)*20))
9039         if [[ $NR -gt $LIMIT ]]; then
9040                 log "Limit lock number by $LIMIT locks"
9041                 NR=$LIMIT
9042         fi
9043
9044         IFree=$(mdsrate_inodes_available)
9045         if [ $IFree -lt $NR ]; then
9046                 log "Limit lock number by $IFree inodes"
9047                 NR=$IFree
9048         fi
9049
9050         lru_resize_disable mdc
9051         test_mkdir -p $DIR/$tdir/disable_lru_resize
9052
9053         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
9054         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
9055         cancel_lru_locks mdc
9056         stime=`date +%s`
9057         PID=""
9058         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9059         PID="$PID $!"
9060         sleep 2
9061         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9062         PID="$PID $!"
9063         sleep 2
9064         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9065         PID="$PID $!"
9066         wait $PID
9067         etime=`date +%s`
9068         nolruresize_delta=$((etime-stime))
9069         log "ls -la time: $nolruresize_delta seconds"
9070         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9071         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
9072
9073         lru_resize_enable mdc
9074         test_mkdir -p $DIR/$tdir/enable_lru_resize
9075
9076         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
9077         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
9078         cancel_lru_locks mdc
9079         stime=`date +%s`
9080         PID=""
9081         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9082         PID="$PID $!"
9083         sleep 2
9084         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9085         PID="$PID $!"
9086         sleep 2
9087         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9088         PID="$PID $!"
9089         wait $PID
9090         etime=`date +%s`
9091         lruresize_delta=$((etime-stime))
9092         log "ls -la time: $lruresize_delta seconds"
9093         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9094
9095         if [ $lruresize_delta -gt $nolruresize_delta ]; then
9096                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
9097         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
9098                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
9099         else
9100                 log "lru resize performs the same with no lru resize"
9101         fi
9102         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
9103 }
9104 run_test 124b "lru resize (performance test) ======================="
9105
9106 test_124c() {
9107         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9108         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
9109                 { skip "no lru resize on server"; return 0; }
9110
9111         # cache ununsed locks on client
9112         local nr=100
9113         cancel_lru_locks mdc
9114         test_mkdir $DIR/$tdir
9115         createmany -o $DIR/$tdir/f $nr ||
9116                 error "failed to create $nr files in $DIR/$tdir"
9117         ls -l $DIR/$tdir > /dev/null
9118
9119         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9120         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9121         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
9122         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
9123         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
9124
9125         # set lru_max_age to 1 sec
9126         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
9127         echo "sleep $((recalc_p * 2)) seconds..."
9128         sleep $((recalc_p * 2))
9129
9130         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
9131         # restore lru_max_age
9132         $LCTL set_param -n $nsdir.lru_max_age $max_age
9133         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
9134         unlinkmany $DIR/$tdir/f $nr
9135 }
9136 run_test 124c "LRUR cancel very aged locks"
9137
9138 test_125() { # 13358
9139         $LCTL get_param -n llite.*.client_type | grep -q local ||
9140                 { skip "must run as local client"; return; }
9141         $LCTL get_param -n mdc.*-mdc-*.connect_flags | grep -q acl ||
9142                 { skip "must have acl enabled"; return; }
9143         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9144         test_mkdir $DIR/$tdir
9145         $LFS setstripe -S 65536 -c -1 $DIR/$tdir || error "setstripe failed"
9146         setfacl -R -m u:bin:rwx $DIR/$tdir || error "setfacl $DIR/$tdir failed"
9147         ls -ld $DIR/$tdir || error "cannot access $DIR/$tdir"
9148 }
9149 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
9150
9151 test_126() { # bug 12829/13455
9152         $LCTL get_param -n llite.*.client_type | grep -q local ||
9153                 { skip "must run as local client"; return; }
9154         [ "$UID" != 0 ] && skip_env "$TESTNAME (must run as root)" && return
9155         $GSS && skip "must run as gss disabled" && return
9156
9157         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
9158         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
9159         rm -f $DIR/$tfile
9160         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
9161 }
9162 run_test 126 "check that the fsgid provided by the client is taken into account"
9163
9164 test_127a() { # bug 15521
9165         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9166         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
9167         $LCTL set_param osc.*.stats=0
9168         FSIZE=$((2048 * 1024))
9169         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9170         cancel_lru_locks osc
9171         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
9172
9173         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
9174         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9175                 echo "got $COUNT $NAME"
9176                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
9177                 eval $NAME=$COUNT || error "Wrong proc format"
9178
9179                 case $NAME in
9180                         read_bytes|write_bytes)
9181                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
9182                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
9183                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
9184                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
9185                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
9186                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
9187                                 error "sumsquare is too small: $SUMSQ"
9188                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
9189                                 error "sumsquare is too big: $SUMSQ"
9190                         ;;
9191                         *) ;;
9192                 esac
9193         done < $DIR/${tfile}.tmp
9194
9195         #check that we actually got some stats
9196         [ "$read_bytes" ] || error "Missing read_bytes stats"
9197         [ "$write_bytes" ] || error "Missing write_bytes stats"
9198         [ "$read_bytes" != 0 ] || error "no read done"
9199         [ "$write_bytes" != 0 ] || error "no write done"
9200 }
9201 run_test 127a "verify the client stats are sane"
9202
9203 test_127b() { # bug LU-333
9204         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9205         $LCTL set_param llite.*.stats=0
9206         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
9207         # perform 2 reads and writes so MAX is different from SUM.
9208         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9209         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9210         cancel_lru_locks osc
9211         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9212         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9213
9214         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
9215         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9216                 echo "got $COUNT $NAME"
9217                 eval $NAME=$COUNT || error "Wrong proc format"
9218
9219         case $NAME in
9220                 read_bytes)
9221                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9222                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9223                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9224                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9225                         ;;
9226                 write_bytes)
9227                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9228                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9229                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9230                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9231                         ;;
9232                         *) ;;
9233                 esac
9234         done < $TMP/${tfile}.tmp
9235
9236         #check that we actually got some stats
9237         [ "$read_bytes" ] || error "Missing read_bytes stats"
9238         [ "$write_bytes" ] || error "Missing write_bytes stats"
9239         [ "$read_bytes" != 0 ] || error "no read done"
9240         [ "$write_bytes" != 0 ] || error "no write done"
9241
9242         rm -f $TMP/${tfile}.tmp
9243 }
9244 run_test 127b "verify the llite client stats are sane"
9245
9246 test_128() { # bug 15212
9247         touch $DIR/$tfile
9248         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
9249                 find $DIR/$tfile
9250                 find $DIR/$tfile
9251         EOF
9252
9253         result=$(grep error $TMP/$tfile.log)
9254         rm -f $DIR/$tfile $TMP/$tfile.log
9255         [ -z "$result" ] ||
9256                 error "consecutive find's under interactive lfs failed"
9257 }
9258 run_test 128 "interactive lfs for 2 consecutive find's"
9259
9260 set_dir_limits () {
9261         local mntdev
9262         local canondev
9263         local node
9264
9265         local ldproc=/proc/fs/ldiskfs
9266         local facets=$(get_facets MDS)
9267
9268         for facet in ${facets//,/ }; do
9269                 canondev=$(ldiskfs_canon \
9270                            *.$(convert_facet2label $facet).mntdev $facet)
9271                 do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
9272                         ldproc=/sys/fs/ldiskfs
9273                 do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
9274                 do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
9275         done
9276 }
9277
9278 check_mds_dmesg() {
9279         local facets=$(get_facets MDS)
9280         for facet in ${facets//,/ }; do
9281                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
9282         done
9283         return 1
9284 }
9285
9286 test_129() {
9287         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.56) ]] ||
9288                 { skip "Need MDS version with at least 2.5.56"; return 0; }
9289
9290         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9291         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
9292                 skip "ldiskfs only test"
9293                 return
9294         fi
9295         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9296         local ENOSPC=28
9297         local EFBIG=27
9298         local has_warning=false
9299
9300         rm -rf $DIR/$tdir
9301         mkdir -p $DIR/$tdir
9302
9303         # block size of mds1
9304         local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
9305         set_dir_limits $maxsize $maxsize
9306         local dirsize=$(stat -c%s "$DIR/$tdir")
9307         local nfiles=0
9308         while [[ $dirsize -le $maxsize ]]; do
9309                 $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
9310                 rc=$?
9311                 if ! $has_warning; then
9312                         check_mds_dmesg '"is approaching"' && has_warning=true
9313                 fi
9314                 # check two errors:
9315                 # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
9316                 # EFBIG for previous versions included in ldiskfs series
9317                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
9318                         set_dir_limits 0 0
9319                         echo "return code $rc received as expected"
9320
9321                         createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
9322                                 error_exit "create failed w/o dir size limit"
9323
9324                         check_mds_dmesg '"has reached"' ||
9325                                 error_exit "reached message should be output"
9326
9327                         [ $has_warning -eq 0 ] &&
9328                                 error_exit "warning message should be output"
9329
9330                         dirsize=$(stat -c%s "$DIR/$tdir")
9331
9332                         [[ $dirsize -ge $maxsize ]] && return 0
9333                         error_exit "current dir size $dirsize, " \
9334                                    "previous limit $maxsize"
9335                 elif [ $rc -ne 0 ]; then
9336                         set_dir_limits 0 0
9337                         error_exit "return $rc received instead of expected " \
9338                                    "$EFBIG or $ENOSPC, files in dir $dirsize"
9339                 fi
9340                 nfiles=$((nfiles + 1))
9341                 dirsize=$(stat -c%s "$DIR/$tdir")
9342         done
9343
9344         set_dir_limits 0 0
9345         error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
9346 }
9347 run_test 129 "test directory size limit ========================"
9348
9349 OLDIFS="$IFS"
9350 cleanup_130() {
9351         trap 0
9352         IFS="$OLDIFS"
9353 }
9354
9355 test_130a() {
9356         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9357         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9358                 return
9359
9360         trap cleanup_130 EXIT RETURN
9361
9362         local fm_file=$DIR/$tfile
9363         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
9364         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
9365                 error "dd failed for $fm_file"
9366
9367         # LU-1795: test filefrag/FIEMAP once, even if unsupported
9368         filefrag -ves $fm_file
9369         RC=$?
9370         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9371                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9372         [ $RC != 0 ] && error "filefrag $fm_file failed"
9373
9374         filefrag_op=$(filefrag -ve $fm_file |
9375                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9376         lun=$($GETSTRIPE -i $fm_file)
9377
9378         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
9379         IFS=$'\n'
9380         tot_len=0
9381         for line in $filefrag_op
9382         do
9383                 frag_lun=`echo $line | cut -d: -f5`
9384                 ext_len=`echo $line | cut -d: -f4`
9385                 if (( $frag_lun != $lun )); then
9386                         cleanup_130
9387                         error "FIEMAP on 1-stripe file($fm_file) failed"
9388                         return
9389                 fi
9390                 (( tot_len += ext_len ))
9391         done
9392
9393         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
9394                 cleanup_130
9395                 error "FIEMAP on 1-stripe file($fm_file) failed;"
9396                 return
9397         fi
9398
9399         cleanup_130
9400
9401         echo "FIEMAP on single striped file succeeded"
9402 }
9403 run_test 130a "FIEMAP (1-stripe file)"
9404
9405 test_130b() {
9406         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
9407
9408         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9409         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9410                 return
9411
9412         trap cleanup_130 EXIT RETURN
9413
9414         local fm_file=$DIR/$tfile
9415         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9416                         error "setstripe on $fm_file"
9417         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9418                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9419
9420         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
9421                 error "dd failed on $fm_file"
9422
9423         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9424         filefrag_op=$(filefrag -ve $fm_file |
9425                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9426
9427         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9428                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9429
9430         IFS=$'\n'
9431         tot_len=0
9432         num_luns=1
9433         for line in $filefrag_op
9434         do
9435                 frag_lun=$(echo $line | cut -d: -f5 |
9436                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9437                 ext_len=$(echo $line | cut -d: -f4)
9438                 if (( $frag_lun != $last_lun )); then
9439                         if (( tot_len != 1024 )); then
9440                                 cleanup_130
9441                                 error "FIEMAP on $fm_file failed; returned " \
9442                                 "len $tot_len for OST $last_lun instead of 1024"
9443                                 return
9444                         else
9445                                 (( num_luns += 1 ))
9446                                 tot_len=0
9447                         fi
9448                 fi
9449                 (( tot_len += ext_len ))
9450                 last_lun=$frag_lun
9451         done
9452         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
9453                 cleanup_130
9454                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9455                         "luns or wrong len for OST $last_lun"
9456                 return
9457         fi
9458
9459         cleanup_130
9460
9461         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
9462 }
9463 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
9464
9465 test_130c() {
9466         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9467
9468         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9469         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9470                 return
9471
9472         trap cleanup_130 EXIT RETURN
9473
9474         local fm_file=$DIR/$tfile
9475         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
9476         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9477                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9478
9479         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
9480                         error "dd failed on $fm_file"
9481
9482         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9483         filefrag_op=$(filefrag -ve $fm_file |
9484                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9485
9486         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9487                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9488
9489         IFS=$'\n'
9490         tot_len=0
9491         num_luns=1
9492         for line in $filefrag_op
9493         do
9494                 frag_lun=$(echo $line | cut -d: -f5 |
9495                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9496                 ext_len=$(echo $line | cut -d: -f4)
9497                 if (( $frag_lun != $last_lun )); then
9498                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
9499                         if (( logical != 512 )); then
9500                                 cleanup_130
9501                                 error "FIEMAP on $fm_file failed; returned " \
9502                                 "logical start for lun $logical instead of 512"
9503                                 return
9504                         fi
9505                         if (( tot_len != 512 )); then
9506                                 cleanup_130
9507                                 error "FIEMAP on $fm_file failed; returned " \
9508                                 "len $tot_len for OST $last_lun instead of 1024"
9509                                 return
9510                         else
9511                                 (( num_luns += 1 ))
9512                                 tot_len=0
9513                         fi
9514                 fi
9515                 (( tot_len += ext_len ))
9516                 last_lun=$frag_lun
9517         done
9518         if (( num_luns != 2 || tot_len != 512 )); then
9519                 cleanup_130
9520                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9521                         "luns or wrong len for OST $last_lun"
9522                 return
9523         fi
9524
9525         cleanup_130
9526
9527         echo "FIEMAP on 2-stripe file with hole succeeded"
9528 }
9529 run_test 130c "FIEMAP (2-stripe file with hole)"
9530
9531 test_130d() {
9532         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
9533
9534         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9535         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9536                 return
9537
9538         trap cleanup_130 EXIT RETURN
9539
9540         local fm_file=$DIR/$tfile
9541         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9542                         error "setstripe on $fm_file"
9543         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9544                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9545
9546         local actual_stripe_count=$($GETSTRIPE -c $fm_file)
9547         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripe_count ||
9548                 error "dd failed on $fm_file"
9549
9550         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9551         filefrag_op=$(filefrag -ve $fm_file |
9552                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9553
9554         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9555                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9556
9557         IFS=$'\n'
9558         tot_len=0
9559         num_luns=1
9560         for line in $filefrag_op
9561         do
9562                 frag_lun=$(echo $line | cut -d: -f5 |
9563                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9564                 ext_len=$(echo $line | cut -d: -f4)
9565                 if (( $frag_lun != $last_lun )); then
9566                         if (( tot_len != 1024 )); then
9567                                 cleanup_130
9568                                 error "FIEMAP on $fm_file failed; returned " \
9569                                 "len $tot_len for OST $last_lun instead of 1024"
9570                                 return
9571                         else
9572                                 (( num_luns += 1 ))
9573                                 tot_len=0
9574                         fi
9575                 fi
9576                 (( tot_len += ext_len ))
9577                 last_lun=$frag_lun
9578         done
9579         if (( num_luns != actual_stripe_count || tot_len != 1024 )); then
9580                 cleanup_130
9581                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9582                         "luns or wrong len for OST $last_lun"
9583                 return
9584         fi
9585
9586         cleanup_130
9587
9588         echo "FIEMAP on N-stripe file succeeded"
9589 }
9590 run_test 130d "FIEMAP (N-stripe file)"
9591
9592 test_130e() {
9593         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9594
9595         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9596         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9597
9598         trap cleanup_130 EXIT RETURN
9599
9600         local fm_file=$DIR/$tfile
9601         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9602         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9603                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9604
9605         NUM_BLKS=512
9606         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9607         for ((i = 0; i < $NUM_BLKS; i++))
9608         do
9609                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9610         done
9611
9612         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9613         filefrag_op=$(filefrag -ve $fm_file |
9614                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9615
9616         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9617                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9618
9619         IFS=$'\n'
9620         tot_len=0
9621         num_luns=1
9622         for line in $filefrag_op
9623         do
9624                 frag_lun=$(echo $line | cut -d: -f5 |
9625                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9626                 ext_len=$(echo $line | cut -d: -f4)
9627                 if (( $frag_lun != $last_lun )); then
9628                         if (( tot_len != $EXPECTED_LEN )); then
9629                                 cleanup_130
9630                                 error "FIEMAP on $fm_file failed; returned " \
9631                                 "len $tot_len for OST $last_lun instead " \
9632                                 "of $EXPECTED_LEN"
9633                                 return
9634                         else
9635                                 (( num_luns += 1 ))
9636                                 tot_len=0
9637                         fi
9638                 fi
9639                 (( tot_len += ext_len ))
9640                 last_lun=$frag_lun
9641         done
9642         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9643                 cleanup_130
9644                 error "FIEMAP on $fm_file failed; returned wrong number " \
9645                         "of luns or wrong len for OST $last_lun"
9646                 return
9647         fi
9648
9649         cleanup_130
9650
9651         echo "FIEMAP with continuation calls succeeded"
9652 }
9653 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9654
9655 # Test for writev/readv
9656 test_131a() {
9657         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
9658                 error "writev test failed"
9659         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 ||
9660                 error "readv failed"
9661         rm -f $DIR/$tfile
9662 }
9663 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9664
9665 test_131b() {
9666         local fsize=$((524288 + 1048576 + 1572864))
9667         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 &&
9668                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9669                         error "append writev test failed"
9670
9671         ((fsize += 1572864 + 1048576))
9672         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 &&
9673                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9674                         error "append writev test failed"
9675         rm -f $DIR/$tfile
9676 }
9677 run_test 131b "test append writev"
9678
9679 test_131c() {
9680         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9681         error "NOT PASS"
9682 }
9683 run_test 131c "test read/write on file w/o objects"
9684
9685 test_131d() {
9686         rwv -f $DIR/$tfile -w -n 1 1572864
9687         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9688         if [ "$NOB" != 1572864 ]; then
9689                 error "Short read filed: read $NOB bytes instead of 1572864"
9690         fi
9691         rm -f $DIR/$tfile
9692 }
9693 run_test 131d "test short read"
9694
9695 test_131e() {
9696         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9697         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9698         error "read hitting hole failed"
9699         rm -f $DIR/$tfile
9700 }
9701 run_test 131e "test read hitting hole"
9702
9703 check_stats() {
9704         local facet=$1
9705         local op=$2
9706         local want=${3:-0}
9707         local res
9708
9709         case $facet in
9710         mds*) res=$(do_facet $facet \
9711                    $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
9712                  ;;
9713         ost*) res=$(do_facet $facet \
9714                    $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
9715                  ;;
9716         *) error "Wrong facet '$facet'" ;;
9717         esac
9718         echo $res
9719         [ "$res" ] || error "The counter for $op on $facet was not incremented"
9720         # if the argument $3 is zero, it means any stat increment is ok.
9721         if [[ $want -gt 0 ]]; then
9722                 local count=$(echo $res | awk '{ print $2 }')
9723                 [[ $count -ne $want ]] &&
9724                         error "The $op counter on $facet is $count, not $want"
9725         fi
9726 }
9727
9728 test_133a() {
9729         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9730         remote_ost_nodsh && skip "remote OST with nodsh" && return
9731         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9732
9733         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9734                 { skip "MDS doesn't support rename stats"; return; }
9735         local testdir=$DIR/${tdir}/stats_testdir
9736         mkdir -p $DIR/${tdir}
9737
9738         # clear stats.
9739         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9740         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9741
9742         # verify mdt stats first.
9743         mkdir ${testdir} || error "mkdir failed"
9744         check_stats $SINGLEMDS "mkdir" 1
9745         touch ${testdir}/${tfile} || error "touch failed"
9746         check_stats $SINGLEMDS "open" 1
9747         check_stats $SINGLEMDS "close" 1
9748         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ] && {
9749                 mknod ${testdir}/${tfile}-pipe p || error "mknod failed"
9750                 check_stats $SINGLEMDS "mknod" 2
9751         }
9752         rm -f ${testdir}/${tfile}-pipe || error "pipe remove failed"
9753         check_stats $SINGLEMDS "unlink" 1
9754         rm -f ${testdir}/${tfile} || error "file remove failed"
9755         check_stats $SINGLEMDS "unlink" 2
9756
9757         # remove working dir and check mdt stats again.
9758         rmdir ${testdir} || error "rmdir failed"
9759         check_stats $SINGLEMDS "rmdir" 1
9760
9761         local testdir1=$DIR/${tdir}/stats_testdir1
9762         mkdir -p ${testdir}
9763         mkdir -p ${testdir1}
9764         touch ${testdir1}/test1
9765         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9766         check_stats $SINGLEMDS "crossdir_rename" 1
9767
9768         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9769         check_stats $SINGLEMDS "samedir_rename" 1
9770
9771         rm -rf $DIR/${tdir}
9772 }
9773 run_test 133a "Verifying MDT stats ========================================"
9774
9775 test_133b() {
9776         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9777         remote_ost_nodsh && skip "remote OST with nodsh" && return
9778         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9779         local testdir=$DIR/${tdir}/stats_testdir
9780         mkdir -p ${testdir} || error "mkdir failed"
9781         touch ${testdir}/${tfile} || error "touch failed"
9782         cancel_lru_locks mdc
9783
9784         # clear stats.
9785         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9786         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9787
9788         # extra mdt stats verification.
9789         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9790         check_stats $SINGLEMDS "setattr" 1
9791         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9792         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9793         then            # LU-1740
9794                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9795                 check_stats $SINGLEMDS "getattr" 1
9796         fi
9797         $LFS df || error "lfs failed"
9798         check_stats $SINGLEMDS "statfs" 1
9799
9800         rm -rf $DIR/${tdir}
9801 }
9802 run_test 133b "Verifying extra MDT stats =================================="
9803
9804 test_133c() {
9805         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9806         remote_ost_nodsh && skip "remote OST with nodsh" && return
9807         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9808         local testdir=$DIR/$tdir/stats_testdir
9809         test_mkdir -p $testdir
9810
9811         # verify obdfilter stats.
9812         $SETSTRIPE -c 1 -i 0 $testdir/$tfile
9813         sync
9814         cancel_lru_locks osc
9815         wait_delete_completed
9816
9817         # clear stats.
9818         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9819         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9820
9821         dd if=/dev/zero of=$testdir/$tfile conv=notrunc bs=512k count=1 ||
9822                 error "dd failed"
9823         sync
9824         cancel_lru_locks osc
9825         check_stats ost1 "write" 1
9826
9827         dd if=$testdir/$tfile of=/dev/null bs=1k count=1 || error "dd failed"
9828         check_stats ost1 "read" 1
9829
9830         > $testdir/$tfile || error "truncate failed"
9831         check_stats ost1 "punch" 1
9832
9833         rm -f $testdir/$tfile || error "file remove failed"
9834         wait_delete_completed
9835         check_stats ost1 "destroy" 1
9836
9837         rm -rf $DIR/$tdir
9838 }
9839 run_test 133c "Verifying OST stats ========================================"
9840
9841 order_2() {
9842         local value=$1
9843         local orig=$value
9844         local order=1
9845
9846         while [ $value -ge 2 ]; do
9847                 order=$((order*2))
9848                 value=$((value/2))
9849         done
9850
9851         if [ $orig -gt $order ]; then
9852                 order=$((order*2))
9853         fi
9854         echo $order
9855 }
9856
9857 size_in_KMGT() {
9858     local value=$1
9859     local size=('K' 'M' 'G' 'T');
9860     local i=0
9861     local size_string=$value
9862
9863     while [ $value -ge 1024 ]; do
9864         if [ $i -gt 3 ]; then
9865             #T is the biggest unit we get here, if that is bigger,
9866             #just return XXXT
9867             size_string=${value}T
9868             break
9869         fi
9870         value=$((value >> 10))
9871         if [ $value -lt 1024 ]; then
9872             size_string=${value}${size[$i]}
9873             break
9874         fi
9875         i=$((i + 1))
9876     done
9877
9878     echo $size_string
9879 }
9880
9881 get_rename_size() {
9882     local size=$1
9883     local context=${2:-.}
9884     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9885                 grep -A1 $context |
9886                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9887     echo $sample
9888 }
9889
9890 test_133d() {
9891         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9892         remote_ost_nodsh && skip "remote OST with nodsh" && return
9893         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9894         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9895         { skip "MDS doesn't support rename stats"; return; }
9896
9897         local testdir1=$DIR/${tdir}/stats_testdir1
9898         local testdir2=$DIR/${tdir}/stats_testdir2
9899
9900         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9901
9902         mkdir -p ${testdir1} || error "mkdir failed"
9903         mkdir -p ${testdir2} || error "mkdir failed"
9904
9905         createmany -o $testdir1/test 512 || error "createmany failed"
9906
9907         # check samedir rename size
9908         mv ${testdir1}/test0 ${testdir1}/test_0
9909
9910         local testdir1_size=$(ls -l $DIR/${tdir} |
9911                 awk '/stats_testdir1/ {print $5}')
9912         local testdir2_size=$(ls -l $DIR/${tdir} |
9913                 awk '/stats_testdir2/ {print $5}')
9914
9915         testdir1_size=$(order_2 $testdir1_size)
9916         testdir2_size=$(order_2 $testdir2_size)
9917
9918         testdir1_size=$(size_in_KMGT $testdir1_size)
9919         testdir2_size=$(size_in_KMGT $testdir2_size)
9920
9921         echo "source rename dir size: ${testdir1_size}"
9922         echo "target rename dir size: ${testdir2_size}"
9923
9924         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9925         eval $cmd || error "$cmd failed"
9926         local samedir=$($cmd | grep 'same_dir')
9927         local same_sample=$(get_rename_size $testdir1_size)
9928         [ -z "$samedir" ] && error "samedir_rename_size count error"
9929         [[ $same_sample -eq 1 ]] ||
9930                 error "samedir_rename_size error $same_sample"
9931         echo "Check same dir rename stats success"
9932
9933         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9934
9935         # check crossdir rename size
9936         mv ${testdir1}/test_0 ${testdir2}/test_0
9937
9938         testdir1_size=$(ls -l $DIR/${tdir} |
9939                 awk '/stats_testdir1/ {print $5}')
9940         testdir2_size=$(ls -l $DIR/${tdir} |
9941                 awk '/stats_testdir2/ {print $5}')
9942
9943         testdir1_size=$(order_2 $testdir1_size)
9944         testdir2_size=$(order_2 $testdir2_size)
9945
9946         testdir1_size=$(size_in_KMGT $testdir1_size)
9947         testdir2_size=$(size_in_KMGT $testdir2_size)
9948
9949         echo "source rename dir size: ${testdir1_size}"
9950         echo "target rename dir size: ${testdir2_size}"
9951
9952         eval $cmd || error "$cmd failed"
9953         local crossdir=$($cmd | grep 'crossdir')
9954         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9955         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9956         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9957         [[ $src_sample -eq 1 ]] ||
9958                 error "crossdir_rename_size error $src_sample"
9959         [[ $tgt_sample -eq 1 ]] ||
9960                 error "crossdir_rename_size error $tgt_sample"
9961         echo "Check cross dir rename stats success"
9962         rm -rf $DIR/${tdir}
9963 }
9964 run_test 133d "Verifying rename_stats ========================================"
9965
9966 test_133e() {
9967         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9968         remote_ost_nodsh && skip "remote OST with nodsh" && return
9969         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9970         local testdir=$DIR/${tdir}/stats_testdir
9971         local ctr f0 f1 bs=32768 count=42 sum
9972
9973         mkdir -p ${testdir} || error "mkdir failed"
9974
9975         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9976
9977         for ctr in {write,read}_bytes; do
9978                 sync
9979                 cancel_lru_locks osc
9980
9981                 do_facet ost1 $LCTL set_param -n \
9982                         "obdfilter.*.exports.clear=clear"
9983
9984                 if [ $ctr = write_bytes ]; then
9985                         f0=/dev/zero
9986                         f1=${testdir}/${tfile}
9987                 else
9988                         f0=${testdir}/${tfile}
9989                         f1=/dev/null
9990                 fi
9991
9992                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9993                         error "dd failed"
9994                 sync
9995                 cancel_lru_locks osc
9996
9997                 sum=$(do_facet ost1 $LCTL get_param \
9998                         "obdfilter.*.exports.*.stats" |
9999                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
10000                                 $1 == ctr { sum += $7 }
10001                                 END { printf("%0.0f", sum) }')
10002
10003                 if ((sum != bs * count)); then
10004                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
10005                 fi
10006         done
10007
10008         rm -rf $DIR/${tdir}
10009 }
10010 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
10011
10012 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
10013
10014 test_133f() {
10015         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10016         remote_ost_nodsh && skip "remote OST with nodsh" && return
10017         # First without trusting modes.
10018         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
10019         echo "proc_dirs='$proc_dirs'"
10020         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
10021         find $proc_dirs -exec cat '{}' \; &> /dev/null
10022
10023         # Second verifying readability.
10024         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
10025
10026         # eventually, this can also be replaced with "lctl get_param -R",
10027         # but not until that option is always available on the server
10028         local facet
10029         for facet in mds1 ost1; do
10030                 local facet_proc_dirs=$(do_facet $facet \
10031                                         \\\ls -d $proc_regexp 2>/dev/null)
10032                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10033                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10034                 do_facet $facet find $facet_proc_dirs \
10035                         ! -name req_history \
10036                         -exec cat '{}' \\\; &> /dev/null
10037
10038                 do_facet $facet find $facet_proc_dirs \
10039                         ! -name req_history \
10040                         -type f \
10041                         -exec cat '{}' \\\; &> /dev/null ||
10042                                 error "proc file read failed"
10043         done
10044 }
10045 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
10046
10047 test_133g() {
10048         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10049         remote_ost_nodsh && skip "remote OST with nodsh" && return
10050         # Second verifying writability.
10051         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
10052         echo "proc_dirs='$proc_dirs'"
10053         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
10054         find $proc_dirs \
10055                 -type f \
10056                 -not -name force_lbug \
10057                 -not -name changelog_mask \
10058                 -exec badarea_io '{}' \; &> /dev/null ||
10059                 error "find $proc_dirs failed"
10060
10061         local facet
10062         for facet in mds1 ost1; do
10063                 [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
10064                         skip "Too old lustre on $facet" && continue
10065                 local facet_proc_dirs=$(do_facet $facet \
10066                                         \\\ls -d $proc_regexp 2> /dev/null)
10067                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10068                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10069                 do_facet $facet find $facet_proc_dirs \
10070                         -type f \
10071                         -not -name force_lbug \
10072                         -not -name changelog_mask \
10073                         -exec badarea_io '{}' \\\; &> /dev/null ||
10074                                 error "$facet find $facet_proc_dirs failed"
10075         done
10076
10077         # remount the FS in case writes/reads /proc break the FS
10078         cleanup || error "failed to unmount"
10079         setup || error "failed to setup"
10080         true
10081 }
10082 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
10083
10084 test_133h() {
10085         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10086         remote_ost_nodsh && skip "remote OST with nodsh" && return
10087         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.54) ]] &&
10088                 skip "Need MDS version at least 2.9.54" && return
10089
10090         local facet
10091         for facet in client mds1 ost1; do
10092                 local facet_proc_dirs=$(do_facet $facet \
10093                                         \\\ls -d $proc_regexp 2> /dev/null)
10094                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10095                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10096                 # Get the list of files that are missing the terminating newline
10097                 local missing=($(do_facet $facet \
10098                         find ${facet_proc_dirs} -type f \|              \
10099                                 while read F\; do                       \
10100                                         awk -v FS='\v' -v RS='\v\v'     \
10101                                         "'END { if(NR>0 &&              \
10102                                         \\\$NF !~ /.*\\\n\$/)           \
10103                                                 print FILENAME}'"       \
10104                                         '\$F'\;                         \
10105                                 done 2>/dev/null))
10106                 [ ${#missing[*]} -eq 0 ] ||
10107                         error "files do not end with newline: ${missing[*]}"
10108         done
10109 }
10110 run_test 133h "Proc files should end with newlines"
10111
10112 test_134a() {
10113         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10114         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10115                 skip "Need MDS version at least 2.7.54" && return
10116
10117         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10118         cancel_lru_locks mdc
10119
10120         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
10121         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10122         [ $unused -eq 0 ] || error "$unused locks are not cleared"
10123
10124         local nr=1000
10125         createmany -o $DIR/$tdir/f $nr ||
10126                 error "failed to create $nr files in $DIR/$tdir"
10127         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10128
10129         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
10130         do_facet mds1 $LCTL set_param fail_loc=0x327
10131         do_facet mds1 $LCTL set_param fail_val=500
10132         touch $DIR/$tdir/m
10133
10134         echo "sleep 10 seconds ..."
10135         sleep 10
10136         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
10137
10138         do_facet mds1 $LCTL set_param fail_loc=0
10139         do_facet mds1 $LCTL set_param fail_val=0
10140         [ $lck_cnt -lt $unused ] ||
10141                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
10142
10143         rm $DIR/$tdir/m
10144         unlinkmany $DIR/$tdir/f $nr
10145 }
10146 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
10147
10148 test_134b() {
10149         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10150         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10151                 skip "Need MDS version at least 2.7.54" && return
10152
10153         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10154         cancel_lru_locks mdc
10155
10156         local low_wm=$(do_facet mds1 $LCTL get_param -n \
10157                         ldlm.lock_reclaim_threshold_mb)
10158         # disable reclaim temporarily
10159         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
10160
10161         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
10162         do_facet mds1 $LCTL set_param fail_loc=0x328
10163         do_facet mds1 $LCTL set_param fail_val=500
10164
10165         $LCTL set_param debug=+trace
10166
10167         local nr=600
10168         createmany -o $DIR/$tdir/f $nr &
10169         local create_pid=$!
10170
10171         echo "Sleep $TIMEOUT seconds ..."
10172         sleep $TIMEOUT
10173         if ! ps -p $create_pid  > /dev/null 2>&1; then
10174                 do_facet mds1 $LCTL set_param fail_loc=0
10175                 do_facet mds1 $LCTL set_param fail_val=0
10176                 do_facet mds1 $LCTL set_param \
10177                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
10178                 error "createmany finished incorrectly!"
10179         fi
10180         do_facet mds1 $LCTL set_param fail_loc=0
10181         do_facet mds1 $LCTL set_param fail_val=0
10182         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
10183         wait $create_pid || return 1
10184
10185         unlinkmany $DIR/$tdir/f $nr
10186 }
10187 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
10188
10189 test_140() { #bug-17379
10190         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10191         test_mkdir $DIR/$tdir
10192         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
10193         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
10194
10195         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
10196         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
10197         local i=0
10198         while i=$((i + 1)); do
10199                 test_mkdir $i
10200                 cd $i || error "Changing to $i"
10201                 ln -s ../stat stat || error "Creating stat symlink"
10202                 # Read the symlink until ELOOP present,
10203                 # not LBUGing the system is considered success,
10204                 # we didn't overrun the stack.
10205                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
10206                 if [ $ret -ne 0 ]; then
10207                         if [ $ret -eq 40 ]; then
10208                                 break  # -ELOOP
10209                         else
10210                                 error "Open stat symlink"
10211                                         return
10212                         fi
10213                 fi
10214         done
10215         i=$((i - 1))
10216         echo "The symlink depth = $i"
10217         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
10218                                         error "Invalid symlink depth"
10219
10220         # Test recursive symlink
10221         ln -s symlink_self symlink_self
10222         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
10223         echo "open symlink_self returns $ret"
10224         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
10225 }
10226 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
10227
10228 test_150() {
10229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10230         local TF="$TMP/$tfile"
10231
10232         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10233         cp $TF $DIR/$tfile
10234         cancel_lru_locks $OSC
10235         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
10236         remount_client $MOUNT
10237         df -P $MOUNT
10238         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
10239
10240         $TRUNCATE $TF 6000
10241         $TRUNCATE $DIR/$tfile 6000
10242         cancel_lru_locks $OSC
10243         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
10244
10245         echo "12345" >>$TF
10246         echo "12345" >>$DIR/$tfile
10247         cancel_lru_locks $OSC
10248         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
10249
10250         echo "12345" >>$TF
10251         echo "12345" >>$DIR/$tfile
10252         cancel_lru_locks $OSC
10253         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
10254
10255         rm -f $TF
10256         true
10257 }
10258 run_test 150 "truncate/append tests"
10259
10260 #LU-2902 roc_hit was not able to read all values from lproc
10261 function roc_hit_init() {
10262         local list=$(comma_list $(osts_nodes))
10263         local dir=$DIR/$tdir-check
10264         local file=$dir/$tfile
10265         local BEFORE
10266         local AFTER
10267         local idx
10268
10269         test_mkdir $dir
10270         #use setstripe to do a write to every ost
10271         for i in $(seq 0 $((OSTCOUNT-1))); do
10272                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
10273                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
10274                 idx=$(printf %04x $i)
10275                 BEFORE=$(get_osd_param $list *OST*$idx stats |
10276                         awk '$1 == "cache_access" {sum += $7}
10277                                 END { printf("%0.0f", sum) }')
10278
10279                 cancel_lru_locks osc
10280                 cat $file >/dev/null
10281
10282                 AFTER=$(get_osd_param $list *OST*$idx stats |
10283                         awk '$1 == "cache_access" {sum += $7}
10284                                 END { printf("%0.0f", sum) }')
10285
10286                 echo BEFORE:$BEFORE AFTER:$AFTER
10287                 if ! let "AFTER - BEFORE == 4"; then
10288                         rm -rf $dir
10289                         error "roc_hit is not safe to use"
10290                 fi
10291                 rm $file
10292         done
10293
10294         rm -rf $dir
10295 }
10296
10297 function roc_hit() {
10298         local list=$(comma_list $(osts_nodes))
10299         echo $(get_osd_param $list '' stats |
10300                 awk '$1 == "cache_hit" {sum += $7}
10301                         END { printf("%0.0f", sum) }')
10302 }
10303
10304 function set_cache() {
10305         local on=1
10306
10307         if [ "$2" == "off" ]; then
10308                 on=0;
10309         fi
10310         local list=$(comma_list $(osts_nodes))
10311         set_osd_param $list '' $1_cache_enable $on
10312
10313         cancel_lru_locks osc
10314 }
10315
10316 test_151() {
10317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10318         remote_ost_nodsh && skip "remote OST with nodsh" && return
10319
10320         local CPAGES=3
10321         local list=$(comma_list $(osts_nodes))
10322
10323         # check whether obdfilter is cache capable at all
10324         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
10325                 echo "not cache-capable obdfilter"
10326                 return 0
10327         fi
10328
10329         # check cache is enabled on all obdfilters
10330         if get_osd_param $list '' read_cache_enable | grep 0; then
10331                 echo "oss cache is disabled"
10332                 return 0
10333         fi
10334
10335         set_osd_param $list '' writethrough_cache_enable 1
10336
10337         # check write cache is enabled on all obdfilters
10338         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
10339                 echo "oss write cache is NOT enabled"
10340                 return 0
10341         fi
10342
10343         roc_hit_init
10344
10345         #define OBD_FAIL_OBD_NO_LRU  0x609
10346         do_nodes $list $LCTL set_param fail_loc=0x609
10347
10348         # pages should be in the case right after write
10349         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
10350                 error "dd failed"
10351
10352         local BEFORE=$(roc_hit)
10353         cancel_lru_locks osc
10354         cat $DIR/$tfile >/dev/null
10355         local AFTER=$(roc_hit)
10356
10357         do_nodes $list $LCTL set_param fail_loc=0
10358
10359         if ! let "AFTER - BEFORE == CPAGES"; then
10360                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10361         fi
10362
10363         # the following read invalidates the cache
10364         cancel_lru_locks osc
10365         set_osd_param $list '' read_cache_enable 0
10366         cat $DIR/$tfile >/dev/null
10367
10368         # now data shouldn't be found in the cache
10369         BEFORE=$(roc_hit)
10370         cancel_lru_locks osc
10371         cat $DIR/$tfile >/dev/null
10372         AFTER=$(roc_hit)
10373         if let "AFTER - BEFORE != 0"; then
10374                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10375         fi
10376
10377         set_osd_param $list '' read_cache_enable 1
10378         rm -f $DIR/$tfile
10379 }
10380 run_test 151 "test cache on oss and controls ==============================="
10381
10382 test_152() {
10383         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10384         local TF="$TMP/$tfile"
10385
10386         # simulate ENOMEM during write
10387 #define OBD_FAIL_OST_NOMEM      0x226
10388         lctl set_param fail_loc=0x80000226
10389         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10390         cp $TF $DIR/$tfile
10391         sync || error "sync failed"
10392         lctl set_param fail_loc=0
10393
10394         # discard client's cache
10395         cancel_lru_locks osc
10396
10397         # simulate ENOMEM during read
10398         lctl set_param fail_loc=0x80000226
10399         cmp $TF $DIR/$tfile || error "cmp failed"
10400         lctl set_param fail_loc=0
10401
10402         rm -f $TF
10403 }
10404 run_test 152 "test read/write with enomem ============================"
10405
10406 test_153() {
10407         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
10408 }
10409 run_test 153 "test if fdatasync does not crash ======================="
10410
10411 dot_lustre_fid_permission_check() {
10412         local fid=$1
10413         local ffid=$MOUNT/.lustre/fid/$fid
10414         local test_dir=$2
10415
10416         echo "stat fid $fid"
10417         stat $ffid > /dev/null || error "stat $ffid failed."
10418         echo "touch fid $fid"
10419         touch $ffid || error "touch $ffid failed."
10420         echo "write to fid $fid"
10421         cat /etc/hosts > $ffid || error "write $ffid failed."
10422         echo "read fid $fid"
10423         diff /etc/hosts $ffid || error "read $ffid failed."
10424         echo "append write to fid $fid"
10425         cat /etc/hosts >> $ffid || error "append write $ffid failed."
10426         echo "rename fid $fid"
10427         mv $ffid $test_dir/$tfile.1 &&
10428                 error "rename $ffid to $tfile.1 should fail."
10429         touch $test_dir/$tfile.1
10430         mv $test_dir/$tfile.1 $ffid &&
10431                 error "rename $tfile.1 to $ffid should fail."
10432         rm -f $test_dir/$tfile.1
10433         echo "truncate fid $fid"
10434         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
10435         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
10436                 echo "link fid $fid"
10437                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
10438         fi
10439         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
10440                 echo "setfacl fid $fid"
10441                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
10442                 echo "getfacl fid $fid"
10443                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
10444         fi
10445         echo "unlink fid $fid"
10446         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
10447         echo "mknod fid $fid"
10448         mknod $ffid c 1 3 && error "mknod $ffid should fail."
10449
10450         fid=[0xf00000400:0x1:0x0]
10451         ffid=$MOUNT/.lustre/fid/$fid
10452
10453         echo "stat non-exist fid $fid"
10454         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
10455         echo "write to non-exist fid $fid"
10456         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
10457         echo "link new fid $fid"
10458         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
10459
10460         mkdir -p $test_dir/$tdir
10461         touch $test_dir/$tdir/$tfile
10462         fid=$($LFS path2fid $test_dir/$tdir)
10463         rc=$?
10464         [ $rc -ne 0 ] &&
10465                 error "error: could not get fid for $test_dir/$dir/$tfile."
10466
10467         ffid=$MOUNT/.lustre/fid/$fid
10468
10469         echo "ls $fid"
10470         ls $ffid > /dev/null || error "ls $ffid failed."
10471         echo "touch $fid/$tfile.1"
10472         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
10473
10474         echo "touch $MOUNT/.lustre/fid/$tfile"
10475         touch $MOUNT/.lustre/fid/$tfile && \
10476                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
10477
10478         echo "setxattr to $MOUNT/.lustre/fid"
10479         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
10480
10481         echo "listxattr for $MOUNT/.lustre/fid"
10482         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
10483
10484         echo "delxattr from $MOUNT/.lustre/fid"
10485         setfattr -x trusted.name1 $MOUNT/.lustre/fid
10486
10487         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
10488         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
10489                 error "touch invalid fid should fail."
10490
10491         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
10492         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
10493                 error "touch non-normal fid should fail."
10494
10495         echo "rename $tdir to $MOUNT/.lustre/fid"
10496         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
10497                 error "rename to $MOUNT/.lustre/fid should fail."
10498
10499         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
10500         then            # LU-3547
10501                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
10502                 local new_obf_mode=777
10503
10504                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
10505                 chmod $new_obf_mode $DIR/.lustre/fid ||
10506                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
10507
10508                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
10509                 [ $obf_mode -eq $new_obf_mode ] ||
10510                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
10511
10512                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
10513                 chmod $old_obf_mode $DIR/.lustre/fid ||
10514                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
10515         fi
10516
10517         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
10518         fid=$($LFS path2fid $test_dir/$tfile-2)
10519
10520         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
10521         then # LU-5424
10522                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
10523                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
10524                         error "create lov data thru .lustre failed"
10525         fi
10526         echo "cp /etc/passwd $test_dir/$tfile-2"
10527         cp /etc/passwd $test_dir/$tfile-2 ||
10528                 error "copy to $test_dir/$tfile-2 failed."
10529         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
10530         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
10531                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
10532
10533         rm -rf $test_dir/tfile.lnk
10534         rm -rf $test_dir/$tfile-2
10535 }
10536
10537 test_154A() {
10538         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10539                 skip "Need MDS version at least 2.4.1" && return
10540
10541         local tf=$DIR/$tfile
10542         touch $tf
10543
10544         local fid=$($LFS path2fid $tf)
10545         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
10546
10547         # check that we get the same pathname back
10548         local found=$($LFS fid2path $MOUNT "$fid")
10549         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
10550         [ "$found" == "$tf" ] ||
10551                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
10552 }
10553 run_test 154A "lfs path2fid and fid2path basic checks"
10554
10555 test_154B() {
10556         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10557                 skip "Need MDS version at least 2.4.1" && return
10558
10559         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
10560         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
10561         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
10562         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
10563
10564         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
10565         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
10566
10567         # check that we get the same pathname
10568         echo "PFID: $PFID, name: $name"
10569         local FOUND=$($LFS fid2path $MOUNT "$PFID")
10570         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
10571         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
10572                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
10573
10574         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
10575 }
10576 run_test 154B "verify the ll_decode_linkea tool"
10577
10578 test_154a() {
10579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10580         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10581                 { skip "Need MDS version at least 2.2.51"; return 0; }
10582         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
10583         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10584
10585         cp /etc/hosts $DIR/$tfile
10586
10587         fid=$($LFS path2fid $DIR/$tfile)
10588         rc=$?
10589         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
10590
10591         dot_lustre_fid_permission_check "$fid" $DIR ||
10592                 error "dot lustre permission check $fid failed"
10593
10594         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
10595
10596         touch $MOUNT/.lustre/file &&
10597                 error "creation is not allowed under .lustre"
10598
10599         mkdir $MOUNT/.lustre/dir &&
10600                 error "mkdir is not allowed under .lustre"
10601
10602         rm -rf $DIR/$tfile
10603 }
10604 run_test 154a "Open-by-FID"
10605
10606 test_154b() {
10607         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10608         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10609                 { skip "Need MDS version at least 2.2.51"; return 0; }
10610         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10611
10612         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10613
10614         local remote_dir=$DIR/$tdir/remote_dir
10615         local MDTIDX=1
10616         local rc=0
10617
10618         mkdir -p $DIR/$tdir
10619         $LFS mkdir -i $MDTIDX $remote_dir ||
10620                 error "create remote directory failed"
10621
10622         cp /etc/hosts $remote_dir/$tfile
10623
10624         fid=$($LFS path2fid $remote_dir/$tfile)
10625         rc=$?
10626         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
10627
10628         dot_lustre_fid_permission_check "$fid" $remote_dir ||
10629                 error "dot lustre permission check $fid failed"
10630         rm -rf $DIR/$tdir
10631 }
10632 run_test 154b "Open-by-FID for remote directory"
10633
10634 test_154c() {
10635         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10636                 skip "Need MDS version at least 2.4.1" && return
10637
10638         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
10639         local FID1=$($LFS path2fid $DIR/$tfile.1)
10640         local FID2=$($LFS path2fid $DIR/$tfile.2)
10641         local FID3=$($LFS path2fid $DIR/$tfile.3)
10642
10643         local N=1
10644         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
10645                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
10646                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
10647                 local want=FID$N
10648                 [ "$FID" = "${!want}" ] ||
10649                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
10650                 N=$((N + 1))
10651         done
10652
10653         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10654         do
10655                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10656                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10657                 N=$((N + 1))
10658         done
10659 }
10660 run_test 154c "lfs path2fid and fid2path multiple arguments"
10661
10662 test_154d() {
10663         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10664         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10665                 skip "Need MDS version at least 2.5.53" && return
10666
10667         if remote_mds; then
10668                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10669         else
10670                 nid="0@lo"
10671         fi
10672         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10673         local fd
10674         local cmd
10675
10676         rm -f $DIR/$tfile
10677         touch $DIR/$tfile
10678
10679         local fid=$($LFS path2fid $DIR/$tfile)
10680         # Open the file
10681         fd=$(free_fd)
10682         cmd="exec $fd<$DIR/$tfile"
10683         eval $cmd
10684         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10685         echo "$fid_list" | grep "$fid"
10686         rc=$?
10687
10688         cmd="exec $fd>/dev/null"
10689         eval $cmd
10690         if [ $rc -ne 0 ]; then
10691                 error "FID $fid not found in open files list $fid_list"
10692         fi
10693 }
10694 run_test 154d "Verify open file fid"
10695
10696 test_154e()
10697 {
10698         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10699                 skip "Need MDS version at least 2.6.50" && return
10700
10701         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10702                 error ".lustre returned by readdir"
10703         fi
10704 }
10705 run_test 154e ".lustre is not returned by readdir"
10706
10707 test_154f() {
10708         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10709         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10710         test_mkdir -p -c1 $DIR/$tdir/d
10711         # test dirs inherit from its stripe
10712         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10713         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10714         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10715         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10716         touch $DIR/f
10717
10718         # get fid of parents
10719         local FID0=$($LFS path2fid $DIR/$tdir/d)
10720         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10721         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10722         local FID3=$($LFS path2fid $DIR)
10723
10724         # check that path2fid --parents returns expected <parent_fid>/name
10725         # 1) test for a directory (single parent)
10726         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
10727         [ "$parent" == "$FID0/foo1" ] ||
10728                 error "expected parent: $FID0/foo1, got: $parent"
10729
10730         # 2) test for a file with nlink > 1 (multiple parents)
10731         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
10732         echo "$parent" | grep -F "$FID1/$tfile" ||
10733                 error "$FID1/$tfile not returned in parent list"
10734         echo "$parent" | grep -F "$FID2/link" ||
10735                 error "$FID2/link not returned in parent list"
10736
10737         # 3) get parent by fid
10738         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
10739         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10740         echo "$parent" | grep -F "$FID1/$tfile" ||
10741                 error "$FID1/$tfile not returned in parent list (by fid)"
10742         echo "$parent" | grep -F "$FID2/link" ||
10743                 error "$FID2/link not returned in parent list (by fid)"
10744
10745         # 4) test for entry in root directory
10746         parent=$($LFS path2fid --parents $DIR/f)
10747         echo "$parent" | grep -F "$FID3/f" ||
10748                 error "$FID3/f not returned in parent list"
10749
10750         # 5) test it on root directory
10751         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
10752                 error "$MOUNT should not have parents"
10753
10754         # enable xattr caching and check that linkea is correctly updated
10755         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10756         save_lustre_params client "llite.*.xattr_cache" > $save
10757         lctl set_param llite.*.xattr_cache 1
10758
10759         # 6.1) linkea update on rename
10760         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
10761
10762         # get parents by fid
10763         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10764         # foo1 should no longer be returned in parent list
10765         echo "$parent" | grep -F "$FID1" &&
10766                 error "$FID1 should no longer be in parent list"
10767         # the new path should appear
10768         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
10769                 error "$FID2/$tfile.moved is not in parent list"
10770
10771         # 6.2) linkea update on unlink
10772         rm -f $DIR/$tdir/d/foo2/link
10773         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10774         # foo2/link should no longer be returned in parent list
10775         echo "$parent" | grep -F "$FID2/link" &&
10776                 error "$FID2/link should no longer be in parent list"
10777         true
10778
10779         rm -f $DIR/f
10780         restore_lustre_params < $save
10781         rm -f $save
10782 }
10783 run_test 154f "get parent fids by reading link ea"
10784
10785 test_154g()
10786 {
10787         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) && \
10788            $(lustre_version_code client) -gt $(version_code 2.6.99) ]] ||
10789                 { skip "Need MDS version at least 2.6.92"; return 0; }
10790         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10791
10792         mkdir -p $DIR/$tdir
10793         llapi_fid_test -d $DIR/$tdir
10794 }
10795 run_test 154g "various llapi FID tests"
10796
10797 test_155_small_load() {
10798     local temp=$TMP/$tfile
10799     local file=$DIR/$tfile
10800
10801     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
10802         error "dd of=$temp bs=6096 count=1 failed"
10803     cp $temp $file
10804     cancel_lru_locks $OSC
10805     cmp $temp $file || error "$temp $file differ"
10806
10807     $TRUNCATE $temp 6000
10808     $TRUNCATE $file 6000
10809     cmp $temp $file || error "$temp $file differ (truncate1)"
10810
10811     echo "12345" >>$temp
10812     echo "12345" >>$file
10813     cmp $temp $file || error "$temp $file differ (append1)"
10814
10815     echo "12345" >>$temp
10816     echo "12345" >>$file
10817     cmp $temp $file || error "$temp $file differ (append2)"
10818
10819     rm -f $temp $file
10820     true
10821 }
10822
10823 test_155_big_load() {
10824     remote_ost_nodsh && skip "remote OST with nodsh" && return
10825     local temp=$TMP/$tfile
10826     local file=$DIR/$tfile
10827
10828     free_min_max
10829     local cache_size=$(do_facet ost$((MAXI+1)) \
10830         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
10831     local large_file_size=$((cache_size * 2))
10832
10833     echo "OSS cache size: $cache_size KB"
10834     echo "Large file size: $large_file_size KB"
10835
10836     [ $MAXV -le $large_file_size ] && \
10837         skip_env "max available OST size needs > $large_file_size KB" && \
10838         return 0
10839
10840     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
10841
10842     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
10843         error "dd of=$temp bs=$large_file_size count=1k failed"
10844     cp $temp $file
10845     ls -lh $temp $file
10846     cancel_lru_locks osc
10847     cmp $temp $file || error "$temp $file differ"
10848
10849     rm -f $temp $file
10850     true
10851 }
10852
10853 save_writethrough() {
10854         local facets=$(get_facets OST)
10855
10856         save_lustre_params $facets "obdfilter.*.writethrough_cache_enable" > $1
10857         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" >> $1
10858 }
10859
10860 test_155a() {
10861         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10862         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10863         save_writethrough $p
10864
10865         set_cache read on
10866         set_cache writethrough on
10867         test_155_small_load
10868         restore_lustre_params < $p
10869         rm -f $p
10870 }
10871 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10872
10873 test_155b() {
10874         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10875         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10876         save_writethrough $p
10877
10878         set_cache read on
10879         set_cache writethrough off
10880         test_155_small_load
10881         restore_lustre_params < $p
10882         rm -f $p
10883 }
10884 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10885
10886 test_155c() {
10887         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10888         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10889         save_writethrough $p
10890
10891         set_cache read off
10892         set_cache writethrough on
10893         test_155_small_load
10894         restore_lustre_params < $p
10895         rm -f $p
10896 }
10897 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10898
10899 test_155d() {
10900         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10901         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10902         save_writethrough $p
10903
10904         set_cache read off
10905         set_cache writethrough off
10906         test_155_small_load
10907         restore_lustre_params < $p
10908         rm -f $p
10909 }
10910 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10911
10912 test_155e() {
10913         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10914         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10915         save_writethrough $p
10916
10917         set_cache read on
10918         set_cache writethrough on
10919         test_155_big_load
10920         restore_lustre_params < $p
10921         rm -f $p
10922 }
10923 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10924
10925 test_155f() {
10926         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10927         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10928         save_writethrough $p
10929
10930         set_cache read on
10931         set_cache writethrough off
10932         test_155_big_load
10933         restore_lustre_params < $p
10934         rm -f $p
10935 }
10936 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10937
10938 test_155g() {
10939         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10940         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10941         save_writethrough $p
10942
10943         set_cache read off
10944         set_cache writethrough on
10945         test_155_big_load
10946         restore_lustre_params < $p
10947         rm -f $p
10948 }
10949 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10950
10951 test_155h() {
10952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10953         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10954         save_writethrough $p
10955
10956         set_cache read off
10957         set_cache writethrough off
10958         test_155_big_load
10959         restore_lustre_params < $p
10960         rm -f $p
10961 }
10962 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10963
10964 test_156() {
10965         remote_ost_nodsh && skip "remote OST with nodsh" && return
10966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10967         local CPAGES=3
10968         local BEFORE
10969         local AFTER
10970         local file="$DIR/$tfile"
10971         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10972
10973         [ "$(facet_fstype ost1)" = "zfs" -a \
10974            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
10975                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
10976                 return
10977
10978         save_writethrough $p
10979         roc_hit_init
10980
10981         log "Turn on read and write cache"
10982         set_cache read on
10983         set_cache writethrough on
10984
10985         log "Write data and read it back."
10986         log "Read should be satisfied from the cache."
10987         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10988         BEFORE=$(roc_hit)
10989         cancel_lru_locks osc
10990         cat $file >/dev/null
10991         AFTER=$(roc_hit)
10992         if ! let "AFTER - BEFORE == CPAGES"; then
10993                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10994         else
10995                 log "cache hits:: before: $BEFORE, after: $AFTER"
10996         fi
10997
10998         log "Read again; it should be satisfied from the cache."
10999         BEFORE=$AFTER
11000         cancel_lru_locks osc
11001         cat $file >/dev/null
11002         AFTER=$(roc_hit)
11003         if ! let "AFTER - BEFORE == CPAGES"; then
11004                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11005         else
11006                 log "cache hits:: before: $BEFORE, after: $AFTER"
11007         fi
11008
11009         log "Turn off the read cache and turn on the write cache"
11010         set_cache read off
11011         set_cache writethrough on
11012
11013         log "Read again; it should be satisfied from the cache."
11014         BEFORE=$(roc_hit)
11015         cancel_lru_locks osc
11016         cat $file >/dev/null
11017         AFTER=$(roc_hit)
11018         if ! let "AFTER - BEFORE == CPAGES"; then
11019                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11020         else
11021                 log "cache hits:: before: $BEFORE, after: $AFTER"
11022         fi
11023
11024         log "Read again; it should not be satisfied from the cache."
11025         BEFORE=$AFTER
11026         cancel_lru_locks osc
11027         cat $file >/dev/null
11028         AFTER=$(roc_hit)
11029         if ! let "AFTER - BEFORE == 0"; then
11030                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11031         else
11032                 log "cache hits:: before: $BEFORE, after: $AFTER"
11033         fi
11034
11035         log "Write data and read it back."
11036         log "Read should be satisfied from the cache."
11037         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11038         BEFORE=$(roc_hit)
11039         cancel_lru_locks osc
11040         cat $file >/dev/null
11041         AFTER=$(roc_hit)
11042         if ! let "AFTER - BEFORE == CPAGES"; then
11043                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11044         else
11045                 log "cache hits:: before: $BEFORE, after: $AFTER"
11046         fi
11047
11048         log "Read again; it should not be satisfied from the cache."
11049         BEFORE=$AFTER
11050         cancel_lru_locks osc
11051         cat $file >/dev/null
11052         AFTER=$(roc_hit)
11053         if ! let "AFTER - BEFORE == 0"; then
11054                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11055         else
11056                 log "cache hits:: before: $BEFORE, after: $AFTER"
11057         fi
11058
11059         log "Turn off read and write cache"
11060         set_cache read off
11061         set_cache writethrough off
11062
11063         log "Write data and read it back"
11064         log "It should not be satisfied from the cache."
11065         rm -f $file
11066         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11067         cancel_lru_locks osc
11068         BEFORE=$(roc_hit)
11069         cat $file >/dev/null
11070         AFTER=$(roc_hit)
11071         if ! let "AFTER - BEFORE == 0"; then
11072                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
11073         else
11074                 log "cache hits:: before: $BEFORE, after: $AFTER"
11075         fi
11076
11077         log "Turn on the read cache and turn off the write cache"
11078         set_cache read on
11079         set_cache writethrough off
11080
11081         log "Write data and read it back"
11082         log "It should not be satisfied from the cache."
11083         rm -f $file
11084         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11085         BEFORE=$(roc_hit)
11086         cancel_lru_locks osc
11087         cat $file >/dev/null
11088         AFTER=$(roc_hit)
11089         if ! let "AFTER - BEFORE == 0"; then
11090                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
11091         else
11092                 log "cache hits:: before: $BEFORE, after: $AFTER"
11093         fi
11094
11095         log "Read again; it should be satisfied from the cache."
11096         BEFORE=$(roc_hit)
11097         cancel_lru_locks osc
11098         cat $file >/dev/null
11099         AFTER=$(roc_hit)
11100         if ! let "AFTER - BEFORE == CPAGES"; then
11101                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11102         else
11103                 log "cache hits:: before: $BEFORE, after: $AFTER"
11104         fi
11105
11106         rm -f $file
11107         restore_lustre_params < $p
11108         rm -f $p
11109 }
11110 run_test 156 "Verification of tunables"
11111
11112 #Changelogs
11113 cleanup_changelog () {
11114         trap 0
11115         echo "Deregistering changelog client $CL_USER"
11116         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
11117 }
11118
11119 err17935 () {
11120         if [[ $MDSCOUNT -gt 1 ]]; then
11121                 error_ignore bz17935 $*
11122         else
11123                 error $*
11124         fi
11125 }
11126
11127 changelog_chmask()
11128 {
11129         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11130
11131         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
11132
11133         if [ $MASK -eq 1 ]; then
11134                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
11135         else
11136                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
11137         fi
11138 }
11139
11140 changelog_extract_field() {
11141         local mdt=$1
11142         local cltype=$2
11143         local file=$3
11144         local identifier=$4
11145
11146         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
11147                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
11148                 tail -1
11149 }
11150
11151 test_160a() {
11152         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11153         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11154         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11155                 { skip "Need MDS version at least 2.2.0"; return; }
11156
11157         local CL_USERS="mdd.$MDT0.changelog_users"
11158         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11159         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11160                 changelog_register -n)
11161         echo "Registered as changelog user $CL_USER"
11162         trap cleanup_changelog EXIT
11163         $GET_CL_USERS | grep -q $CL_USER ||
11164                 error "User $CL_USER not found in changelog_users"
11165
11166         # change something
11167         test_mkdir -p $DIR/$tdir/pics/2008/zachy
11168         touch $DIR/$tdir/pics/2008/zachy/timestamp
11169         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
11170         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
11171         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
11172         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
11173         rm $DIR/$tdir/pics/desktop.jpg
11174
11175         $LFS changelog $MDT0 | tail -5
11176
11177         echo "verifying changelog mask"
11178         changelog_chmask "MKDIR"
11179         changelog_chmask "CLOSE"
11180
11181         test_mkdir -p $DIR/$tdir/pics/zach/sofia
11182         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11183
11184         changelog_chmask "MKDIR"
11185         changelog_chmask "CLOSE"
11186
11187         test_mkdir -p $DIR/$tdir/pics/2008/sofia
11188         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11189
11190         $LFS changelog $MDT0
11191         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
11192         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
11193         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
11194         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
11195
11196         # verify contents
11197         echo "verifying target fid"
11198         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
11199         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
11200         [ "$fidc" == "$fidf" ] ||
11201                 err17935 "fid in changelog $fidc != file fid $fidf"
11202         echo "verifying parent fid"
11203         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
11204         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
11205         [ "$fidc" == "$fidf" ] ||
11206                 err17935 "pfid in changelog $fidc != dir fid $fidf"
11207
11208         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11209         $LFS changelog_clear $MDT0 $CL_USER $(($USER_REC1 + 5))
11210         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11211         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
11212         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
11213                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
11214
11215         MIN_REC=$($GET_CL_USERS |
11216                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
11217         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
11218         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
11219         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
11220                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
11221
11222         # LU-3446 changelog index reset on MDT restart
11223         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11224         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11225         $LFS changelog_clear $MDT0 $CL_USER 0
11226         stop $SINGLEMDS || error "Fail to stop MDT."
11227         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11228         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11229         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
11230         [ $CUR_REC1 == $CUR_REC2 ] ||
11231                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
11232
11233         echo "verifying user deregister"
11234         cleanup_changelog
11235         $GET_CL_USERS | grep -q $CL_USER &&
11236                 error "User $CL_USER still in changelog_users"
11237
11238         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
11239         if [ $CL_USER -eq 0 ]; then
11240                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11241                 touch $DIR/$tdir/chloe
11242                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11243                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
11244                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
11245         else
11246                 echo "$CL_USER other changelog users; can't verify off"
11247         fi
11248 }
11249 run_test 160a "changelog sanity"
11250
11251 test_160b() { # LU-3587
11252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11253         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11254         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11255                 { skip "Need MDS version at least 2.2.0"; return; }
11256
11257         local CL_USERS="mdd.$MDT0.changelog_users"
11258         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11259         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11260                 changelog_register -n)
11261         echo "Registered as changelog user $CL_USER"
11262         trap cleanup_changelog EXIT
11263         $GET_CL_USERS | grep -q $CL_USER ||
11264                 error "User $CL_USER not found in changelog_users"
11265
11266         local LONGNAME1=$(str_repeat a 255)
11267         local LONGNAME2=$(str_repeat b 255)
11268
11269         cd $DIR
11270         echo "creating very long named file"
11271         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
11272         echo "moving very long named file"
11273         mv $LONGNAME1 $LONGNAME2
11274
11275         $LFS changelog $MDT0 | grep RENME
11276         rm -f $LONGNAME2
11277         cleanup_changelog
11278 }
11279 run_test 160b "Verify that very long rename doesn't crash in changelog"
11280
11281 test_160c() {
11282         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11283
11284         local rc=0
11285         local server_version=$(lustre_version_code $SINGLEMDS)
11286
11287         [[ $server_version -gt $(version_code 2.5.57) ]] ||
11288                 [[ $server_version -gt $(version_code 2.5.1) &&
11289                    $server_version -lt $(version_code 2.5.50) ]] ||
11290                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
11291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11292
11293         # Registration step
11294         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11295                 changelog_register -n)
11296         trap cleanup_changelog EXIT
11297
11298         rm -rf $DIR/$tdir
11299         mkdir -p $DIR/$tdir
11300         $MCREATE $DIR/$tdir/foo_160c
11301         changelog_chmask "TRUNC"
11302         $TRUNCATE $DIR/$tdir/foo_160c 200
11303         changelog_chmask "TRUNC"
11304         $TRUNCATE $DIR/$tdir/foo_160c 199
11305         $LFS changelog $MDT0
11306         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
11307         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
11308         $LFS changelog_clear $MDT0 $CL_USER 0
11309
11310         # Deregistration step
11311         cleanup_changelog
11312 }
11313 run_test 160c "verify that changelog log catch the truncate event"
11314
11315 test_160d() {
11316         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11317         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11318
11319         local server_version=$(lustre_version_code mds1)
11320         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11321
11322         [[ $server_version -ge $(version_code 2.7.60) ]] ||
11323                 { skip "Need MDS version at least 2.7.60+"; return; }
11324         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11325
11326         # Registration step
11327         CL_USER=$(do_facet mds1 $LCTL --device $MDT0 \
11328                 changelog_register -n)
11329
11330         trap cleanup_changelog EXIT
11331         mkdir -p $DIR/$tdir/migrate_dir
11332         $LFS changelog_clear $MDT0 $CL_USER 0
11333
11334         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
11335         $LFS changelog $MDT0
11336         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
11337         $LFS changelog_clear $MDT0 $CL_USER 0
11338         [ $MIGRATES -eq 1 ] ||
11339                 error "MIGRATE changelog mask count $MIGRATES != 1"
11340
11341         # Deregistration step
11342         cleanup_changelog
11343 }
11344 run_test 160d "verify that changelog log catch the migrate event"
11345
11346 test_160e() {
11347         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11348
11349         # Create a user
11350         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11351                 changelog_register -n)
11352         echo "Registered as changelog user $CL_USER"
11353         trap cleanup_changelog EXIT
11354
11355         # Delete a future user (expect fail)
11356         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister cl77
11357         local rc=$?
11358
11359         if [ $rc -eq 0 ]; then
11360                 error "Deleted non-existant user cl77"
11361         elif [ $rc -ne 2 ]; then
11362                 error "changelog_deregister failed with $rc, " \
11363                         "expected 2 (ENOENT)"
11364         fi
11365
11366         # Clear to a bad index (1 billion should be safe)
11367         $LFS changelog_clear $MDT0 $CL_USER 1000000000
11368         rc=$?
11369
11370         if [ $rc -eq 0 ]; then
11371                 error "Successfully cleared to invalid CL index"
11372         elif [ $rc -ne 22 ]; then
11373                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
11374         fi
11375 }
11376 run_test 160e "changelog negative testing"
11377
11378 test_161a() {
11379         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11380         test_mkdir -c1 $DIR/$tdir
11381         cp /etc/hosts $DIR/$tdir/$tfile
11382         test_mkdir -c1 $DIR/$tdir/foo1
11383         test_mkdir -c1 $DIR/$tdir/foo2
11384         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
11385         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
11386         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
11387         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
11388         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
11389         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11390                 $LFS fid2path $DIR $FID
11391                 err17935 "bad link ea"
11392         fi
11393     # middle
11394     rm $DIR/$tdir/foo2/zachary
11395     # last
11396     rm $DIR/$tdir/foo2/thor
11397     # first
11398     rm $DIR/$tdir/$tfile
11399     # rename
11400     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
11401     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
11402         then
11403         $LFS fid2path $DIR $FID
11404         err17935 "bad link rename"
11405     fi
11406     rm $DIR/$tdir/foo2/maggie
11407
11408         # overflow the EA
11409         local longname=filename_avg_len_is_thirty_two_
11410         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
11411                 error "failed to hardlink many files"
11412         links=$($LFS fid2path $DIR $FID | wc -l)
11413         echo -n "${links}/1000 links in link EA"
11414         [[ $links -gt 60 ]] ||
11415                 err17935 "expected at least 60 links in link EA"
11416         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
11417                 error "failed to unlink many hardlinks"
11418 }
11419 run_test 161a "link ea sanity"
11420
11421 test_161b() {
11422         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11423         [ $MDSCOUNT -lt 2 ] && skip "skipping remote directory test" && return
11424         local MDTIDX=1
11425         local remote_dir=$DIR/$tdir/remote_dir
11426
11427         mkdir -p $DIR/$tdir
11428         $LFS mkdir -i $MDTIDX $remote_dir ||
11429                 error "create remote directory failed"
11430
11431         cp /etc/hosts $remote_dir/$tfile
11432         mkdir -p $remote_dir/foo1
11433         mkdir -p $remote_dir/foo2
11434         ln $remote_dir/$tfile $remote_dir/foo1/sofia
11435         ln $remote_dir/$tfile $remote_dir/foo2/zachary
11436         ln $remote_dir/$tfile $remote_dir/foo1/luna
11437         ln $remote_dir/$tfile $remote_dir/foo2/thor
11438
11439         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
11440                      tr -d ']')
11441         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11442                 $LFS fid2path $DIR $FID
11443                 err17935 "bad link ea"
11444         fi
11445         # middle
11446         rm $remote_dir/foo2/zachary
11447         # last
11448         rm $remote_dir/foo2/thor
11449         # first
11450         rm $remote_dir/$tfile
11451         # rename
11452         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
11453         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
11454         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
11455                 $LFS fid2path $DIR $FID
11456                 err17935 "bad link rename"
11457         fi
11458         rm $remote_dir/foo2/maggie
11459
11460         # overflow the EA
11461         local longname=filename_avg_len_is_thirty_two_
11462         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
11463                 error "failed to hardlink many files"
11464         links=$($LFS fid2path $DIR $FID | wc -l)
11465         echo -n "${links}/1000 links in link EA"
11466         [[ ${links} -gt 60 ]] ||
11467                 err17935 "expected at least 60 links in link EA"
11468         unlinkmany $remote_dir/foo2/$longname 1000 ||
11469         error "failed to unlink many hardlinks"
11470 }
11471 run_test 161b "link ea sanity under remote directory"
11472
11473 test_161c() {
11474         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11475         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11476         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
11477                 skip "Need MDS version at least 2.1.5" && return
11478
11479         # define CLF_RENAME_LAST 0x0001
11480         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
11481         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11482                 changelog_register -n)
11483
11484         trap cleanup_changelog EXIT
11485         rm -rf $DIR/$tdir
11486         mkdir -p $DIR/$tdir
11487         touch $DIR/$tdir/foo_161c
11488         touch $DIR/$tdir/bar_161c
11489         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11490         $LFS changelog $MDT0 | grep RENME
11491         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
11492                 cut -f5 -d' ')
11493         $LFS changelog_clear $MDT0 $CL_USER 0
11494         if [ x$flags != "x0x1" ]; then
11495                 error "flag $flags is not 0x1"
11496         fi
11497         echo "rename overwrite a target having nlink = 1," \
11498                 "changelog record has flags of $flags"
11499
11500         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
11501         touch $DIR/$tdir/foo_161c
11502         touch $DIR/$tdir/bar_161c
11503         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11504         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11505         $LFS changelog $MDT0 | grep RENME
11506         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11507         $LFS changelog_clear $MDT0 $CL_USER 0
11508         if [ x$flags != "x0x0" ]; then
11509                 error "flag $flags is not 0x0"
11510         fi
11511         echo "rename overwrite a target having nlink > 1," \
11512                 "changelog record has flags of $flags"
11513
11514         # rename doesn't overwrite a target (changelog flag 0x0)
11515         touch $DIR/$tdir/foo_161c
11516         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
11517         $LFS changelog $MDT0 | grep RENME
11518         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11519         $LFS changelog_clear $MDT0 $CL_USER 0
11520         if [ x$flags != "x0x0" ]; then
11521                 error "flag $flags is not 0x0"
11522         fi
11523         echo "rename doesn't overwrite a target," \
11524                 "changelog record has flags of $flags"
11525
11526         # define CLF_UNLINK_LAST 0x0001
11527         # unlink a file having nlink = 1 (changelog flag 0x1)
11528         rm -f $DIR/$tdir/foo2_161c
11529         $LFS changelog $MDT0 | grep UNLNK
11530         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11531         $LFS changelog_clear $MDT0 $CL_USER 0
11532         if [ x$flags != "x0x1" ]; then
11533                 error "flag $flags is not 0x1"
11534         fi
11535         echo "unlink a file having nlink = 1," \
11536                 "changelog record has flags of $flags"
11537
11538         # unlink a file having nlink > 1 (changelog flag 0x0)
11539         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11540         rm -f $DIR/$tdir/foobar_161c
11541         $LFS changelog $MDT0 | grep UNLNK
11542         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11543         $LFS changelog_clear $MDT0 $CL_USER 0
11544         if [ x$flags != "x0x0" ]; then
11545                 error "flag $flags is not 0x0"
11546         fi
11547         echo "unlink a file having nlink > 1," \
11548                 "changelog record has flags of $flags"
11549         cleanup_changelog
11550 }
11551 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
11552
11553 test_161d() {
11554         local user
11555         local pid
11556         local fid
11557
11558         # cleanup previous run
11559         rm -rf $DIR/$tdir/$tfile
11560
11561         user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11562                 changelog_register -n)
11563         [[ $? -eq 0 ]] || error "changelog_register failed"
11564
11565         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
11566         # interfer with $MOUNT/.lustre/fid/ access
11567         mkdir $DIR/$tdir
11568         [[ $? -eq 0 ]] || error "mkdir failed"
11569
11570         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
11571         $LCTL set_param fail_loc=0x8000140c
11572         # 5s pause
11573         $LCTL set_param fail_val=5
11574
11575         # create file
11576         echo foofoo > $DIR/$tdir/$tfile &
11577         pid=$!
11578
11579         # wait for create to be delayed
11580         sleep 2
11581
11582         ps -p $pid
11583         [[ $? -eq 0 ]] || error "create should be blocked"
11584
11585         local tempfile=$(mktemp)
11586         fid=$(changelog_extract_field $MDT0 "CREAT" "$tfile" "t=")
11587         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
11588         # some delay may occur during ChangeLog publishing and file read just
11589         # above, that could allow file write to happen finally
11590         [[ -s $tempfile ]] && echo "file should be empty"
11591
11592         $LCTL set_param fail_loc=0
11593
11594         wait $pid
11595         [[ $? -eq 0 ]] || error "create failed"
11596
11597         $LFS changelog_clear $MDT0 $user 0
11598         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $user
11599 }
11600 run_test 161d "create with concurrent .lustre/fid access"
11601
11602 check_path() {
11603     local expected=$1
11604     shift
11605     local fid=$2
11606
11607     local path=$(${LFS} fid2path $*)
11608     # Remove the '//' indicating a remote directory
11609     path=$(echo $path | sed 's#//#/#g')
11610     RC=$?
11611
11612     if [ $RC -ne 0 ]; then
11613         err17935 "path looked up of $expected failed. Error $RC"
11614         return $RC
11615     elif [ "${path}" != "${expected}" ]; then
11616         err17935 "path looked up \"${path}\" instead of \"${expected}\""
11617         return 2
11618     fi
11619     echo "fid $fid resolves to path $path (expected $expected)"
11620 }
11621
11622 test_162a() { # was test_162
11623         # Make changes to filesystem
11624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11625         test_mkdir -p -c1 $DIR/$tdir/d2
11626         touch $DIR/$tdir/d2/$tfile
11627         touch $DIR/$tdir/d2/x1
11628         touch $DIR/$tdir/d2/x2
11629         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
11630         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
11631         # regular file
11632         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
11633         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
11634                 error "check path $tdir/d2/$tfile failed"
11635
11636         # softlink
11637         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
11638         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
11639         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
11640                 error "check path $tdir/d2/p/q/r/slink failed"
11641
11642         # softlink to wrong file
11643         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
11644         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
11645         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
11646                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
11647
11648         # hardlink
11649         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
11650         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
11651         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
11652         # fid2path dir/fsname should both work
11653         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
11654                 error "check path $tdir/d2/a/b/c/new_file failed"
11655         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
11656                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
11657
11658         # hardlink count: check that there are 2 links
11659         # Doesnt work with CMD yet: 17935
11660         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
11661                 err17935 "expected 2 links"
11662
11663         # hardlink indexing: remove the first link
11664         rm $DIR/$tdir/d2/p/q/r/hlink
11665         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
11666                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
11667
11668         return 0
11669 }
11670 run_test 162a "path lookup sanity"
11671
11672 test_162b() {
11673         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11674         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11675
11676         mkdir $DIR/$tdir
11677         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
11678                                 error "create striped dir failed"
11679
11680         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
11681                                         tail -n 1 | awk '{print $2}')
11682         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
11683
11684         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
11685         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
11686
11687         # regular file
11688         for ((i=0;i<5;i++)); do
11689                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
11690                         error "get fid for f$i failed"
11691                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
11692                         error "check path $tdir/striped_dir/f$i failed"
11693
11694                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
11695                         error "get fid for d$i failed"
11696                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
11697                         error "check path $tdir/striped_dir/d$i failed"
11698         done
11699
11700         return 0
11701 }
11702 run_test 162b "striped directory path lookup sanity"
11703
11704 # LU-4239: Verify fid2path works with paths 100 or more directories deep
11705 test_162c() {
11706         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
11707                 skip "Need MDS version at least 2.7.51" && return
11708         test_mkdir $DIR/$tdir.local
11709         test_mkdir $DIR/$tdir.remote
11710         local lpath=$tdir.local
11711         local rpath=$tdir.remote
11712
11713         for ((i = 0; i <= 101; i++)); do
11714                 lpath="$lpath/$i"
11715                 mkdir $DIR/$lpath
11716                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
11717                         error "get fid for local directory $DIR/$lpath failed"
11718                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
11719                         error "check path for local directory $DIR/$lpath failed"
11720
11721                 rpath="$rpath/$i"
11722                 test_mkdir $DIR/$rpath
11723                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
11724                         error "get fid for remote directory $DIR/$rpath failed"
11725                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
11726                         error "check path for remote directory $DIR/$rpath failed"
11727         done
11728
11729         return 0
11730 }
11731 run_test 162c "fid2path works with paths 100 or more directories deep"
11732
11733 test_169() {
11734         # do directio so as not to populate the page cache
11735         log "creating a 10 Mb file"
11736         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11737         log "starting reads"
11738         dd if=$DIR/$tfile of=/dev/null bs=4096 &
11739         log "truncating the file"
11740         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11741         log "killing dd"
11742         kill %+ || true # reads might have finished
11743         echo "wait until dd is finished"
11744         wait
11745         log "removing the temporary file"
11746         rm -rf $DIR/$tfile || error "tmp file removal failed"
11747 }
11748 run_test 169 "parallel read and truncate should not deadlock"
11749
11750 test_170() {
11751         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11752         $LCTL clear     # bug 18514
11753         $LCTL debug_daemon start $TMP/${tfile}_log_good
11754         touch $DIR/$tfile
11755         $LCTL debug_daemon stop
11756         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
11757                error "sed failed to read log_good"
11758
11759         $LCTL debug_daemon start $TMP/${tfile}_log_good
11760         rm -rf $DIR/$tfile
11761         $LCTL debug_daemon stop
11762
11763         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
11764                error "lctl df log_bad failed"
11765
11766         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11767         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11768
11769         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
11770         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
11771
11772         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
11773                 error "bad_line good_line1 good_line2 are empty"
11774
11775         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11776         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
11777         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11778
11779         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
11780         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11781         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11782
11783         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
11784                 error "bad_line_new good_line_new are empty"
11785
11786         local expected_good=$((good_line1 + good_line2*2))
11787
11788         rm -f $TMP/${tfile}*
11789         # LU-231, short malformed line may not be counted into bad lines
11790         if [ $bad_line -ne $bad_line_new ] &&
11791                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
11792                 error "expected $bad_line bad lines, but got $bad_line_new"
11793                 return 1
11794         fi
11795
11796         if [ $expected_good -ne $good_line_new ]; then
11797                 error "expected $expected_good good lines, but got $good_line_new"
11798                 return 2
11799         fi
11800         true
11801 }
11802 run_test 170 "test lctl df to handle corrupted log ====================="
11803
11804 test_171() { # bug20592
11805         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11806 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
11807         $LCTL set_param fail_loc=0x50e
11808         $LCTL set_param fail_val=3000
11809         multiop_bg_pause $DIR/$tfile O_s || true
11810         local MULTIPID=$!
11811         kill -USR1 $MULTIPID
11812         # cause log dump
11813         sleep 3
11814         wait $MULTIPID
11815         if dmesg | grep "recursive fault"; then
11816                 error "caught a recursive fault"
11817         fi
11818         $LCTL set_param fail_loc=0
11819         true
11820 }
11821 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
11822
11823 # it would be good to share it with obdfilter-survey/iokit-libecho code
11824 setup_obdecho_osc () {
11825         local rc=0
11826         local ost_nid=$1
11827         local obdfilter_name=$2
11828         echo "Creating new osc for $obdfilter_name on $ost_nid"
11829         # make sure we can find loopback nid
11830         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
11831
11832         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
11833                            ${obdfilter_name}_osc_UUID || rc=2; }
11834         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
11835                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
11836         return $rc
11837 }
11838
11839 cleanup_obdecho_osc () {
11840         local obdfilter_name=$1
11841         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
11842         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
11843         return 0
11844 }
11845
11846 obdecho_test() {
11847         local OBD=$1
11848         local node=$2
11849         local pages=${3:-64}
11850         local rc=0
11851         local id
11852
11853         local count=10
11854         local obd_size=$(get_obd_size $node $OBD)
11855         local page_size=$(get_page_size $node)
11856         if [[ -n "$obd_size" ]]; then
11857                 local new_count=$((obd_size / (pages * page_size / 1024)))
11858                 [[ $new_count -ge $count ]] || count=$new_count
11859         fi
11860
11861         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
11862         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
11863                            rc=2; }
11864         if [ $rc -eq 0 ]; then
11865             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
11866             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
11867         fi
11868         echo "New object id is $id"
11869         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
11870                            rc=4; }
11871         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
11872                            "test_brw $count w v $pages $id" || rc=4; }
11873         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
11874                            rc=4; }
11875         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
11876                                         "cleanup" || rc=5; }
11877         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
11878                                         "detach" || rc=6; }
11879         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
11880         return $rc
11881 }
11882
11883 test_180a() {
11884         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11885         remote_ost_nodsh && skip "remote OST with nodsh" && return
11886         local rc=0
11887         local rmmod_local=0
11888
11889         if ! module_loaded obdecho; then
11890             load_module obdecho/obdecho
11891             rmmod_local=1
11892         fi
11893
11894         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
11895         local host=$(lctl get_param -n osc.$osc.import |
11896                              awk '/current_connection:/ {print $2}' )
11897         local target=$(lctl get_param -n osc.$osc.import |
11898                              awk '/target:/ {print $2}' )
11899         target=${target%_UUID}
11900
11901         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
11902         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
11903         [[ -n $target ]] && cleanup_obdecho_osc $target
11904         [ $rmmod_local -eq 1 ] && rmmod obdecho
11905         return $rc
11906 }
11907 run_test 180a "test obdecho on osc"
11908
11909 test_180b() {
11910         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11911         remote_ost_nodsh && skip "remote OST with nodsh" && return
11912         local rc=0
11913         local rmmod_remote=0
11914
11915         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11916                 rmmod_remote=true || error "failed to load module obdecho"
11917         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
11918         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
11919         $rmmod_remote && do_facet ost1 "rmmod obdecho"
11920         return $rc
11921 }
11922 run_test 180b "test obdecho directly on obdfilter"
11923
11924 test_180c() { # LU-2598
11925         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11926         remote_ost_nodsh && skip "remote OST with nodsh" && return
11927         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
11928                 skip "Need MDS version at least 2.4.0" && return
11929
11930         local rc=0
11931         local rmmod_remote=false
11932         local pages=16384 # 64MB bulk I/O RPC size
11933         local target
11934
11935         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11936                 rmmod_remote=true || error "failed to load module obdecho"
11937
11938         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
11939                 head -n1)
11940         if [ -n "$target" ]; then
11941                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
11942         else
11943                 echo "there is no obdfilter target on ost1"
11944                 rc=2
11945         fi
11946         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
11947         return $rc
11948 }
11949 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
11950
11951 test_181() { # bug 22177
11952         test_mkdir $DIR/$tdir
11953         # create enough files to index the directory
11954         createmany -o $DIR/$tdir/foobar 4000
11955         # print attributes for debug purpose
11956         lsattr -d .
11957         # open dir
11958         multiop_bg_pause $DIR/$tdir D_Sc || return 1
11959         MULTIPID=$!
11960         # remove the files & current working dir
11961         unlinkmany $DIR/$tdir/foobar 4000
11962         rmdir $DIR/$tdir
11963         kill -USR1 $MULTIPID
11964         wait $MULTIPID
11965         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
11966         return 0
11967 }
11968 run_test 181 "Test open-unlinked dir ========================"
11969
11970 test_182() {
11971         local fcount=1000
11972         local tcount=10
11973
11974         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11975
11976         $LCTL set_param mdc.*.rpc_stats=clear
11977
11978         for (( i = 0; i < $tcount; i++ )) ; do
11979                 mkdir $DIR/$tdir/$i
11980         done
11981
11982         for (( i = 0; i < $tcount; i++ )) ; do
11983                 createmany -o $DIR/$tdir/$i/f- $fcount &
11984         done
11985         wait
11986
11987         for (( i = 0; i < $tcount; i++ )) ; do
11988                 unlinkmany $DIR/$tdir/$i/f- $fcount &
11989         done
11990         wait
11991
11992         $LCTL get_param mdc.*.rpc_stats
11993
11994         rm -rf $DIR/$tdir
11995 }
11996 run_test 182 "Test parallel modify metadata operations ================"
11997
11998 test_183() { # LU-2275
11999         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12000         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
12001                 skip "Need MDS version at least 2.3.56" && return
12002
12003         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12004         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12005         echo aaa > $DIR/$tdir/$tfile
12006
12007 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
12008         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
12009
12010         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
12011         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
12012
12013         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
12014
12015         # Flush negative dentry cache
12016         touch $DIR/$tdir/$tfile
12017
12018         # We are not checking for any leaked references here, they'll
12019         # become evident next time we do cleanup with module unload.
12020         rm -rf $DIR/$tdir
12021 }
12022 run_test 183 "No crash or request leak in case of strange dispositions ========"
12023
12024 # test suite 184 is for LU-2016, LU-2017
12025 test_184a() {
12026         check_swap_layouts_support && return 0
12027
12028         dir0=$DIR/$tdir/$testnum
12029         test_mkdir -p -c1 $dir0
12030         ref1=/etc/passwd
12031         ref2=/etc/group
12032         file1=$dir0/f1
12033         file2=$dir0/f2
12034         $SETSTRIPE -c1 $file1
12035         cp $ref1 $file1
12036         $SETSTRIPE -c2 $file2
12037         cp $ref2 $file2
12038         gen1=$($GETSTRIPE -g $file1)
12039         gen2=$($GETSTRIPE -g $file2)
12040
12041         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
12042         gen=$($GETSTRIPE -g $file1)
12043         [[ $gen1 != $gen ]] ||
12044                 "Layout generation on $file1 does not change"
12045         gen=$($GETSTRIPE -g $file2)
12046         [[ $gen2 != $gen ]] ||
12047                 "Layout generation on $file2 does not change"
12048
12049         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
12050         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12051 }
12052 run_test 184a "Basic layout swap"
12053
12054 test_184b() {
12055         check_swap_layouts_support && return 0
12056
12057         dir0=$DIR/$tdir/$testnum
12058         mkdir -p $dir0 || error "creating dir $dir0"
12059         file1=$dir0/f1
12060         file2=$dir0/f2
12061         file3=$dir0/f3
12062         dir1=$dir0/d1
12063         dir2=$dir0/d2
12064         mkdir $dir1 $dir2
12065         $SETSTRIPE -c1 $file1
12066         $SETSTRIPE -c2 $file2
12067         $SETSTRIPE -c1 $file3
12068         chown $RUNAS_ID $file3
12069         gen1=$($GETSTRIPE -g $file1)
12070         gen2=$($GETSTRIPE -g $file2)
12071
12072         $LFS swap_layouts $dir1 $dir2 &&
12073                 error "swap of directories layouts should fail"
12074         $LFS swap_layouts $dir1 $file1 &&
12075                 error "swap of directory and file layouts should fail"
12076         $RUNAS $LFS swap_layouts $file1 $file2 &&
12077                 error "swap of file we cannot write should fail"
12078         $LFS swap_layouts $file1 $file3 &&
12079                 error "swap of file with different owner should fail"
12080         /bin/true # to clear error code
12081 }
12082 run_test 184b "Forbidden layout swap (will generate errors)"
12083
12084 test_184c() {
12085         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
12086         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n" && return
12087         check_swap_layouts_support && return 0
12088
12089         local dir0=$DIR/$tdir/$testnum
12090         mkdir -p $dir0 || error "creating dir $dir0"
12091
12092         local ref1=$dir0/ref1
12093         local ref2=$dir0/ref2
12094         local file1=$dir0/file1
12095         local file2=$dir0/file2
12096         # create a file large enough for the concurrent test
12097         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
12098         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
12099         echo "ref file size: ref1($(stat -c %s $ref1))," \
12100              "ref2($(stat -c %s $ref2))"
12101
12102         cp $ref2 $file2
12103         dd if=$ref1 of=$file1 bs=16k &
12104         local DD_PID=$!
12105
12106         # Make sure dd starts to copy file
12107         while [ ! -f $file1 ]; do sleep 0.1; done
12108
12109         $LFS swap_layouts $file1 $file2
12110         local rc=$?
12111         wait $DD_PID
12112         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
12113         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
12114
12115         # how many bytes copied before swapping layout
12116         local copied=$(stat -c %s $file2)
12117         local remaining=$(stat -c %s $ref1)
12118         remaining=$((remaining - copied))
12119         echo "Copied $copied bytes before swapping layout..."
12120
12121         cmp -n $copied $file1 $ref2 | grep differ &&
12122                 error "Content mismatch [0, $copied) of ref2 and file1"
12123         cmp -n $copied $file2 $ref1 ||
12124                 error "Content mismatch [0, $copied) of ref1 and file2"
12125         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
12126                 error "Content mismatch [$copied, EOF) of ref1 and file1"
12127
12128         # clean up
12129         rm -f $ref1 $ref2 $file1 $file2
12130 }
12131 run_test 184c "Concurrent write and layout swap"
12132
12133 test_184d() {
12134         check_swap_layouts_support && return 0
12135         [ -z "$(which getfattr 2>/dev/null)" ] &&
12136                 skip "no getfattr command" && return 0
12137
12138         local file1=$DIR/$tdir/$tfile-1
12139         local file2=$DIR/$tdir/$tfile-2
12140         local file3=$DIR/$tdir/$tfile-3
12141         local lovea1
12142         local lovea2
12143
12144         mkdir -p $DIR/$tdir
12145         touch $file1 || error "create $file1 failed"
12146         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12147                 error "create $file2 failed"
12148         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12149                 error "create $file3 failed"
12150         lovea1=$(get_layout_param $file1)
12151
12152         $LFS swap_layouts $file2 $file3 ||
12153                 error "swap $file2 $file3 layouts failed"
12154         $LFS swap_layouts $file1 $file2 ||
12155                 error "swap $file1 $file2 layouts failed"
12156
12157         lovea2=$(get_layout_param $file2)
12158         echo "$lovea1"
12159         echo "$lovea2"
12160         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
12161
12162         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12163         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
12164 }
12165 run_test 184d "allow stripeless layouts swap"
12166
12167 test_184e() {
12168         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
12169                 { skip "Need MDS version at least 2.6.94"; return 0; }
12170         check_swap_layouts_support && return 0
12171         [ -z "$(which getfattr 2>/dev/null)" ] &&
12172                 skip "no getfattr command" && return 0
12173
12174         local file1=$DIR/$tdir/$tfile-1
12175         local file2=$DIR/$tdir/$tfile-2
12176         local file3=$DIR/$tdir/$tfile-3
12177         local lovea
12178
12179         mkdir -p $DIR/$tdir
12180         touch $file1 || error "create $file1 failed"
12181         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12182                 error "create $file2 failed"
12183         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12184                 error "create $file3 failed"
12185
12186         $LFS swap_layouts $file1 $file2 ||
12187                 error "swap $file1 $file2 layouts failed"
12188
12189         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12190         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
12191
12192         echo 123 > $file1 || error "Should be able to write into $file1"
12193
12194         $LFS swap_layouts $file1 $file3 ||
12195                 error "swap $file1 $file3 layouts failed"
12196
12197         echo 123 > $file1 || error "Should be able to write into $file1"
12198
12199         rm -rf $file1 $file2 $file3
12200 }
12201 run_test 184e "Recreate layout after stripeless layout swaps"
12202
12203 test_185() { # LU-2441
12204         # LU-3553 - no volatile file support in old servers
12205         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
12206                 { skip "Need MDS version at least 2.3.60"; return 0; }
12207
12208         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12209         touch $DIR/$tdir/spoo
12210         local mtime1=$(stat -c "%Y" $DIR/$tdir)
12211         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
12212                 error "cannot create/write a volatile file"
12213         [ "$FILESET" == "" ] &&
12214         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
12215                 error "FID is still valid after close"
12216
12217         multiop_bg_pause $DIR/$tdir vVw4096_c
12218         local multi_pid=$!
12219
12220         local OLD_IFS=$IFS
12221         IFS=":"
12222         local fidv=($fid)
12223         IFS=$OLD_IFS
12224         # assume that the next FID for this client is sequential, since stdout
12225         # is unfortunately eaten by multiop_bg_pause
12226         local n=$((${fidv[1]} + 1))
12227         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
12228         if [ "$FILESET" == "" ]; then
12229                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
12230                         error "FID is missing before close"
12231         fi
12232         kill -USR1 $multi_pid
12233         # 1 second delay, so if mtime change we will see it
12234         sleep 1
12235         local mtime2=$(stat -c "%Y" $DIR/$tdir)
12236         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
12237 }
12238 run_test 185 "Volatile file support"
12239
12240 test_187a() {
12241         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12242         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12243                 skip "Need MDS version at least 2.3.0" && return
12244
12245         local dir0=$DIR/$tdir/$testnum
12246         mkdir -p $dir0 || error "creating dir $dir0"
12247
12248         local file=$dir0/file1
12249         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
12250         local dv1=$($LFS data_version $file)
12251         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
12252         local dv2=$($LFS data_version $file)
12253         [[ $dv1 != $dv2 ]] ||
12254                 error "data version did not change on write $dv1 == $dv2"
12255
12256         # clean up
12257         rm -f $file1
12258 }
12259 run_test 187a "Test data version change"
12260
12261 test_187b() {
12262         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12263         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12264                 skip "Need MDS version at least 2.3.0" && return
12265
12266         local dir0=$DIR/$tdir/$testnum
12267         mkdir -p $dir0 || error "creating dir $dir0"
12268
12269         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
12270         [[ ${DV[0]} != ${DV[1]} ]] ||
12271                 error "data version did not change on write"\
12272                       " ${DV[0]} == ${DV[1]}"
12273
12274         # clean up
12275         rm -f $file1
12276 }
12277 run_test 187b "Test data version change on volatile file"
12278
12279 test_200() {
12280         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12281         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12282         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
12283
12284         local POOL=${POOL:-cea1}
12285         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
12286         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
12287         # Pool OST targets
12288         local first_ost=0
12289         local last_ost=$(($OSTCOUNT - 1))
12290         local ost_step=2
12291         local ost_list=$(seq $first_ost $ost_step $last_ost)
12292         local ost_range="$first_ost $last_ost $ost_step"
12293         local test_path=$POOL_ROOT/$POOL_DIR_NAME
12294         local file_dir=$POOL_ROOT/file_tst
12295         local subdir=$test_path/subdir
12296
12297         local rc=0
12298         while : ; do
12299                 # former test_200a test_200b
12300                 pool_add $POOL                          || { rc=$? ; break; }
12301                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
12302                 # former test_200c test_200d
12303                 mkdir -p $test_path
12304                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
12305                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
12306                 mkdir -p $subdir
12307                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
12308                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
12309                                                         || { rc=$? ; break; }
12310                 # former test_200e test_200f
12311                 local files=$((OSTCOUNT*3))
12312                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
12313                                                         || { rc=$? ; break; }
12314                 pool_create_files $POOL $file_dir $files "$ost_list" \
12315                                                         || { rc=$? ; break; }
12316                 # former test_200g test_200h
12317                 pool_lfs_df $POOL                       || { rc=$? ; break; }
12318                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
12319
12320                 # former test_201a test_201b test_201c
12321                 pool_remove_first_target $POOL          || { rc=$? ; break; }
12322
12323                 local f=$test_path/$tfile
12324                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
12325                 pool_remove $POOL $f                    || { rc=$? ; break; }
12326                 break
12327         done
12328
12329         destroy_test_pools
12330         return $rc
12331 }
12332 run_test 200 "OST pools"
12333
12334 # usage: default_attr <count | size | offset>
12335 default_attr() {
12336         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
12337 }
12338
12339 # usage: check_default_stripe_attr
12340 check_default_stripe_attr() {
12341         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
12342         case $1 in
12343         --stripe-count|-c)
12344                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
12345         --stripe-size|-S)
12346                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
12347         --stripe-index|-i)
12348                 EXPECTED=-1;;
12349         *)
12350                 error "unknown getstripe attr '$1'"
12351         esac
12352
12353         [ $ACTUAL == $EXPECTED ] ||
12354                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
12355 }
12356
12357 test_204a() {
12358         test_mkdir $DIR/$tdir
12359         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
12360
12361         check_default_stripe_attr --stripe-count
12362         check_default_stripe_attr --stripe-size
12363         check_default_stripe_attr --stripe-index
12364 }
12365 run_test 204a "Print default stripe attributes"
12366
12367 test_204b() {
12368         test_mkdir $DIR/$tdir
12369         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12370
12371         check_default_stripe_attr --stripe-size
12372         check_default_stripe_attr --stripe-index
12373 }
12374 run_test 204b "Print default stripe size and offset"
12375
12376 test_204c() {
12377         test_mkdir $DIR/$tdir
12378         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12379
12380         check_default_stripe_attr --stripe-count
12381         check_default_stripe_attr --stripe-index
12382 }
12383 run_test 204c "Print default stripe count and offset"
12384
12385 test_204d() {
12386         test_mkdir $DIR/$tdir
12387         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12388
12389         check_default_stripe_attr --stripe-count
12390         check_default_stripe_attr --stripe-size
12391 }
12392 run_test 204d "Print default stripe count and size"
12393
12394 test_204e() {
12395         test_mkdir $DIR/$tdir
12396         $SETSTRIPE -d $DIR/$tdir
12397
12398         check_default_stripe_attr --stripe-count --raw
12399         check_default_stripe_attr --stripe-size --raw
12400         check_default_stripe_attr --stripe-index --raw
12401 }
12402 run_test 204e "Print raw stripe attributes"
12403
12404 test_204f() {
12405         test_mkdir $DIR/$tdir
12406         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12407
12408         check_default_stripe_attr --stripe-size --raw
12409         check_default_stripe_attr --stripe-index --raw
12410 }
12411 run_test 204f "Print raw stripe size and offset"
12412
12413 test_204g() {
12414         test_mkdir $DIR/$tdir
12415         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12416
12417         check_default_stripe_attr --stripe-count --raw
12418         check_default_stripe_attr --stripe-index --raw
12419 }
12420 run_test 204g "Print raw stripe count and offset"
12421
12422 test_204h() {
12423         test_mkdir $DIR/$tdir
12424         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12425
12426         check_default_stripe_attr --stripe-count --raw
12427         check_default_stripe_attr --stripe-size --raw
12428 }
12429 run_test 204h "Print raw stripe count and size"
12430
12431 # Figure out which job scheduler is being used, if any,
12432 # or use a fake one
12433 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
12434         JOBENV=SLURM_JOB_ID
12435 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
12436         JOBENV=LSB_JOBID
12437 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
12438         JOBENV=PBS_JOBID
12439 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
12440         JOBENV=LOADL_STEP_ID
12441 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
12442         JOBENV=JOB_ID
12443 else
12444         $LCTL list_param jobid_name > /dev/null 2>&1
12445         if [ $? -eq 0 ]; then
12446                 JOBENV=nodelocal
12447         else
12448                 JOBENV=FAKE_JOBID
12449         fi
12450 fi
12451
12452 verify_jobstats() {
12453         local cmd=($1)
12454         shift
12455         local facets="$@"
12456
12457 # we don't really need to clear the stats for this test to work, since each
12458 # command has a unique jobid, but it makes debugging easier if needed.
12459 #       for facet in $facets; do
12460 #               local dev=$(convert_facet2label $facet)
12461 #               # clear old jobstats
12462 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
12463 #       done
12464
12465         # use a new JobID for each test, or we might see an old one
12466         [ "$JOBENV" = "FAKE_JOBID" ] &&
12467                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12468
12469         JOBVAL=${!JOBENV}
12470
12471         [ "$JOBENV" = "nodelocal" ] && {
12472                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12473                 $LCTL set_param jobid_name=$FAKE_JOBID
12474                 JOBVAL=$FAKE_JOBID
12475         }
12476
12477         log "Test: ${cmd[*]}"
12478         log "Using JobID environment variable $JOBENV=$JOBVAL"
12479
12480         if [ $JOBENV = "FAKE_JOBID" ]; then
12481                 FAKE_JOBID=$JOBVAL ${cmd[*]}
12482         else
12483                 ${cmd[*]}
12484         fi
12485
12486         # all files are created on OST0000
12487         for facet in $facets; do
12488                 local stats="*.$(convert_facet2label $facet).job_stats"
12489                 if [ $(do_facet $facet lctl get_param $stats |
12490                        grep -c $JOBVAL) -ne 1 ]; then
12491                         do_facet $facet lctl get_param $stats
12492                         error "No jobstats for $JOBVAL found on $facet::$stats"
12493                 fi
12494         done
12495 }
12496
12497 jobstats_set() {
12498         trap 0
12499         NEW_JOBENV=${1:-$OLD_JOBENV}
12500         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
12501         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
12502 }
12503
12504 cleanup_205() {
12505         trap 0
12506         do_facet $SINGLEMDS \
12507                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
12508         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
12509         cleanup_changelog
12510 }
12511
12512 test_205() { # Job stats
12513         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.1) ]] ||
12514                 { skip "Need MDS version with at least 2.7.1"; return 0; }
12515
12516         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12517         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12518         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12519         remote_ost_nodsh && skip "remote OST with nodsh" && return
12520
12521         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
12522                 skip "Server doesn't support jobstats" && return 0
12523         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
12524
12525         OLD_JOBENV=$($LCTL get_param -n jobid_var)
12526         if [ $OLD_JOBENV != $JOBENV ]; then
12527                 jobstats_set $JOBENV
12528                 trap cleanup_205 EXIT
12529         fi
12530
12531         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
12532         echo "Registered as changelog user $CL_USER"
12533
12534         OLD_INTERVAL=$(do_facet $SINGLEMDS \
12535                        lctl get_param -n mdt.*.job_cleanup_interval)
12536         local interval_new=5
12537         do_facet $SINGLEMDS \
12538                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
12539         local start=$SECONDS
12540
12541         local cmd
12542         # mkdir
12543         cmd="mkdir $DIR/$tdir"
12544         verify_jobstats "$cmd" "$SINGLEMDS"
12545         # rmdir
12546         cmd="rmdir $DIR/$tdir"
12547         verify_jobstats "$cmd" "$SINGLEMDS"
12548         # mkdir on secondary MDT
12549         if [ $MDSCOUNT -gt 1 ]; then
12550                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
12551                 verify_jobstats "$cmd" "mds2"
12552         fi
12553         # mknod
12554         cmd="mknod $DIR/$tfile c 1 3"
12555         verify_jobstats "$cmd" "$SINGLEMDS"
12556         # unlink
12557         cmd="rm -f $DIR/$tfile"
12558         verify_jobstats "$cmd" "$SINGLEMDS"
12559         # create all files on OST0000 so verify_jobstats can find OST stats
12560         # open & close
12561         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
12562         verify_jobstats "$cmd" "$SINGLEMDS"
12563         # setattr
12564         cmd="touch $DIR/$tfile"
12565         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12566         # write
12567         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
12568         verify_jobstats "$cmd" "ost1"
12569         # read
12570         cancel_lru_locks osc
12571         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
12572         verify_jobstats "$cmd" "ost1"
12573         # truncate
12574         cmd="$TRUNCATE $DIR/$tfile 0"
12575         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12576         # rename
12577         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
12578         verify_jobstats "$cmd" "$SINGLEMDS"
12579         # jobstats expiry - sleep until old stats should be expired
12580         local left=$((interval_new + 5 - (SECONDS - start)))
12581         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
12582                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
12583                         "0" $left
12584         cmd="mkdir $DIR/$tdir.expire"
12585         verify_jobstats "$cmd" "$SINGLEMDS"
12586         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
12587             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
12588
12589         # Ensure that jobid are present in changelog (if supported by MDS)
12590         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
12591         then
12592                 $LFS changelog $MDT0 | tail -9
12593                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
12594                 [ $jobids -eq 9 ] ||
12595                         error "Wrong changelog jobid count $jobids != 9"
12596
12597                 # LU-5862
12598                 JOBENV="disable"
12599                 jobstats_set $JOBENV
12600                 touch $DIR/$tfile
12601                 $LFS changelog $MDT0 | tail -1
12602                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
12603                 [ $jobids -eq 0 ] ||
12604                         error "Unexpected jobids when jobid_var=$JOBENV"
12605         fi
12606
12607         cleanup_205
12608 }
12609 run_test 205 "Verify job stats"
12610
12611 # LU-1480, LU-1773 and LU-1657
12612 test_206() {
12613         mkdir -p $DIR/$tdir
12614         $SETSTRIPE -c -1 $DIR/$tdir
12615 #define OBD_FAIL_LOV_INIT 0x1403
12616         $LCTL set_param fail_loc=0xa0001403
12617         $LCTL set_param fail_val=1
12618         touch $DIR/$tdir/$tfile || true
12619 }
12620 run_test 206 "fail lov_init_raid0() doesn't lbug"
12621
12622 test_207a() {
12623         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12624         local fsz=`stat -c %s $DIR/$tfile`
12625         cancel_lru_locks mdc
12626
12627         # do not return layout in getattr intent
12628 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
12629         $LCTL set_param fail_loc=0x170
12630         local sz=`stat -c %s $DIR/$tfile`
12631
12632         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
12633
12634         rm -rf $DIR/$tfile
12635 }
12636 run_test 207a "can refresh layout at glimpse"
12637
12638 test_207b() {
12639         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12640         local cksum=`md5sum $DIR/$tfile`
12641         local fsz=`stat -c %s $DIR/$tfile`
12642         cancel_lru_locks mdc
12643         cancel_lru_locks osc
12644
12645         # do not return layout in getattr intent
12646 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
12647         $LCTL set_param fail_loc=0x171
12648
12649         # it will refresh layout after the file is opened but before read issues
12650         echo checksum is "$cksum"
12651         echo "$cksum" |md5sum -c --quiet || error "file differs"
12652
12653         rm -rf $DIR/$tfile
12654 }
12655 run_test 207b "can refresh layout at open"
12656
12657 test_208() {
12658         # FIXME: in this test suite, only RD lease is used. This is okay
12659         # for now as only exclusive open is supported. After generic lease
12660         # is done, this test suite should be revised. - Jinshan
12661
12662         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12663         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
12664                 { skip "Need MDS version at least 2.4.52"; return 0; }
12665
12666         echo "==== test 1: verify get lease work"
12667         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
12668
12669         echo "==== test 2: verify lease can be broken by upcoming open"
12670         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12671         local PID=$!
12672         sleep 1
12673
12674         $MULTIOP $DIR/$tfile oO_RDONLY:c
12675         kill -USR1 $PID && wait $PID || error "break lease error"
12676
12677         echo "==== test 3: verify lease can't be granted if an open already exists"
12678         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
12679         local PID=$!
12680         sleep 1
12681
12682         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
12683         kill -USR1 $PID && wait $PID || error "open file error"
12684
12685         echo "==== test 4: lease can sustain over recovery"
12686         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
12687         PID=$!
12688         sleep 1
12689
12690         fail mds1
12691
12692         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
12693
12694         echo "==== test 5: lease broken can't be regained by replay"
12695         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12696         PID=$!
12697         sleep 1
12698
12699         # open file to break lease and then recovery
12700         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
12701         fail mds1
12702
12703         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
12704
12705         rm -f $DIR/$tfile
12706 }
12707 run_test 208 "Exclusive open"
12708
12709 test_209() {
12710         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
12711                 skip_env "must have disp_stripe" && return
12712
12713         touch $DIR/$tfile
12714         sync; sleep 5; sync;
12715
12716         echo 3 > /proc/sys/vm/drop_caches
12717         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12718
12719         # open/close 500 times
12720         for i in $(seq 500); do
12721                 cat $DIR/$tfile
12722         done
12723
12724         echo 3 > /proc/sys/vm/drop_caches
12725         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12726
12727         echo "before: $req_before, after: $req_after"
12728         [ $((req_after - req_before)) -ge 300 ] &&
12729                 error "open/close requests are not freed"
12730         return 0
12731 }
12732 run_test 209 "read-only open/close requests should be freed promptly"
12733
12734 test_212() {
12735         size=`date +%s`
12736         size=$((size % 8192 + 1))
12737         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
12738         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
12739         rm -f $DIR/f212 $DIR/f212.xyz
12740 }
12741 run_test 212 "Sendfile test ============================================"
12742
12743 test_213() {
12744         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
12745         cancel_lru_locks osc
12746         lctl set_param fail_loc=0x8000040f
12747         # generate a read lock
12748         cat $DIR/$tfile > /dev/null
12749         # write to the file, it will try to cancel the above read lock.
12750         cat /etc/hosts >> $DIR/$tfile
12751 }
12752 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
12753
12754 test_214() { # for bug 20133
12755         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
12756         for (( i=0; i < 340; i++ )) ; do
12757                 touch $DIR/$tdir/d214c/a$i
12758         done
12759
12760         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
12761         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
12762         ls $DIR/d214c || error "ls $DIR/d214c failed"
12763         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
12764         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
12765 }
12766 run_test 214 "hash-indexed directory test - bug 20133"
12767
12768 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
12769 create_lnet_proc_files() {
12770         lctl get_param -n $1 >$TMP/lnet_$1.sys || error "cannot read lnet.$1"
12771 }
12772
12773 # counterpart of create_lnet_proc_files
12774 remove_lnet_proc_files() {
12775         rm -f $TMP/lnet_$1.sys
12776 }
12777
12778 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12779 # 3rd arg as regexp for body
12780 check_lnet_proc_stats() {
12781         local l=$(cat "$TMP/lnet_$1" |wc -l)
12782         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
12783
12784         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
12785 }
12786
12787 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12788 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
12789 # optional and can be regexp for 2nd line (lnet.routes case)
12790 check_lnet_proc_entry() {
12791         local blp=2          # blp stands for 'position of 1st line of body'
12792         [ -z "$5" ] || blp=3 # lnet.routes case
12793
12794         local l=$(cat "$TMP/lnet_$1" |wc -l)
12795         # subtracting one from $blp because the body can be empty
12796         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
12797
12798         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
12799                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
12800
12801         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
12802                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
12803
12804         # bail out if any unexpected line happened
12805         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
12806         [ "$?" != 0 ] || error "$2 misformatted"
12807 }
12808
12809 test_215() { # for bugs 18102, 21079, 21517
12810         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12811         local N='(0|[1-9][0-9]*)'       # non-negative numeric
12812         local P='[1-9][0-9]*'           # positive numeric
12813         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
12814         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
12815         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
12816         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
12817
12818         local L1 # regexp for 1st line
12819         local L2 # regexp for 2nd line (optional)
12820         local BR # regexp for the rest (body)
12821
12822         # lnet.stats should look as 11 space-separated non-negative numerics
12823         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
12824         create_lnet_proc_files "stats"
12825         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
12826         remove_lnet_proc_files "stats"
12827
12828         # lnet.routes should look like this:
12829         # Routing disabled/enabled
12830         # net hops priority state router
12831         # where net is a string like tcp0, hops > 0, priority >= 0,
12832         # state is up/down,
12833         # router is a string like 192.168.1.1@tcp2
12834         L1="^Routing (disabled|enabled)$"
12835         L2="^net +hops +priority +state +router$"
12836         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
12837         create_lnet_proc_files "routes"
12838         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
12839         remove_lnet_proc_files "routes"
12840
12841         # lnet.routers should look like this:
12842         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
12843         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
12844         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
12845         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
12846         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
12847         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
12848         create_lnet_proc_files "routers"
12849         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
12850         remove_lnet_proc_files "routers"
12851
12852         # lnet.peers should look like this:
12853         # nid refs state last max rtr min tx min queue
12854         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
12855         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
12856         # numeric (0 or >0 or <0), queue >= 0.
12857         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
12858         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
12859         create_lnet_proc_files "peers"
12860         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
12861         remove_lnet_proc_files "peers"
12862
12863         # lnet.buffers  should look like this:
12864         # pages count credits min
12865         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
12866         L1="^pages +count +credits +min$"
12867         BR="^ +$N +$N +$I +$I$"
12868         create_lnet_proc_files "buffers"
12869         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
12870         remove_lnet_proc_files "buffers"
12871
12872         # lnet.nis should look like this:
12873         # nid status alive refs peer rtr max tx min
12874         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
12875         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
12876         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
12877         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
12878         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
12879         create_lnet_proc_files "nis"
12880         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
12881         remove_lnet_proc_files "nis"
12882
12883         # can we successfully write to lnet.stats?
12884         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
12885 }
12886 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
12887
12888 test_216() { # bug 20317
12889         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12890         remote_ost_nodsh && skip "remote OST with nodsh" && return
12891
12892         local node
12893         local facets=$(get_facets OST)
12894         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
12895
12896         save_lustre_params client "osc.*.contention_seconds" > $p
12897         save_lustre_params $facets \
12898                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
12899         save_lustre_params $facets \
12900                 "ldlm.namespaces.filter-*.contended_locks" >> $p
12901         save_lustre_params $facets \
12902                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
12903         clear_stats osc.*.osc_stats
12904
12905         # agressive lockless i/o settings
12906         do_nodes $(comma_list $(osts_nodes)) \
12907                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
12908                         ldlm.namespaces.filter-*.contended_locks=0 \
12909                         ldlm.namespaces.filter-*.contention_seconds=60"
12910         lctl set_param -n osc.*.contention_seconds=60
12911
12912         $DIRECTIO write $DIR/$tfile 0 10 4096
12913         $CHECKSTAT -s 40960 $DIR/$tfile
12914
12915         # disable lockless i/o
12916         do_nodes $(comma_list $(osts_nodes)) \
12917                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
12918                         ldlm.namespaces.filter-*.contended_locks=32 \
12919                         ldlm.namespaces.filter-*.contention_seconds=0"
12920         lctl set_param -n osc.*.contention_seconds=0
12921         clear_stats osc.*.osc_stats
12922
12923         dd if=/dev/zero of=$DIR/$tfile count=0
12924         $CHECKSTAT -s 0 $DIR/$tfile
12925
12926         restore_lustre_params <$p
12927         rm -f $p
12928         rm $DIR/$tfile
12929 }
12930 run_test 216 "check lockless direct write updates file size and kms correctly"
12931
12932 test_217() { # bug 22430
12933         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12934         local node
12935         local nid
12936
12937         for node in $(nodes_list); do
12938                 nid=$(host_nids_address $node $NETTYPE)
12939                 if [[ $nid = *-* ]] ; then
12940                         echo "lctl ping $(h2nettype $nid)"
12941                         lctl ping $(h2nettype $nid)
12942                 else
12943                         echo "skipping $node (no hyphen detected)"
12944                 fi
12945         done
12946 }
12947 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
12948
12949 test_218() {
12950        # do directio so as not to populate the page cache
12951        log "creating a 10 Mb file"
12952        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12953        log "starting reads"
12954        dd if=$DIR/$tfile of=/dev/null bs=4096 &
12955        log "truncating the file"
12956        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12957        log "killing dd"
12958        kill %+ || true # reads might have finished
12959        echo "wait until dd is finished"
12960        wait
12961        log "removing the temporary file"
12962        rm -rf $DIR/$tfile || error "tmp file removal failed"
12963 }
12964 run_test 218 "parallel read and truncate should not deadlock ======================="
12965
12966 test_219() {
12967         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12968         # write one partial page
12969         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
12970         # set no grant so vvp_io_commit_write will do sync write
12971         $LCTL set_param fail_loc=0x411
12972         # write a full page at the end of file
12973         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
12974
12975         $LCTL set_param fail_loc=0
12976         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
12977         $LCTL set_param fail_loc=0x411
12978         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
12979
12980         # LU-4201
12981         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
12982         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
12983 }
12984 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
12985
12986 test_220() { #LU-325
12987         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12988         remote_ost_nodsh && skip "remote OST with nodsh" && return
12989         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12990         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12991         local OSTIDX=0
12992
12993         # create on MDT0000 so the last_id and next_id are correct
12994         mkdir $DIR/$tdir
12995         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
12996         OST=${OST%_UUID}
12997
12998         # on the mdt's osc
12999         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
13000         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
13001                         osc.$mdtosc_proc1.prealloc_last_id)
13002         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
13003                         osc.$mdtosc_proc1.prealloc_next_id)
13004
13005         $LFS df -i
13006
13007         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
13008         #define OBD_FAIL_OST_ENOINO              0x229
13009         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
13010         create_pool $FSNAME.$TESTNAME || return 1
13011         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
13012
13013         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
13014
13015         MDSOBJS=$((last_id - next_id))
13016         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
13017
13018         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
13019         echo "OST still has $count kbytes free"
13020
13021         echo "create $MDSOBJS files @next_id..."
13022         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
13023
13024         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
13025                         osc.$mdtosc_proc1.prealloc_last_id)
13026         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
13027                         osc.$mdtosc_proc1.prealloc_next_id)
13028
13029         echo "after creation, last_id=$last_id2, next_id=$next_id2"
13030         $LFS df -i
13031
13032         echo "cleanup..."
13033
13034         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
13035         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
13036
13037         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
13038         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
13039         echo "unlink $MDSOBJS files @$next_id..."
13040         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
13041 }
13042 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
13043
13044 test_221() {
13045         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13046         dd if=`which date` of=$MOUNT/date oflag=sync
13047         chmod +x $MOUNT/date
13048
13049         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
13050         $LCTL set_param fail_loc=0x80001401
13051
13052         $MOUNT/date > /dev/null
13053         rm -f $MOUNT/date
13054 }
13055 run_test 221 "make sure fault and truncate race to not cause OOM"
13056
13057 test_222a () {
13058         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13059         rm -rf $DIR/$tdir
13060         test_mkdir $DIR/$tdir
13061         $LFS setstripe -c 1 -i 0 $DIR/$tdir
13062         createmany -o $DIR/$tdir/$tfile 10
13063         cancel_lru_locks mdc
13064         cancel_lru_locks osc
13065         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
13066         $LCTL set_param fail_loc=0x31a
13067         ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
13068         $LCTL set_param fail_loc=0
13069         rm -r $DIR/$tdir
13070 }
13071 run_test 222a "AGL for ls should not trigger CLIO lock failure"
13072
13073 test_222b () {
13074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13075         rm -rf $DIR/$tdir
13076         test_mkdir $DIR/$tdir
13077         $LFS setstripe -c 1 -i 0 $DIR/$tdir
13078         createmany -o $DIR/$tdir/$tfile 10
13079         cancel_lru_locks mdc
13080         cancel_lru_locks osc
13081         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
13082         $LCTL set_param fail_loc=0x31a
13083         rm -r $DIR/$tdir || error "AGL for rmdir failed"
13084         $LCTL set_param fail_loc=0
13085 }
13086 run_test 222b "AGL for rmdir should not trigger CLIO lock failure"
13087
13088 test_223 () {
13089         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13090         rm -rf $DIR/$tdir
13091         test_mkdir $DIR/$tdir
13092         $LFS setstripe -c 1 -i 0 $DIR/$tdir
13093         createmany -o $DIR/$tdir/$tfile 10
13094         cancel_lru_locks mdc
13095         cancel_lru_locks osc
13096         #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
13097         $LCTL set_param fail_loc=0x31b
13098         ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
13099         $LCTL set_param fail_loc=0
13100         rm -r $DIR/$tdir
13101 }
13102 run_test 223 "osc reenqueue if without AGL lock granted ======================="
13103
13104 test_224a() { # LU-1039, MRP-303
13105         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13106         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
13107         $LCTL set_param fail_loc=0x508
13108         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
13109         $LCTL set_param fail_loc=0
13110         df $DIR
13111 }
13112 run_test 224a "Don't panic on bulk IO failure"
13113
13114 test_224b() { # LU-1039, MRP-303
13115         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13116         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
13117         cancel_lru_locks osc
13118         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
13119         $LCTL set_param fail_loc=0x515
13120         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
13121         $LCTL set_param fail_loc=0
13122         df $DIR
13123 }
13124 run_test 224b "Don't panic on bulk IO failure"
13125
13126 test_224c() { # LU-6441
13127         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13128         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13129
13130         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13131         save_writethrough $p
13132         set_cache writethrough on
13133
13134         local pages_per_rpc=$($LCTL get_param \
13135                                 osc.*.max_pages_per_rpc)
13136         local at_max=$($LCTL get_param -n at_max)
13137         local timeout=$($LCTL get_param -n timeout)
13138         local test_at="$LCTL get_param -n at_max"
13139         local param_at="$FSNAME.sys.at_max"
13140         local test_timeout="$LCTL get_param -n timeout"
13141         local param_timeout="$FSNAME.sys.timeout"
13142
13143         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
13144
13145         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
13146                 error "conf_param at_max=0 failed"
13147         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
13148                 error "conf_param timeout=5 failed"
13149
13150         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
13151         do_facet ost1 $LCTL set_param fail_loc=0x520
13152         $LFS setstripe -c 1 -i 0 $DIR/$tfile
13153         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
13154         sync
13155         do_facet ost1 $LCTL set_param fail_loc=0
13156
13157         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
13158                 error "conf_param at_max=$at_max failed"
13159         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
13160                 $timeout || error "conf_param timeout=$timeout failed"
13161
13162         $LCTL set_param -n $pages_per_rpc
13163         restore_lustre_params < $p
13164         rm -f $p
13165 }
13166 run_test 224c "Don't hang if one of md lost during large bulk RPC"
13167
13168 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
13169 test_225a () {
13170         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13171         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13172         if [ -z ${MDSSURVEY} ]; then
13173               skip_env "mds-survey not found" && return
13174         fi
13175
13176         [ $MDSCOUNT -ge 2 ] &&
13177                 skip "skipping now for more than one MDT" && return
13178
13179        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13180             { skip "Need MDS version at least 2.2.51"; return; }
13181
13182        local mds=$(facet_host $SINGLEMDS)
13183        local target=$(do_nodes $mds 'lctl dl' | \
13184                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13185
13186        local cmd1="file_count=1000 thrhi=4"
13187        local cmd2="dir_count=2 layer=mdd stripe_count=0"
13188        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13189        local cmd="$cmd1 $cmd2 $cmd3"
13190
13191        rm -f ${TMP}/mds_survey*
13192        echo + $cmd
13193        eval $cmd || error "mds-survey with zero-stripe failed"
13194        cat ${TMP}/mds_survey*
13195        rm -f ${TMP}/mds_survey*
13196 }
13197 run_test 225a "Metadata survey sanity with zero-stripe"
13198
13199 test_225b () {
13200         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13201         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13202         if [ -z ${MDSSURVEY} ]; then
13203               skip_env "mds-survey not found" && return
13204         fi
13205         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13206             { skip "Need MDS version at least 2.2.51"; return; }
13207
13208         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
13209               skip_env "Need to mount OST to test" && return
13210         fi
13211
13212         [ $MDSCOUNT -ge 2 ] &&
13213                 skip "skipping now for more than one MDT" && return
13214        local mds=$(facet_host $SINGLEMDS)
13215        local target=$(do_nodes $mds 'lctl dl' | \
13216                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13217
13218        local cmd1="file_count=1000 thrhi=4"
13219        local cmd2="dir_count=2 layer=mdd stripe_count=1"
13220        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13221        local cmd="$cmd1 $cmd2 $cmd3"
13222
13223        rm -f ${TMP}/mds_survey*
13224        echo + $cmd
13225        eval $cmd || error "mds-survey with stripe_count failed"
13226        cat ${TMP}/mds_survey*
13227        rm -f ${TMP}/mds_survey*
13228 }
13229 run_test 225b "Metadata survey sanity with stripe_count = 1"
13230
13231 mcreate_path2fid () {
13232         local mode=$1
13233         local major=$2
13234         local minor=$3
13235         local name=$4
13236         local desc=$5
13237         local path=$DIR/$tdir/$name
13238         local fid
13239         local rc
13240         local fid_path
13241
13242         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
13243                 error "cannot create $desc"
13244
13245         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
13246         rc=$?
13247         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
13248
13249         fid_path=$($LFS fid2path $MOUNT $fid)
13250         rc=$?
13251         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
13252
13253         [ "$path" == "$fid_path" ] ||
13254                 error "fid2path returned $fid_path, expected $path"
13255
13256         echo "pass with $path and $fid"
13257 }
13258
13259 test_226a () {
13260         rm -rf $DIR/$tdir
13261         mkdir -p $DIR/$tdir
13262
13263         mcreate_path2fid 0010666 0 0 fifo "FIFO"
13264         mcreate_path2fid 0020666 1 3 null "character special file (null)"
13265         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
13266         mcreate_path2fid 0040666 0 0 dir "directory"
13267         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
13268         mcreate_path2fid 0100666 0 0 file "regular file"
13269         mcreate_path2fid 0120666 0 0 link "symbolic link"
13270         mcreate_path2fid 0140666 0 0 sock "socket"
13271 }
13272 run_test 226a "call path2fid and fid2path on files of all type"
13273
13274 test_226b () {
13275         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13276         rm -rf $DIR/$tdir
13277         local MDTIDX=1
13278
13279         mkdir -p $DIR/$tdir
13280         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
13281                 error "create remote directory failed"
13282         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
13283         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
13284                                 "character special file (null)"
13285         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
13286                                 "character special file (no device)"
13287         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
13288         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
13289                                 "block special file (loop)"
13290         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
13291         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
13292         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
13293 }
13294 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
13295
13296 # LU-1299 Executing or running ldd on a truncated executable does not
13297 # cause an out-of-memory condition.
13298 test_227() {
13299         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13300         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
13301         dd if=$(which date) of=$MOUNT/date bs=1k count=1
13302         chmod +x $MOUNT/date
13303
13304         $MOUNT/date > /dev/null
13305         ldd $MOUNT/date > /dev/null
13306         rm -f $MOUNT/date
13307 }
13308 run_test 227 "running truncated executable does not cause OOM"
13309
13310 # LU-1512 try to reuse idle OI blocks
13311 test_228a() {
13312         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13313         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13314         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13315                 skip "ldiskfs only test" && return
13316
13317         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13318         local myDIR=$DIR/$tdir
13319
13320         mkdir -p $myDIR
13321         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13322         $LCTL set_param fail_loc=0x80001002
13323         createmany -o $myDIR/t- 10000
13324         $LCTL set_param fail_loc=0
13325         # The guard is current the largest FID holder
13326         touch $myDIR/guard
13327         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13328                     tr -d '[')
13329         local IDX=$(($SEQ % 64))
13330
13331         do_facet $SINGLEMDS sync
13332         # Make sure journal flushed.
13333         sleep 6
13334         local blk1=$(do_facet $SINGLEMDS \
13335                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13336                      grep Blockcount | awk '{print $4}')
13337
13338         # Remove old files, some OI blocks will become idle.
13339         unlinkmany $myDIR/t- 10000
13340         # Create new files, idle OI blocks should be reused.
13341         createmany -o $myDIR/t- 2000
13342         do_facet $SINGLEMDS sync
13343         # Make sure journal flushed.
13344         sleep 6
13345         local blk2=$(do_facet $SINGLEMDS \
13346                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13347                      grep Blockcount | awk '{print $4}')
13348
13349         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13350 }
13351 run_test 228a "try to reuse idle OI blocks"
13352
13353 test_228b() {
13354         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13355         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13356         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13357                 skip "ldiskfs only test" && return
13358
13359         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13360         local myDIR=$DIR/$tdir
13361
13362         mkdir -p $myDIR
13363         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13364         $LCTL set_param fail_loc=0x80001002
13365         createmany -o $myDIR/t- 10000
13366         $LCTL set_param fail_loc=0
13367         # The guard is current the largest FID holder
13368         touch $myDIR/guard
13369         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13370                     tr -d '[')
13371         local IDX=$(($SEQ % 64))
13372
13373         do_facet $SINGLEMDS sync
13374         # Make sure journal flushed.
13375         sleep 6
13376         local blk1=$(do_facet $SINGLEMDS \
13377                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13378                      grep Blockcount | awk '{print $4}')
13379
13380         # Remove old files, some OI blocks will become idle.
13381         unlinkmany $myDIR/t- 10000
13382
13383         # stop the MDT
13384         stop $SINGLEMDS || error "Fail to stop MDT."
13385         # remount the MDT
13386         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
13387
13388         df $MOUNT || error "Fail to df."
13389         # Create new files, idle OI blocks should be reused.
13390         createmany -o $myDIR/t- 2000
13391         do_facet $SINGLEMDS sync
13392         # Make sure journal flushed.
13393         sleep 6
13394         local blk2=$(do_facet $SINGLEMDS \
13395                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13396                      grep Blockcount | awk '{print $4}')
13397
13398         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13399 }
13400 run_test 228b "idle OI blocks can be reused after MDT restart"
13401
13402 #LU-1881
13403 test_228c() {
13404         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13405         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13406         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13407                 skip "ldiskfs only test" && return
13408
13409         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13410         local myDIR=$DIR/$tdir
13411
13412         mkdir -p $myDIR
13413         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13414         $LCTL set_param fail_loc=0x80001002
13415         # 20000 files can guarantee there are index nodes in the OI file
13416         createmany -o $myDIR/t- 20000
13417         $LCTL set_param fail_loc=0
13418         # The guard is current the largest FID holder
13419         touch $myDIR/guard
13420         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13421                     tr -d '[')
13422         local IDX=$(($SEQ % 64))
13423
13424         do_facet $SINGLEMDS sync
13425         # Make sure journal flushed.
13426         sleep 6
13427         local blk1=$(do_facet $SINGLEMDS \
13428                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13429                      grep Blockcount | awk '{print $4}')
13430
13431         # Remove old files, some OI blocks will become idle.
13432         unlinkmany $myDIR/t- 20000
13433         rm -f $myDIR/guard
13434         # The OI file should become empty now
13435
13436         # Create new files, idle OI blocks should be reused.
13437         createmany -o $myDIR/t- 2000
13438         do_facet $SINGLEMDS sync
13439         # Make sure journal flushed.
13440         sleep 6
13441         local blk2=$(do_facet $SINGLEMDS \
13442                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13443                      grep Blockcount | awk '{print $4}')
13444
13445         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13446 }
13447 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
13448
13449 test_229() { # LU-2482, LU-3448
13450         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
13451                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
13452                 return
13453         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13454         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
13455
13456         rm -f $DIR/$tfile
13457
13458         # Create a file with a released layout and stripe count 2.
13459         $MULTIOP $DIR/$tfile H2c ||
13460                 error "failed to create file with released layout"
13461
13462         $GETSTRIPE -v $DIR/$tfile
13463
13464         local pattern=$($GETSTRIPE -L $DIR/$tfile)
13465         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
13466
13467         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
13468         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
13469         stat $DIR/$tfile || error "failed to stat released file"
13470
13471         chown $RUNAS_ID $DIR/$tfile ||
13472                 error "chown $RUNAS_ID $DIR/$tfile failed"
13473
13474         chgrp $RUNAS_ID $DIR/$tfile ||
13475                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
13476
13477         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
13478         rm $DIR/$tfile || error "failed to remove released file"
13479 }
13480 run_test 229 "getstripe/stat/rm/attr changes work on released files"
13481
13482 test_230a() {
13483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13484         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13485         local MDTIDX=1
13486
13487         test_mkdir $DIR/$tdir
13488         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
13489         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
13490         [ $mdt_idx -ne 0 ] &&
13491                 error "create local directory on wrong MDT $mdt_idx"
13492
13493         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
13494                         error "create remote directory failed"
13495         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
13496         [ $mdt_idx -ne $MDTIDX ] &&
13497                 error "create remote directory on wrong MDT $mdt_idx"
13498
13499         createmany -o $DIR/$tdir/test_230/t- 10 ||
13500                 error "create files on remote directory failed"
13501         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
13502         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
13503         rm -r $DIR/$tdir || error "unlink remote directory failed"
13504 }
13505 run_test 230a "Create remote directory and files under the remote directory"
13506
13507 test_230b() {
13508         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13509         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13510         local MDTIDX=1
13511         local mdt_index
13512         local i
13513         local file
13514         local pid
13515         local stripe_count
13516         local migrate_dir=$DIR/$tdir/migrate_dir
13517         local other_dir=$DIR/$tdir/other_dir
13518
13519         test_mkdir $DIR/$tdir
13520         test_mkdir -i0 -c1 $migrate_dir
13521         test_mkdir -i0 -c1 $other_dir
13522         for ((i=0; i<10; i++)); do
13523                 mkdir -p $migrate_dir/dir_${i}
13524                 createmany -o $migrate_dir/dir_${i}/f 10 ||
13525                         error "create files under remote dir failed $i"
13526         done
13527
13528         cp /etc/passwd $migrate_dir/$tfile
13529         cp /etc/passwd $other_dir/$tfile
13530         chattr +SAD $migrate_dir
13531         chattr +SAD $migrate_dir/$tfile
13532
13533         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13534         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13535         local old_dir_mode=$(stat -c%f $migrate_dir)
13536         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
13537
13538         mkdir -p $migrate_dir/dir_default_stripe2
13539         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
13540         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
13541
13542         mkdir -p $other_dir
13543         ln $migrate_dir/$tfile $other_dir/luna
13544         ln $migrate_dir/$tfile $migrate_dir/sofia
13545         ln $other_dir/$tfile $migrate_dir/david
13546         ln -s $migrate_dir/$tfile $other_dir/zachary
13547         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
13548         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
13549
13550         $LFS migrate -m $MDTIDX $migrate_dir ||
13551                 error "fails on migrating remote dir to MDT1"
13552
13553         echo "migratate to MDT1, then checking.."
13554         for ((i = 0; i < 10; i++)); do
13555                 for file in $(find $migrate_dir/dir_${i}); do
13556                         mdt_index=$($LFS getstripe -M $file)
13557                         [ $mdt_index == $MDTIDX ] ||
13558                                 error "$file is not on MDT${MDTIDX}"
13559                 done
13560         done
13561
13562         # the multiple link file should still in MDT0
13563         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
13564         [ $mdt_index == 0 ] ||
13565                 error "$file is not on MDT${MDTIDX}"
13566
13567         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13568         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13569                 error " expect $old_dir_flag get $new_dir_flag"
13570
13571         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13572         [ "$old_file_flag" = "$new_file_flag" ] ||
13573                 error " expect $old_file_flag get $new_file_flag"
13574
13575         local new_dir_mode=$(stat -c%f $migrate_dir)
13576         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13577                 error "expect mode $old_dir_mode get $new_dir_mode"
13578
13579         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13580         [ "$old_file_mode" = "$new_file_mode" ] ||
13581                 error "expect mode $old_file_mode get $new_file_mode"
13582
13583         diff /etc/passwd $migrate_dir/$tfile ||
13584                 error "$tfile different after migration"
13585
13586         diff /etc/passwd $other_dir/luna ||
13587                 error "luna different after migration"
13588
13589         diff /etc/passwd $migrate_dir/sofia ||
13590                 error "sofia different after migration"
13591
13592         diff /etc/passwd $migrate_dir/david ||
13593                 error "david different after migration"
13594
13595         diff /etc/passwd $other_dir/zachary ||
13596                 error "zachary different after migration"
13597
13598         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13599                 error "${tfile}_ln different after migration"
13600
13601         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13602                 error "${tfile}_ln_other different after migration"
13603
13604         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
13605         [ $stripe_count = 2 ] ||
13606                 error "dir strpe_count $d != 2 after migration."
13607
13608         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
13609         [ $stripe_count = 2 ] ||
13610                 error "file strpe_count $d != 2 after migration."
13611
13612         #migrate back to MDT0
13613         MDTIDX=0
13614
13615         $LFS migrate -m $MDTIDX $migrate_dir ||
13616                 error "fails on migrating remote dir to MDT0"
13617
13618         echo "migrate back to MDT0, checking.."
13619         for file in $(find $migrate_dir); do
13620                 mdt_index=$($LFS getstripe -M $file)
13621                 [ $mdt_index == $MDTIDX ] ||
13622                         error "$file is not on MDT${MDTIDX}"
13623         done
13624
13625         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13626         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13627                 error " expect $old_dir_flag get $new_dir_flag"
13628
13629         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13630         [ "$old_file_flag" = "$new_file_flag" ] ||
13631                 error " expect $old_file_flag get $new_file_flag"
13632
13633         local new_dir_mode=$(stat -c%f $migrate_dir)
13634         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13635                 error "expect mode $old_dir_mode get $new_dir_mode"
13636
13637         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13638         [ "$old_file_mode" = "$new_file_mode" ] ||
13639                 error "expect mode $old_file_mode get $new_file_mode"
13640
13641         diff /etc/passwd ${migrate_dir}/$tfile ||
13642                 error "$tfile different after migration"
13643
13644         diff /etc/passwd ${other_dir}/luna ||
13645                 error "luna different after migration"
13646
13647         diff /etc/passwd ${migrate_dir}/sofia ||
13648                 error "sofia different after migration"
13649
13650         diff /etc/passwd ${other_dir}/zachary ||
13651                 error "zachary different after migration"
13652
13653         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13654                 error "${tfile}_ln different after migration"
13655
13656         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13657                 error "${tfile}_ln_other different after migration"
13658
13659         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
13660         [ $stripe_count = 2 ] ||
13661                 error "dir strpe_count $d != 2 after migration."
13662
13663         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
13664         [ $stripe_count = 2 ] ||
13665                 error "file strpe_count $d != 2 after migration."
13666
13667         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13668 }
13669 run_test 230b "migrate directory"
13670
13671 test_230c() {
13672         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13673         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13674         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13675         local MDTIDX=1
13676         local mdt_index
13677         local file
13678         local migrate_dir=$DIR/$tdir/migrate_dir
13679
13680         #If migrating directory fails in the middle, all entries of
13681         #the directory is still accessiable.
13682         test_mkdir $DIR/$tdir
13683         test_mkdir -i0 -c1 $migrate_dir
13684         stat $migrate_dir
13685         createmany -o $migrate_dir/f 10 ||
13686                 error "create files under ${migrate_dir} failed"
13687
13688         #failed after migrating 5 entries
13689         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
13690         do_facet mds1 lctl set_param fail_loc=0x20001801
13691         do_facet mds1 lctl  set_param fail_val=5
13692         local t=$(ls $migrate_dir | wc -l)
13693         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
13694                 error "migrate should fail after 5 entries"
13695
13696         mkdir $migrate_dir/dir &&
13697                 error "mkdir succeeds under migrating directory"
13698         touch $migrate_dir/file &&
13699                 error "touch file succeeds under migrating directory"
13700
13701         local u=$(ls $migrate_dir | wc -l)
13702         [ "$u" == "$t" ] || error "$u != $t during migration"
13703
13704         for file in $(find $migrate_dir); do
13705                 stat $file || error "stat $file failed"
13706         done
13707
13708         do_facet mds1 lctl set_param fail_loc=0
13709         do_facet mds1 lctl set_param fail_val=0
13710
13711         $LFS migrate -m $MDTIDX $migrate_dir ||
13712                 error "migrate open files should failed with open files"
13713
13714         echo "Finish migration, then checking.."
13715         for file in $(find $migrate_dir); do
13716                 mdt_index=$($LFS getstripe -M $file)
13717                 [ $mdt_index == $MDTIDX ] ||
13718                         error "$file is not on MDT${MDTIDX}"
13719         done
13720
13721         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13722 }
13723 run_test 230c "check directory accessiblity if migration is failed"
13724
13725 test_230d() {
13726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13727         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13728         local MDTIDX=1
13729         local mdt_index
13730         local migrate_dir=$DIR/$tdir/migrate_dir
13731         local i
13732         local j
13733
13734         test_mkdir $DIR/$tdir
13735         test_mkdir -i0 -c1 $migrate_dir
13736
13737         for ((i=0; i<100; i++)); do
13738                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
13739                 createmany -o $migrate_dir/dir_${i}/f 100 ||
13740                         error "create files under remote dir failed $i"
13741         done
13742
13743         $LFS migrate -m $MDTIDX $migrate_dir ||
13744                 error "migrate remote dir error"
13745
13746         echo "Finish migration, then checking.."
13747         for file in $(find $migrate_dir); do
13748                 mdt_index=$($LFS getstripe -M $file)
13749                 [ $mdt_index == $MDTIDX ] ||
13750                         error "$file is not on MDT${MDTIDX}"
13751         done
13752
13753         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13754 }
13755 run_test 230d "check migrate big directory"
13756
13757 test_230e() {
13758         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13759         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13760         local i
13761         local j
13762         local a_fid
13763         local b_fid
13764
13765         mkdir -p $DIR/$tdir
13766         mkdir $DIR/$tdir/migrate_dir
13767         mkdir $DIR/$tdir/other_dir
13768         touch $DIR/$tdir/migrate_dir/a
13769         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
13770         ls $DIR/$tdir/other_dir
13771
13772         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13773                 error "migrate dir fails"
13774
13775         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13776         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13777
13778         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13779         [ $mdt_index == 0 ] || error "a is not on MDT0"
13780
13781         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
13782                 error "migrate dir fails"
13783
13784         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
13785         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
13786
13787         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13788         [ $mdt_index == 1 ] || error "a is not on MDT1"
13789
13790         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
13791         [ $mdt_index == 1 ] || error "b is not on MDT1"
13792
13793         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13794         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
13795
13796         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
13797
13798         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13799 }
13800 run_test 230e "migrate mulitple local link files"
13801
13802 test_230f() {
13803         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13804         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13805         local a_fid
13806         local ln_fid
13807
13808         mkdir -p $DIR/$tdir
13809         mkdir $DIR/$tdir/migrate_dir
13810         $LFS mkdir -i1 $DIR/$tdir/other_dir
13811         touch $DIR/$tdir/migrate_dir/a
13812         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
13813         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
13814         ls $DIR/$tdir/other_dir
13815
13816         # a should be migrated to MDT1, since no other links on MDT0
13817         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13818                 error "#1 migrate dir fails"
13819         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13820         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13821         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13822         [ $mdt_index == 1 ] || error "a is not on MDT1"
13823
13824         # a should stay on MDT1, because it is a mulitple link file
13825         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13826                 error "#2 migrate dir fails"
13827         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13828         [ $mdt_index == 1 ] || error "a is not on MDT1"
13829
13830         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13831                 error "#3 migrate dir fails"
13832
13833         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13834         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
13835         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
13836
13837         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
13838         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
13839
13840         # a should be migrated to MDT0, since no other links on MDT1
13841         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13842                 error "#4 migrate dir fails"
13843         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13844         [ $mdt_index == 0 ] || error "a is not on MDT0"
13845
13846         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13847 }
13848 run_test 230f "migrate mulitple remote link files"
13849
13850 test_230g() {
13851         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13852         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13853
13854         mkdir -p $DIR/$tdir/migrate_dir
13855
13856         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
13857                 error "migrating dir to non-exist MDT succeeds"
13858         true
13859 }
13860 run_test 230g "migrate dir to non-exist MDT"
13861
13862 test_230h() {
13863         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13864         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13865         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
13866                 skip "Need MDS version at least 2.7.64" && return
13867         local mdt_index
13868
13869         mkdir -p $DIR/$tdir/migrate_dir
13870
13871         $LFS migrate -m1 $DIR &&
13872                 error "migrating mountpoint1 should fail"
13873
13874         $LFS migrate -m1 $DIR/$tdir/.. &&
13875                 error "migrating mountpoint2 should fail"
13876
13877         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
13878                 error "migrating $tdir fail"
13879
13880         mdt_index=$($LFS getstripe -M $DIR/$tdir)
13881         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13882
13883         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13884         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13885
13886 }
13887 run_test 230h "migrate .. and root"
13888
13889 test_230i() {
13890         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13891         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13892
13893         mkdir -p $DIR/$tdir/migrate_dir
13894
13895         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
13896                 error "migration fails with a tailing slash"
13897
13898         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
13899                 error "migration fails with two tailing slashes"
13900 }
13901 run_test 230i "lfs migrate -m tolerates trailing slashes"
13902
13903 test_231a()
13904 {
13905         # For simplicity this test assumes that max_pages_per_rpc
13906         # is the same across all OSCs
13907         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
13908         local bulk_size=$((max_pages * 4096))
13909         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
13910                                        head -n 1)
13911
13912         mkdir -p $DIR/$tdir
13913         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
13914                 error "failed to set stripe with -S ${brw_size}M option"
13915
13916         # clear the OSC stats
13917         $LCTL set_param osc.*.stats=0 &>/dev/null
13918         stop_writeback
13919
13920         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
13921         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
13922                 oflag=direct &>/dev/null || error "dd failed"
13923
13924         sync; sleep 1; sync # just to be safe
13925         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
13926         if [ x$nrpcs != "x1" ]; then
13927                 $LCTL get_param osc.*.stats
13928                 error "found $nrpcs ost_write RPCs, not 1 as expected"
13929         fi
13930
13931         start_writeback
13932         # Drop the OSC cache, otherwise we will read from it
13933         cancel_lru_locks osc
13934
13935         # clear the OSC stats
13936         $LCTL set_param osc.*.stats=0 &>/dev/null
13937
13938         # Client reads $bulk_size.
13939         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
13940                 iflag=direct &>/dev/null || error "dd failed"
13941
13942         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
13943         if [ x$nrpcs != "x1" ]; then
13944                 $LCTL get_param osc.*.stats
13945                 error "found $nrpcs ost_read RPCs, not 1 as expected"
13946         fi
13947 }
13948 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
13949
13950 test_231b() {
13951         mkdir -p $DIR/$tdir
13952         local i
13953         for i in {0..1023}; do
13954                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
13955                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
13956                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
13957         done
13958         sync
13959 }
13960 run_test 231b "must not assert on fully utilized OST request buffer"
13961
13962 test_232() {
13963         mkdir -p $DIR/$tdir
13964         #define OBD_FAIL_LDLM_OST_LVB            0x31c
13965         $LCTL set_param fail_loc=0x31c
13966
13967         # ignore dd failure
13968         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
13969
13970         $LCTL set_param fail_loc=0
13971         umount_client $MOUNT || error "umount failed"
13972         mount_client $MOUNT || error "mount failed"
13973 }
13974 run_test 232 "failed lock should not block umount"
13975
13976 test_233a() {
13977         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
13978         { skip "Need MDS version at least 2.3.64"; return; }
13979         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13980
13981         local fid=$($LFS path2fid $MOUNT)
13982         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13983                 error "cannot access $MOUNT using its FID '$fid'"
13984 }
13985 run_test 233a "checking that OBF of the FS root succeeds"
13986
13987 test_233b() {
13988         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
13989         { skip "Need MDS version at least 2.5.90"; return; }
13990         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13991
13992         local fid=$($LFS path2fid $MOUNT/.lustre)
13993         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13994                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
13995
13996         fid=$($LFS path2fid $MOUNT/.lustre/fid)
13997         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13998                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
13999 }
14000 run_test 233b "checking that OBF of the FS .lustre succeeds"
14001
14002 test_234() {
14003         local p="$TMP/sanityN-$TESTNAME.parameters"
14004         save_lustre_params client "llite.*.xattr_cache" > $p
14005         lctl set_param llite.*.xattr_cache 1 ||
14006                 { skip "xattr cache is not supported"; return 0; }
14007
14008         mkdir -p $DIR/$tdir || error "mkdir failed"
14009         touch $DIR/$tdir/$tfile || error "touch failed"
14010         # OBD_FAIL_LLITE_XATTR_ENOMEM
14011         $LCTL set_param fail_loc=0x1405
14012         # output of the form: attr 2 4 44 3 fc13 x86_64
14013         V=($(IFS=".-" rpm -q attr))
14014         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
14015               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
14016                 # attr pre-2.4.44-7 had a bug with rc
14017                 # LU-3703 - SLES 11 and FC13 clients have older attr
14018                 getfattr -n user.attr $DIR/$tdir/$tfile &&
14019                         error "getfattr should have failed with ENOMEM"
14020         else
14021                 skip "LU-3703: attr version $(getfattr --version) too old"
14022         fi
14023         $LCTL set_param fail_loc=0x0
14024         rm -rf $DIR/$tdir
14025
14026         restore_lustre_params < $p
14027         rm -f $p
14028 }
14029 run_test 234 "xattr cache should not crash on ENOMEM"
14030
14031 test_235() {
14032         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
14033                 skip "Need MDS version at least 2.4.52" && return
14034         flock_deadlock $DIR/$tfile
14035         local RC=$?
14036         case $RC in
14037                 0)
14038                 ;;
14039                 124) error "process hangs on a deadlock"
14040                 ;;
14041                 *) error "error executing flock_deadlock $DIR/$tfile"
14042                 ;;
14043         esac
14044 }
14045 run_test 235 "LU-1715: flock deadlock detection does not work properly"
14046
14047 #LU-2935
14048 test_236() {
14049         check_swap_layouts_support && return 0
14050         test_mkdir -c1 $DIR/$tdir
14051
14052         local ref1=/etc/passwd
14053         local ref2=/etc/group
14054         local file1=$DIR/$tdir/f1
14055         local file2=$DIR/$tdir/f2
14056
14057         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
14058         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
14059         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
14060         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
14061         local fd=$(free_fd)
14062         local cmd="exec $fd<>$file2"
14063         eval $cmd
14064         rm $file2
14065         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
14066                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
14067         cmd="exec $fd>&-"
14068         eval $cmd
14069         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
14070
14071         #cleanup
14072         rm -rf $DIR/$tdir
14073 }
14074 run_test 236 "Layout swap on open unlinked file"
14075
14076 # test to verify file handle related system calls
14077 # (name_to_handle_at/open_by_handle_at)
14078 # The new system calls are supported in glibc >= 2.14.
14079
14080 test_237() {
14081         echo "Test file_handle syscalls" > $DIR/$tfile ||
14082                 error "write failed"
14083         check_fhandle_syscalls $DIR/$tfile ||
14084                 error "check_fhandle_syscalls failed"
14085 }
14086 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
14087
14088 # LU-4659 linkea consistency
14089 test_238() {
14090         local server_version=$(lustre_version_code $SINGLEMDS)
14091
14092         [[ $server_version -gt $(version_code 2.5.57) ]] ||
14093                 [[ $server_version -gt $(version_code 2.5.1) &&
14094                    $server_version -lt $(version_code 2.5.50) ]] ||
14095                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
14096
14097         touch $DIR/$tfile
14098         ln $DIR/$tfile $DIR/$tfile.lnk
14099         touch $DIR/$tfile.new
14100         mv $DIR/$tfile.new $DIR/$tfile
14101         local fid1=$($LFS path2fid $DIR/$tfile)
14102         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
14103         local path1=$($LFS fid2path $FSNAME "$fid1")
14104         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
14105         local path2=$($LFS fid2path $FSNAME "$fid2")
14106         [ $tfile.lnk == $path2 ] ||
14107                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
14108         rm -f $DIR/$tfile*
14109 }
14110 run_test 238 "Verify linkea consistency"
14111
14112 test_239() {
14113         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
14114                 skip "Need MDS version at least 2.5.60" && return
14115         local list=$(comma_list $(mdts_nodes))
14116
14117         mkdir -p $DIR/$tdir
14118         createmany -o $DIR/$tdir/f- 5000
14119         unlinkmany $DIR/$tdir/f- 5000
14120         [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ] &&
14121                 do_nodes $list "lctl set_param -n osp.*.force_sync=1"
14122         changes=$(do_nodes $list "lctl get_param -n osp.*MDT*.sync_changes \
14123                         osp.*MDT*.sync_in_flight" | calc_sum)
14124         [ "$changes" -eq 0 ] || error "$changes not synced"
14125 }
14126 run_test 239 "osp_sync test"
14127
14128 test_239a() { #LU-5297
14129         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14130         touch $DIR/$tfile
14131         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
14132         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
14133         chgrp $RUNAS_GID $DIR/$tfile
14134         wait_delete_completed
14135 }
14136 run_test 239a "process invalid osp sync record correctly"
14137
14138 test_239b() { #LU-5297
14139         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14140         touch $DIR/$tfile1
14141         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
14142         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
14143         chgrp $RUNAS_GID $DIR/$tfile1
14144         wait_delete_completed
14145         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
14146         touch $DIR/$tfile2
14147         chgrp $RUNAS_GID $DIR/$tfile2
14148         wait_delete_completed
14149 }
14150 run_test 239b "process osp sync record with ENOMEM error correctly"
14151
14152 test_240() {
14153         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14154         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14155
14156         mkdir -p $DIR/$tdir
14157
14158         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
14159                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
14160         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
14161                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
14162
14163         umount_client $MOUNT || error "umount failed"
14164         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
14165         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
14166         mount_client $MOUNT || error "failed to mount client"
14167
14168         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
14169         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
14170 }
14171 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
14172
14173 test_241_bio() {
14174         for LOOP in $(seq $1); do
14175                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
14176                 cancel_lru_locks $OSC || true
14177         done
14178 }
14179
14180 test_241_dio() {
14181         for LOOP in $(seq $1); do
14182                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
14183                                                 iflag=direct 2>/dev/null
14184         done
14185 }
14186
14187 test_241a() { # was test_241
14188         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14189         ls -la $DIR/$tfile
14190         cancel_lru_locks $OSC
14191         test_241_bio 1000 &
14192         PID=$!
14193         test_241_dio 1000
14194         wait $PID
14195 }
14196 run_test 241a "bio vs dio"
14197
14198 test_241b() {
14199         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14200         ls -la $DIR/$tfile
14201         test_241_dio 1000 &
14202         PID=$!
14203         test_241_dio 1000
14204         wait $PID
14205 }
14206 run_test 241b "dio vs dio"
14207
14208 test_242() {
14209         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14210         mkdir -p $DIR/$tdir
14211         touch $DIR/$tdir/$tfile
14212
14213         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
14214         do_facet mds1 lctl set_param fail_loc=0x105
14215         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
14216
14217         do_facet mds1 lctl set_param fail_loc=0
14218         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
14219 }
14220 run_test 242 "mdt_readpage failure should not cause directory unreadable"
14221
14222 test_243()
14223 {
14224         test_mkdir $DIR/$tdir
14225         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
14226 }
14227 run_test 243 "various group lock tests"
14228
14229 test_244()
14230 {
14231         test_mkdir $DIR/$tdir
14232         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
14233         sendfile_grouplock $DIR/$tdir/$tfile || \
14234                 error "sendfile+grouplock failed"
14235         rm -rf $DIR/$tdir
14236 }
14237 run_test 244 "sendfile with group lock tests"
14238
14239 test_245() {
14240         local flagname="multi_mod_rpcs"
14241         local connect_data_name="max_mod_rpcs"
14242         local out
14243
14244         # check if multiple modify RPCs flag is set
14245         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
14246                 grep "connect_flags:")
14247         echo "$out"
14248
14249         echo "$out" | grep -qw $flagname
14250         if [ $? -ne 0 ]; then
14251                 echo "connect flag $flagname is not set"
14252                 return
14253         fi
14254
14255         # check if multiple modify RPCs data is set
14256         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
14257         echo "$out"
14258
14259         echo "$out" | grep -qw $connect_data_name ||
14260                 error "import should have connect data $connect_data_name"
14261 }
14262 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
14263
14264 test_246() { # LU-7371
14265         remote_ost_nodsh && skip "remote OST with nodsh" && return
14266         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
14267                 skip "Need OST version >= 2.7.62" && return 0
14268         do_facet ost1 $LCTL set_param fail_val=4095
14269 #define OBD_FAIL_OST_READ_SIZE          0x234
14270         do_facet ost1 $LCTL set_param fail_loc=0x234
14271         $LFS setstripe $DIR/$tfile -i 0 -c 1
14272         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
14273         cancel_lru_locks $FSNAME-OST0000
14274         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
14275 }
14276 run_test 246 "Read file of size 4095 should return right length"
14277
14278 test_247a() {
14279         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14280                 grep -q subtree ||
14281                 { skip "Fileset feature is not supported"; return; }
14282
14283         local submount=${MOUNT}_$tdir
14284
14285         mkdir $MOUNT/$tdir
14286         mkdir -p $submount || error "mkdir $submount failed"
14287         FILESET="$FILESET/$tdir" mount_client $submount ||
14288                 error "mount $submount failed"
14289         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
14290         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
14291                 error "read $MOUNT/$tdir/$tfile failed"
14292         umount_client $submount || error "umount $submount failed"
14293         rmdir $submount
14294 }
14295 run_test 247a "mount subdir as fileset"
14296
14297 test_247b() {
14298         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14299                 { skip "Fileset feature is not supported"; return; }
14300
14301         local submount=${MOUNT}_$tdir
14302
14303         rm -rf $MOUNT/$tdir
14304         mkdir -p $submount || error "mkdir $submount failed"
14305         SKIP_FILESET=1
14306         FILESET="$FILESET/$tdir" mount_client $submount &&
14307                 error "mount $submount should fail"
14308         rmdir $submount
14309 }
14310 run_test 247b "mount subdir that dose not exist"
14311
14312 test_247c() {
14313         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14314                 { skip "Fileset feature is not supported"; return; }
14315
14316         local submount=${MOUNT}_$tdir
14317
14318         mkdir -p $MOUNT/$tdir/dir1
14319         mkdir -p $submount || error "mkdir $submount failed"
14320         FILESET="$FILESET/$tdir" mount_client $submount ||
14321                 error "mount $submount failed"
14322         local fid=$($LFS path2fid $MOUNT/)
14323         $LFS fid2path $submount $fid && error "fid2path should fail"
14324         umount_client $submount || error "umount $submount failed"
14325         rmdir $submount
14326 }
14327 run_test 247c "running fid2path outside root"
14328
14329 test_247d() {
14330         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14331                 { skip "Fileset feature is not supported"; return; }
14332
14333         local submount=${MOUNT}_$tdir
14334
14335         mkdir -p $MOUNT/$tdir/dir1
14336         mkdir -p $submount || error "mkdir $submount failed"
14337         FILESET="$FILESET/$tdir" mount_client $submount ||
14338                 error "mount $submount failed"
14339         local fid=$($LFS path2fid $submount/dir1)
14340         $LFS fid2path $submount $fid || error "fid2path should succeed"
14341         umount_client $submount || error "umount $submount failed"
14342         rmdir $submount
14343 }
14344 run_test 247d "running fid2path inside root"
14345
14346 # LU-8037
14347 test_247e() {
14348         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14349                 grep -q subtree ||
14350                 { skip "Fileset feature is not supported"; return; }
14351
14352         local submount=${MOUNT}_$tdir
14353
14354         mkdir $MOUNT/$tdir
14355         mkdir -p $submount || error "mkdir $submount failed"
14356         FILESET="$FILESET/.." mount_client $submount &&
14357                 error "mount $submount should fail"
14358         rmdir $submount
14359 }
14360 run_test 247e "mount .. as fileset"
14361
14362 test_248() {
14363         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
14364         [ -z "$fast_read_sav" ] && skip "no fast read support" && return
14365
14366         # create a large file for fast read verification
14367         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
14368
14369         # make sure the file is created correctly
14370         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
14371                 { rm -f $DIR/$tfile; skip "file creation error" && return; }
14372
14373         echo "Test 1: verify that fast read is 4 times faster on cache read"
14374
14375         # small read with fast read enabled
14376         $LCTL set_param -n llite.*.fast_read=1
14377         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14378                 awk '/copied/ { print $6 }')
14379
14380         # small read with fast read disabled
14381         $LCTL set_param -n llite.*.fast_read=0
14382         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14383                 awk '/copied/ { print $6 }')
14384
14385         # verify that fast read is 4 times faster for cache read
14386         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
14387                 error_not_in_vm "fast read was not 4 times faster: " \
14388                            "$t_fast vs $t_slow"
14389
14390         echo "Test 2: verify the performance between big and small read"
14391         $LCTL set_param -n llite.*.fast_read=1
14392
14393         # 1k non-cache read
14394         cancel_lru_locks osc
14395         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14396                 awk '/copied/ { print $6 }')
14397
14398         # 1M non-cache read
14399         cancel_lru_locks osc
14400         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14401                 awk '/copied/ { print $6 }')
14402
14403         # verify that big IO is not 4 times faster than small IO
14404         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
14405                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
14406
14407         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
14408         rm -f $DIR/$tfile
14409 }
14410 run_test 248 "fast read verification"
14411
14412 test_249() { # LU-7890
14413         rm -f $DIR/$tfile
14414         $SETSTRIPE -c 1 $DIR/$tfile
14415
14416         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
14417         skip "Need at least version 2.8.54"
14418
14419         # Offset 2T == 4k * 512M
14420         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
14421                 error "dd to 2T offset failed"
14422 }
14423 run_test 249 "Write above 2T file size"
14424
14425 test_250() {
14426         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
14427          && skip "no 16TB file size limit on ZFS" && return
14428
14429         $SETSTRIPE -c 1 $DIR/$tfile
14430         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
14431         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
14432         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
14433         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
14434                 conv=notrunc,fsync && error "append succeeded"
14435         return 0
14436 }
14437 run_test 250 "Write above 16T limit"
14438
14439 test_251() {
14440         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
14441
14442         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
14443         #Skip once - writing the first stripe will succeed
14444         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14445         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
14446                 error "short write happened"
14447
14448         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14449         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
14450                 error "short read happened"
14451
14452         rm -f $DIR/$tfile
14453 }
14454 run_test 251 "Handling short read and write correctly"
14455
14456 test_252() {
14457         local tgt
14458         local dev
14459         local out
14460         local uuid
14461         local num
14462         local gen
14463
14464         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14465         remote_ost_nodsh && skip "remote OST with nodsh" && return
14466         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
14467              "$(facet_fstype mds1)" != "ldiskfs" ]; then
14468                 skip "ldiskfs only test"
14469                 return
14470         fi
14471
14472         # check lr_reader on OST0000
14473         tgt=ost1
14474         dev=$(facet_device $tgt)
14475         out=$(do_facet $tgt $LR_READER $dev)
14476         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14477         echo "$out"
14478         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
14479         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
14480                 error "Invalid uuid returned by $LR_READER on target $tgt"
14481         echo -e "uuid returned by $LR_READER is '$uuid'\n"
14482
14483         # check lr_reader -c on MDT0000
14484         tgt=mds1
14485         dev=$(facet_device $tgt)
14486         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
14487                 echo "$LR_READER does not support additional options"
14488                 return 0
14489         fi
14490         out=$(do_facet $tgt $LR_READER -c $dev)
14491         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14492         echo "$out"
14493         num=$(echo "$out" | grep -c "mdtlov")
14494         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
14495                 error "Invalid number of mdtlov clients returned by $LR_READER"
14496         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
14497
14498         # check lr_reader -cr on MDT0000
14499         out=$(do_facet $tgt $LR_READER -cr $dev)
14500         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14501         echo "$out"
14502         echo "$out" | grep -q "^reply_data:$" ||
14503                 error "$LR_READER should have returned 'reply_data' section"
14504         num=$(echo "$out" | grep -c "client_generation")
14505         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
14506 }
14507 run_test 252 "check lr_reader tool"
14508
14509 test_253_fill_ost() {
14510         local size_mb #how many MB should we write to pass watermark
14511         local lwm=$3  #low watermark
14512         local free_10mb #10% of free space
14513
14514         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14515         size_mb=$((free_kb / 1024 - lwm))
14516         free_10mb=$((free_kb / 10240))
14517         #If 10% of free space cross low watermark use it
14518         if (( free_10mb > size_mb )); then
14519                 size_mb=$free_10mb
14520         else
14521                 #At least we need to store 1.1 of difference between
14522                 #free space and low watermark
14523                 size_mb=$((size_mb + size_mb / 10))
14524         fi
14525         if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
14526                 dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
14527                          oflag=append conv=notrunc
14528         fi
14529
14530         sleep_maxage
14531
14532         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14533         echo "OST still has $((free_kb / 1024)) mbytes free"
14534 }
14535
14536 test_253() {
14537         local ostidx=0
14538         local rc=0
14539
14540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14541         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14542         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
14543
14544         local ost_name=$($LFS osts |
14545                 sed -n 's/^'$ostidx': \(.*\)_UUID .*/\1/p')
14546         # on the mdt's osc
14547         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
14548         do_facet $SINGLEMDS $LCTL get_param -n \
14549                 osp.$mdtosc_proc1.reserved_mb_high ||
14550                 { skip  "remote MDS does not support reserved_mb_high" &&
14551                   return; }
14552
14553         rm -rf $DIR/$tdir
14554         wait_mds_ost_sync
14555         wait_delete_completed
14556         mkdir $DIR/$tdir
14557
14558         local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
14559                         osp.$mdtosc_proc1.reserved_mb_high)
14560         local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
14561                         osp.$mdtosc_proc1.reserved_mb_low)
14562         echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
14563
14564         create_pool $FSNAME.$TESTNAME || error "Pool creation failed"
14565         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
14566                 error "Adding $ost_name to pool failed"
14567
14568         # Wait for client to see a OST at pool
14569         wait_update $HOSTNAME "$LCTL get_param -n
14570                 lov.$FSNAME-*.pools.$TESTNAME | sort -u |
14571                 grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
14572                 error "Client can not see the pool"
14573         $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
14574                 error "Setstripe failed"
14575
14576         dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
14577         local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
14578         echo "OST still has $((blocks/1024)) mbytes free"
14579
14580         local new_lwm=$((blocks/1024-10))
14581         do_facet $SINGLEMDS $LCTL set_param \
14582                         osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
14583         do_facet $SINGLEMDS $LCTL set_param \
14584                         osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
14585
14586         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14587
14588         #First enospc could execute orphan deletion so repeat.
14589         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14590
14591         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14592                         osp.$mdtosc_proc1.prealloc_status)
14593         echo "prealloc_status $oa_status"
14594
14595         dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
14596                 error "File creation should fail"
14597         #object allocation was stopped, but we still able to append files
14598         dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
14599                 error "Append failed"
14600         rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
14601
14602         wait_delete_completed
14603
14604         sleep_maxage
14605
14606         for i in $(seq 10 12); do
14607                 dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
14608                         error "File creation failed after rm";
14609         done
14610
14611         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14612                         osp.$mdtosc_proc1.prealloc_status)
14613         echo "prealloc_status $oa_status"
14614
14615         if (( oa_status != 0 )); then
14616                 error "Object allocation still disable after rm"
14617         fi
14618         do_facet $SINGLEMDS $LCTL set_param \
14619                         osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
14620         do_facet $SINGLEMDS $LCTL set_param \
14621                         osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
14622
14623
14624         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
14625                 error "Remove $ost_name from pool failed"
14626         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
14627                 error "Pool destroy fialed"
14628 }
14629 run_test 253 "Check object allocation limit"
14630
14631 test_254() {
14632         local cl_user
14633
14634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14635         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14636         do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
14637                 { skip "MDS does not support changelog_size" && return; }
14638
14639         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
14640         echo "Registered as changelog user $cl_user"
14641
14642         $LFS changelog_clear $MDT0 $cl_user 0
14643
14644         local size1=$(do_facet mds1 \
14645                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14646         echo "Changelog size $size1"
14647
14648         rm -rf $DIR/$tdir
14649         $LFS mkdir -i 0 $DIR/$tdir
14650         # change something
14651         mkdir -p $DIR/$tdir/pics/2008/zachy
14652         touch $DIR/$tdir/pics/2008/zachy/timestamp
14653         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
14654         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
14655         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
14656         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
14657         rm $DIR/$tdir/pics/desktop.jpg
14658
14659         local size2=$(do_facet mds1 \
14660                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14661         echo "Changelog size after work $size2"
14662
14663         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
14664
14665         if (( size2 <= size1 )); then
14666                 error "Changelog size after work should be greater than original"
14667         fi
14668         return 0
14669 }
14670 run_test 254 "Check changelog size"
14671
14672 ladvise_no_type()
14673 {
14674         local type=$1
14675         local file=$2
14676
14677         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
14678                 awk -F: '{print $2}' | grep $type > /dev/null
14679         if [ $? -ne 0 ]; then
14680                 return 0
14681         fi
14682         return 1
14683 }
14684
14685 ladvise_no_ioctl()
14686 {
14687         local file=$1
14688
14689         lfs ladvise -a willread $file > /dev/null 2>&1
14690         if [ $? -eq 0 ]; then
14691                 return 1
14692         fi
14693
14694         lfs ladvise -a willread $file 2>&1 |
14695                 grep "Inappropriate ioctl for device" > /dev/null
14696         if [ $? -eq 0 ]; then
14697                 return 0
14698         fi
14699         return 1
14700 }
14701
14702 percent() {
14703         bc <<<"scale=2; ($1 - $2) * 100 / $2"
14704 }
14705
14706 # run a random read IO workload
14707 # usage: random_read_iops <filename> <filesize> <iosize>
14708 random_read_iops() {
14709         local file=$1
14710         local fsize=$2
14711         local iosize=${3:-4096}
14712
14713         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
14714                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
14715 }
14716
14717 drop_file_oss_cache() {
14718         local file="$1"
14719         local nodes="$2"
14720
14721         $LFS ladvise -a dontneed $file 2>/dev/null ||
14722                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
14723 }
14724
14725 ladvise_willread_performance()
14726 {
14727         local repeat=10
14728         local average_origin=0
14729         local average_cache=0
14730         local average_ladvise=0
14731
14732         for ((i = 1; i <= $repeat; i++)); do
14733                 echo "Iter $i/$repeat: reading without willread hint"
14734                 cancel_lru_locks osc
14735                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
14736                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
14737                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
14738                 average_origin=$(bc <<<"$average_origin + $speed_origin")
14739
14740                 cancel_lru_locks osc
14741                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
14742                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
14743                 average_cache=$(bc <<<"$average_cache + $speed_cache")
14744
14745                 cancel_lru_locks osc
14746                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
14747                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
14748                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
14749                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
14750                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
14751         done
14752         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
14753         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
14754         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
14755
14756         speedup_cache=$(percent $average_cache $average_origin)
14757         speedup_ladvise=$(percent $average_ladvise $average_origin)
14758
14759         echo "Average uncached read: $average_origin"
14760         echo "Average speedup with OSS cached read: " \
14761                 "$average_cache = +$speedup_cache%"
14762         echo "Average speedup with ladvise willread: " \
14763                 "$average_ladvise = +$speedup_ladvise%"
14764
14765         local lowest_speedup=20
14766         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
14767                 echo "Speedup with OSS cached read less than $lowest_speedup%, "
14768                         "got $average_cache%. Skipping ladvise willread check."
14769                 return 0
14770         fi
14771
14772         # the test won't work on ZFS until it supports 'ladvise dontneed', but
14773         # it is still good to run until then to exercise 'ladvise willread'
14774         ! $LFS ladvise -a dontneed $DIR/$tfile &&
14775                 [ "$(facet_fstype ost1)" = "zfs" ] &&
14776                 echo "osd-zfs does not support dontneed or drop_caches" &&
14777                 return 0
14778
14779         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
14780         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
14781                 error_not_in_vm "Speedup with willread is less than " \
14782                         "$lowest_speedup%, got $average_ladvise%"
14783 }
14784
14785 test_255a() {
14786         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
14787                 skip "lustre < 2.8.54 does not support ladvise " && return
14788         remote_ost_nodsh && skip "remote OST with nodsh" && return
14789
14790         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
14791
14792         ladvise_no_type willread $DIR/$tfile &&
14793                 skip "willread ladvise is not supported" && return
14794
14795         ladvise_no_ioctl $DIR/$tfile &&
14796                 skip "ladvise ioctl is not supported" && return
14797
14798         local size_mb=100
14799         local size=$((size_mb * 1048576))
14800         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
14801                 error "dd to $DIR/$tfile failed"
14802
14803         lfs ladvise -a willread $DIR/$tfile ||
14804                 error "Ladvise failed with no range argument"
14805
14806         lfs ladvise -a willread -s 0 $DIR/$tfile ||
14807                 error "Ladvise failed with no -l or -e argument"
14808
14809         lfs ladvise -a willread -e 1 $DIR/$tfile ||
14810                 error "Ladvise failed with only -e argument"
14811
14812         lfs ladvise -a willread -l 1 $DIR/$tfile ||
14813                 error "Ladvise failed with only -l argument"
14814
14815         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
14816                 error "End offset should not be smaller than start offset"
14817
14818         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
14819                 error "End offset should not be equal to start offset"
14820
14821         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
14822                 error "Ladvise failed with overflowing -s argument"
14823
14824         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
14825                 error "Ladvise failed with overflowing -e argument"
14826
14827         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
14828                 error "Ladvise failed with overflowing -l argument"
14829
14830         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
14831                 error "Ladvise succeeded with conflicting -l and -e arguments"
14832
14833         echo "Synchronous ladvise should wait"
14834         local delay=4
14835 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
14836         do_nodes $(comma_list $(osts_nodes)) \
14837                 $LCTL set_param fail_val=$delay fail_loc=0x237
14838
14839         local start_ts=$SECONDS
14840         lfs ladvise -a willread $DIR/$tfile ||
14841                 error "Ladvise failed with no range argument"
14842         local end_ts=$SECONDS
14843         local inteval_ts=$((end_ts - start_ts))
14844
14845         if [ $inteval_ts -lt $(($delay - 1)) ]; then
14846                 error "Synchronous advice didn't wait reply"
14847         fi
14848
14849         echo "Asynchronous ladvise shouldn't wait"
14850         local start_ts=$SECONDS
14851         lfs ladvise -a willread -b $DIR/$tfile ||
14852                 error "Ladvise failed with no range argument"
14853         local end_ts=$SECONDS
14854         local inteval_ts=$((end_ts - start_ts))
14855
14856         if [ $inteval_ts -gt $(($delay / 2)) ]; then
14857                 error "Asynchronous advice blocked"
14858         fi
14859
14860         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
14861         ladvise_willread_performance
14862 }
14863 run_test 255a "check 'lfs ladvise -a willread'"
14864
14865 facet_meminfo() {
14866         local facet=$1
14867         local info=$2
14868
14869         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
14870 }
14871
14872 test_255b() {
14873         remote_ost_nodsh && skip "remote OST with nodsh" && return
14874
14875         lfs setstripe -c 1 -i 0 $DIR/$tfile
14876
14877         ladvise_no_type dontneed $DIR/$tfile &&
14878                 skip "dontneed ladvise is not supported" && return
14879
14880         ladvise_no_ioctl $DIR/$tfile &&
14881                 skip "ladvise ioctl is not supported" && return
14882
14883         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
14884                 skip "lustre < 2.8.54 does not support ladvise" && return
14885
14886         ! $LFS ladvise -a dontneed $DIR/$tfile &&
14887                 [ "$(facet_fstype ost1)" = "zfs" ] &&
14888                 skip "zfs-osd does not support 'ladvise dontneed'" && return
14889
14890         local size_mb=100
14891         local size=$((size_mb * 1048576))
14892         # In order to prevent disturbance of other processes, only check 3/4
14893         # of the memory usage
14894         local kibibytes=$((size_mb * 1024 * 3 / 4))
14895
14896         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
14897                 error "dd to $DIR/$tfile failed"
14898
14899         local total=$(facet_meminfo ost1 MemTotal)
14900         echo "Total memory: $total KiB"
14901
14902         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
14903         local before_read=$(facet_meminfo ost1 Cached)
14904         echo "Cache used before read: $before_read KiB"
14905
14906         lfs ladvise -a willread $DIR/$tfile ||
14907                 error "Ladvise willread failed"
14908         local after_read=$(facet_meminfo ost1 Cached)
14909         echo "Cache used after read: $after_read KiB"
14910
14911         lfs ladvise -a dontneed $DIR/$tfile ||
14912                 error "Ladvise dontneed again failed"
14913         local no_read=$(facet_meminfo ost1 Cached)
14914         echo "Cache used after dontneed ladvise: $no_read KiB"
14915
14916         if [ $total -lt $((before_read + kibibytes)) ]; then
14917                 echo "Memory is too small, abort checking"
14918                 return 0
14919         fi
14920
14921         if [ $((before_read + kibibytes)) -gt $after_read ]; then
14922                 error "Ladvise willread should use more memory" \
14923                         "than $kibibytes KiB"
14924         fi
14925
14926         if [ $((no_read + kibibytes)) -gt $after_read ]; then
14927                 error "Ladvise dontneed should release more memory" \
14928                         "than $kibibytes KiB"
14929         fi
14930 }
14931 run_test 255b "check 'lfs ladvise -a dontneed'"
14932
14933 test_255c() {
14934         local count
14935         local new_count
14936         local difference
14937         local i
14938         local rc
14939         test_mkdir -p $DIR/$tdir
14940         $SETSTRIPE -i 0 $DIR/$tdir
14941
14942         #test 10 returns only success/failure
14943         i=10
14944         lockahead_test -d $DIR/$tdir -t $i
14945         rc=$?
14946         if [ $rc -eq 255 ]; then
14947                 error "Ladvise test${i} failed, ${rc}"
14948         fi
14949
14950         #test 11 counts lock enqueue requests, all others count new locks
14951         i=11
14952         count=$(do_facet ost1 \
14953                 $LCTL get_param -n ost.OSS.ost.stats)
14954         count=$(echo "$count" | grep ldlm_extent_enqueue | awk '{ print $2 }')
14955
14956         lockahead_test -d $DIR/$tdir -t $i
14957         rc=$?
14958         if [ $rc -eq 255 ]; then
14959                 error "Ladvise test${i} failed, ${rc}"
14960         fi
14961
14962         new_count=$(do_facet ost1 \
14963                 $LCTL get_param -n ost.OSS.ost.stats)
14964         new_count=$(echo "$new_count" | grep ldlm_extent_enqueue | \
14965                    awk '{ print $2 }')
14966
14967         difference="$((new_count - count))"
14968         if [ $difference -ne $rc ]; then
14969                 error "Ladvise test${i}, bad enqueue count, returned " \
14970                       "${rc}, actual ${difference}"
14971         fi
14972
14973         for i in $(seq 12 21); do
14974                 # If we do not do this, we run the risk of having too many
14975                 # locks and starting lock cancellation while we are checking
14976                 # lock counts.
14977                 cancel_lru_locks osc
14978
14979                 count=$($LCTL get_param -n \
14980                        ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
14981
14982                 lockahead_test -d $DIR/$tdir -t $i
14983                 rc=$?
14984                 if [ $rc -eq 255 ]; then
14985                         error "Ladvise test ${i} failed, ${rc}"
14986                 fi
14987
14988                 new_count=$($LCTL get_param -n \
14989                        ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
14990                 difference="$((new_count - count))"
14991
14992                 # Test 15 output is divided by 1000 to map down to valid return
14993                 if [ $i -eq 15 ]; then
14994                         rc="$((rc * 1000))"
14995                 fi
14996
14997                 if [ $difference -ne $rc ]; then
14998                         error "Ladvise test ${i}, bad lock count, returned " \
14999                               "${rc}, actual ${difference}"
15000                 fi
15001         done
15002
15003         #test 22 returns only success/failure
15004         i=22
15005         lockahead_test -d $DIR/$tdir -t $i
15006         rc=$?
15007         if [ $rc -eq 255 ]; then
15008                 error "Ladvise test${i} failed, ${rc}"
15009         fi
15010
15011 }
15012 run_test 255c "suite of ladvise lockahead tests"
15013
15014 test_256() {
15015         local cl_user
15016         local cat_sl
15017         local mdt_dev
15018
15019         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15020         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15021         [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
15022                 skip "ldiskfs only test" && return
15023
15024         mdt_dev=$(mdsdevname 1)
15025         echo $mdt_dev
15026         cl_user=$(do_facet mds1 \
15027         "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
15028         if [[ -n $cl_user ]]; then
15029                 skip "active changelog user"
15030                 return
15031         fi
15032
15033         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
15034         echo "Registered as changelog user $cl_user"
15035
15036         rm -rf $DIR/$tdir
15037         mkdir -p $DIR/$tdir
15038
15039         $LFS changelog_clear $MDT0 $cl_user 0
15040
15041         # change something
15042         touch $DIR/$tdir/{1..10}
15043
15044         # stop the MDT
15045         stop mds1 || error "Fail to stop MDT."
15046
15047         # remount the MDT
15048         start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
15049
15050         #after mount new plainllog is used
15051         touch $DIR/$tdir/{11..19}
15052         do_facet mds1 sync
15053         local TEMP256FILE=$(mktemp -u TEMP256XXXXXX)
15054         cat_sl=$(do_facet mds1 \
15055         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
15056          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
15057         do_facet mds1 rm $TEMP256FILE
15058
15059         if (( cat_sl != 2 )); then
15060                 do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
15061                 error "Changelog catalog has wrong number of slots $cat_sl"
15062         fi
15063
15064         $LFS changelog_clear $MDT0 $cl_user 0
15065
15066         do_facet mds1 sync
15067         TEMP256FILE=$(mktemp -u TEMP256XXXXXX)
15068         cat_sl=$(do_facet mds1 \
15069         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
15070          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
15071         do_facet mds1 rm $TEMP256FILE
15072
15073         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
15074
15075         if (( cat_sl == 2 )); then
15076                 error "Empty plain llog was not deleted from changelog catalog"
15077         fi
15078         if (( cat_sl != 1 )); then
15079                 error "Active plain llog shouldn\`t be deleted from catalog"
15080         fi
15081 }
15082 run_test 256 "Check llog delete for empty and not full state"
15083
15084 test_257() {
15085         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15086         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
15087                 skip "Need MDS version at least 2.8.55" && return
15088
15089         test_mkdir $DIR/$tdir
15090
15091         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
15092                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
15093         stat $DIR/$tdir
15094
15095 #define OBD_FAIL_MDS_XATTR_REP                  0x161
15096         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
15097         local facet=mds$((mdtidx + 1))
15098         set_nodes_failloc $(facet_active_host $facet) 0x80000161
15099         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
15100
15101         stop $facet || error "stop MDS failed"
15102         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
15103                 error "start MDS fail"
15104 }
15105 run_test 257 "xattr locks are not lost"
15106
15107 # Verify we take the i_mutex when security requires it
15108 test_258a() {
15109 #define OBD_FAIL_IMUTEX_SEC 0x141c
15110         $LCTL set_param fail_loc=0x141c
15111         touch $DIR/$tfile
15112         chmod u+s $DIR/$tfile
15113         chmod a+rwx $DIR/$tfile
15114         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
15115         RC=$?
15116         if [ $RC -ne 0 ]; then
15117                 error "error, failed to take i_mutex, rc=$?"
15118         fi
15119         rm -f $DIR/$tfile
15120 }
15121 run_test 258a
15122
15123 # Verify we do NOT take the i_mutex in the normal case
15124 test_258b() {
15125 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
15126         $LCTL set_param fail_loc=0x141d
15127         touch $DIR/$tfile
15128         chmod a+rwx $DIR
15129         chmod a+rw $DIR/$tfile
15130         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
15131         RC=$?
15132         if [ $RC -ne 0 ]; then
15133                 error "error, took i_mutex unnecessarily, rc=$?"
15134         fi
15135         rm -f $DIR/$tfile
15136
15137 }
15138 run_test 258b "verify i_mutex security behavior"
15139
15140 test_260() {
15141 #define OBD_FAIL_MDC_CLOSE               0x806
15142         $LCTL set_param fail_loc=0x80000806
15143         touch $DIR/$tfile
15144
15145 }
15146 run_test 260 "Check mdc_close fail"
15147
15148 ### Data-on-MDT sanity tests ###
15149 test_270a() {
15150         # create DoM file
15151         local dom=$DIR/$tdir/dom_file
15152         local tmp=$DIR/$tdir/tmp_file
15153
15154         mkdir -p $DIR/$tdir
15155
15156         # basic checks for DoM component creation
15157         $LFS setstripe -E 1024K -E 1024K -L mdt $dom 2>/dev/null &&
15158                 error "Can set MDT layout to non-first entry"
15159
15160         $LFS setstripe -E 1024K -L mdt -E 1024K -L mdt $dom 2>/dev/null &&
15161                 error "Can define multiple entries as MDT layout"
15162
15163         $LFS setstripe -E 1M -L mdt $dom ||
15164                 error "Can't create DoM layout"
15165
15166         [ $($LFS getstripe -L $dom) == 100 ] || error "bad pattern"
15167         [ $($LFS getstripe -c $dom) == 0 ] || error "bad stripe count"
15168         [ $($LFS getstripe -S $dom) == 1048576 ] || error "bad stripe size"
15169
15170         local mdtidx=$($GETSTRIPE -M $dom)
15171         local mdtname=MDT$(printf %04x $mdtidx)
15172         local facet=mds$((mdtidx + 1))
15173         local space_check=1
15174
15175         # Skip free space checks with ZFS
15176         if [ "$(facet_fstype $facet)" == "zfs" ]; then
15177                 space_check=0
15178         fi
15179
15180         # write
15181         sync
15182         local mdtfree1=$(do_facet $facet \
15183                 lctl get_param -n osd*.*$mdtname.kbytesfree)
15184         dd if=/dev/urandom of=$tmp bs=1024 count=100
15185         # check also direct IO along write
15186         dd if=$tmp of=$dom bs=102400 count=1 oflag=direct
15187         sync
15188         cmp $tmp $dom || error "file data is different"
15189         [ $(stat -c%s $dom) == 102400 ] || error "bad size after write"
15190         if [ $space_check == 1 ]; then
15191                 local mdtfree2=$(do_facet $facet \
15192                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
15193                 [ $(($mdtfree1 - $mdtfree2)) -ge 102 ] ||
15194                         error "MDT free space is wrong after write"
15195         fi
15196
15197         # truncate
15198         $TRUNCATE $dom 10000
15199         [ $(stat -c%s $dom) == 10000 ] || error "bad size after truncate"
15200         if [ $space_check == 1 ]; then
15201                 mdtfree1=$(do_facet $facet \
15202                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
15203                 [ $(($mdtfree1 - $mdtfree2)) -ge 92 ] ||
15204                         error "MDT free space is wrong after truncate"
15205         fi
15206
15207         # append
15208         cat $tmp >> $dom
15209         sync
15210         [ $(stat -c%s $dom) == 112400 ] || error "bad size after append"
15211         if [ $space_check == 1 ]; then
15212                 mdtfree2=$(do_facet $facet \
15213                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
15214                 [ $(($mdtfree1 - $mdtfree2)) -ge 102 ] ||
15215                         error "MDT free space is wrong after append"
15216         fi
15217
15218         # delete
15219         rm $dom
15220         if [ $space_check == 1 ]; then
15221                 mdtfree1=$(do_facet $facet \
15222                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
15223                 [ $(($mdtfree1 - $mdtfree2)) -ge 112 ] ||
15224                         error "MDT free space is wrong after removal"
15225         fi
15226
15227         # combined striping
15228         $LFS setstripe -E 1024K -L mdt -E EOF $dom ||
15229                 error "Can't create DoM + OST striping"
15230
15231         dd if=/dev/urandom of=$tmp bs=1024 count=2000
15232         # check also direct IO along write
15233         dd if=$tmp of=$dom bs=102400 count=20 oflag=direct
15234         sync
15235         cmp $tmp $dom || error "file data is different"
15236         [ $(stat -c%s $dom) == 2048000 ] || error "bad size after write"
15237         rm $dom
15238         rm $tmp
15239
15240         return 0
15241 }
15242 run_test 270a "DoM: basic functionality tests"
15243
15244 test_270b() {
15245         local dom=$DIR/$tdir/dom_file
15246         local max_size=1048576
15247
15248         mkdir -p $DIR/$tdir
15249         $LFS setstripe -E $max_size -L mdt $dom
15250
15251         # truncate over the limit
15252         $TRUNCATE $dom $(($max_size + 1)) &&
15253                 error "successful truncate over the maximum size"
15254         # write over the limit
15255         dd if=/dev/zero of=$dom bs=$max_size seek=1 count=1 &&
15256                 error "successful write over the maximum size"
15257         # append over the limit
15258         dd if=/dev/zero of=$dom bs=$(($max_size - 3)) count=1
15259         echo "12345" >> $dom && error "successful append over the maximum size"
15260         rm $dom
15261
15262         return 0
15263 }
15264 run_test 270b "DoM: maximum size overflow checks for DoM-only file"
15265
15266 test_270c() {
15267         mkdir -p $DIR/$tdir
15268         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
15269
15270         # check files inherit DoM EA
15271         touch $DIR/$tdir/first
15272         [ $($GETSTRIPE -L $DIR/$tdir/first) == 100 ] ||
15273                 error "bad pattern"
15274         [ $($LFS getstripe -c $DIR/$tdir/first) == 0 ] ||
15275                 error "bad stripe count"
15276         [ $($LFS getstripe -S $DIR/$tdir/first) == 1048576 ] ||
15277                 error "bad stripe size"
15278
15279         # check directory inherits DoM EA and uses it as default
15280         mkdir $DIR/$tdir/subdir
15281         touch $DIR/$tdir/subdir/second
15282         [ $($LFS getstripe -L $DIR/$tdir/subdir/second) == 100 ] ||
15283                 error "bad pattern in sub-directory"
15284         [ $($LFS getstripe -c $DIR/$tdir/subdir/second) == 0 ] ||
15285                 error "bad stripe count in sub-directory"
15286         [ $($LFS getstripe -S $DIR/$tdir/subdir/second) == 1048576 ] ||
15287                 error "bad stripe size in sub-directory"
15288         return 0
15289 }
15290 run_test 270c "DoM: DoM EA inheritance tests"
15291
15292 test_270d() {
15293         mkdir -p $DIR/$tdir
15294         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
15295
15296         # inherit default DoM striping
15297         mkdir $DIR/$tdir/subdir
15298         touch $DIR/$tdir/subdir/f1
15299
15300         # change default directory striping
15301         $LFS setstripe -c 1 $DIR/$tdir/subdir
15302         touch $DIR/$tdir/subdir/f2
15303         [ $($LFS getstripe -c $DIR/$tdir/subdir/f2) == 1 ] ||
15304                 error "wrong default striping in file 2"
15305         [ $($LFS getstripe -L $DIR/$tdir/subdir/f2) == 1 ] ||
15306                 error "bad pattern in file 2"
15307         return 0
15308 }
15309 run_test 270d "DoM: change striping from DoM to RAID0"
15310
15311 test_270e() {
15312         mkdir -p $DIR/$tdir/dom
15313         mkdir -p $DIR/$tdir/norm
15314         DOMFILES=20
15315         NORMFILES=10
15316         $LFS setstripe -E 1M -L mdt $DIR/$tdir/dom
15317         $LFS setstripe -i 0 -S 2M $DIR/$tdir/norm
15318
15319         createmany -o $DIR/$tdir/dom/dom- $DOMFILES
15320         createmany -o $DIR/$tdir/norm/norm- $NORMFILES
15321
15322         # find DoM files by layout
15323         NUM=$($LFIND -L mdt -type f $DIR/$tdir 2>/dev/null | wc -l)
15324         [ $NUM -eq  $DOMFILES ] ||
15325                 error "lfs find -L: found $NUM, expected $DOMFILES"
15326         echo "Test 1: lfs find 20 DOM files by layout: OK"
15327
15328         # there should be 1 dir with default DOM striping
15329         NUM=$($LFIND -L mdt -type d $DIR/$tdir 2>/dev/null | wc -l)
15330         [ $NUM -eq  1 ] ||
15331                 error "lfs find -L: found $NUM, expected 1 dir"
15332         echo "Test 2: lfs find 1 DOM dir by layout: OK"
15333
15334         # find DoM files by stripe size
15335         NUM=$($LFIND -S -1200K -type f $DIR/$tdir 2>/dev/null | wc -l)
15336         [ $NUM -eq  $DOMFILES ] ||
15337                 error "lfs find -S: found $NUM, expected $DOMFILES"
15338         echo "Test 4: lfs find 20 DOM files by stripe size: OK"
15339
15340         # find files by stripe offset except DoM files
15341         NUM=$($LFIND -i 0 -type f $DIR/$tdir 2>/dev/null | wc -l)
15342         [ $NUM -eq  $NORMFILES ] ||
15343                 error "lfs find -i: found $NUM, expected $NORMFILES"
15344         echo "Test 5: lfs find no DOM files by stripe index: OK"
15345         return 0
15346 }
15347 run_test 270e "DoM: lfs find with DoM files test"
15348
15349 test_270f() {
15350         local mdtname=${FSNAME}-MDT0000-mdtlov
15351         local dom=$DIR/$tdir/dom_file
15352         local dom_limit_saved=$(do_facet mds1 $LCTL get_param -n \
15353                                                 lod.$mdtname.dom_stripesize)
15354         local dom_limit=131072
15355
15356         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=$dom_limit
15357         local dom_current=$(do_facet mds1 $LCTL get_param -n \
15358                                                 lod.$mdtname.dom_stripesize)
15359         [ ${dom_limit} -eq ${dom_current} ] ||
15360                 error "Cannot change per-MDT DoM stripe limit to $dom_limit"
15361
15362         $LFS mkdir -i 0 -c 1 $DIR/$tdir
15363         $LFS setstripe -d $DIR/$tdir
15364         $LFS setstripe -E $dom_limit -L mdt $DIR/$tdir ||
15365                 error "Can't set directory default striping"
15366
15367         # exceed maximum stripe size
15368         $LFS setstripe -E $(($dom_limit * 2)) -L mdt $dom &&
15369                 error "Able to create DoM component size more than LOD limit"
15370
15371         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=0
15372         dom_current=$(do_facet mds1 $LCTL get_param -n \
15373                                                 lod.$mdtname.dom_stripesize)
15374         [ 0 -eq ${dom_current} ] ||
15375                 error "Can't set zero DoM stripe limit"
15376
15377         # too low values to be aligned with smallest stripe size 64K
15378         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=30000
15379         dom_current=$(do_facet mds1 $LCTL get_param -n \
15380                                                 lod.$mdtname.dom_stripesize)
15381         [ 30000 -eq ${dom_current} ] &&
15382                 error "Can set too small DoM stripe limit"
15383
15384         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=2147483648
15385         dom_current=$(do_facet mds1 $LCTL get_param -n \
15386                                                 lod.$mdtname.dom_stripesize)
15387         echo $dom_current
15388         [ 2147483648 -eq ${dom_current} ] &&
15389                 error "Can set too large DoM stripe limit"
15390
15391         do_facet mds1 $LCTL set_param -n \
15392                                 lod.$mdtname.dom_stripesize=$((dom_limit * 2))
15393         $LFS setstripe -E $((dom_limit * 2)) -L mdt $dom ||
15394                 error "Can't create DoM component size after limit change"
15395         do_facet mds1 $LCTL set_param -n \
15396                                 lod.$mdtname.dom_stripesize=$((dom_limit / 2))
15397         $LFS setstripe -E $dom_limit -L mdt ${dom}_big &&
15398                 error "Can create big DoM component after limit decrease"
15399         touch ${dom}_def ||
15400                 error "Can't create file with old default layout"
15401
15402         do_facet mds1 $LCTL set_param -n lod.*.dom_stripesize=$dom_limit_saved
15403         return 0
15404 }
15405 run_test 270f "DoM: maximum DoM stripe size checks"
15406
15407 test_271a() {
15408         local dom=$DIR/$tdir/dom
15409
15410         mkdir -p $DIR/$tdir
15411
15412         $LFS setstripe -E 1024K -L mdt $dom
15413
15414         lctl set_param -n mdc.*.stats=clear
15415         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
15416         cat $dom > /dev/null
15417         local reads=$(lctl get_param -n mdc.*.stats |
15418                         awk '/ost_read/ {print $2}')
15419         [ -z $reads ] || error "Unexpected $reads READ RPCs"
15420         ls $dom
15421         rm -f $dom
15422 }
15423 run_test 271a "DoM: data is cached for read after write"
15424
15425 test_271b() {
15426         local dom=$DIR/$tdir/dom
15427
15428         mkdir -p $DIR/$tdir
15429
15430         $LFS setstripe -E 1024K -L mdt -E EOF $dom
15431
15432         lctl set_param -n mdc.*.stats=clear
15433         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
15434         cancel_lru_locks mdc
15435         $CHECKSTAT -t file -s 4096 $dom || error "stat #1 fails"
15436         # second stat to check size is cached on client
15437         $CHECKSTAT -t file -s 4096 $dom || error "stat #2 fails"
15438         local gls=$(lctl get_param -n mdc.*.stats |
15439                         awk '/ldlm_glimpse/ {print $2}')
15440         [ -z $gls ] || error "Unexpected $gls glimpse RPCs"
15441         rm -f $dom
15442 }
15443 run_test 271b "DoM: no glimpse RPC for stat (DoM only file)"
15444
15445 test_271ba() {
15446         local dom=$DIR/$tdir/dom
15447
15448         mkdir -p $DIR/$tdir
15449
15450         $LFS setstripe -E 1024K -L mdt -E EOF $dom
15451
15452         lctl set_param -n mdc.*.stats=clear
15453         lctl set_param -n osc.*.stats=clear
15454         dd if=/dev/zero of=$dom bs=2048K count=1 || return 1
15455         cancel_lru_locks mdc
15456         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
15457         # second stat to check size is cached on client
15458         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
15459         local gls=$(lctl get_param -n mdc.*.stats |
15460                         awk '/ldlm_glimpse/ {print $2}')
15461         [ -z $gls ] || error "Unexpected $gls glimpse RPCs"
15462         local gls=$(lctl get_param -n osc.*.stats |
15463                         awk '/ldlm_glimpse/ {print $2}')
15464         [ -z $gls ] || error "Unexpected $gls OSC glimpse RPCs"
15465         rm -f $dom
15466 }
15467 run_test 271ba "DoM: no glimpse RPC for stat (combined file)"
15468
15469 test_271c() {
15470         # test to be enabled with lock_convert
15471         skip "skipped until lock convert will be implemented" && return
15472
15473         local dom=$DIR/$tdir/dom
15474
15475         mkdir -p $DIR/$tdir
15476
15477         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
15478
15479         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
15480         local facet=mds$((mdtidx + 1))
15481
15482         cancel_lru_locks mdc
15483         do_facet $facet lctl set_param -n mdt.*.dom_lock=0
15484         createmany -o $dom 1000
15485         lctl set_param -n mdc.*.stats=clear
15486         smalliomany -w $dom 1000 200
15487         lctl get_param -n mdc.*.stats
15488         local enq=$(lctl get_param -n mdc.*.stats |
15489                         awk '/ldlm_ibits_enqueue/ {print $2}')
15490         # Each file has 1 open, 1 IO enqueues, total 2000
15491         # but now we have also +1 getxattr for security.capability, total 3000
15492         [ $enq -ge 2000 ] || error "Too few enqueues $enq, expected > 2000"
15493         unlinkmany $dom 1000
15494
15495         cancel_lru_locks mdc
15496         do_facet $facet lctl set_param -n mdt.*.dom_lock=1
15497         createmany -o $dom 1000
15498         lctl set_param -n mdc.*.stats=clear
15499         smalliomany -w $dom 1000 200
15500         lctl get_param -n mdc.*.stats
15501         local enq_2=$(lctl get_param -n mdc.*.stats |
15502                         awk '/ldlm_ibits_enqueue/ {print $2}')
15503         # Expect to see reduced amount of RPCs by 1000 due to single enqueue
15504         # for OPEN and IO lock.
15505         [ $((enq - enq_2)) -ge 1000 ] ||
15506                 error "Too many enqueues $enq_2, expected about $((enq - 1000))"
15507         unlinkmany $dom 1000
15508         return 0
15509 }
15510 run_test 271c "DoM: IO lock at open saves enqueue RPCs"
15511
15512 cleanup_test_300() {
15513         trap 0
15514         umask $SAVE_UMASK
15515 }
15516 test_striped_dir() {
15517         local mdt_index=$1
15518         local stripe_count
15519         local stripe_index
15520
15521         mkdir -p $DIR/$tdir
15522
15523         SAVE_UMASK=$(umask)
15524         trap cleanup_test_300 RETURN EXIT
15525
15526         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
15527                                                 $DIR/$tdir/striped_dir ||
15528                 error "set striped dir error"
15529
15530         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
15531         [ "$mode" = "755" ] || error "expect 755 got $mode"
15532
15533         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
15534                 error "getdirstripe failed"
15535         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
15536         if [ "$stripe_count" != "2" ]; then
15537                 error "1:stripe_count is $stripe_count, expect 2"
15538         fi
15539         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
15540         if [ "$stripe_count" != "2" ]; then
15541                 error "2:stripe_count is $stripe_count, expect 2"
15542         fi
15543
15544         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
15545         if [ "$stripe_index" != "$mdt_index" ]; then
15546                 error "stripe_index is $stripe_index, expect $mdt_index"
15547         fi
15548
15549         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15550                 error "nlink error after create striped dir"
15551
15552         mkdir $DIR/$tdir/striped_dir/a
15553         mkdir $DIR/$tdir/striped_dir/b
15554
15555         stat $DIR/$tdir/striped_dir/a ||
15556                 error "create dir under striped dir failed"
15557         stat $DIR/$tdir/striped_dir/b ||
15558                 error "create dir under striped dir failed"
15559
15560         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
15561                 error "nlink error after mkdir"
15562
15563         rmdir $DIR/$tdir/striped_dir/a
15564         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
15565                 error "nlink error after rmdir"
15566
15567         rmdir $DIR/$tdir/striped_dir/b
15568         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15569                 error "nlink error after rmdir"
15570
15571         chattr +i $DIR/$tdir/striped_dir
15572         createmany -o $DIR/$tdir/striped_dir/f 10 &&
15573                 error "immutable flags not working under striped dir!"
15574         chattr -i $DIR/$tdir/striped_dir
15575
15576         rmdir $DIR/$tdir/striped_dir ||
15577                 error "rmdir striped dir error"
15578
15579         cleanup_test_300
15580
15581         true
15582 }
15583
15584 test_300a() {
15585         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15586                 skip "skipped for lustre < 2.7.0" && return
15587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15588         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15589
15590         test_striped_dir 0 || error "failed on striped dir on MDT0"
15591         test_striped_dir 1 || error "failed on striped dir on MDT0"
15592 }
15593 run_test 300a "basic striped dir sanity test"
15594
15595 test_300b() {
15596         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15597                 skip "skipped for lustre < 2.7.0" && return
15598         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15599         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15600         local i
15601         local mtime1
15602         local mtime2
15603         local mtime3
15604
15605         test_mkdir $DIR/$tdir
15606         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15607                 error "set striped dir error"
15608         for ((i=0; i<10; i++)); do
15609                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
15610                 sleep 1
15611                 touch $DIR/$tdir/striped_dir/file_$i ||
15612                                         error "touch error $i"
15613                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
15614                 [ $mtime1 -eq $mtime2 ] &&
15615                         error "mtime not change after create"
15616                 sleep 1
15617                 rm -f $DIR/$tdir/striped_dir/file_$i ||
15618                                         error "unlink error $i"
15619                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
15620                 [ $mtime2 -eq $mtime3 ] &&
15621                         error "mtime did not change after unlink"
15622         done
15623         true
15624 }
15625 run_test 300b "check ctime/mtime for striped dir"
15626
15627 test_300c() {
15628         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15629                 skip "skipped for lustre < 2.7.0" && return
15630         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15631         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15632         local file_count
15633
15634         mkdir -p $DIR/$tdir
15635         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
15636                 error "set striped dir error"
15637
15638         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
15639                 error "chown striped dir failed"
15640
15641         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
15642                 error "create 5k files failed"
15643
15644         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
15645
15646         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
15647
15648         rm -rf $DIR/$tdir
15649 }
15650 run_test 300c "chown && check ls under striped directory"
15651
15652 test_300d() {
15653         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15654                 skip "skipped for lustre < 2.7.0" && return
15655         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15656         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15657         local stripe_count
15658         local file
15659
15660         mkdir -p $DIR/$tdir
15661         $SETSTRIPE -c 2 $DIR/$tdir
15662
15663         #local striped directory
15664         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15665                 error "set striped dir error"
15666         createmany -o $DIR/$tdir/striped_dir/f 10 ||
15667                 error "create 10 files failed"
15668
15669         #remote striped directory
15670         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
15671                 error "set striped dir error"
15672         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
15673                 error "create 10 files failed"
15674
15675         for file in $(find $DIR/$tdir); do
15676                 stripe_count=$($GETSTRIPE -c $file)
15677                 [ $stripe_count -eq 2 ] ||
15678                         error "wrong stripe $stripe_count for $file"
15679         done
15680
15681         rm -rf $DIR/$tdir
15682 }
15683 run_test 300d "check default stripe under striped directory"
15684
15685 test_300e() {
15686         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15687                 skip "Need MDS version at least 2.7.55" && return
15688         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15689         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15690         local stripe_count
15691         local file
15692
15693         mkdir -p $DIR/$tdir
15694
15695         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15696                 error "set striped dir error"
15697
15698         touch $DIR/$tdir/striped_dir/a
15699         touch $DIR/$tdir/striped_dir/b
15700         touch $DIR/$tdir/striped_dir/c
15701
15702         mkdir $DIR/$tdir/striped_dir/dir_a
15703         mkdir $DIR/$tdir/striped_dir/dir_b
15704         mkdir $DIR/$tdir/striped_dir/dir_c
15705
15706         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
15707                 error "set striped adir under striped dir error"
15708
15709         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
15710                 error "set striped bdir under striped dir error"
15711
15712         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
15713                 error "set striped cdir under striped dir error"
15714
15715         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
15716                 error "rename dir under striped dir fails"
15717
15718         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
15719                 error "rename dir under different stripes fails"
15720
15721         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
15722                 error "rename file under striped dir should succeed"
15723
15724         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
15725                 error "rename dir under striped dir should succeed"
15726
15727         rm -rf $DIR/$tdir
15728 }
15729 run_test 300e "check rename under striped directory"
15730
15731 test_300f() {
15732         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15733                 skip "Need MDS version at least 2.7.55" && return
15734         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15735         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15736         local stripe_count
15737         local file
15738
15739         rm -rf $DIR/$tdir
15740         mkdir -p $DIR/$tdir
15741
15742         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15743                 error "set striped dir error"
15744
15745         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
15746                 error "set striped dir error"
15747
15748         touch $DIR/$tdir/striped_dir/a
15749         mkdir $DIR/$tdir/striped_dir/dir_a
15750         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
15751                 error "create striped dir under striped dir fails"
15752
15753         touch $DIR/$tdir/striped_dir1/b
15754         mkdir $DIR/$tdir/striped_dir1/dir_b
15755         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
15756                 error "create striped dir under striped dir fails"
15757
15758         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
15759                 error "rename dir under different striped dir should fail"
15760
15761         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
15762                 error "rename striped dir under diff striped dir should fail"
15763
15764         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
15765                 error "rename file under diff striped dirs fails"
15766
15767         rm -rf $DIR/$tdir
15768 }
15769 run_test 300f "check rename cross striped directory"
15770
15771 test_300_check_default_striped_dir()
15772 {
15773         local dirname=$1
15774         local default_count=$2
15775         local default_index=$3
15776         local stripe_count
15777         local stripe_index
15778         local dir_stripe_index
15779         local dir
15780
15781         echo "checking $dirname $default_count $default_index"
15782         $LFS setdirstripe -D -c $default_count -i $default_index \
15783                                 -t all_char $DIR/$tdir/$dirname ||
15784                 error "set default stripe on striped dir error"
15785         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
15786         [ $stripe_count -eq $default_count ] ||
15787                 error "expect $default_count get $stripe_count for $dirname"
15788
15789         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
15790         [ $stripe_index -eq $default_index ] ||
15791                 error "expect $default_index get $stripe_index for $dirname"
15792
15793         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
15794                                                 error "create dirs failed"
15795
15796         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
15797         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
15798         for dir in $(find $DIR/$tdir/$dirname/*); do
15799                 stripe_count=$($LFS getdirstripe -c $dir)
15800                 [ $stripe_count -eq $default_count ] ||
15801                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
15802                 error "stripe count $default_count != $stripe_count for $dir"
15803
15804                 stripe_index=$($LFS getdirstripe -i $dir)
15805                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
15806                         error "$stripe_index != $default_index for $dir"
15807
15808                 #check default stripe
15809                 stripe_count=$($LFS getdirstripe -D -c $dir)
15810                 [ $stripe_count -eq $default_count ] ||
15811                 error "default count $default_count != $stripe_count for $dir"
15812
15813                 stripe_index=$($LFS getdirstripe -D -i $dir)
15814                 [ $stripe_index -eq $default_index ] ||
15815                 error "default index $default_index != $stripe_index for $dir"
15816         done
15817         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
15818 }
15819
15820 test_300g() {
15821         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15822                 skip "Need MDS version at least 2.7.55" && return
15823         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15824         local dir
15825         local stripe_count
15826         local stripe_index
15827
15828         mkdir $DIR/$tdir
15829         mkdir $DIR/$tdir/normal_dir
15830
15831         #Checking when client cache stripe index
15832         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
15833         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
15834                 error "create striped_dir failed"
15835
15836         $LFS setdirstripe -i0 $DIR/$tdir/striped_dir/dir0 ||
15837                 error "create dir0 fails"
15838         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir0)
15839         [ $stripe_index -eq 0 ] ||
15840                 error "dir0 expect index 0 got $stripe_index"
15841
15842         mkdir $DIR/$tdir/striped_dir/dir1 ||
15843                 error "create dir1 fails"
15844         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
15845         [ $stripe_index -eq 1 ] ||
15846                 error "dir1 expect index 1 got $stripe_index"
15847
15848         #check default stripe count/stripe index
15849         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
15850         test_300_check_default_striped_dir normal_dir 1 0
15851         test_300_check_default_striped_dir normal_dir 2 1
15852         test_300_check_default_striped_dir normal_dir 2 -1
15853
15854         #delete default stripe information
15855         echo "delete default stripeEA"
15856         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
15857                 error "set default stripe on striped dir error"
15858
15859         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
15860         for dir in $(find $DIR/$tdir/normal_dir/*); do
15861                 stripe_count=$($LFS getdirstripe -c $dir)
15862                 [ $stripe_count -eq 0 ] ||
15863                         error "expect 1 get $stripe_count for $dir"
15864                 stripe_index=$($LFS getdirstripe -i $dir)
15865                 [ $stripe_index -eq 0 ] ||
15866                         error "expect 0 get $stripe_index for $dir"
15867         done
15868 }
15869 run_test 300g "check default striped directory for normal directory"
15870
15871 test_300h() {
15872         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15873                 skip "Need MDS version at least 2.7.55" && return
15874         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15875         local dir
15876         local stripe_count
15877
15878         mkdir $DIR/$tdir
15879         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
15880                                         $DIR/$tdir/striped_dir ||
15881                 error "set striped dir error"
15882
15883         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
15884         test_300_check_default_striped_dir striped_dir 1 0
15885         test_300_check_default_striped_dir striped_dir 2 1
15886         test_300_check_default_striped_dir striped_dir 2 -1
15887
15888         #delete default stripe information
15889         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
15890                 error "set default stripe on striped dir error"
15891
15892         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
15893         for dir in $(find $DIR/$tdir/striped_dir/*); do
15894                 stripe_count=$($LFS getdirstripe -c $dir)
15895                 [ $stripe_count -eq 0 ] ||
15896                         error "expect 1 get $stripe_count for $dir"
15897         done
15898 }
15899 run_test 300h "check default striped directory for striped directory"
15900
15901 test_300i() {
15902         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15903                 skip "Need MDS version at least 2.7.55" && return
15904         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15905         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15906         local stripe_count
15907         local file
15908
15909         mkdir $DIR/$tdir
15910
15911         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15912                 error "set striped dir error"
15913
15914         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15915                 error "create files under striped dir failed"
15916
15917         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
15918                 error "set striped hashdir error"
15919
15920         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
15921                 error "create dir0 under hash dir failed"
15922         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
15923                 error "create dir1 under hash dir failed"
15924
15925         # unfortunately, we need to umount to clear dir layout cache for now
15926         # once we fully implement dir layout, we can drop this
15927         umount_client $MOUNT || error "umount failed"
15928         mount_client $MOUNT || error "mount failed"
15929
15930         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
15931         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
15932         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
15933
15934         #set the stripe to be unknown hash type
15935         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
15936         $LCTL set_param fail_loc=0x1901
15937         for ((i = 0; i < 10; i++)); do
15938                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
15939                         error "stat f-$i failed"
15940                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
15941         done
15942
15943         touch $DIR/$tdir/striped_dir/f0 &&
15944                 error "create under striped dir with unknown hash should fail"
15945
15946         $LCTL set_param fail_loc=0
15947
15948         umount_client $MOUNT || error "umount failed"
15949         mount_client $MOUNT || error "mount failed"
15950
15951         return 0
15952 }
15953 run_test 300i "client handle unknown hash type striped directory"
15954
15955 test_300j() {
15956         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15957         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15958                 skip "Need MDS version at least 2.7.55" && return
15959         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15960         local stripe_count
15961         local file
15962
15963         mkdir $DIR/$tdir
15964
15965         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
15966         $LCTL set_param fail_loc=0x1702
15967         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15968                 error "set striped dir error"
15969
15970         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15971                 error "create files under striped dir failed"
15972
15973         $LCTL set_param fail_loc=0
15974
15975         rm -rf $DIR/$tdir || error "unlink striped dir fails"
15976
15977         return 0
15978 }
15979 run_test 300j "test large update record"
15980
15981 test_300k() {
15982         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15983                 skip "Need MDS version at least 2.7.55" && return
15984         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15985         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15986         local stripe_count
15987         local file
15988
15989         mkdir $DIR/$tdir
15990
15991         #define OBD_FAIL_LARGE_STRIPE   0x1703
15992         $LCTL set_param fail_loc=0x1703
15993         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
15994                 error "set striped dir error"
15995         $LCTL set_param fail_loc=0
15996
15997         $LFS getdirstripe $DIR/$tdir/striped_dir ||
15998                 error "getstripeddir fails"
15999         rm -rf $DIR/$tdir/striped_dir ||
16000                 error "unlink striped dir fails"
16001
16002         return 0
16003 }
16004 run_test 300k "test large striped directory"
16005
16006 test_300l() {
16007         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16008                 skip "Need MDS version at least 2.7.55" && return
16009         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16010         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16011         local stripe_index
16012
16013         test_mkdir -p $DIR/$tdir/striped_dir
16014         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
16015                         error "chown $RUNAS_ID failed"
16016         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
16017                 error "set default striped dir failed"
16018
16019         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
16020         $LCTL set_param fail_loc=0x80000158
16021         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
16022
16023         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
16024         [ $stripe_index -eq 1 ] ||
16025                 error "expect 1 get $stripe_index for $dir"
16026 }
16027 run_test 300l "non-root user to create dir under striped dir with stale layout"
16028
16029 test_300m() {
16030         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16031                 skip "Need MDS version at least 2.7.55" && return
16032         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16033         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
16034
16035         mkdir -p $DIR/$tdir/striped_dir
16036         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
16037                 error "set default stripes dir error"
16038
16039         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
16040
16041         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
16042         [ $stripe_count -eq 0 ] ||
16043                         error "expect 0 get $stripe_count for a"
16044
16045         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
16046                 error "set default stripes dir error"
16047
16048         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
16049
16050         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
16051         [ $stripe_count -eq 0 ] ||
16052                         error "expect 0 get $stripe_count for b"
16053
16054         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
16055                 error "set default stripes dir error"
16056
16057         mkdir $DIR/$tdir/striped_dir/c &&
16058                 error "default stripe_index is invalid, mkdir c should fails"
16059
16060         rm -rf $DIR/$tdir || error "rmdir fails"
16061 }
16062 run_test 300m "setstriped directory on single MDT FS"
16063
16064 cleanup_300n() {
16065         local list=$(comma_list $(mdts_nodes))
16066
16067         trap 0
16068         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
16069 }
16070
16071 test_300n() {
16072         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16073                 skip "Need MDS version at least 2.7.55" && return
16074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16075         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16076         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16077
16078         local stripe_index
16079         local list=$(comma_list $(mdts_nodes))
16080
16081         trap cleanup_300n RETURN EXIT
16082         mkdir -p $DIR/$tdir
16083         chmod 777 $DIR/$tdir
16084         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
16085                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
16086                 error "create striped dir succeeds with gid=0"
16087
16088         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
16089         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
16090                 error "create striped dir fails with gid=-1"
16091
16092         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
16093         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
16094                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
16095                 error "set default striped dir succeeds with gid=0"
16096
16097
16098         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
16099         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
16100                 error "set default striped dir fails with gid=-1"
16101
16102
16103         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
16104         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
16105                                         error "create test_dir fails"
16106         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
16107                                         error "create test_dir1 fails"
16108         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
16109                                         error "create test_dir2 fails"
16110         cleanup_300n
16111 }
16112 run_test 300n "non-root user to create dir under striped dir with default EA"
16113
16114 test_300o() {
16115         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16116                 skip "Need MDS version at least 2.7.55" && return
16117         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16118         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16119         local numfree1
16120         local numfree2
16121
16122         mkdir -p $DIR/$tdir
16123
16124         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
16125         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
16126         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
16127                 skip "not enough free inodes $numfree1 $numfree2"
16128                 return
16129         fi
16130
16131         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
16132         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
16133         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
16134                 skip "not enough free space $numfree1 $numfree2"
16135                 return
16136         fi
16137
16138         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
16139                 error "setdirstripe fails"
16140
16141         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
16142                 error "create dirs fails"
16143
16144         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
16145         ls $DIR/$tdir/striped_dir > /dev/null ||
16146                 error "ls striped dir fails"
16147         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
16148                 error "unlink big striped dir fails"
16149 }
16150 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
16151
16152 test_300p() {
16153         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16154         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16155         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16156
16157         mkdir -p $DIR/$tdir
16158
16159         #define OBD_FAIL_OUT_ENOSPC     0x1704
16160         do_facet mds2 lctl set_param fail_loc=0x80001704
16161         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
16162                         error "create striped directory should fail"
16163
16164         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
16165
16166         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
16167         true
16168 }
16169 run_test 300p "create striped directory without space"
16170
16171 test_300q() {
16172         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16173         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16174
16175         local fd=$(free_fd)
16176         local cmd="exec $fd<$tdir"
16177         cd $DIR
16178         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
16179         eval $cmd
16180         cmd="exec $fd<&-"
16181         trap "eval $cmd" EXIT
16182         cd $tdir || error "cd $tdir fails"
16183         rmdir  ../$tdir || error "rmdir $tdir fails"
16184         mkdir local_dir && error "create dir succeeds"
16185         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
16186         eval $cmd
16187         return 0
16188 }
16189 run_test 300q "create remote directory under orphan directory"
16190
16191 prepare_remote_file() {
16192         mkdir $DIR/$tdir/src_dir ||
16193                 error "create remote source failed"
16194
16195         cp /etc/hosts $DIR/$tdir/src_dir/a || error
16196         touch $DIR/$tdir/src_dir/a
16197
16198         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
16199                 error "create remote target dir failed"
16200
16201         touch $DIR/$tdir/tgt_dir/b
16202
16203         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
16204                 error "rename dir cross MDT failed!"
16205
16206         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
16207                 error "src_child still exists after rename"
16208
16209         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
16210                 error "missing file(a) after rename"
16211
16212         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
16213                 error "diff after rename"
16214 }
16215
16216 test_310a() {
16217         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
16218         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16219         local remote_file=$DIR/$tdir/tgt_dir/b
16220
16221         mkdir -p $DIR/$tdir
16222
16223         prepare_remote_file || error "prepare remote file failed"
16224
16225         #open-unlink file
16226         $OPENUNLINK $remote_file $remote_file || error
16227         $CHECKSTAT -a $remote_file || error
16228 }
16229 run_test 310a "open unlink remote file"
16230
16231 test_310b() {
16232         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
16233         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16234         local remote_file=$DIR/$tdir/tgt_dir/b
16235
16236         mkdir -p $DIR/$tdir
16237
16238         prepare_remote_file || error "prepare remote file failed"
16239
16240         ln $remote_file $DIR/$tfile || error "link failed for remote file"
16241         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
16242         $CHECKSTAT -t file $remote_file || error "check file failed"
16243 }
16244 run_test 310b "unlink remote file with multiple links while open"
16245
16246 test_310c() {
16247         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
16248         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16249         local remote_file=$DIR/$tdir/tgt_dir/b
16250
16251         mkdir -p $DIR/$tdir
16252
16253         prepare_remote_file || error "prepare remote file failed"
16254
16255         ln $remote_file $DIR/$tfile || error "link failed for remote file"
16256         multiop_bg_pause $remote_file O_uc ||
16257                         error "mulitop failed for remote file"
16258         MULTIPID=$!
16259         $MULTIOP $DIR/$tfile Ouc
16260         kill -USR1 $MULTIPID
16261         wait $MULTIPID
16262 }
16263 run_test 310c "open-unlink remote file with multiple links"
16264
16265 #LU-4825
16266 test_311() {
16267         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.54) ] &&
16268                 skip "lustre < 2.8.54 does not contain LU-4825 fix" && return
16269         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16270         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16271
16272         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
16273
16274         mkdir -p $DIR/$tdir
16275         $SETSTRIPE -i 0 -c 1 $DIR/$tdir
16276         createmany -o $DIR/$tdir/$tfile. 1000
16277
16278         # statfs data is not real time, let's just calculate it
16279         old_iused=$((old_iused + 1000))
16280
16281         local count=$(do_facet $SINGLEMDS "lctl get_param -n \
16282                         osp.*OST0000*MDT0000.create_count")
16283         local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
16284                                 osp.*OST0000*MDT0000.max_create_count")
16285         for idx in $(seq $MDSCOUNT); do
16286                 do_facet mds$idx "lctl set_param -n \
16287                         osp.*OST0000*MDT000?.max_create_count=0"
16288         done
16289
16290         $SETSTRIPE -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
16291         local index=$($GETSTRIPE -i $DIR/$tdir/$tfile)
16292         [ $index -ne 0 ] || error "$tfile stripe index is 0"
16293
16294         unlinkmany $DIR/$tdir/$tfile. 1000
16295
16296         for idx in $(seq $MDSCOUNT); do
16297                 do_facet mds$idx "lctl set_param -n \
16298                         osp.*OST0000*MDT000?.max_create_count=$max_count"
16299                 do_facet mds$idx "lctl set_param -n \
16300                         osp.*OST0000*MDT000?.create_count=$count"
16301         done
16302
16303         local new_iused
16304         for i in $(seq 120); do
16305                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
16306                 # system may be too busy to destroy all objs in time, use
16307                 # a somewhat small value to not fail autotest
16308                 [ $((old_iused - new_iused)) -gt 400 ] && break
16309                 sleep 1
16310         done
16311
16312         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
16313         [ $((old_iused - new_iused)) -gt 400 ] ||
16314                 error "objs not destroyed after unlink"
16315 }
16316 run_test 311 "disable OSP precreate, and unlink should destroy objs"
16317
16318 zfs_oid_to_objid()
16319 {
16320         local ost=$1
16321         local objid=$2
16322
16323         local vdevdir=$(dirname $(facet_vdevice $ost))
16324         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
16325         local zfs_zapid=$(do_facet $ost $cmd |
16326                           grep -w "/O/0/d$((objid%32))" -C 5 |
16327                           awk '/Object/{getline; print $1}')
16328         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
16329                           awk "/$objid = /"'{printf $3}')
16330
16331         echo $zfs_objid
16332 }
16333
16334 zfs_object_blksz() {
16335         local ost=$1
16336         local objid=$2
16337
16338         local vdevdir=$(dirname $(facet_vdevice $ost))
16339         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
16340         local blksz=$(do_facet $ost $cmd $objid |
16341                       awk '/dblk/{getline; printf $4}')
16342
16343         case "${blksz: -1}" in
16344                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
16345                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
16346                 *) ;;
16347         esac
16348
16349         echo $blksz
16350 }
16351
16352 test_312() { # LU-4856
16353         remote_ost_nodsh && skip "remote OST with nodsh" && return
16354
16355         [ $(facet_fstype ost1) = "zfs" ] ||
16356                 { skip "the test only applies to zfs" && return; }
16357
16358         local max_blksz=$(do_facet ost1 \
16359                           $ZFS get -p recordsize $(facet_device ost1) |
16360                           awk '!/VALUE/{print $3}')
16361         local min_blksz=$(getconf PAGE_SIZE)
16362
16363         # to make life a little bit easier
16364         $LFS mkdir -c 1 -i 0 $DIR/$tdir
16365         $LFS setstripe -c 1 -i 0 $DIR/$tdir
16366
16367         local tf=$DIR/$tdir/$tfile
16368         touch $tf
16369         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
16370
16371         # Get ZFS object id
16372         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
16373
16374         # block size change by sequential over write
16375         local blksz
16376         for ((bs=$min_blksz; bs <= max_blksz; bs <<= 2)); do
16377                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
16378
16379                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
16380                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
16381         done
16382         rm -f $tf
16383
16384         # block size change by sequential append write
16385         dd if=/dev/zero of=$tf bs=$min_blksz count=1 oflag=sync conv=notrunc
16386         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
16387         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
16388
16389         for ((count = 1; count < $((max_blksz / min_blksz)); count *= 2)); do
16390                 dd if=/dev/zero of=$tf bs=$min_blksz count=$count seek=$count \
16391                         oflag=sync conv=notrunc
16392
16393                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
16394                 [ $blksz -eq $((2 * count * min_blksz)) ] ||
16395                         error "blksz error, actual $blksz, "    \
16396                                 "expected: 2 * $count * $min_blksz"
16397         done
16398         rm -f $tf
16399
16400         # random write
16401         touch $tf
16402         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
16403         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
16404
16405         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
16406         blksz=$(zfs_object_blksz ost1 $zfs_objid)
16407         [ $blksz -eq $min_blksz ] ||
16408                 error "blksz error: $blksz, expected: $min_blksz"
16409
16410         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
16411         blksz=$(zfs_object_blksz ost1 $zfs_objid)
16412         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
16413
16414         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
16415         blksz=$(zfs_object_blksz ost1 $zfs_objid)
16416         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
16417 }
16418 run_test 312 "make sure ZFS adjusts its block size by write pattern"
16419
16420 test_313() {
16421         remote_ost_nodsh && skip "remote OST with nodsh" && return
16422
16423         local file=$DIR/$tfile
16424         rm -f $file
16425         $SETSTRIPE -c 1 -i 0 $file || error "setstripe failed"
16426
16427         # define OBD_FAIL_TGT_RCVD_EIO           0x720
16428         do_facet ost1 "$LCTL set_param fail_loc=0x720"
16429         dd if=/dev/zero of=$file bs=4096 oflag=direct count=1 &&
16430                 error "write should failed"
16431         do_facet ost1 "$LCTL set_param fail_loc=0"
16432         rm -f $file
16433 }
16434 run_test 313 "io should fail after last_rcvd update fail"
16435
16436 test_fake_rw() {
16437         local read_write=$1
16438         if [ "$read_write" = "write" ]; then
16439                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
16440         elif [ "$read_write" = "read" ]; then
16441                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
16442         else
16443                 error "argument error"
16444         fi
16445
16446         # turn off debug for performance testing
16447         local saved_debug=$($LCTL get_param -n debug)
16448         $LCTL set_param debug=0
16449
16450         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
16451
16452         # get ost1 size - lustre-OST0000
16453         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
16454         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
16455         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
16456
16457         if [ "$read_write" = "read" ]; then
16458                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
16459         fi
16460
16461         local start_time=$(date +%s.%N)
16462         $dd_cmd bs=1M count=$blocks oflag=sync ||
16463                 error "real dd $read_write error"
16464         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
16465
16466         if [ "$read_write" = "write" ]; then
16467                 rm -f $DIR/$tfile
16468         fi
16469
16470         # define OBD_FAIL_OST_FAKE_RW           0x238
16471         do_facet ost1 $LCTL set_param fail_loc=0x238
16472
16473         local start_time=$(date +%s.%N)
16474         $dd_cmd bs=1M count=$blocks oflag=sync ||
16475                 error "fake dd $read_write error"
16476         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
16477
16478         if [ "$read_write" = "write" ]; then
16479                 # verify file size
16480                 cancel_lru_locks osc
16481                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
16482                         error "$tfile size not $blocks MB"
16483         fi
16484         do_facet ost1 $LCTL set_param fail_loc=0
16485
16486         echo "fake $read_write $duration_fake vs. normal $read_write" \
16487                 "$duration in seconds"
16488         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
16489                 error_not_in_vm "fake write is slower"
16490
16491         $LCTL set_param -n debug="$saved_debug"
16492         rm -f $DIR/$tfile
16493 }
16494 test_399a() { # LU-7655 for OST fake write
16495         remote_ost_nodsh && skip "remote OST with nodsh" && return
16496
16497         test_fake_rw write
16498 }
16499 run_test 399a "fake write should not be slower than normal write"
16500
16501 test_399b() { # LU-8726 for OST fake read
16502         remote_ost_nodsh && skip "remote OST with nodsh" && return
16503
16504         if [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
16505                 skip "ldiskfs only test" && return 0
16506         fi
16507         test_fake_rw read
16508 }
16509 run_test 399b "fake read should not be slower than normal read"
16510
16511 test_400a() { # LU-1606, was conf-sanity test_74
16512         local extra_flags=''
16513         local out=$TMP/$tfile
16514         local prefix=/usr/include/lustre
16515         local prog
16516
16517         if ! which $CC > /dev/null 2>&1; then
16518                 skip_env "$CC is not installed"
16519                 return 0
16520         fi
16521
16522         if ! [[ -d $prefix ]]; then
16523                 # Assume we're running in tree and fixup the include path.
16524                 extra_flags+=" -I$LUSTRE/include"
16525                 extra_flags+=" -L$LUSTRE/utils"
16526         fi
16527
16528         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
16529                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
16530                         error "client api broken"
16531         done
16532         rm -f $out
16533 }
16534 run_test 400a "Lustre client api program can compile and link"
16535
16536 test_400b() { # LU-1606, LU-5011
16537         local header
16538         local out=$TMP/$tfile
16539         local prefix=/usr/include/linux/lustre
16540
16541         # We use a hard coded prefix so that this test will not fail
16542         # when run in tree. There are headers in lustre/include/lustre/
16543         # that are not packaged (like lustre_idl.h) and have more
16544         # complicated include dependencies (like config.h and lnet/types.h).
16545         # Since this test about correct packaging we just skip them when
16546         # they don't exist (see below) rather than try to fixup cppflags.
16547
16548         if ! which $CC > /dev/null 2>&1; then
16549                 skip_env "$CC is not installed"
16550                 return 0
16551         fi
16552
16553         for header in $prefix/*.h; do
16554                 if ! [[ -f "$header" ]]; then
16555                         continue
16556                 fi
16557
16558                 if [[ "$(basename $header)" == lustre_ioctl.h ]]; then
16559                         continue # lustre_ioctl.h is internal header
16560                 fi
16561
16562                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
16563                         error "cannot compile '$header'"
16564         done
16565         rm -f $out
16566 }
16567 run_test 400b "packaged headers can be compiled"
16568
16569 test_401a() { #LU-7437
16570         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
16571         [ -n "$printf_arg" ] && skip_env "find does not support -printf" &&
16572                 return
16573         #count the number of parameters by "list_param -R"
16574         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
16575         #count the number of parameters by listing proc files
16576         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
16577         echo "proc_dirs='$proc_dirs'"
16578         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
16579         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
16580                       sort -u | wc -l)
16581
16582         [ $params -eq $procs ] ||
16583                 error "found $params parameters vs. $procs proc files"
16584
16585         # test the list_param -D option only returns directories
16586         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
16587         #count the number of parameters by listing proc directories
16588         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
16589                 sort -u | wc -l)
16590
16591         [ $params -eq $procs ] ||
16592                 error "found $params parameters vs. $procs proc files"
16593 }
16594 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
16595
16596 test_401b() {
16597         local save=$($LCTL get_param -n jobid_var)
16598         local tmp=testing
16599
16600         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
16601                 error "no error returned when setting bad parameters"
16602
16603         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
16604         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
16605
16606         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
16607         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
16608         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
16609 }
16610 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
16611
16612 test_401c() {
16613         local jobid_var_old=$($LCTL get_param -n jobid_var)
16614         local jobid_var_new
16615
16616         $LCTL set_param jobid_var= &&
16617                 error "no error returned for 'set_param a='"
16618
16619         jobid_var_new=$($LCTL get_param -n jobid_var)
16620         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16621                 error "jobid_var was changed by setting without value"
16622
16623         $LCTL set_param jobid_var &&
16624                 error "no error returned for 'set_param a'"
16625
16626         jobid_var_new=$($LCTL get_param -n jobid_var)
16627         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16628                 error "jobid_var was changed by setting without value"
16629 }
16630 run_test 401c "Verify 'lctl set_param' without value fails in either format."
16631
16632 test_401d() {
16633         local jobid_var_old=$($LCTL get_param -n jobid_var)
16634         local jobid_var_new
16635         local new_value="foo=bar"
16636
16637         $LCTL set_param jobid_var=$new_value ||
16638                 error "'set_param a=b' did not accept a value containing '='"
16639
16640         jobid_var_new=$($LCTL get_param -n jobid_var)
16641         [[ "$jobid_var_new" == "$new_value" ]] ||
16642                 error "'set_param a=b' failed on a value containing '='"
16643
16644         # Reset the jobid_var to test the other format
16645         $LCTL set_param jobid_var=$jobid_var_old
16646         jobid_var_new=$($LCTL get_param -n jobid_var)
16647         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16648                 error "failed to reset jobid_var"
16649
16650         $LCTL set_param jobid_var $new_value ||
16651                 error "'set_param a b' did not accept a value containing '='"
16652
16653         jobid_var_new=$($LCTL get_param -n jobid_var)
16654         [[ "$jobid_var_new" == "$new_value" ]] ||
16655                 error "'set_param a b' failed on a value containing '='"
16656
16657         $LCTL set_param jobid_var $jobid_var_old
16658         jobid_var_new=$($LCTL get_param -n jobid_var)
16659         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16660                 error "failed to reset jobid_var"
16661 }
16662 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
16663
16664 test_402() {
16665         local server_version=$(lustre_version_code $SINGLEMDS)
16666         [[ $server_version -ge $(version_code 2.7.66) ]] ||
16667         [[ $server_version -ge $(version_code 2.7.18.4) &&
16668                 $server_version -lt $(version_code 2.7.50) ]] ||
16669         [[ $server_version -ge $(version_code 2.7.2) &&
16670                 $server_version -lt $(version_code 2.7.11) ]] ||
16671                 { skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+";
16672                         return; }
16673         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16674         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
16675 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
16676         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
16677         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
16678                 echo "Touch failed - OK"
16679 }
16680 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
16681
16682 test_403() {
16683         local file1=$DIR/$tfile.1
16684         local file2=$DIR/$tfile.2
16685         local tfile=$TMP/$tfile
16686
16687         rm -f $file1 $file2 $tfile
16688
16689         touch $file1
16690         ln $file1 $file2
16691
16692         # 30 sec OBD_TIMEOUT in ll_getattr()
16693         # right before populating st_nlink
16694         $LCTL set_param fail_loc=0x80001409
16695         stat -c %h $file1 > $tfile &
16696
16697         # create an alias, drop all locks and reclaim the dentry
16698         < $file2
16699         cancel_lru_locks mdc
16700         cancel_lru_locks osc
16701         sysctl -w vm.drop_caches=2
16702
16703         wait
16704
16705         [ `cat $tfile` -gt 0 ] || error "wrong nlink count: `cat $tfile`"
16706
16707         rm -f $tfile $file1 $file2
16708 }
16709 run_test 403 "i_nlink should not drop to zero due to aliasing"
16710
16711 test_404() { # LU-6601
16712         local server_version=$(lustre_version_code $SINGLEMDS)
16713         [[ $server_version -ge $(version_code 2.8.53) ]] ||
16714                 { skip "Need server version newer than 2.8.52"; return 0; }
16715
16716         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16717         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
16718                 awk '/osp .*-osc-MDT/ { print $4}')
16719
16720         local osp
16721         for osp in $mosps; do
16722                 echo "Deactivate: " $osp
16723                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
16724                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16725                         awk -vp=$osp '$4 == p { print $2 }')
16726                 [ $stat = IN ] || {
16727                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16728                         error "deactivate error"
16729                 }
16730                 echo "Activate: " $osp
16731                 do_facet $SINGLEMDS $LCTL --device %$osp activate
16732                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16733                         awk -vp=$osp '$4 == p { print $2 }')
16734                 [ $stat = UP ] || {
16735                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16736                         error "activate error"
16737                 }
16738         done
16739 }
16740 run_test 404 "validate manual {de}activated works properly for OSPs"
16741
16742 test_405() {
16743         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) -o \
16744         [ $(lustre_version_code client) -lt $(version_code 2.6.99) ] &&
16745                 skip "Layout swap lock is not supported" && return
16746
16747         check_swap_layouts_support && return 0
16748
16749         test_mkdir $DIR/$tdir
16750         swap_lock_test -d $DIR/$tdir ||
16751                 error "One layout swap locked test failed"
16752 }
16753 run_test 405 "Various layout swap lock tests"
16754
16755 test_406() {
16756         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16757         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
16758         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
16759         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16760         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.50) ] &&
16761                 skip "Need MDS version at least 2.8.50" && return
16762
16763         local def_stripe_count=$($GETSTRIPE -c $MOUNT)
16764         local def_stripe_size=$($GETSTRIPE -S $MOUNT)
16765         local def_stripe_offset=$($GETSTRIPE -i $MOUNT)
16766         local def_pool=$($GETSTRIPE -p $MOUNT)
16767
16768         local test_pool=$TESTNAME
16769         pool_add $test_pool || error "pool_add failed"
16770         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
16771                 error "pool_add_targets failed"
16772
16773         # parent set default stripe count only, child will stripe from both
16774         # parent and fs default
16775         $SETSTRIPE -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
16776                 error "setstripe $MOUNT failed"
16777         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
16778         $SETSTRIPE -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
16779         for i in $(seq 10); do
16780                 local f=$DIR/$tdir/$tfile.$i
16781                 touch $f || error "touch failed"
16782                 local count=$($GETSTRIPE -c $f)
16783                 [ $count -eq $OSTCOUNT ] ||
16784                         error "$f stripe count $count != $OSTCOUNT"
16785                 local offset=$($GETSTRIPE -i $f)
16786                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
16787                 local size=$($GETSTRIPE -S $f)
16788                 [ $size -eq $((def_stripe_size * 2)) ] ||
16789                         error "$f stripe size $size != $((def_stripe_size * 2))"
16790                 local pool=$($GETSTRIPE -p $f)
16791                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
16792         done
16793
16794         # change fs default striping, delete parent default striping, now child
16795         # will stripe from new fs default striping only
16796         $SETSTRIPE -c 1 -S $def_stripe_size -i 0 $MOUNT ||
16797                 error "change $MOUNT default stripe failed"
16798         $SETSTRIPE -c 0 $DIR/$tdir || error "delete $tdir default stripe failed"
16799         for i in $(seq 11 20); do
16800                 local f=$DIR/$tdir/$tfile.$i
16801                 touch $f || error "touch $f failed"
16802                 local count=$($GETSTRIPE -c $f)
16803                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
16804                 local offset=$($GETSTRIPE -i $f)
16805                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
16806                 local size=$($GETSTRIPE -S $f)
16807                 [ $size -eq $def_stripe_size ] ||
16808                         error "$f stripe size $size != $def_stripe_size"
16809                 local pool=$($GETSTRIPE -p $f)
16810                 [ "#$pool" == "#" ] || error "$f pool $pool is set"
16811
16812         done
16813
16814         unlinkmany $DIR/$tdir/$tfile. 1 20
16815
16816         # restore FS default striping
16817         if [ -z $def_pool ]; then
16818                 $SETSTRIPE -c $def_stripe_count -S $def_stripe_size \
16819                         -i $def_stripe_offset $MOUNT ||
16820                         error "restore default striping failed"
16821         else
16822                 $SETSTRIPE -c $def_stripe_count -S $def_stripe_size \
16823                         -i $def_stripe_offset -p $def_pool $MOUNT ||
16824                         error "restore default striping with $def_pool failed"
16825         fi
16826
16827         local f=$DIR/$tdir/$tfile
16828         pool_remove_all_targets $test_pool $f
16829         pool_remove $test_pool $f
16830 }
16831 run_test 406 "DNE support fs default striping"
16832
16833 test_407() {
16834         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16835         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
16836                 skip "Need MDS version at least 2.8.55" && return
16837         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16838
16839         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
16840                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
16841         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
16842                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
16843         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
16844
16845         #define OBD_FAIL_DT_TXN_STOP    0x2019
16846         for idx in $(seq $MDSCOUNT); do
16847                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
16848         done
16849         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
16850         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
16851                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
16852         true
16853 }
16854 run_test 407 "transaction fail should cause operation fail"
16855
16856 test_408() {
16857         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
16858
16859         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
16860         lctl set_param fail_loc=0x8000040a
16861         # let ll_prepare_partial_page() fail
16862         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
16863
16864         rm -f $DIR/$tfile
16865
16866         # create at least 100 unused inodes so that
16867         # shrink_icache_memory(0) should not return 0
16868         touch $DIR/$tfile-{0..100}
16869         rm -f $DIR/$tfile-{0..100}
16870         sync
16871
16872         echo 2 > /proc/sys/vm/drop_caches
16873 }
16874 run_test 408 "drop_caches should not hang due to page leaks"
16875
16876 test_409()
16877 {
16878         [ $MDSCOUNT -lt 2 ] &&
16879                 skip "We need at least 2 MDTs for this test" && return
16880
16881         check_mount_and_prep
16882
16883         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
16884         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
16885         touch $DIR/$tdir/guard || error "(2) Fail to create"
16886
16887         local PREFIX=$(str_repeat 'A' 128)
16888         echo "Create 1K hard links start at $(date)"
16889         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16890                 error "(3) Fail to hard link"
16891
16892         echo "Links count should be right although linkEA overflow"
16893         stat $DIR/$tdir/guard || error "(4) Fail to stat"
16894         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
16895         [ $linkcount -eq 1001 ] ||
16896                 error "(5) Unexpected hard links count: $linkcount"
16897
16898         echo "List all links start at $(date)"
16899         ls -l $DIR/$tdir/foo > /dev/null ||
16900                 error "(6) Fail to list $DIR/$tdir/foo"
16901
16902         echo "Unlink hard links start at $(date)"
16903         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16904                 error "(7) Fail to unlink"
16905 }
16906 run_test 409 "Large amount of cross-MDTs hard links on the same file"
16907
16908 test_410()
16909 {
16910         [[ $(lustre_version_code client) -lt $(version_code 2.9.59) ]] &&
16911                 skip "Need client version at least 2.9.59" && return
16912
16913         # Create a file, and stat it from the kernel
16914         local testfile=$DIR/$tfile
16915         touch $testfile
16916
16917         local run_id=$RANDOM
16918         local my_ino=$(stat --format "%i" $testfile)
16919
16920         # Try to insert the module. This will always fail as the
16921         # module is designed to not be inserted.
16922         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
16923             &> /dev/null
16924
16925         # Anything but success is a test failure
16926         dmesg | grep -q \
16927             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
16928             error "no inode match"
16929 }
16930 run_test 410 "Test inode number returned from kernel thread"
16931
16932 cleanup_test411_cgroup() {
16933         trap 0
16934         rmdir "$1"
16935 }
16936
16937 test_411() {
16938         local cg_basedir=/sys/fs/cgroup/memory
16939         # LU-9966
16940         test -f "$cg_basedir/memory.kmem.limit_in_bytes" ||
16941                 { skip "no setup for cgroup"; return; }
16942
16943         dd if=/dev/zero of=$DIR/$tfile bs=1M count=100 conv=fsync ||
16944                 error "test file creation failed"
16945         cancel_lru_locks osc
16946
16947         # Create a very small memory cgroup to force a slab allocation error
16948         local cgdir=$cg_basedir/osc_slab_alloc
16949         mkdir $cgdir || error "cgroup mkdir '$cgdir' failed"
16950         trap "cleanup_test411_cgroup $cgdir" EXIT
16951         echo 2M > $cgdir/memory.kmem.limit_in_bytes
16952         echo 1M > $cgdir/memory.limit_in_bytes
16953
16954         # Should not LBUG, just be killed by oom-killer
16955         sh -c "echo \$$ > $cgdir/tasks && dd if=$DIR/$tfile of=/dev/null" &&
16956                 error "fail to trigger a memory allocation error"
16957
16958         cleanup_test411_cgroup $cgdir
16959
16960         return 0
16961 }
16962 run_test 411 "Slab allocation error with cgroup does not LBUG"
16963
16964 prep_801() {
16965         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
16966         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
16967                 skip "Need server version at least 2.9.55" & exit 0
16968         start_full_debug_logging
16969 }
16970
16971 post_801() {
16972         stop_full_debug_logging
16973 }
16974
16975 barrier_stat() {
16976         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16977                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16978                            awk '/The barrier for/ { print $7 }')
16979                 echo $st
16980         else
16981                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
16982                 echo \'$st\'
16983         fi
16984 }
16985
16986 barrier_expired() {
16987         local expired
16988
16989         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16990                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16991                           awk '/will be expired/ { print $7 }')
16992         else
16993                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
16994         fi
16995
16996         echo $expired
16997 }
16998
16999 test_801a() {
17000         prep_801
17001
17002         echo "Start barrier_freeze at: $(date)"
17003         #define OBD_FAIL_BARRIER_DELAY          0x2202
17004         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
17005         do_facet mgs $LCTL barrier_freeze $FSNAME 10 &
17006
17007         sleep 2
17008         local b_status=$(barrier_stat)
17009         echo "Got barrier status at: $(date)"
17010         [ "$b_status" = "'freezing_p1'" ] ||
17011                 error "(1) unexpected barrier status $b_status"
17012
17013         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
17014         wait
17015         b_status=$(barrier_stat)
17016         [ "$b_status" = "'frozen'" ] ||
17017                 error "(2) unexpected barrier status $b_status"
17018
17019         local expired=$(barrier_expired)
17020         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
17021         sleep $((expired + 3))
17022
17023         b_status=$(barrier_stat)
17024         [ "$b_status" = "'expired'" ] ||
17025                 error "(3) unexpected barrier status $b_status"
17026
17027         do_facet mgs $LCTL barrier_freeze $FSNAME 10 ||
17028                 error "(4) fail to freeze barrier"
17029
17030         b_status=$(barrier_stat)
17031         [ "$b_status" = "'frozen'" ] ||
17032                 error "(5) unexpected barrier status $b_status"
17033
17034         echo "Start barrier_thaw at: $(date)"
17035         #define OBD_FAIL_BARRIER_DELAY          0x2202
17036         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
17037         do_facet mgs $LCTL barrier_thaw $FSNAME &
17038
17039         sleep 2
17040         b_status=$(barrier_stat)
17041         echo "Got barrier status at: $(date)"
17042         [ "$b_status" = "'thawing'" ] ||
17043                 error "(6) unexpected barrier status $b_status"
17044
17045         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
17046         wait
17047         b_status=$(barrier_stat)
17048         [ "$b_status" = "'thawed'" ] ||
17049                 error "(7) unexpected barrier status $b_status"
17050
17051         #define OBD_FAIL_BARRIER_FAILURE        0x2203
17052         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
17053         do_facet mgs $LCTL barrier_freeze $FSNAME
17054
17055         b_status=$(barrier_stat)
17056         [ "$b_status" = "'failed'" ] ||
17057                 error "(8) unexpected barrier status $b_status"
17058
17059         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
17060         do_facet mgs $LCTL barrier_thaw $FSNAME
17061
17062         post_801
17063 }
17064 run_test 801a "write barrier user interfaces and stat machine"
17065
17066 test_801b() {
17067         prep_801
17068
17069         mkdir $DIR/$tdir || error "(1) fail to mkdir"
17070         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
17071         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
17072         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
17073         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
17074
17075         cancel_lru_locks mdc
17076
17077         # 180 seconds should be long enough
17078         do_facet mgs $LCTL barrier_freeze $FSNAME 180
17079
17080         local b_status=$(barrier_stat)
17081         [ "$b_status" = "'frozen'" ] ||
17082                 error "(6) unexpected barrier status $b_status"
17083
17084         mkdir $DIR/$tdir/d0/d10 &
17085         mkdir_pid=$!
17086
17087         touch $DIR/$tdir/d1/f13 &
17088         touch_pid=$!
17089
17090         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
17091         ln_pid=$!
17092
17093         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
17094         mv_pid=$!
17095
17096         rm -f $DIR/$tdir/d4/f12 &
17097         rm_pid=$!
17098
17099         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
17100
17101         # To guarantee taht the 'stat' is not blocked
17102         b_status=$(barrier_stat)
17103         [ "$b_status" = "'frozen'" ] ||
17104                 error "(8) unexpected barrier status $b_status"
17105
17106         # let above commands to run at background
17107         sleep 5
17108
17109         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
17110         ps -p $touch_pid || error "(10) touch should be blocked"
17111         ps -p $ln_pid || error "(11) link should be blocked"
17112         ps -p $mv_pid || error "(12) rename should be blocked"
17113         ps -p $rm_pid || error "(13) unlink should be blocked"
17114
17115         b_status=$(barrier_stat)
17116         [ "$b_status" = "'frozen'" ] ||
17117                 error "(14) unexpected barrier status $b_status"
17118
17119         do_facet mgs $LCTL barrier_thaw $FSNAME
17120         b_status=$(barrier_stat)
17121         [ "$b_status" = "'thawed'" ] ||
17122                 error "(15) unexpected barrier status $b_status"
17123
17124         wait $mkdir_pid || error "(16) mkdir should succeed"
17125         wait $touch_pid || error "(17) touch should succeed"
17126         wait $ln_pid || error "(18) link should succeed"
17127         wait $mv_pid || error "(19) rename should succeed"
17128         wait $rm_pid || error "(20) unlink should succeed"
17129
17130         post_801
17131 }
17132 run_test 801b "modification will be blocked by write barrier"
17133
17134 test_801c() {
17135         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
17136
17137         prep_801
17138
17139         stop mds2 || error "(1) Fail to stop mds2"
17140
17141         do_facet mgs $LCTL barrier_freeze $FSNAME 30
17142
17143         local b_status=$(barrier_stat)
17144         [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || {
17145                 do_facet mgs $LCTL barrier_thaw $FSNAME
17146                 error "(2) unexpected barrier status $b_status"
17147         }
17148
17149         do_facet mgs $LCTL barrier_rescan $FSNAME ||
17150                 error "(3) Fail to rescan barrier bitmap"
17151
17152         do_facet mgs $LCTL barrier_freeze $FSNAME 10
17153
17154         b_status=$(barrier_stat)
17155         [ "$b_status" = "'frozen'" ] ||
17156                 error "(4) unexpected barrier status $b_status"
17157
17158         do_facet mgs $LCTL barrier_thaw $FSNAME
17159         b_status=$(barrier_stat)
17160         [ "$b_status" = "'thawed'" ] ||
17161                 error "(5) unexpected barrier status $b_status"
17162
17163         local devname=$(mdsdevname 2)
17164
17165         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
17166
17167         do_facet mgs $LCTL barrier_rescan $FSNAME ||
17168                 error "(7) Fail to rescan barrier bitmap"
17169
17170         post_801
17171 }
17172 run_test 801c "rescan barrier bitmap"
17173
17174 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
17175 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
17176 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
17177
17178 cleanup_802() {
17179         trap 0
17180
17181         stopall
17182         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
17183         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
17184         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
17185         setupall
17186 }
17187
17188 test_802() {
17189
17190         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
17191         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
17192                 skip "Need server version at least 2.9.55" & exit 0
17193
17194         mkdir $DIR/$tdir || error "(1) fail to mkdir"
17195
17196         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
17197                 error "(2) Fail to copy"
17198
17199         trap cleanup_802 EXIT
17200
17201         # sync by force before remount as readonly
17202         sync; sync_all_data; sleep 3; sync_all_data
17203
17204         stopall
17205
17206         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
17207         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
17208         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
17209
17210         echo "Mount the server as read only"
17211         setupall server_only || error "(3) Fail to start servers"
17212
17213         echo "Mount client without ro should fail"
17214         mount_client $MOUNT &&
17215                 error "(4) Mount client without 'ro' should fail"
17216
17217         echo "Mount client with ro should succeed"
17218         mount_client $MOUNT ro ||
17219                 error "(5) Mount client with 'ro' should succeed"
17220
17221         echo "Modify should be refused"
17222         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
17223
17224         echo "Read should be allowed"
17225         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
17226                 error "(7) Read should succeed under ro mode"
17227
17228         cleanup_802
17229 }
17230 run_test 802 "simulate readonly device"
17231
17232 #
17233 # tests that do cleanup/setup should be run at the end
17234 #
17235
17236 test_900() {
17237         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
17238         local ls
17239         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
17240         $LCTL set_param fail_loc=0x903
17241
17242         cancel_lru_locks MGC
17243
17244         FAIL_ON_ERROR=true cleanup
17245         FAIL_ON_ERROR=true setup
17246 }
17247 run_test 900 "umount should not race with any mgc requeue thread"
17248
17249 complete $SECONDS
17250 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
17251 check_and_cleanup_lustre
17252 if [ "$I_MOUNTED" != "yes" ]; then
17253         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
17254 fi
17255 exit_status