Whamcloud - gitweb
LU-10507 tests: use {save,restore}_layout() in test
[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
12 ALWAYS_EXCEPT="$SANITY_EXCEPT  42a     42b     42c"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # skipped tests: LU-8411 LU-9096 LU-9054
16 ALWAYS_EXCEPT="  407     253     312 $ALWAYS_EXCEPT"
17
18 # Check Grants after these tests
19 GRANT_CHECK_LIST="$GRANT_CHECK_LIST 42a 42b 42c 42d 42e 63a 63b 64a 64b 64c"
20
21 SRCDIR=$(cd $(dirname $0); echo $PWD)
22 export PATH=$PATH:/sbin
23
24 TMP=${TMP:-/tmp}
25
26 CC=${CC:-cc}
27 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
28 CREATETEST=${CREATETEST:-createtest}
29 LFS=${LFS:-lfs}
30 LFIND=${LFIND:-"$LFS find"}
31 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
32 LCTL=${LCTL:-lctl}
33 OPENFILE=${OPENFILE:-openfile}
34 OPENUNLINK=${OPENUNLINK:-openunlink}
35 export MULTIOP=${MULTIOP:-multiop}
36 READS=${READS:-"reads"}
37 MUNLINK=${MUNLINK:-munlink}
38 SOCKETSERVER=${SOCKETSERVER:-socketserver}
39 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
40 MEMHOG=${MEMHOG:-memhog}
41 DIRECTIO=${DIRECTIO:-directio}
42 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
43 STRIPES_PER_OBJ=-1
44 CHECK_GRANT=${CHECK_GRANT:-"yes"}
45 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
46 export PARALLEL=${PARALLEL:-"no"}
47
48 export NAME=${NAME:-local}
49
50 SAVE_PWD=$PWD
51
52 CLEANUP=${CLEANUP:-:}
53 SETUP=${SETUP:-:}
54 TRACE=${TRACE:-""}
55 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
56 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
57 . $LUSTRE/tests/test-framework.sh
58 init_test_env $@
59 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
60 init_logging
61
62 #                                  5          12          (min)"
63 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 300o"
64
65 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
66         # bug number for skipped test: LU-4536 LU-1957
67         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180"
68         #                                               13    (min)"
69         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
70 fi
71
72
73 is_sles11()                                             # LU-4341
74 {
75         if [ -r /etc/SuSE-release ]
76         then
77                 local vers=$(grep VERSION /etc/SuSE-release | awk '{print $3}')
78                 local patchlev=$(grep PATCHLEVEL /etc/SuSE-release |
79                         awk '{ print $3 }')
80                 if [ $vers -eq 11 ] && [ $patchlev -ge 3 ]; then
81                         return 0
82                 fi
83         fi
84         return 1
85 }
86
87 # Check if we are running on Ubuntu or SLES so we can make decisions on
88 # what tests to run
89 if is_sles11; then
90         # bug number for skipped test: LU-4341
91         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  170"
92 elif [ -r /etc/os-release ]; then
93         if grep -qi ubuntu /etc/os-release; then
94                 ubuntu_version=$(version_code $(sed -n -e 's/"//g' \
95                                                 -e 's/^VERSION=//p' \
96                                                 /etc/os-release |
97                                                 awk '{ print $1 }'))
98
99                 if [[ $ubuntu_version -gt $(version_code 16.0.0) ]]; then
100                         # bug number for skipped test:
101                         #                LU-10334 LU-10335 LU-10335 LU-10335
102                         ALWAYS_EXCEPT+=" 103a     130a     130b     130c"
103                         #                LU-10335 LU-10335 LU-10365 LU-10366
104                         ALWAYS_EXCEPT+=" 130d     130e     400a     410"
105                 fi
106         fi
107 fi
108
109 FAIL_ON_ERROR=false
110
111 cleanup() {
112         echo -n "cln.."
113         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
114         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
115 }
116 setup() {
117         echo -n "mnt.."
118         load_modules
119         setupall || exit 10
120         echo "done"
121 }
122
123 check_swap_layouts_support()
124 {
125         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
126                 { skip "Does not support layout lock."; return 0; }
127         return 1
128 }
129
130 check_and_setup_lustre
131 DIR=${DIR:-$MOUNT}
132 assert_DIR
133
134 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
135         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
136 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
137
138 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
139 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
140 rm -rf $DIR/[Rdfs][0-9]*
141
142 # $RUNAS_ID may get set incorrectly somewhere else
143 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
144
145 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
146
147 build_test_filter
148
149 if [ "${ONLY}" = "MOUNT" ] ; then
150         echo "Lustre is up, please go on"
151         exit
152 fi
153
154 echo "preparing for tests involving mounts"
155 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
156 touch $EXT2_DEV
157 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
158 echo # add a newline after mke2fs.
159
160 umask 077
161
162 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
163 lctl set_param debug=-1 2> /dev/null || true
164 test_0a() {
165         touch $DIR/$tfile
166         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
167         rm $DIR/$tfile
168         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
169 }
170 run_test 0a "touch; rm ====================="
171
172 test_0b() {
173         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
174         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
175 }
176 run_test 0b "chmod 0755 $DIR ============================="
177
178 test_0c() {
179         $LCTL get_param mdc.*.import | grep "state: FULL" ||
180                 error "import not FULL"
181         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
182                 error "bad target"
183 }
184 run_test 0c "check import proc ============================="
185
186 test_1() {
187         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
188         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
189         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
190         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
191         rmdir $DIR/$tdir/d2
192         rmdir $DIR/$tdir
193         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
194 }
195 run_test 1 "mkdir; remkdir; rmdir =============================="
196
197 test_2() {
198         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
199         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
200         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
201         rm -r $DIR/$tdir
202         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
203 }
204 run_test 2 "mkdir; touch; rmdir; check file ===================="
205
206 test_3() {
207         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
208         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
209         touch $DIR/$tdir/$tfile
210         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
211         rm -r $DIR/$tdir
212         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
213 }
214 run_test 3 "mkdir; touch; rmdir; check dir ====================="
215
216 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
217 test_4() {
218         local MDTIDX=1
219
220         test_mkdir $DIR/$tdir ||
221                 error "Create remote directory failed"
222
223         touch $DIR/$tdir/$tfile ||
224                 error "Create file under remote directory failed"
225
226         rmdir $DIR/$tdir &&
227                 error "Expect error removing in-use dir $DIR/$tdir"
228
229         test -d $DIR/$tdir || error "Remote directory disappeared"
230
231         rm -rf $DIR/$tdir || error "remove remote dir error"
232 }
233 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
234
235 test_5() {
236         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
237         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
238         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
239         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
240         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
241 }
242 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
243
244 test_6a() {
245         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
246         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
247         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
248                 error "$tfile does not have perm 0666 or UID $UID"
249         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
250         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
251                 error "$tfile should be 0666 and owned by UID $UID"
252 }
253 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
254
255 test_6c() {
256         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
257         touch $DIR/$tfile
258         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
259         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
260                 error "$tfile should be owned by UID $RUNAS_ID"
261         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
262         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
263                 error "$tfile should be owned by UID $RUNAS_ID"
264 }
265 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
266
267 test_6e() {
268         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
269         touch $DIR/$tfile
270         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
271         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
272                 error "$tfile should be owned by GID $UID"
273         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
274         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
275                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
276 }
277 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
278
279 test_6g() {
280         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
281         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
282         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
283         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
284         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
285         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
286         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
287                 error "$tdir/d/subdir should be GID $RUNAS_GID"
288         if [[ $MDSCOUNT -gt 1 ]]; then
289                 # check remote dir sgid inherite
290                 $LFS mkdir -i 0 $DIR/$tdir.local ||
291                         error "mkdir $tdir.local failed"
292                 chmod g+s $DIR/$tdir.local ||
293                         error "chmod $tdir.local failed"
294                 chgrp $RUNAS_GID $DIR/$tdir.local ||
295                         error "chgrp $tdir.local failed"
296                 $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
297                         error "mkdir $tdir.remote failed"
298                 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
299                         error "$tdir.remote should be owned by $UID.$RUNAS_ID"
300                 $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
301                         error "$tdir.remote should be mode 02755"
302         fi
303 }
304 run_test 6g "Is new dir in sgid dir inheriting group?"
305
306 test_6h() { # bug 7331
307         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
308         touch $DIR/$tfile || error "touch failed"
309         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
310         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
311                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
312         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
313                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
314 }
315 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
316
317 test_7a() {
318         test_mkdir $DIR/$tdir
319         $MCREATE $DIR/$tdir/$tfile
320         chmod 0666 $DIR/$tdir/$tfile
321         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
322                 error "$tdir/$tfile should be mode 0666"
323 }
324 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
325
326 test_7b() {
327         if [ ! -d $DIR/$tdir ]; then
328                 test_mkdir $DIR/$tdir
329         fi
330         $MCREATE $DIR/$tdir/$tfile
331         echo -n foo > $DIR/$tdir/$tfile
332         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
333         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
334 }
335 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
336
337 test_8() {
338         test_mkdir $DIR/$tdir
339         touch $DIR/$tdir/$tfile
340         chmod 0666 $DIR/$tdir/$tfile
341         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
342                 error "$tfile mode not 0666"
343 }
344 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
345
346 test_9() {
347         test_mkdir $DIR/$tdir
348         test_mkdir $DIR/$tdir/d2
349         test_mkdir $DIR/$tdir/d2/d3
350         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
351 }
352 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
353
354 test_10() {
355         test_mkdir $DIR/$tdir
356         test_mkdir $DIR/$tdir/d2
357         touch $DIR/$tdir/d2/$tfile
358         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
359                 error "$tdir/d2/$tfile not a file"
360 }
361 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
362
363 test_11() {
364         test_mkdir $DIR/$tdir
365         test_mkdir $DIR/$tdir/d2
366         chmod 0666 $DIR/$tdir/d2
367         chmod 0705 $DIR/$tdir/d2
368         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
369                 error "$tdir/d2 mode not 0705"
370 }
371 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
372
373 test_12() {
374         test_mkdir $DIR/$tdir
375         touch $DIR/$tdir/$tfile
376         chmod 0666 $DIR/$tdir/$tfile
377         chmod 0654 $DIR/$tdir/$tfile
378         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
379                 error "$tdir/d2 mode not 0654"
380 }
381 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
382
383 test_13() {
384         test_mkdir $DIR/$tdir
385         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
386         >  $DIR/$tdir/$tfile
387         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
388                 error "$tdir/$tfile size not 0 after truncate"
389 }
390 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
391
392 test_14() {
393         test_mkdir $DIR/$tdir
394         touch $DIR/$tdir/$tfile
395         rm $DIR/$tdir/$tfile
396         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
397 }
398 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
399
400 test_15() {
401         test_mkdir $DIR/$tdir
402         touch $DIR/$tdir/$tfile
403         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
404         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
405                 error "$tdir/${tfile_2} not a file after rename"
406         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
407 }
408 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
409
410 test_16() {
411         test_mkdir $DIR/$tdir
412         touch $DIR/$tdir/$tfile
413         rm -rf $DIR/$tdir/$tfile
414         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
415 }
416 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
417
418 test_17a() {
419         test_mkdir -p $DIR/$tdir
420         touch $DIR/$tdir/$tfile
421         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
422         ls -l $DIR/$tdir
423         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
424                 error "$tdir/l-exist not a symlink"
425         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
426                 error "$tdir/l-exist not referencing a file"
427         rm -f $DIR/$tdir/l-exist
428         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
429 }
430 run_test 17a "symlinks: create, remove (real) =================="
431
432 test_17b() {
433         test_mkdir -p $DIR/$tdir
434         ln -s no-such-file $DIR/$tdir/l-dangle
435         ls -l $DIR/$tdir
436         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
437                 error "$tdir/l-dangle not referencing no-such-file"
438         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
439                 error "$tdir/l-dangle not referencing non-existent file"
440         rm -f $DIR/$tdir/l-dangle
441         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
442 }
443 run_test 17b "symlinks: create, remove (dangling) =============="
444
445 test_17c() { # bug 3440 - don't save failed open RPC for replay
446         test_mkdir -p $DIR/$tdir
447         ln -s foo $DIR/$tdir/$tfile
448         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
449 }
450 run_test 17c "symlinks: open dangling (should return error) ===="
451
452 test_17d() {
453         test_mkdir -p $DIR/$tdir
454         ln -s foo $DIR/$tdir/$tfile
455         touch $DIR/$tdir/$tfile || error "creating to new symlink"
456 }
457 run_test 17d "symlinks: create dangling ========================"
458
459 test_17e() {
460         test_mkdir -p $DIR/$tdir
461         local foo=$DIR/$tdir/$tfile
462         ln -s $foo $foo || error "create symlink failed"
463         ls -l $foo || error "ls -l failed"
464         ls $foo && error "ls not failed" || true
465 }
466 run_test 17e "symlinks: create recursive symlink (should return error) ===="
467
468 test_17f() {
469         test_mkdir -p $DIR/$tdir
470         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
471         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
472         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
473         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
474         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
475         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
476         ls -l  $DIR/$tdir
477 }
478 run_test 17f "symlinks: long and very long symlink name ========================"
479
480 # str_repeat(S, N) generate a string that is string S repeated N times
481 str_repeat() {
482         local s=$1
483         local n=$2
484         local ret=''
485         while [ $((n -= 1)) -ge 0 ]; do
486                 ret=$ret$s
487         done
488         echo $ret
489 }
490
491 # Long symlinks and LU-2241
492 test_17g() {
493         test_mkdir -p $DIR/$tdir
494         local TESTS="59 60 61 4094 4095"
495
496         # Fix for inode size boundary in 2.1.4
497         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
498                 TESTS="4094 4095"
499
500         # Patch not applied to 2.2 or 2.3 branches
501         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
502         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
503                 TESTS="4094 4095"
504
505         # skip long symlink name for rhel6.5.
506         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
507         grep -q '6.5' /etc/redhat-release &>/dev/null &&
508                 TESTS="59 60 61 4062 4063"
509
510         for i in $TESTS; do
511                 local SYMNAME=$(str_repeat 'x' $i)
512                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
513                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
514         done
515 }
516 run_test 17g "symlinks: really long symlink name and inode boundaries"
517
518 test_17h() { #bug 17378
519         remote_mds_nodsh && skip "remote MDS with nodsh" && return
520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
521         local mdt_idx
522         test_mkdir -p $DIR/$tdir
523         if [[ $MDSCOUNT -gt 1 ]]; then
524                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
525         else
526                 mdt_idx=0
527         fi
528         $SETSTRIPE -c -1 $DIR/$tdir
529 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
530         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
531         touch $DIR/$tdir/$tfile || true
532 }
533 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
534
535 test_17i() { #bug 20018
536         remote_mds_nodsh && skip "remote MDS with nodsh" && return
537         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
538         test_mkdir -c1 $DIR/$tdir
539         local foo=$DIR/$tdir/$tfile
540         local mdt_idx
541         if [[ $MDSCOUNT -gt 1 ]]; then
542                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
543         else
544                 mdt_idx=0
545         fi
546         ln -s $foo $foo || error "create symlink failed"
547 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
548         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
549         ls -l $foo && error "error not detected"
550         return 0
551 }
552 run_test 17i "don't panic on short symlink"
553
554 test_17k() { #bug 22301
555         [[ -z "$(which rsync 2>/dev/null)" ]] &&
556                 skip "no rsync command" && return 0
557         rsync --help | grep -q xattr ||
558                 skip_env "$(rsync --version | head -n1) does not support xattrs"
559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
560         test_mkdir -p $DIR/$tdir
561         test_mkdir -p $DIR/$tdir.new
562         touch $DIR/$tdir/$tfile
563         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
564         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
565                 error "rsync failed with xattrs enabled"
566 }
567 run_test 17k "symlinks: rsync with xattrs enabled ========================="
568
569 test_17l() { # LU-279
570         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
571                 skip "no getfattr command" && return 0
572         test_mkdir -p $DIR/$tdir
573         touch $DIR/$tdir/$tfile
574         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
575         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
576                 # -h to not follow symlinks. -m '' to list all the xattrs.
577                 # grep to remove first line: '# file: $path'.
578                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
579                 do
580                         lgetxattr_size_check $path $xattr ||
581                                 error "lgetxattr_size_check $path $xattr failed"
582                 done
583         done
584 }
585 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
586
587 # LU-1540
588 test_17m() {
589         local short_sym="0123456789"
590         local WDIR=$DIR/${tdir}m
591         local i
592
593         remote_mds_nodsh && skip "remote MDS with nodsh" && return
594         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
595         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
596                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
597
598         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
599                 skip "ldiskfs only test" && return 0
600
601         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
602
603         test_mkdir -p $WDIR
604         long_sym=$short_sym
605         # create a long symlink file
606         for ((i = 0; i < 4; ++i)); do
607                 long_sym=${long_sym}${long_sym}
608         done
609
610         echo "create 512 short and long symlink files under $WDIR"
611         for ((i = 0; i < 256; ++i)); do
612                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
613                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
614         done
615
616         echo "erase them"
617         rm -f $WDIR/*
618         sync
619         wait_delete_completed
620
621         echo "recreate the 512 symlink files with a shorter string"
622         for ((i = 0; i < 512; ++i)); do
623                 # rewrite the symlink file with a shorter string
624                 ln -sf ${long_sym} $WDIR/long-$i || error "long_sym failed"
625                 ln -sf ${short_sym} $WDIR/short-$i || error "short_sym failed"
626         done
627
628         local mds_index=$(($($LFS getstripe -M $WDIR) + 1))
629         local devname=$(mdsdevname $mds_index)
630
631         echo "stop and checking mds${mds_index}:"
632         # e2fsck should not return error
633         stop mds${mds_index}
634         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
635         rc=$?
636
637         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
638         df $MOUNT > /dev/null 2>&1
639         [ $rc -eq 0 ] ||
640                 error "e2fsck detected error for short/long symlink: rc=$rc"
641 }
642 run_test 17m "run e2fsck against MDT which contains short/long symlink"
643
644 check_fs_consistency_17n() {
645         local mdt_index
646         local rc=0
647
648         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
649         # so it only check MDT1/MDT2 instead of all of MDTs.
650         for mdt_index in 1 2; do
651                 local devname=$(mdsdevname $mdt_index)
652                 # e2fsck should not return error
653                 stop mds${mdt_index}
654                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
655                         rc=$((rc + $?))
656
657                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
658                         error "mount mds$mdt_index failed"
659                 df $MOUNT > /dev/null 2>&1
660         done
661         return $rc
662 }
663
664 test_17n() {
665         local i
666
667         remote_mds_nodsh && skip "remote MDS with nodsh" && return
668         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
669         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
670                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
671
672         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
673                 skip "ldiskfs only test" && return 0
674
675         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
676
677         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
678
679         test_mkdir $DIR/$tdir
680         for ((i=0; i<10; i++)); do
681                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
682                         error "create remote dir error $i"
683                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
684                         error "create files under remote dir failed $i"
685         done
686
687         check_fs_consistency_17n ||
688                 error "e2fsck report error after create files under remote dir"
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 ||
696                 error "e2fsck report error after unlink files under remote dir"
697
698         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
699                 skip "lustre < 2.11.56 does not support migrate -m "
700
701         for ((i = 0; i < 10; i++)); do
702                 mkdir -p $DIR/$tdir/remote_dir_${i}
703                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
704                         error "create files under remote dir failed $i"
705                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
706                         error "migrate remote dir error $i"
707         done
708         check_fs_consistency_17n || error "e2fsck report error after migration"
709
710         for ((i = 0; i < 10; i++)); do
711                 rm -rf $DIR/$tdir/remote_dir_${i} ||
712                         error "destroy remote dir error $i"
713         done
714
715         check_fs_consistency_17n || error "e2fsck report error after unlink"
716 }
717 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
718
719 test_17o() {
720         remote_mds_nodsh && skip "remote MDS with nodsh" && return
721         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
722                 skip "Need MDS version at least 2.3.64" && return
723
724         local WDIR=$DIR/${tdir}o
725         local mdt_index
726         local rc=0
727
728         test_mkdir -p $WDIR
729         touch $WDIR/$tfile
730         mdt_index=$($LFS getstripe -M $WDIR/$tfile)
731         mdt_index=$((mdt_index+1))
732
733         cancel_lru_locks mdc
734         #fail mds will wait the failover finish then set
735         #following fail_loc to avoid interfer the recovery process.
736         fail mds${mdt_index}
737
738         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
739         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
740         ls -l $WDIR/$tfile && rc=1
741         do_facet mds${mdt_index} lctl set_param fail_loc=0
742         [[ $rc -ne 0 ]] && error "stat file should fail"
743         true
744 }
745 run_test 17o "stat file with incompat LMA feature"
746
747 test_18() {
748         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
749         ls $DIR || error "Failed to ls $DIR: $?"
750 }
751 run_test 18 "touch .../f ; ls ... =============================="
752
753 test_19a() {
754         touch $DIR/$tfile
755         ls -l $DIR
756         rm $DIR/$tfile
757         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
758 }
759 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
760
761 test_19b() {
762         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
763 }
764 run_test 19b "ls -l .../f19 (should return error) =============="
765
766 test_19c() {
767         [ $RUNAS_ID -eq $UID ] &&
768                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
769         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
770 }
771 run_test 19c "$RUNAS touch .../f19 (should return error) =="
772
773 test_19d() {
774         cat $DIR/f19 && error || true
775 }
776 run_test 19d "cat .../f19 (should return error) =============="
777
778 test_20() {
779         touch $DIR/$tfile
780         rm $DIR/$tfile
781         touch $DIR/$tfile
782         rm $DIR/$tfile
783         touch $DIR/$tfile
784         rm $DIR/$tfile
785         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
786 }
787 run_test 20 "touch .../f ; ls -l ... ==========================="
788
789 test_21() {
790         test_mkdir -p $DIR/$tdir
791         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
792         ln -s dangle $DIR/$tdir/link
793         echo foo >> $DIR/$tdir/link
794         cat $DIR/$tdir/dangle
795         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
796         $CHECKSTAT -f -t file $DIR/$tdir/link ||
797                 error "$tdir/link not linked to a file"
798 }
799 run_test 21 "write to dangling link ============================"
800
801 test_22() {
802         WDIR=$DIR/$tdir
803         test_mkdir -p $DIR/$tdir
804         chown $RUNAS_ID:$RUNAS_GID $WDIR
805         (cd $WDIR || error "cd $WDIR failed";
806         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
807         $RUNAS tar xf -)
808         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
809         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
810         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
811 }
812 run_test 22 "unpack tar archive as non-root user ==============="
813
814 # was test_23
815 test_23a() {
816         test_mkdir -p $DIR/$tdir
817         local file=$DIR/$tdir/$tfile
818
819         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
820         openfile -f O_CREAT:O_EXCL $file &&
821                 error "$file recreate succeeded" || true
822 }
823 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
824
825 test_23b() { # bug 18988
826         test_mkdir -p $DIR/$tdir
827         local file=$DIR/$tdir/$tfile
828
829         rm -f $file
830         echo foo > $file || error "write filed"
831         echo bar >> $file || error "append filed"
832         $CHECKSTAT -s 8 $file || error "wrong size"
833         rm $file
834 }
835 run_test 23b "O_APPEND check =========================="
836
837 # LU-11069 file offset is correct after appending writes
838 test_23d() {
839         local file=$DIR/$tfile
840         local offset
841
842         echo CentaurHauls > $file
843         offset=$($MULTIOP $file oO_WRONLY:O_APPEND:w13Zp)
844         if ((offset != 26)); then
845                 error "wrong offset, expected 26, got '$offset'"
846         fi
847 }
848 run_test 23d "file offset is correct after appending writes"
849
850 # rename sanity
851 test_24a() {
852         echo '-- same directory rename'
853         test_mkdir $DIR/$tdir
854         touch $DIR/$tdir/$tfile.1
855         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
856         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
857 }
858 run_test 24a "rename file to non-existent target"
859
860 test_24b() {
861         test_mkdir $DIR/$tdir
862         touch $DIR/$tdir/$tfile.{1,2}
863         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
864         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
865         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
866 }
867 run_test 24b "rename file to existing target"
868
869 test_24c() {
870         test_mkdir $DIR/$tdir
871         test_mkdir $DIR/$tdir/d$testnum.1
872         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
873         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
874         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
875 }
876 run_test 24c "rename directory to non-existent target"
877
878 test_24d() {
879         test_mkdir -c1 $DIR/$tdir
880         test_mkdir -c1 $DIR/$tdir/d$testnum.1
881         test_mkdir -c1 $DIR/$tdir/d$testnum.2
882         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
883         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
884         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
885 }
886 run_test 24d "rename directory to existing target"
887
888 test_24e() {
889         echo '-- cross directory renames --'
890         test_mkdir $DIR/R5a
891         test_mkdir $DIR/R5b
892         touch $DIR/R5a/f
893         mv $DIR/R5a/f $DIR/R5b/g
894         $CHECKSTAT -a $DIR/R5a/f || error
895         $CHECKSTAT -t file $DIR/R5b/g || error
896 }
897 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
898
899 test_24f() {
900         test_mkdir $DIR/R6a
901         test_mkdir $DIR/R6b
902         touch $DIR/R6a/f $DIR/R6b/g
903         mv $DIR/R6a/f $DIR/R6b/g
904         $CHECKSTAT -a $DIR/R6a/f || error
905         $CHECKSTAT -t file $DIR/R6b/g || error
906 }
907 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
908
909 test_24g() {
910         test_mkdir $DIR/R7a
911         test_mkdir $DIR/R7b
912         test_mkdir $DIR/R7a/d
913         mv $DIR/R7a/d $DIR/R7b/e
914         $CHECKSTAT -a $DIR/R7a/d || error
915         $CHECKSTAT -t dir $DIR/R7b/e || error
916 }
917 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
918
919 test_24h() {
920         test_mkdir -c1 $DIR/R8a
921         test_mkdir -c1 $DIR/R8b
922         test_mkdir -c1 $DIR/R8a/d
923         test_mkdir -c1 $DIR/R8b/e
924         mrename $DIR/R8a/d $DIR/R8b/e
925         $CHECKSTAT -a $DIR/R8a/d || error
926         $CHECKSTAT -t dir $DIR/R8b/e || error
927 }
928 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
929
930 test_24i() {
931         echo "-- rename error cases"
932         test_mkdir $DIR/R9
933         test_mkdir $DIR/R9/a
934         touch $DIR/R9/f
935         mrename $DIR/R9/f $DIR/R9/a
936         $CHECKSTAT -t file $DIR/R9/f || error
937         $CHECKSTAT -t dir  $DIR/R9/a || error
938         $CHECKSTAT -a $DIR/R9/a/f || error
939 }
940 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
941
942 test_24j() {
943         test_mkdir $DIR/R10
944         mrename $DIR/R10/f $DIR/R10/g
945         $CHECKSTAT -t dir $DIR/R10 || error
946         $CHECKSTAT -a $DIR/R10/f || error
947         $CHECKSTAT -a $DIR/R10/g || error
948 }
949 run_test 24j "source does not exist ============================"
950
951 test_24k() {
952         test_mkdir $DIR/R11a
953         test_mkdir $DIR/R11a/d
954         touch $DIR/R11a/f
955         mv $DIR/R11a/f $DIR/R11a/d
956         $CHECKSTAT -a $DIR/R11a/f || error
957         $CHECKSTAT -t file $DIR/R11a/d/f || error
958 }
959 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
960
961 # bug 2429 - rename foo foo foo creates invalid file
962 test_24l() {
963         f="$DIR/f24l"
964         $MULTIOP $f OcNs || error
965 }
966 run_test 24l "Renaming a file to itself ========================"
967
968 test_24m() {
969         f="$DIR/f24m"
970         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
971         # on ext3 this does not remove either the source or target files
972         # though the "expected" operation would be to remove the source
973         $CHECKSTAT -t file ${f} || error "${f} missing"
974         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
975 }
976 run_test 24m "Renaming a file to a hard link to itself ========="
977
978 test_24n() {
979     f="$DIR/f24n"
980     # this stats the old file after it was renamed, so it should fail
981     touch ${f}
982     $CHECKSTAT ${f}
983     mv ${f} ${f}.rename
984     $CHECKSTAT ${f}.rename
985     $CHECKSTAT -a ${f}
986 }
987 run_test 24n "Statting the old file after renaming (Posix rename 2)"
988
989 test_24o() {
990         test_mkdir -p $DIR/d24o
991         rename_many -s random -v -n 10 $DIR/d24o
992 }
993 run_test 24o "rename of files during htree split ==============="
994
995 test_24p() {
996         test_mkdir $DIR/R12a
997         test_mkdir $DIR/R12b
998         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
999         mrename $DIR/R12a $DIR/R12b
1000         $CHECKSTAT -a $DIR/R12a || error
1001         $CHECKSTAT -t dir $DIR/R12b || error
1002         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
1003         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
1004 }
1005 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
1006
1007 cleanup_multiop_pause() {
1008         trap 0
1009         kill -USR1 $MULTIPID
1010 }
1011
1012 test_24q() {
1013         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1014         test_mkdir $DIR/R13a
1015         test_mkdir $DIR/R13b
1016         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
1017         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
1018         MULTIPID=$!
1019
1020         trap cleanup_multiop_pause EXIT
1021         mrename $DIR/R13a $DIR/R13b
1022         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
1023         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
1024         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
1025         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
1026         cleanup_multiop_pause
1027         wait $MULTIPID || error "multiop close failed"
1028 }
1029 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
1030
1031 test_24r() { #bug 3789
1032         test_mkdir $DIR/R14a
1033         test_mkdir $DIR/R14a/b
1034         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1035         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1036         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1037 }
1038 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1039
1040 test_24s() {
1041         test_mkdir $DIR/R15a
1042         test_mkdir $DIR/R15a/b
1043         test_mkdir $DIR/R15a/b/c
1044         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1045         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1046         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1047 }
1048 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1049 test_24t() {
1050         test_mkdir $DIR/R16a
1051         test_mkdir $DIR/R16a/b
1052         test_mkdir $DIR/R16a/b/c
1053         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1054         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1055         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1056 }
1057 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1058
1059 test_24u() { # bug12192
1060         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1061         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1062 }
1063 run_test 24u "create stripe file"
1064
1065 page_size() {
1066         local size
1067         size=$(getconf PAGE_SIZE 2>/dev/null)
1068         echo -n ${size:-4096}
1069 }
1070
1071 simple_cleanup_common() {
1072         local rc=0
1073         trap 0
1074         [ -z "$DIR" -o -z "$tdir" ] && return 0
1075
1076         local start=$SECONDS
1077         rm -rf $DIR/$tdir
1078         rc=$?
1079         wait_delete_completed
1080         echo "cleanup time $((SECONDS - start))"
1081         return $rc
1082 }
1083
1084 max_pages_per_rpc() {
1085         local mdtname="$(printf "MDT%04x" ${1:-0})"
1086         $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
1087 }
1088
1089 test_24v() {
1090         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1091         local nrfiles=${COUNT:-100000}
1092         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1093         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && nrfiles=${COUNT:-10000}
1094
1095         local fname="$DIR/$tdir/$tfile"
1096         test_mkdir "$(dirname $fname)"
1097         # assume MDT0000 has the fewest inodes
1098         local stripes=$($LFS getdirstripe -c $(dirname $fname))
1099         local free_inodes=$(($(mdt_free_inodes 0) * stripes))
1100         [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
1101
1102         trap simple_cleanup_common EXIT
1103
1104         createmany -m "$fname" $nrfiles
1105
1106         cancel_lru_locks mdc
1107         lctl set_param mdc.*.stats clear
1108
1109         # was previously test_24D: LU-6101
1110         # readdir() returns correct number of entries after cursor reload
1111         local num_ls=$(ls $DIR/$tdir | wc -l)
1112         local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
1113         local num_all=$(ls -a $DIR/$tdir | wc -l)
1114         if [ $num_ls -ne $nrfiles -o $num_uniq -ne $nrfiles -o \
1115              $num_all -ne $((nrfiles + 2)) ]; then
1116                 error "Expected $nrfiles files, got $num_ls " \
1117                         "($num_uniq unique $num_all .&..)"
1118         fi
1119         # LU-5 large readdir
1120         # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
1121         #               N bytes for name (len($nrfiles) rounded to 8 bytes) +
1122         #               8 bytes for luda_type (4 bytes rounded to 8 bytes)
1123         # take into account of overhead in lu_dirpage header and end mark in
1124         # each page, plus one in rpc_num calculation.
1125         local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
1126         local page_entries=$((($(page_size) - 24) / dirent_size))
1127         local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
1128         local rpc_pages=$(max_pages_per_rpc $mdt_idx)
1129         local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
1130         local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
1131         echo "readpages: $mds_readpage rpc_max: $rpc_max"
1132         (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
1133                 error "large readdir doesn't take effect: " \
1134                       "$mds_readpage should be about $rpc_max"
1135
1136         simple_cleanup_common
1137 }
1138 run_test 24v "list large directory (test hash collision, b=17560)"
1139
1140 test_24w() { # bug21506
1141         SZ1=234852
1142         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1143         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1144         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1145         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1146         [[ "$SZ1" -eq "$SZ2" ]] ||
1147                 error "Error reading at the end of the file $tfile"
1148 }
1149 run_test 24w "Reading a file larger than 4Gb"
1150
1151 test_24x() {
1152         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1153
1154         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1155                 skip "Need MDS version at least 2.7.56" && return
1156
1157         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1158         local MDTIDX=1
1159         local remote_dir=$DIR/$tdir/remote_dir
1160
1161         test_mkdir -p $DIR/$tdir
1162         $LFS mkdir -i $MDTIDX $remote_dir ||
1163                 error "create remote directory failed"
1164
1165         test_mkdir -p $DIR/$tdir/src_dir
1166         touch $DIR/$tdir/src_file
1167         test_mkdir -p $remote_dir/tgt_dir
1168         touch $remote_dir/tgt_file
1169
1170         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1171                 error "rename dir cross MDT failed!"
1172
1173         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1174                 error "rename file cross MDT failed!"
1175
1176         touch $DIR/$tdir/ln_file
1177         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1178                 error "ln file cross MDT failed"
1179
1180         rm -rf $DIR/$tdir || error "Can not delete directories"
1181 }
1182 run_test 24x "cross MDT rename/link"
1183
1184 test_24y() {
1185         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1186         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1187         local MDTIDX=1
1188         local remote_dir=$DIR/$tdir/remote_dir
1189
1190         test_mkdir -p $DIR/$tdir
1191         $LFS mkdir -i $MDTIDX $remote_dir ||
1192                    error "create remote directory failed"
1193
1194         test_mkdir -p $remote_dir/src_dir
1195         touch $remote_dir/src_file
1196         test_mkdir -p $remote_dir/tgt_dir
1197         touch $remote_dir/tgt_file
1198
1199         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1200                 error "rename subdir in the same remote dir failed!"
1201
1202         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1203                 error "rename files in the same remote dir failed!"
1204
1205         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1206                 error "link files in the same remote dir failed!"
1207
1208         rm -rf $DIR/$tdir || error "Can not delete directories"
1209 }
1210 run_test 24y "rename/link on the same dir should succeed"
1211
1212 test_24A() { # LU-3182
1213         local NFILES=5000
1214
1215         rm -rf $DIR/$tdir
1216         test_mkdir -p $DIR/$tdir
1217         trap simple_cleanup_common EXIT
1218         createmany -m $DIR/$tdir/$tfile $NFILES
1219         local t=$(ls $DIR/$tdir | wc -l)
1220         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1221         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1222         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1223                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1224         fi
1225
1226         simple_cleanup_common || error "Can not delete directories"
1227 }
1228 run_test 24A "readdir() returns correct number of entries."
1229
1230 test_24B() { # LU-4805
1231         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1232         local count
1233
1234         test_mkdir $DIR/$tdir
1235         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1236                 error "create striped dir failed"
1237
1238         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1239         [ $count -eq 2 ] || error "Expected 2, got $count"
1240
1241         touch $DIR/$tdir/striped_dir/a
1242
1243         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1244         [ $count -eq 3 ] || error "Expected 3, got $count"
1245
1246         touch $DIR/$tdir/striped_dir/.f
1247
1248         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1249         [ $count -eq 4 ] || error "Expected 4, got $count"
1250
1251         rm -rf $DIR/$tdir || error "Can not delete directories"
1252 }
1253 run_test 24B "readdir for striped dir return correct number of entries"
1254
1255 test_24C() {
1256         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1257
1258         mkdir $DIR/$tdir
1259         mkdir $DIR/$tdir/d0
1260         mkdir $DIR/$tdir/d1
1261
1262         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1263                 error "create striped dir failed"
1264
1265         cd $DIR/$tdir/d0/striped_dir
1266
1267         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1268         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1269         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1270
1271         [ "$d0_ino" = "$parent_ino" ] ||
1272                 error ".. wrong, expect $d0_ino, get $parent_ino"
1273
1274         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1275                 error "mv striped dir failed"
1276
1277         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1278
1279         [ "$d1_ino" = "$parent_ino" ] ||
1280                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1281 }
1282 run_test 24C "check .. in striped dir"
1283
1284 test_24E() {
1285         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1286         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1287
1288         mkdir -p $DIR/$tdir
1289         mkdir $DIR/$tdir/src_dir
1290         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1291                 error "create remote source failed"
1292
1293         touch $DIR/$tdir/src_dir/src_child/a
1294
1295         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1296                 error "create remote target dir failed"
1297
1298         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1299                 error "create remote target child failed"
1300
1301         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1302                 error "rename dir cross MDT failed!"
1303
1304         find $DIR/$tdir
1305
1306         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1307                 error "src_child still exists after rename"
1308
1309         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1310                 error "missing file(a) after rename"
1311
1312         rm -rf $DIR/$tdir || error "Can not delete directories"
1313 }
1314 run_test 24E "cross MDT rename/link"
1315
1316 test_25a() {
1317         echo '== symlink sanity ============================================='
1318
1319         test_mkdir $DIR/d25
1320         ln -s d25 $DIR/s25
1321         touch $DIR/s25/foo || error
1322 }
1323 run_test 25a "create file in symlinked directory ==============="
1324
1325 test_25b() {
1326         [ ! -d $DIR/d25 ] && test_25a
1327         $CHECKSTAT -t file $DIR/s25/foo || error
1328 }
1329 run_test 25b "lookup file in symlinked directory ==============="
1330
1331 test_26a() {
1332         test_mkdir $DIR/d26
1333         test_mkdir $DIR/d26/d26-2
1334         ln -s d26/d26-2 $DIR/s26
1335         touch $DIR/s26/foo || error
1336 }
1337 run_test 26a "multiple component symlink ======================="
1338
1339 test_26b() {
1340         test_mkdir -p $DIR/d26b/d26-2
1341         ln -s d26b/d26-2/foo $DIR/s26-2
1342         touch $DIR/s26-2 || error
1343 }
1344 run_test 26b "multiple component symlink at end of lookup ======"
1345
1346 test_26c() {
1347         test_mkdir $DIR/d26.2
1348         touch $DIR/d26.2/foo
1349         ln -s d26.2 $DIR/s26.2-1
1350         ln -s s26.2-1 $DIR/s26.2-2
1351         ln -s s26.2-2 $DIR/s26.2-3
1352         chmod 0666 $DIR/s26.2-3/foo
1353 }
1354 run_test 26c "chain of symlinks ================================"
1355
1356 # recursive symlinks (bug 439)
1357 test_26d() {
1358         ln -s d26-3/foo $DIR/d26-3
1359 }
1360 run_test 26d "create multiple component recursive symlink ======"
1361
1362 test_26e() {
1363         [ ! -h $DIR/d26-3 ] && test_26d
1364         rm $DIR/d26-3
1365 }
1366 run_test 26e "unlink multiple component recursive symlink ======"
1367
1368 # recursive symlinks (bug 7022)
1369 test_26f() {
1370         test_mkdir -p $DIR/$tdir
1371         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1372         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1373         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1374         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1375         cd $tfile                || error "cd $tfile failed"
1376         ln -s .. dotdot          || error "ln dotdot failed"
1377         ln -s dotdot/lndir lndir || error "ln lndir failed"
1378         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1379         output=`ls $tfile/$tfile/lndir/bar1`
1380         [ "$output" = bar1 ] && error "unexpected output"
1381         rm -r $tfile             || error "rm $tfile failed"
1382         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1383 }
1384 run_test 26f "rm -r of a directory which has recursive symlink"
1385
1386 test_27a() {
1387         test_mkdir -p $DIR/d27 || error "mkdir failed"
1388         $LFS getstripe $DIR/d27
1389         $LFS setstripe -c 1 $DIR/d27/f0 || error "setstripe failed"
1390         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1391         cp /etc/hosts $DIR/d27/f0 || error
1392 }
1393 run_test 27a "one stripe file"
1394
1395 test_27b() {
1396         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1397         test_mkdir -p $DIR/d27
1398         $LFS setstripe -c 2 $DIR/d27/f01 || error "setstripe failed"
1399         $LFS getstripe -c $DIR/d27/f01
1400         [ $($LFS getstripe -c $DIR/d27/f01) -eq 2 ] ||
1401                 error "two-stripe file doesn't have two stripes"
1402
1403         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1404 }
1405 run_test 27b "create and write to two stripe file"
1406
1407 test_27d() {
1408         test_mkdir -p $DIR/d27
1409         $LFS setstripe -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1410         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1411         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1412 }
1413 run_test 27d "create file with default settings"
1414
1415 test_27e() {
1416         # LU-5839 adds check for existed layout before setting it
1417         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1418                 skip "Need MDS version at least 2.7.56" && return
1419         test_mkdir -p $DIR/d27
1420         $LFS setstripe -c 2 $DIR/d27/f12 || error "setstripe failed"
1421         $LFS setstripe -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1422         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1423 }
1424 run_test 27e "setstripe existing file (should return error)"
1425
1426 test_27f() {
1427         test_mkdir $DIR/$tdir
1428         $LFS setstripe -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1429                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1430         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1431                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1432         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1433         $LFS getstripe $DIR/$tdir/$tfile || error "$LFS getstripe failed"
1434 }
1435 run_test 27f "setstripe with bad stripe size (should return error)"
1436
1437 test_27g() {
1438         test_mkdir -p $DIR/d27
1439         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1440         $LFS getstripe $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1441                 error "$DIR/d27/fnone has object"
1442 }
1443 run_test 27g "$LFS getstripe with no objects"
1444
1445 test_27i() {
1446         test_mkdir $DIR/$tdir
1447         touch $DIR/$tdir/$tfile || error "touch failed"
1448         [[ $($LFS getstripe -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1449                 error "missing objects"
1450 }
1451 run_test 27i "$LFS getstripe with some objects"
1452
1453 test_27j() {
1454         test_mkdir -p $DIR/d27
1455         $LFS setstripe -i $OSTCOUNT $DIR/d27/f27j &&
1456                 error "setstripe failed" || true
1457 }
1458 run_test 27j "setstripe with bad stripe offset (should return error)"
1459
1460 test_27k() { # bug 2844
1461         test_mkdir -p $DIR/d27
1462         FILE=$DIR/d27/f27k
1463         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1464         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1465         $LFS setstripe -S 67108864 $FILE || error "setstripe failed"
1466         BLKSIZE=$(stat $FILE | awk '/IO Block:/ { print $7 }')
1467         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1468         dd if=/dev/zero of=$FILE bs=4k count=1
1469         BLKSIZE=$(stat $FILE | awk '/IO Block:/ { print $7 }')
1470         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1471 }
1472 run_test 27k "limit i_blksize for broken user apps"
1473
1474 test_27l() {
1475         test_mkdir -p $DIR/d27
1476         mcreate $DIR/f27l || error "creating file"
1477         $RUNAS $SETSTRIPE -c 1 $DIR/f27l &&
1478                 error "setstripe should have failed" || true
1479 }
1480 run_test 27l "check setstripe permissions (should return error)"
1481
1482 test_27m() {
1483         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1484
1485         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1486                    head -n1)
1487         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1488                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1489                 return
1490         fi
1491         trap simple_cleanup_common EXIT
1492         test_mkdir -p $DIR/$tdir
1493         $LFS setstripe -i 0 -c 1 $DIR/$tdir/f27m_1
1494         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1495                 error "dd should fill OST0"
1496         i=2
1497         while $LFS setstripe -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1498                 i=$((i + 1))
1499                 [ $i -gt 256 ] && break
1500         done
1501         i=$((i + 1))
1502         touch $DIR/$tdir/f27m_$i
1503         [ $($LFS getstripe $DIR/$tdir/f27m_$i | grep -A 10 obdidx |
1504             awk '{print $1}' | grep -w "0") ] &&
1505                 error "OST0 was full but new created file still use it"
1506         i=$((i + 1))
1507         touch $DIR/$tdir/f27m_$i
1508         [ $($LFS getstripe $DIR/$tdir/f27m_$i | grep -A 10 obdidx |
1509             awk '{print $1}'| grep -w "0") ] &&
1510                 error "OST0 was full but new created file still use it"
1511         simple_cleanup_common
1512 }
1513 run_test 27m "create file while OST0 was full"
1514
1515 sleep_maxage() {
1516         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
1517                       head -n 1 | awk '{print $1 * 2}')
1518         sleep $DELAY
1519 }
1520
1521 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1522 # if the OST isn't full anymore.
1523 reset_enospc() {
1524         local OSTIDX=${1:-""}
1525
1526         local list=$(comma_list $(osts_nodes))
1527         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1528
1529         do_nodes $list lctl set_param fail_loc=0
1530         sync    # initiate all OST_DESTROYs from MDS to OST
1531         sleep_maxage
1532 }
1533
1534 exhaust_precreations() {
1535         local OSTIDX=$1
1536         local FAILLOC=$2
1537         local FAILIDX=${3:-$OSTIDX}
1538         local ofacet=ost$((OSTIDX + 1))
1539
1540         test_mkdir -p -c1 $DIR/$tdir
1541         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1542         local mfacet=mds$((mdtidx + 1))
1543         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1544
1545         local OST=$(ostname_from_index $OSTIDX)
1546
1547         # on the mdt's osc
1548         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1549         local last_id=$(do_facet $mfacet lctl get_param -n \
1550                         osc.$mdtosc_proc1.prealloc_last_id)
1551         local next_id=$(do_facet $mfacet lctl get_param -n \
1552                         osc.$mdtosc_proc1.prealloc_next_id)
1553
1554         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1555         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1556
1557         test_mkdir -p $DIR/$tdir/${OST}
1558         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1559 #define OBD_FAIL_OST_ENOSPC              0x215
1560         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1561         echo "Creating to objid $last_id on ost $OST..."
1562         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1563         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1564         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1565         sleep_maxage
1566 }
1567
1568 exhaust_all_precreations() {
1569         local i
1570         for (( i=0; i < OSTCOUNT; i++ )) ; do
1571                 exhaust_precreations $i $1 -1
1572         done
1573 }
1574
1575 test_27n() {
1576         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1577         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1578         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1579         remote_ost_nodsh && skip "remote OST with nodsh" && return
1580
1581         reset_enospc
1582         rm -f $DIR/$tdir/$tfile
1583         exhaust_precreations 0 0x80000215
1584         $LFS setstripe -c -1 $DIR/$tdir
1585         touch $DIR/$tdir/$tfile || error
1586         $LFS getstripe $DIR/$tdir/$tfile
1587         reset_enospc
1588 }
1589 run_test 27n "create file with some full OSTs"
1590
1591 test_27o() {
1592         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1593         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1594         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1595         remote_ost_nodsh && skip "remote OST with nodsh" && return
1596
1597         reset_enospc
1598         rm -f $DIR/$tdir/$tfile
1599         exhaust_all_precreations 0x215
1600
1601         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1602
1603         reset_enospc
1604         rm -rf $DIR/$tdir/*
1605 }
1606 run_test 27o "create file with all full OSTs (should error)"
1607
1608 test_27p() {
1609         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1610         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1611         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1612         remote_ost_nodsh && skip "remote OST with nodsh" && return
1613
1614         reset_enospc
1615         rm -f $DIR/$tdir/$tfile
1616         test_mkdir -p $DIR/$tdir
1617
1618         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1619         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1620         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1621
1622         exhaust_precreations 0 0x80000215
1623         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1624         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1625         $LFS getstripe $DIR/$tdir/$tfile
1626
1627         reset_enospc
1628 }
1629 run_test 27p "append to a truncated file with some full OSTs"
1630
1631 test_27q() {
1632         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1633         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1634         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1635         remote_ost_nodsh && skip "remote OST with nodsh" && return
1636
1637         reset_enospc
1638         rm -f $DIR/$tdir/$tfile
1639
1640         test_mkdir -p $DIR/$tdir
1641         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1642         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||
1643                 error "truncate $DIR/$tdir/$tfile failed"
1644         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1645
1646         exhaust_all_precreations 0x215
1647
1648         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1649         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1650
1651         reset_enospc
1652 }
1653 run_test 27q "append to truncated file with all OSTs full (should error)"
1654
1655 test_27r() {
1656         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1657         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1658         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1659         remote_ost_nodsh && skip "remote OST with nodsh" && return
1660
1661         reset_enospc
1662         rm -f $DIR/$tdir/$tfile
1663         exhaust_precreations 0 0x80000215
1664
1665         $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile # && error
1666
1667         reset_enospc
1668 }
1669 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1670
1671 test_27s() { # bug 10725
1672         test_mkdir -p $DIR/$tdir
1673         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1674         local stripe_count=0
1675         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1676         $LFS setstripe -S $stripe_size -c $stripe_count $DIR/$tdir &&
1677                 error "stripe width >= 2^32 succeeded" || true
1678
1679 }
1680 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1681
1682 test_27t() { # bug 10864
1683         WDIR=$(pwd)
1684         WLFS=$(which lfs)
1685         cd $DIR
1686         touch $tfile
1687         $WLFS getstripe $tfile
1688         cd $WDIR
1689 }
1690 run_test 27t "check that utils parse path correctly"
1691
1692 test_27u() { # bug 4900
1693         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1694         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1695         local index
1696         local list=$(comma_list $(mdts_nodes))
1697
1698 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1699         do_nodes $list $LCTL set_param fail_loc=0x139
1700         test_mkdir -p $DIR/$tdir
1701         trap simple_cleanup_common EXIT
1702         createmany -o $DIR/$tdir/t- 1000
1703         do_nodes $list $LCTL set_param fail_loc=0
1704
1705         TLOG=$TMP/$tfile.getstripe
1706         $LFS getstripe $DIR/$tdir > $TLOG
1707         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1708         unlinkmany $DIR/$tdir/t- 1000
1709         trap 0
1710         [[ $OBJS -gt 0 ]] &&
1711                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1712 }
1713 run_test 27u "skip object creation on OSC w/o objects"
1714
1715 test_27v() { # bug 4900
1716         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1718         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1719         remote_ost_nodsh && skip "remote OST with nodsh" && return
1720
1721         exhaust_all_precreations 0x215
1722         reset_enospc
1723
1724         test_mkdir $DIR/$tdir
1725         $LFS setstripe -c 1 $DIR/$tdir         # 1 stripe / file
1726
1727         touch $DIR/$tdir/$tfile
1728         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1729         # all except ost1
1730         for (( i=1; i < OSTCOUNT; i++ )); do
1731                 do_facet ost$i lctl set_param fail_loc=0x705
1732         done
1733         local START=`date +%s`
1734         createmany -o $DIR/$tdir/$tfile 32
1735
1736         local FINISH=`date +%s`
1737         local TIMEOUT=`lctl get_param -n timeout`
1738         local PROCESS=$((FINISH - START))
1739         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1740                error "$FINISH - $START >= $TIMEOUT / 2"
1741         sleep $((TIMEOUT / 2 - PROCESS))
1742         reset_enospc
1743 }
1744 run_test 27v "skip object creation on slow OST"
1745
1746 test_27w() { # bug 10997
1747         test_mkdir $DIR/$tdir || error "mkdir failed"
1748         $LFS setstripe -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1749         [ $($LFS getstripe -S $DIR/$tdir/f0) -ne 65536 ] &&
1750                 error "stripe size $size != 65536" || true
1751         [ $($LFS getstripe -d $DIR/$tdir | grep -c "stripe_count") -eq 0 ] &&
1752                 error "$LFS getstripe -d $DIR/$tdir no 'stripe_count'" || true
1753 }
1754 run_test 27w "check $LFS setstripe -S and getstrip -d options"
1755
1756 test_27wa() {
1757         [[ $OSTCOUNT -lt 2 ]] &&
1758                 skip_env "skipping multiple stripe count/offset test" && return
1759
1760         test_mkdir $DIR/$tdir || error "mkdir failed"
1761         for i in $(seq 1 $OSTCOUNT); do
1762                 offset=$((i - 1))
1763                 $LFS setstripe -c $i -i $offset $DIR/$tdir/f$i ||
1764                         error "setstripe -c $i -i $offset failed"
1765                 count=$($LFS getstripe -c $DIR/$tdir/f$i)
1766                 index=$($LFS getstripe -i $DIR/$tdir/f$i)
1767                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1768                 [ $index -ne $offset ] &&
1769                         error "stripe offset $index != $offset" || true
1770         done
1771 }
1772 run_test 27wa "check $LFS setstripe -c -i options"
1773
1774 test_27x() {
1775         remote_ost_nodsh && skip "remote OST with nodsh" && return
1776         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1777         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1778         OFFSET=$(($OSTCOUNT - 1))
1779         OSTIDX=0
1780         local OST=$(ostname_from_index $OSTIDX)
1781
1782         test_mkdir -p $DIR/$tdir
1783         $LFS setstripe -c 1 $DIR/$tdir  # 1 stripe per file
1784         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1785         sleep_maxage
1786         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1787         for i in $(seq 0 $OFFSET); do
1788                 [ $($LFS getstripe $DIR/$tdir/$tfile$i | grep -A 10 obdidx |
1789                         awk '{print $1}' | grep -w "$OSTIDX") ] &&
1790                 error "OST0 was degraded but new created file still use it"
1791         done
1792         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1793 }
1794 run_test 27x "create files while OST0 is degraded"
1795
1796 test_27y() {
1797         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1798         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1799         remote_ost_nodsh && skip "remote OST with nodsh" && return
1800         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1801
1802         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1803         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1804                 osc.$mdtosc.prealloc_last_id)
1805         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1806                 osc.$mdtosc.prealloc_next_id)
1807         local fcount=$((last_id - next_id))
1808         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1809         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1810
1811         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1812                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1813         local OST_DEACTIVE_IDX=-1
1814         local OSC
1815         local OSTIDX
1816         local OST
1817
1818         for OSC in $MDS_OSCS; do
1819                 OST=$(osc_to_ost $OSC)
1820                 OSTIDX=$(index_from_ostuuid $OST)
1821                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1822                         OST_DEACTIVE_IDX=$OSTIDX
1823                 fi
1824                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1825                         echo $OSC "is Deactivated:"
1826                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1827                 fi
1828         done
1829
1830         OSTIDX=$(index_from_ostuuid $OST)
1831         test_mkdir -p $DIR/$tdir
1832         $LFS setstripe -c 1 $DIR/$tdir      # 1 stripe / file
1833
1834         for OSC in $MDS_OSCS; do
1835                 OST=$(osc_to_ost $OSC)
1836                 OSTIDX=$(index_from_ostuuid $OST)
1837                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1838                         echo $OST "is degraded:"
1839                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1840                                                 obdfilter.$OST.degraded=1
1841                 fi
1842         done
1843
1844         sleep_maxage
1845         createmany -o $DIR/$tdir/$tfile $fcount
1846
1847         for OSC in $MDS_OSCS; do
1848                 OST=$(osc_to_ost $OSC)
1849                 OSTIDX=$(index_from_ostuuid $OST)
1850                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1851                         echo $OST "is recovered from degraded:"
1852                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1853                                                 obdfilter.$OST.degraded=0
1854                 else
1855                         do_facet $SINGLEMDS lctl --device %$OSC activate
1856                 fi
1857         done
1858
1859         # all osp devices get activated, hence -1 stripe count restored
1860         local stripe_count=0
1861
1862         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1863         # devices get activated.
1864         sleep_maxage
1865         $LFS setstripe -c -1 $DIR/$tfile
1866         stripe_count=$($LFS getstripe -c $DIR/$tfile)
1867         rm -f $DIR/$tfile
1868         [ $stripe_count -ne $OSTCOUNT ] &&
1869                 error "Of $OSTCOUNT OSTs, only $stripe_count is available"
1870         return 0
1871 }
1872 run_test 27y "create files while OST0 is degraded and the rest inactive"
1873
1874 check_seq_oid()
1875 {
1876         log "check file $1"
1877
1878         lmm_count=$($GETSTRIPE -c $1)
1879         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1880         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1881
1882         local old_ifs="$IFS"
1883         IFS=$'[:]'
1884         fid=($($LFS path2fid $1))
1885         IFS="$old_ifs"
1886
1887         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1888         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1889
1890         # compare lmm_seq and lu_fid->f_seq
1891         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1892         # compare lmm_object_id and lu_fid->oid
1893         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1894
1895         # check the trusted.fid attribute of the OST objects of the file
1896         local have_obdidx=false
1897         local stripe_nr=0
1898         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1899                 # skip lines up to and including "obdidx"
1900                 [ -z "$obdidx" ] && break
1901                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1902                 $have_obdidx || continue
1903
1904                 local ost=$((obdidx + 1))
1905                 local dev=$(ostdevname $ost)
1906                 local oid_hex
1907
1908                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1909
1910                 seq=$(echo $seq | sed -e "s/^0x//g")
1911                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1912                         oid_hex=$(echo $oid)
1913                 else
1914                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1915                 fi
1916                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1917
1918                 local ff=""
1919                 #
1920                 # Don't unmount/remount the OSTs if we don't need to do that.
1921                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1922                 # update too, until that use mount/ll_decode_filter_fid/mount.
1923                 # Re-enable when debugfs will understand new filter_fid.
1924                 #
1925                 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
1926                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1927                                 $dev 2>/dev/null" | grep "parent=")
1928                 fi
1929                 if [ -z "$ff" ]; then
1930                         stop ost$ost
1931                         mount_fstype ost$ost
1932                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1933                                 $(facet_mntpt ost$ost)/$obj_file)
1934                         unmount_fstype ost$ost
1935                         start ost$ost $dev $OST_MOUNT_OPTS
1936                         clients_up
1937                 fi
1938
1939                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1940
1941                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1942
1943                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1944                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1945                 #
1946                 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
1947                 #       stripe_size=1048576 component_id=1 component_start=0 \
1948                 #       component_end=33554432
1949                 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
1950                 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
1951                 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
1952                 local ff_pstripe
1953                 if grep -q 'stripe=' <<<$ff; then
1954                         ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
1955                 else
1956                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1957                         # into f_ver in this case.  See comment on ff_parent.
1958                         ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
1959                 fi
1960
1961                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1962                 [ $ff_pseq = $lmm_seq ] ||
1963                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1964                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1965                 [ $ff_poid = $lmm_oid ] ||
1966                         error "FF parent OID $ff_poid != $lmm_oid"
1967                 (($ff_pstripe == $stripe_nr)) ||
1968                         error "FF stripe $ff_pstripe != $stripe_nr"
1969
1970                 stripe_nr=$((stripe_nr + 1))
1971                 [ $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
1972                         continue
1973                 if grep -q 'stripe_count=' <<<$ff; then
1974                         local ff_scnt=$(sed -e 's/.*stripe_count=//' \
1975                                             -e 's/ .*//' <<<$ff)
1976                         [ $lmm_count = $ff_scnt ] ||
1977                                 error "FF stripe count $lmm_count != $ff_scnt"
1978                 fi
1979         done
1980 }
1981
1982 test_27z() {
1983         remote_ost_nodsh && skip "remote OST with nodsh" && return
1984         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1985         test_mkdir -p $DIR/$tdir
1986
1987         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1988                 { error "setstripe -c -1 failed"; return 1; }
1989         # We need to send a write to every object to get parent FID info set.
1990         # This _should_ also work for setattr, but does not currently.
1991         # touch $DIR/$tdir/$tfile-1 ||
1992         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1993                 { error "dd $tfile-1 failed"; return 2; }
1994         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1995                 { error "setstripe -c -1 failed"; return 3; }
1996         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1997                 { error "dd $tfile-2 failed"; return 4; }
1998
1999         # make sure write RPCs have been sent to OSTs
2000         sync; sleep 5; sync
2001
2002         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
2003         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
2004 }
2005 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
2006
2007 test_27A() { # b=19102
2008         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2009
2010         save_layout_restore_at_exit $MOUNT
2011
2012         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
2013         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
2014                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
2015         local default_size=$($GETSTRIPE -S $MOUNT)
2016         local default_offset=$($GETSTRIPE -i $MOUNT)
2017         local dsize=$((1024 * 1024))
2018         [ $default_size -eq $dsize ] ||
2019                 error "stripe size $default_size != $dsize"
2020         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
2021 }
2022 run_test 27A "check filesystem-wide default LOV EA values"
2023
2024 test_27B() { # LU-2523
2025         test_mkdir -p $DIR/$tdir
2026         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
2027         touch $DIR/$tdir/f0
2028         # open f1 with O_LOV_DELAY_CREATE
2029         # rename f0 onto f1
2030         # call setstripe ioctl on open file descriptor for f1
2031         # close
2032         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
2033                 $DIR/$tdir/f0
2034
2035         rm -f $DIR/$tdir/f1
2036         # open f1 with O_LOV_DELAY_CREATE
2037         # unlink f1
2038         # call setstripe ioctl on open file descriptor for f1
2039         # close
2040         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
2041
2042         # Allow multiop to fail in imitation of NFS's busted semantics.
2043         true
2044 }
2045 run_test 27B "call setstripe on open unlinked file/rename victim"
2046
2047 test_27C() { #LU-2871
2048         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
2049
2050         declare -a ost_idx
2051         local index
2052         local found
2053         local i
2054         local j
2055
2056         test_mkdir -p $DIR/$tdir
2057         cd $DIR/$tdir
2058         for i in $(seq 0 $((OSTCOUNT - 1))); do
2059                 # set stripe across all OSTs starting from OST$i
2060                 $SETSTRIPE -i $i -c -1 $tfile$i
2061                 # get striping information
2062                 ost_idx=($($GETSTRIPE $tfile$i |
2063                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2064                 echo ${ost_idx[@]}
2065
2066                 # check the layout
2067                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2068                         error "${#ost_idx[@]} != $OSTCOUNT"
2069
2070                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2071                         found=0
2072                         for j in $(echo ${ost_idx[@]}); do
2073                                 if [ $index -eq $j ]; then
2074                                         found=1
2075                                         break
2076                                 fi
2077                         done
2078                         [ $found = 1 ] ||
2079                                 error "Can not find $index in ${ost_idx[@]}"
2080                 done
2081         done
2082 }
2083 run_test 27C "check full striping across all OSTs"
2084
2085 test_27D() {
2086         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2087         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
2088         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2089         local POOL=${POOL:-testpool}
2090         local first_ost=0
2091         local last_ost=$(($OSTCOUNT - 1))
2092         local ost_step=1
2093         local ost_list=$(seq $first_ost $ost_step $last_ost)
2094         local ost_range="$first_ost $last_ost $ost_step"
2095
2096         if ! combined_mgs_mds ; then
2097                 mount_mgs_client
2098         fi
2099
2100         test_mkdir -p $DIR/$tdir
2101         pool_add $POOL || error "pool_add failed"
2102         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2103
2104         local skip27D
2105         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ] &&
2106                 skip27D+="-s 29"
2107         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.55) -o \
2108           $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
2109                 skip27D+=" -s 30,31"
2110         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
2111                 error "llapi_layout_test failed"
2112
2113         destroy_test_pools || error "destroy test pools failed"
2114
2115         if ! combined_mgs_mds ; then
2116                 umount_mgs_client
2117         fi
2118 }
2119 run_test 27D "validate llapi_layout API"
2120
2121 # Verify that default_easize is increased from its initial value after
2122 # accessing a widely striped file.
2123 test_27E() {
2124         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2125         [ $(lustre_version_code client) -lt $(version_code 2.5.57) ] &&
2126                 skip "client does not have LU-3338 fix" && return
2127
2128         # 72 bytes is the minimum space required to store striping
2129         # information for a file striped across one OST:
2130         # (sizeof(struct lov_user_md_v3) +
2131         #  sizeof(struct lov_user_ost_data_v1))
2132         local min_easize=72
2133         $LCTL set_param -n llite.*.default_easize $min_easize ||
2134                 error "lctl set_param failed"
2135         local easize=$($LCTL get_param -n llite.*.default_easize)
2136
2137         [ $easize -eq $min_easize ] ||
2138                 error "failed to set default_easize"
2139
2140         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2141                 error "setstripe failed"
2142         cat $DIR/$tfile
2143         rm $DIR/$tfile
2144
2145         easize=$($LCTL get_param -n llite.*.default_easize)
2146
2147         [ $easize -gt $min_easize ] ||
2148                 error "default_easize not updated"
2149 }
2150 run_test 27E "check that default extended attribute size properly increases"
2151
2152 test_27F() { # LU-5346/LU-7975
2153         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
2154         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2155         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.51) ]] &&
2156                 skip "Need MDS version at least 2.8.51" && return
2157         remote_ost_nodsh && skip "remote OST with nodsh" && return
2158
2159         test_mkdir -p $DIR/$tdir
2160         rm -f $DIR/$tdir/f0
2161         $SETSTRIPE -c 2 $DIR/$tdir
2162
2163         # stop all OSTs to reproduce situation for LU-7975 ticket
2164         for num in $(seq $OSTCOUNT); do
2165                 stop ost$num
2166         done
2167
2168         # open/create f0 with O_LOV_DELAY_CREATE
2169         # truncate f0 to a non-0 size
2170         # close
2171         multiop $DIR/$tdir/f0 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T1050000c
2172
2173         $CHECKSTAT -s 1050000 $DIR/$tdir/f0 || error "checkstat failed"
2174         # open/write it again to force delayed layout creation
2175         cat /etc/hosts > $DIR/$tdir/f0 &
2176         catpid=$!
2177
2178         # restart OSTs
2179         for num in $(seq $OSTCOUNT); do
2180                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
2181                         error "ost$num failed to start"
2182         done
2183
2184         wait $catpid || error "cat failed"
2185
2186         cmp /etc/hosts $DIR/$tdir/f0 || error "cmp failed"
2187         [[ $($GETSTRIPE -c $DIR/$tdir/f0) == 2 ]] || error "wrong stripecount"
2188
2189 }
2190 run_test 27F "Client resend delayed layout creation with non-zero size"
2191
2192 test_27G() { #LU-10629
2193         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
2194         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2195         local POOL=${POOL:-testpool}
2196         local ostrange="0 0 1"
2197
2198         test_mkdir $DIR/$tdir
2199         pool_add $POOL || error "pool_add failed"
2200         pool_add_targets $POOL $ostrange || error "pool_add_targets failed"
2201         $LFS setstripe -p $POOL $DIR/$tdir
2202
2203         local pool=$($LFS getstripe -p $DIR/$tdir)
2204
2205         [ "$pool" = "$POOL" ] || error "Striping failed got '$pool' not '$POOL'"
2206
2207         $LFS setstripe -d $DIR/$tdir
2208
2209         pool=$($LFS getstripe -p $DIR/$tdir)
2210
2211         rmdir $DIR/$tdir
2212
2213         [ -z "$pool" ] || error "'$pool' is not empty"
2214 }
2215 run_test 27G "Clear OST pool from stripe"
2216
2217 # createtest also checks that device nodes are created and
2218 # then visible correctly (#2091)
2219 test_28() { # bug 2091
2220         test_mkdir $DIR/d28
2221         $CREATETEST $DIR/d28/ct || error
2222 }
2223 run_test 28 "create/mknod/mkdir with bad file types ============"
2224
2225 test_29() {
2226         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
2227         sync; sleep 1; sync # flush out any dirty pages from previous tests
2228         cancel_lru_locks
2229         test_mkdir $DIR/d29
2230         touch $DIR/d29/foo
2231         log 'first d29'
2232         ls -l $DIR/d29
2233
2234         declare -i LOCKCOUNTORIG=0
2235         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2236                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2237         done
2238         [ $LOCKCOUNTORIG -eq 0 ] && error "No mdc lock count" && return 1
2239
2240         declare -i LOCKUNUSEDCOUNTORIG=0
2241         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2242                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2243         done
2244
2245         log 'second d29'
2246         ls -l $DIR/d29
2247         log 'done'
2248
2249         declare -i LOCKCOUNTCURRENT=0
2250         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2251                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2252         done
2253
2254         declare -i LOCKUNUSEDCOUNTCURRENT=0
2255         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2256                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2257         done
2258
2259         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2260                 $LCTL set_param -n ldlm.dump_namespaces ""
2261                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2262                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2263                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2264                 return 2
2265         fi
2266         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2267                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2268                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2269                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2270                 return 3
2271         fi
2272 }
2273 run_test 29 "IT_GETATTR regression  ============================"
2274
2275 test_30a() { # was test_30
2276         cp $(which ls) $DIR || cp /bin/ls $DIR
2277         $DIR/ls / || error
2278         rm $DIR/ls
2279 }
2280 run_test 30a "execute binary from Lustre (execve) =============="
2281
2282 test_30b() {
2283         cp `which ls` $DIR || cp /bin/ls $DIR
2284         chmod go+rx $DIR/ls
2285         $RUNAS $DIR/ls / || error
2286         rm $DIR/ls
2287 }
2288 run_test 30b "execute binary from Lustre as non-root ==========="
2289
2290 test_30c() { # b=22376
2291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2292         cp `which ls` $DIR || cp /bin/ls $DIR
2293         chmod a-rw $DIR/ls
2294         cancel_lru_locks mdc
2295         cancel_lru_locks osc
2296         $RUNAS $DIR/ls / || error
2297         rm -f $DIR/ls
2298 }
2299 run_test 30c "execute binary from Lustre without read perms ===="
2300
2301 test_31a() {
2302         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2303         $CHECKSTAT -a $DIR/f31 || error
2304 }
2305 run_test 31a "open-unlink file =================================="
2306
2307 test_31b() {
2308         touch $DIR/f31 || error
2309         ln $DIR/f31 $DIR/f31b || error
2310         $MULTIOP $DIR/f31b Ouc || error
2311         $CHECKSTAT -t file $DIR/f31 || error
2312 }
2313 run_test 31b "unlink file with multiple links while open ======="
2314
2315 test_31c() {
2316         touch $DIR/f31 || error
2317         ln $DIR/f31 $DIR/f31c || error
2318         multiop_bg_pause $DIR/f31 O_uc || return 1
2319         MULTIPID=$!
2320         $MULTIOP $DIR/f31c Ouc
2321         kill -USR1 $MULTIPID
2322         wait $MULTIPID
2323 }
2324 run_test 31c "open-unlink file with multiple links ============="
2325
2326 test_31d() {
2327         opendirunlink $DIR/d31d $DIR/d31d || error
2328         $CHECKSTAT -a $DIR/d31d || error
2329 }
2330 run_test 31d "remove of open directory ========================="
2331
2332 test_31e() { # bug 2904
2333         openfilleddirunlink $DIR/d31e || error
2334 }
2335 run_test 31e "remove of open non-empty directory ==============="
2336
2337 test_31f() { # bug 4554
2338         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2339         set -vx
2340         test_mkdir $DIR/d31f
2341         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2342         cp /etc/hosts $DIR/d31f
2343         ls -l $DIR/d31f
2344         $GETSTRIPE $DIR/d31f/hosts
2345         multiop_bg_pause $DIR/d31f D_c || return 1
2346         MULTIPID=$!
2347
2348         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2349         test_mkdir $DIR/d31f
2350         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2351         cp /etc/hosts $DIR/d31f
2352         ls -l $DIR/d31f
2353         $GETSTRIPE $DIR/d31f/hosts
2354         multiop_bg_pause $DIR/d31f D_c || return 1
2355         MULTIPID2=$!
2356
2357         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2358         wait $MULTIPID || error "first opendir $MULTIPID failed"
2359
2360         sleep 6
2361
2362         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2363         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2364         set +vx
2365 }
2366 run_test 31f "remove of open directory with open-unlink file ==="
2367
2368 test_31g() {
2369         echo "-- cross directory link --"
2370         test_mkdir -c1 $DIR/${tdir}ga
2371         test_mkdir -c1 $DIR/${tdir}gb
2372         touch $DIR/${tdir}ga/f
2373         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2374         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2375         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2376         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2377         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2378 }
2379 run_test 31g "cross directory link==============="
2380
2381 test_31h() {
2382         echo "-- cross directory link --"
2383         test_mkdir -c1 $DIR/${tdir}
2384         test_mkdir -c1 $DIR/${tdir}/dir
2385         touch $DIR/${tdir}/f
2386         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2387         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2388         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2389         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2390         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2391 }
2392 run_test 31h "cross directory link under child==============="
2393
2394 test_31i() {
2395         echo "-- cross directory link --"
2396         test_mkdir -c1 $DIR/$tdir
2397         test_mkdir -c1 $DIR/$tdir/dir
2398         touch $DIR/$tdir/dir/f
2399         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2400         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2401         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2402         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2403         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2404 }
2405 run_test 31i "cross directory link under parent==============="
2406
2407 test_31j() {
2408         test_mkdir -c1 -p $DIR/$tdir
2409         test_mkdir -c1 -p $DIR/$tdir/dir1
2410         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2411         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2412         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2413         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2414         return 0
2415 }
2416 run_test 31j "link for directory==============="
2417
2418 test_31k() {
2419         test_mkdir -c1 -p $DIR/$tdir
2420         touch $DIR/$tdir/s
2421         touch $DIR/$tdir/exist
2422         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2423         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2424         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2425         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2426         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2427         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2428         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2429         return 0
2430 }
2431 run_test 31k "link to file: the same, non-existing, dir==============="
2432
2433 test_31m() {
2434         mkdir $DIR/d31m
2435         touch $DIR/d31m/s
2436         mkdir $DIR/d31m2
2437         touch $DIR/d31m2/exist
2438         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2439         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2440         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2441         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2442         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2443         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2444         return 0
2445 }
2446 run_test 31m "link to file: the same, non-existing, dir==============="
2447
2448 test_31n() {
2449         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2450         nlink=$(stat --format=%h $DIR/$tfile)
2451         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2452         local fd=$(free_fd)
2453         local cmd="exec $fd<$DIR/$tfile"
2454         eval $cmd
2455         cmd="exec $fd<&-"
2456         trap "eval $cmd" EXIT
2457         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2458         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2459         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2460         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2461         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2462         eval $cmd
2463 }
2464 run_test 31n "check link count of unlinked file"
2465
2466 link_one() {
2467         local TEMPNAME=$(mktemp $1_XXXXXX)
2468         mlink $TEMPNAME $1 2> /dev/null &&
2469                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2470         munlink $TEMPNAME
2471 }
2472
2473 test_31o() { # LU-2901
2474         test_mkdir -p $DIR/$tdir
2475         for LOOP in $(seq 100); do
2476                 rm -f $DIR/$tdir/$tfile*
2477                 for THREAD in $(seq 8); do
2478                         link_one $DIR/$tdir/$tfile.$LOOP &
2479                 done
2480                 wait
2481                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2482                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2483                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2484                         break || true
2485         done
2486 }
2487 run_test 31o "duplicate hard links with same filename"
2488
2489 test_31p() {
2490         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2491
2492         test_mkdir $DIR/$tdir
2493         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2494         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2495
2496         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2497                 error "open unlink test1 failed"
2498         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2499                 error "open unlink test2 failed"
2500
2501         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2502                 error "test1 still exists"
2503         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2504                 error "test2 still exists"
2505 }
2506 run_test 31p "remove of open striped directory"
2507
2508 cleanup_test32_mount() {
2509         local rc=0
2510         trap 0
2511         local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$//p')
2512         $UMOUNT $DIR/$tdir/ext2-mountpoint || rc=$?
2513         losetup -d $loopdev || true
2514         rm -rf $DIR/$tdir
2515         return $rc
2516 }
2517
2518 test_32a() {
2519         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2520         echo "== more mountpoints and symlinks ================="
2521         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2522         trap cleanup_test32_mount EXIT
2523         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2524         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2525         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2526         cleanup_test32_mount
2527 }
2528 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2529
2530 test_32b() {
2531         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2532         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2533         trap cleanup_test32_mount EXIT
2534         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2535         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2536         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2537         cleanup_test32_mount
2538 }
2539 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2540
2541 test_32c() {
2542         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2543         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2544         trap cleanup_test32_mount EXIT
2545         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2546         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2547         test_mkdir -p $DIR/$tdir/d2/test_dir
2548         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2549         cleanup_test32_mount
2550 }
2551 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2552
2553 test_32d() {
2554         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2555         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2556         trap cleanup_test32_mount EXIT
2557         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2558         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2559         test_mkdir -p $DIR/$tdir/d2/test_dir
2560         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2561         cleanup_test32_mount
2562 }
2563 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2564
2565 test_32e() {
2566         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2567         test_mkdir -p $DIR/d32e/tmp
2568         TMP_DIR=$DIR/d32e/tmp
2569         ln -s $DIR/d32e $TMP_DIR/symlink11
2570         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2571         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2572         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2573 }
2574 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2575
2576 test_32f() {
2577         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2578         test_mkdir -p $DIR/d32f/tmp
2579         TMP_DIR=$DIR/d32f/tmp
2580         ln -s $DIR/d32f $TMP_DIR/symlink11
2581         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2582         ls $DIR/d32f/tmp/symlink11  || error
2583         ls $DIR/d32f/symlink01 || error
2584 }
2585 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2586
2587 test_32g() {
2588         TMP_DIR=$DIR/$tdir/tmp
2589         test_mkdir -p $DIR/$tdir/tmp
2590         test_mkdir $DIR/${tdir}2
2591         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2592         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2593         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2594         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2595         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2596         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2597 }
2598 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2599
2600 test_32h() {
2601         rm -fr $DIR/$tdir $DIR/${tdir}2
2602         TMP_DIR=$DIR/$tdir/tmp
2603         test_mkdir -p $DIR/$tdir/tmp
2604         test_mkdir $DIR/${tdir}2
2605         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2606         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2607         ls $TMP_DIR/symlink12 || error
2608         ls $DIR/$tdir/symlink02  || error
2609 }
2610 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2611
2612 test_32i() {
2613         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2614         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2615         trap cleanup_test32_mount EXIT
2616         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2617         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2618         touch $DIR/$tdir/test_file
2619         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2620         cleanup_test32_mount
2621 }
2622 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2623
2624 test_32j() {
2625         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2626         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2627         trap cleanup_test32_mount EXIT
2628         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2629         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2630         touch $DIR/$tdir/test_file
2631         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2632         cleanup_test32_mount
2633 }
2634 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2635
2636 test_32k() {
2637         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2638         rm -fr $DIR/$tdir
2639         trap cleanup_test32_mount EXIT
2640         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2641         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2642         test_mkdir -p $DIR/$tdir/d2
2643         touch $DIR/$tdir/d2/test_file || error
2644         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2645         cleanup_test32_mount
2646 }
2647 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2648
2649 test_32l() {
2650         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2651         rm -fr $DIR/$tdir
2652         trap cleanup_test32_mount EXIT
2653         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2654         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2655         test_mkdir -p $DIR/$tdir/d2
2656         touch $DIR/$tdir/d2/test_file
2657         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2658         cleanup_test32_mount
2659 }
2660 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2661
2662 test_32m() {
2663         rm -fr $DIR/d32m
2664         test_mkdir -p $DIR/d32m/tmp
2665         TMP_DIR=$DIR/d32m/tmp
2666         ln -s $DIR $TMP_DIR/symlink11
2667         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2668         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2669         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2670 }
2671 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2672
2673 test_32n() {
2674         rm -fr $DIR/d32n
2675         test_mkdir -p $DIR/d32n/tmp
2676         TMP_DIR=$DIR/d32n/tmp
2677         ln -s $DIR $TMP_DIR/symlink11
2678         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2679         ls -l $DIR/d32n/tmp/symlink11  || error
2680         ls -l $DIR/d32n/symlink01 || error
2681 }
2682 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2683
2684 test_32o() {
2685         touch $DIR/$tfile
2686         test_mkdir -p $DIR/d32o/tmp
2687         TMP_DIR=$DIR/d32o/tmp
2688         ln -s $DIR/$tfile $TMP_DIR/symlink12
2689         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2690         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2691         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2692         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2693         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2694 }
2695 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2696
2697 test_32p() {
2698         log 32p_1
2699         rm -fr $DIR/d32p
2700         log 32p_2
2701         rm -f $DIR/$tfile
2702         log 32p_3
2703         touch $DIR/$tfile
2704         log 32p_4
2705         test_mkdir -p $DIR/d32p/tmp
2706         log 32p_5
2707         TMP_DIR=$DIR/d32p/tmp
2708         log 32p_6
2709         ln -s $DIR/$tfile $TMP_DIR/symlink12
2710         log 32p_7
2711         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2712         log 32p_8
2713         cat $DIR/d32p/tmp/symlink12 || error
2714         log 32p_9
2715         cat $DIR/d32p/symlink02 || error
2716         log 32p_10
2717 }
2718 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2719
2720 test_32q() {
2721         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2722         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2723         trap cleanup_test32_mount EXIT
2724         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2725         touch $DIR/$tdir/ext2-mountpoint/under_the_mount
2726         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2727         ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
2728         cleanup_test32_mount
2729 }
2730 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2731
2732 test_32r() {
2733         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2734         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2735         trap cleanup_test32_mount EXIT
2736         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2737         touch $DIR/$tdir/ext2-mountpoint/under_the_mount
2738         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2739         ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
2740         cleanup_test32_mount
2741 }
2742 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2743
2744 test_33aa() {
2745         rm -f $DIR/$tfile
2746         touch $DIR/$tfile
2747         chmod 444 $DIR/$tfile
2748         chown $RUNAS_ID $DIR/$tfile
2749         log 33_1
2750         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2751         log 33_2
2752 }
2753 run_test 33aa "write file with mode 444 (should return error) ===="
2754
2755 test_33a() {
2756         rm -fr $DIR/d33
2757         test_mkdir -p $DIR/d33
2758         chown $RUNAS_ID $DIR/d33
2759         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2760         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2761                 error "open RDWR" || true
2762 }
2763 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2764
2765 test_33b() {
2766         rm -fr $DIR/d33
2767         test_mkdir -p $DIR/d33
2768         chown $RUNAS_ID $DIR/d33
2769         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2770 }
2771 run_test 33b "test open file with malformed flags (No panic)"
2772
2773 test_33c() {
2774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2775         local ostnum
2776         local ostname
2777         local write_bytes
2778         local all_zeros
2779
2780         remote_ost_nodsh && skip "remote OST with nodsh" && return
2781         all_zeros=:
2782         rm -fr $DIR/d33
2783         test_mkdir -p $DIR/d33
2784         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2785
2786         sync
2787         for ostnum in $(seq $OSTCOUNT); do
2788                 # test-framework's OST numbering is one-based, while Lustre's
2789                 # is zero-based
2790                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2791                 # Parsing llobdstat's output sucks; we could grep the /proc
2792                 # path, but that's likely to not be as portable as using the
2793                 # llobdstat utility.  So we parse lctl output instead.
2794                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2795                         obdfilter/$ostname/stats |
2796                         awk '/^write_bytes/ {print $7}' )
2797                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2798                 if (( ${write_bytes:-0} > 0 ))
2799                 then
2800                         all_zeros=false
2801                         break;
2802                 fi
2803         done
2804
2805         $all_zeros || return 0
2806
2807         # Write four bytes
2808         echo foo > $DIR/d33/bar
2809         # Really write them
2810         sync
2811
2812         # Total up write_bytes after writing.  We'd better find non-zeros.
2813         for ostnum in $(seq $OSTCOUNT); do
2814                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2815                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2816                         obdfilter/$ostname/stats |
2817                         awk '/^write_bytes/ {print $7}' )
2818                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2819                 if (( ${write_bytes:-0} > 0 ))
2820                 then
2821                         all_zeros=false
2822                         break;
2823                 fi
2824         done
2825
2826         if $all_zeros
2827         then
2828                 for ostnum in $(seq $OSTCOUNT); do
2829                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2830                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2831                         do_facet ost$ostnum lctl get_param -n \
2832                                 obdfilter/$ostname/stats
2833                 done
2834                 error "OST not keeping write_bytes stats (b22312)"
2835         fi
2836 }
2837 run_test 33c "test llobdstat and write_bytes"
2838
2839 test_33d() {
2840         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2842         local MDTIDX=1
2843         local remote_dir=$DIR/$tdir/remote_dir
2844
2845         test_mkdir -p $DIR/$tdir
2846         $LFS mkdir -i $MDTIDX $remote_dir ||
2847                 error "create remote directory failed"
2848
2849         touch $remote_dir/$tfile
2850         chmod 444 $remote_dir/$tfile
2851         chown $RUNAS_ID $remote_dir/$tfile
2852
2853         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2854
2855         chown $RUNAS_ID $remote_dir
2856         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2857                                         error "create" || true
2858         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2859                                     error "open RDWR" || true
2860         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2861 }
2862 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2863
2864 test_33e() {
2865         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2866
2867         mkdir $DIR/$tdir
2868
2869         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2870         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2871         mkdir $DIR/$tdir/local_dir
2872
2873         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2874         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2875         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2876
2877         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2878                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2879
2880         rmdir $DIR/$tdir/* || error "rmdir failed"
2881
2882         umask 777
2883         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2884         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2885         mkdir $DIR/$tdir/local_dir
2886
2887         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2888         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2889         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2890
2891         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2892                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2893
2894         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2895
2896         umask 000
2897         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2898         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2899         mkdir $DIR/$tdir/local_dir
2900
2901         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2902         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2903         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2904
2905         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2906                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2907 }
2908 run_test 33e "mkdir and striped directory should have same mode"
2909
2910 cleanup_33f() {
2911         trap 0
2912         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2913 }
2914
2915 test_33f() {
2916         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2917         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2918
2919         mkdir $DIR/$tdir
2920         chmod go+rwx $DIR/$tdir
2921         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2922         trap cleanup_33f EXIT
2923
2924         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2925                 error "cannot create striped directory"
2926
2927         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2928                 error "cannot create files in striped directory"
2929
2930         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2931                 error "cannot remove files in striped directory"
2932
2933         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2934                 error "cannot remove striped directory"
2935
2936         cleanup_33f
2937 }
2938 run_test 33f "nonroot user can create, access, and remove a striped directory"
2939
2940 test_33g() {
2941         mkdir -p $DIR/$tdir/dir2
2942
2943         local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
2944         echo $err
2945         [[ $err =~ "exists" ]] || error "Not exists error"
2946 }
2947 run_test 33g "nonroot user create already existing root created file"
2948
2949 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2950 test_34a() {
2951         rm -f $DIR/f34
2952         $MCREATE $DIR/f34 || error
2953         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2954         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2955         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2956         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2957 }
2958 run_test 34a "truncate file that has not been opened ==========="
2959
2960 test_34b() {
2961         [ ! -f $DIR/f34 ] && test_34a
2962         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2963         $OPENFILE -f O_RDONLY $DIR/f34
2964         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2965         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2966 }
2967 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2968
2969 test_34c() {
2970         [ ! -f $DIR/f34 ] && test_34a
2971         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2972         $OPENFILE -f O_RDWR $DIR/f34
2973         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2974         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2975 }
2976 run_test 34c "O_RDWR opening file-with-size works =============="
2977
2978 test_34d() {
2979         [ ! -f $DIR/f34 ] && test_34a
2980         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2981         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2982         rm $DIR/f34
2983 }
2984 run_test 34d "write to sparse file ============================="
2985
2986 test_34e() {
2987         rm -f $DIR/f34e
2988         $MCREATE $DIR/f34e || error
2989         $TRUNCATE $DIR/f34e 1000 || error
2990         $CHECKSTAT -s 1000 $DIR/f34e || error
2991         $OPENFILE -f O_RDWR $DIR/f34e
2992         $CHECKSTAT -s 1000 $DIR/f34e || error
2993 }
2994 run_test 34e "create objects, some with size and some without =="
2995
2996 test_34f() { # bug 6242, 6243
2997         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2998         SIZE34F=48000
2999         rm -f $DIR/f34f
3000         $MCREATE $DIR/f34f || error
3001         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
3002         dd if=$DIR/f34f of=$TMP/f34f
3003         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
3004         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
3005         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
3006         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
3007         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
3008 }
3009 run_test 34f "read from a file with no objects until EOF ======="
3010
3011 test_34g() {
3012         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3013         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
3014         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
3015         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
3016         cancel_lru_locks osc
3017         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
3018                 error "wrong size after lock cancel"
3019
3020         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
3021         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
3022                 error "expanding truncate failed"
3023         cancel_lru_locks osc
3024         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
3025                 error "wrong expanded size after lock cancel"
3026 }
3027 run_test 34g "truncate long file ==============================="
3028
3029 test_34h() {
3030         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3031         local gid=10
3032         local sz=1000
3033
3034         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
3035         sync # Flush the cache so that multiop below does not block on cache
3036              # flush when getting the group lock
3037         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
3038         MULTIPID=$!
3039
3040         # Since just timed wait is not good enough, let's do a sync write
3041         # that way we are sure enough time for a roundtrip + processing
3042         # passed + 2 seconds of extra margin.
3043         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
3044         rm $DIR/${tfile}-1
3045         sleep 2
3046
3047         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
3048                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
3049                 kill -9 $MULTIPID
3050         fi
3051         wait $MULTIPID
3052         local nsz=`stat -c %s $DIR/$tfile`
3053         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
3054 }
3055 run_test 34h "ftruncate file under grouplock should not block"
3056
3057 test_35a() {
3058         cp /bin/sh $DIR/f35a
3059         chmod 444 $DIR/f35a
3060         chown $RUNAS_ID $DIR/f35a
3061         $RUNAS $DIR/f35a && error || true
3062         rm $DIR/f35a
3063 }
3064 run_test 35a "exec file with mode 444 (should return and not leak) ====="
3065
3066 test_36a() {
3067         rm -f $DIR/f36
3068         utime $DIR/f36 || error
3069 }
3070 run_test 36a "MDS utime check (mknod, utime) ==================="
3071
3072 test_36b() {
3073         echo "" > $DIR/f36
3074         utime $DIR/f36 || error
3075 }
3076 run_test 36b "OST utime check (open, utime) ===================="
3077
3078 test_36c() {
3079         rm -f $DIR/d36/f36
3080         test_mkdir $DIR/d36
3081         chown $RUNAS_ID $DIR/d36
3082         $RUNAS utime $DIR/d36/f36 || error
3083 }
3084 run_test 36c "non-root MDS utime check (mknod, utime) =========="
3085
3086 test_36d() {
3087         [ ! -d $DIR/d36 ] && test_36c
3088         echo "" > $DIR/d36/f36
3089         $RUNAS utime $DIR/d36/f36 || error
3090 }
3091 run_test 36d "non-root OST utime check (open, utime) ==========="
3092
3093 test_36e() {
3094         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3095         test_mkdir -p $DIR/$tdir
3096         touch $DIR/$tdir/$tfile
3097         $RUNAS utime $DIR/$tdir/$tfile && \
3098                 error "utime worked, expected failure" || true
3099 }
3100 run_test 36e "utime on non-owned file (should return error) ===="
3101
3102 subr_36fh() {
3103         local fl="$1"
3104         local LANG_SAVE=$LANG
3105         local LC_LANG_SAVE=$LC_LANG
3106         export LANG=C LC_LANG=C # for date language
3107
3108         DATESTR="Dec 20  2000"
3109         test_mkdir -p $DIR/$tdir
3110         lctl set_param fail_loc=$fl
3111         date; date +%s
3112         cp /etc/hosts $DIR/$tdir/$tfile
3113         sync & # write RPC generated with "current" inode timestamp, but delayed
3114         sleep 1
3115         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
3116         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
3117         cancel_lru_locks osc
3118         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
3119         date; date +%s
3120         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
3121                 echo "BEFORE: $LS_BEFORE" && \
3122                 echo "AFTER : $LS_AFTER" && \
3123                 echo "WANT  : $DATESTR" && \
3124                 error "$DIR/$tdir/$tfile timestamps changed" || true
3125
3126         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
3127 }
3128
3129 test_36f() {
3130         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3131         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3132         subr_36fh "0x80000214"
3133 }
3134 run_test 36f "utime on file racing with OST BRW write =========="
3135
3136 test_36g() {
3137         remote_ost_nodsh && skip "remote OST with nodsh" && return
3138         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3139         local fmd_max_age
3140         local fmd_before
3141         local fmd_after
3142
3143         test_mkdir -p $DIR/$tdir
3144         fmd_max_age=$(do_facet ost1 \
3145                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
3146                 head -n 1")
3147
3148         fmd_before=$(do_facet ost1 \
3149                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3150         touch $DIR/$tdir/$tfile
3151         sleep $((fmd_max_age + 12))
3152         fmd_after=$(do_facet ost1 \
3153                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3154
3155         echo "fmd_before: $fmd_before"
3156         echo "fmd_after: $fmd_after"
3157         [[ $fmd_after -gt $fmd_before ]] &&
3158                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
3159                 error "fmd didn't expire after ping" || true
3160 }
3161 run_test 36g "filter mod data cache expiry ====================="
3162
3163 test_36h() {
3164         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3165         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3166         subr_36fh "0x80000227"
3167 }
3168 run_test 36h "utime on file racing with OST BRW write =========="
3169
3170 test_36i() {
3171         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3172
3173         test_mkdir $DIR/$tdir
3174         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3175
3176         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3177         local new_mtime=$((mtime + 200))
3178
3179         #change Modify time of striped dir
3180         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3181                         error "change mtime failed"
3182
3183         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3184
3185         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3186 }
3187 run_test 36i "change mtime on striped directory"
3188
3189 # test_37 - duplicate with tests 32q 32r
3190
3191 test_38() {
3192         local file=$DIR/$tfile
3193         touch $file
3194         openfile -f O_DIRECTORY $file
3195         local RC=$?
3196         local ENOTDIR=20
3197         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3198         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3199 }
3200 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3201
3202 test_39a() { # was test_39
3203         touch $DIR/$tfile
3204         touch $DIR/${tfile}2
3205 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3206 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3207 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3208         sleep 2
3209         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3210         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3211                 echo "mtime"
3212                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3213                 echo "atime"
3214                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3215                 echo "ctime"
3216                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3217                 error "O_TRUNC didn't change timestamps"
3218         fi
3219 }
3220 run_test 39a "mtime changed on create ==========================="
3221
3222 test_39b() {
3223         test_mkdir -p -c1 $DIR/$tdir
3224         cp -p /etc/passwd $DIR/$tdir/fopen
3225         cp -p /etc/passwd $DIR/$tdir/flink
3226         cp -p /etc/passwd $DIR/$tdir/funlink
3227         cp -p /etc/passwd $DIR/$tdir/frename
3228         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3229
3230         sleep 1
3231         echo "aaaaaa" >> $DIR/$tdir/fopen
3232         echo "aaaaaa" >> $DIR/$tdir/flink
3233         echo "aaaaaa" >> $DIR/$tdir/funlink
3234         echo "aaaaaa" >> $DIR/$tdir/frename
3235
3236         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3237         local link_new=`stat -c %Y $DIR/$tdir/flink`
3238         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3239         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3240
3241         cat $DIR/$tdir/fopen > /dev/null
3242         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3243         rm -f $DIR/$tdir/funlink2
3244         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3245
3246         for (( i=0; i < 2; i++ )) ; do
3247                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3248                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3249                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3250                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3251
3252                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3253                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3254                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3255                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3256
3257                 cancel_lru_locks osc
3258                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3259         done
3260 }
3261 run_test 39b "mtime change on open, link, unlink, rename  ======"
3262
3263 # this should be set to past
3264 TEST_39_MTIME=`date -d "1 year ago" +%s`
3265
3266 # bug 11063
3267 test_39c() {
3268         touch $DIR1/$tfile
3269         sleep 2
3270         local mtime0=`stat -c %Y $DIR1/$tfile`
3271
3272         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3273         local mtime1=`stat -c %Y $DIR1/$tfile`
3274         [ "$mtime1" = $TEST_39_MTIME ] || \
3275                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3276
3277         local d1=`date +%s`
3278         echo hello >> $DIR1/$tfile
3279         local d2=`date +%s`
3280         local mtime2=`stat -c %Y $DIR1/$tfile`
3281         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3282                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3283
3284         mv $DIR1/$tfile $DIR1/$tfile-1
3285
3286         for (( i=0; i < 2; i++ )) ; do
3287                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3288                 [ "$mtime2" = "$mtime3" ] || \
3289                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3290
3291                 cancel_lru_locks osc
3292                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3293         done
3294 }
3295 run_test 39c "mtime change on rename ==========================="
3296
3297 # bug 21114
3298 test_39d() {
3299         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3300         touch $DIR1/$tfile
3301
3302         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3303
3304         for (( i=0; i < 2; i++ )) ; do
3305                 local mtime=`stat -c %Y $DIR1/$tfile`
3306                 [ $mtime = $TEST_39_MTIME ] || \
3307                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3308
3309                 cancel_lru_locks osc
3310                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3311         done
3312 }
3313 run_test 39d "create, utime, stat =============================="
3314
3315 # bug 21114
3316 test_39e() {
3317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3318         touch $DIR1/$tfile
3319         local mtime1=`stat -c %Y $DIR1/$tfile`
3320
3321         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3322
3323         for (( i=0; i < 2; i++ )) ; do
3324                 local mtime2=`stat -c %Y $DIR1/$tfile`
3325                 [ $mtime2 = $TEST_39_MTIME ] || \
3326                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3327
3328                 cancel_lru_locks osc
3329                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3330         done
3331 }
3332 run_test 39e "create, stat, utime, stat ========================"
3333
3334 # bug 21114
3335 test_39f() {
3336         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3337         touch $DIR1/$tfile
3338         mtime1=`stat -c %Y $DIR1/$tfile`
3339
3340         sleep 2
3341         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3342
3343         for (( i=0; i < 2; i++ )) ; do
3344                 local mtime2=`stat -c %Y $DIR1/$tfile`
3345                 [ $mtime2 = $TEST_39_MTIME ] || \
3346                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3347
3348                 cancel_lru_locks osc
3349                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3350         done
3351 }
3352 run_test 39f "create, stat, sleep, utime, stat ================="
3353
3354 # bug 11063
3355 test_39g() {
3356         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3357         echo hello >> $DIR1/$tfile
3358         local mtime1=`stat -c %Y $DIR1/$tfile`
3359
3360         sleep 2
3361         chmod o+r $DIR1/$tfile
3362
3363         for (( i=0; i < 2; i++ )) ; do
3364                 local mtime2=`stat -c %Y $DIR1/$tfile`
3365                 [ "$mtime1" = "$mtime2" ] || \
3366                         error "lost mtime: $mtime2, should be $mtime1"
3367
3368                 cancel_lru_locks osc
3369                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3370         done
3371 }
3372 run_test 39g "write, chmod, stat ==============================="
3373
3374 # bug 11063
3375 test_39h() {
3376         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3377         touch $DIR1/$tfile
3378         sleep 1
3379
3380         local d1=`date`
3381         echo hello >> $DIR1/$tfile
3382         local mtime1=`stat -c %Y $DIR1/$tfile`
3383
3384         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3385         local d2=`date`
3386         if [ "$d1" != "$d2" ]; then
3387                 echo "write and touch not within one second"
3388         else
3389                 for (( i=0; i < 2; i++ )) ; do
3390                         local mtime2=`stat -c %Y $DIR1/$tfile`
3391                         [ "$mtime2" = $TEST_39_MTIME ] || \
3392                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3393
3394                         cancel_lru_locks osc
3395                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3396                 done
3397         fi
3398 }
3399 run_test 39h "write, utime within one second, stat ============="
3400
3401 test_39i() {
3402         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3403         touch $DIR1/$tfile
3404         sleep 1
3405
3406         echo hello >> $DIR1/$tfile
3407         local mtime1=`stat -c %Y $DIR1/$tfile`
3408
3409         mv $DIR1/$tfile $DIR1/$tfile-1
3410
3411         for (( i=0; i < 2; i++ )) ; do
3412                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3413
3414                 [ "$mtime1" = "$mtime2" ] || \
3415                         error "lost mtime: $mtime2, should be $mtime1"
3416
3417                 cancel_lru_locks osc
3418                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3419         done
3420 }
3421 run_test 39i "write, rename, stat =============================="
3422
3423 test_39j() {
3424         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3425         start_full_debug_logging
3426         touch $DIR1/$tfile
3427         sleep 1
3428
3429         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3430         lctl set_param fail_loc=0x80000412
3431         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3432                 error "multiop failed"
3433         local multipid=$!
3434         local mtime1=`stat -c %Y $DIR1/$tfile`
3435
3436         mv $DIR1/$tfile $DIR1/$tfile-1
3437
3438         kill -USR1 $multipid
3439         wait $multipid || error "multiop close failed"
3440
3441         for (( i=0; i < 2; i++ )) ; do
3442                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3443                 [ "$mtime1" = "$mtime2" ] ||
3444                         error "mtime is lost on close: $mtime2, " \
3445                               "should be $mtime1"
3446
3447                 cancel_lru_locks osc
3448                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3449         done
3450         lctl set_param fail_loc=0
3451         stop_full_debug_logging
3452 }
3453 run_test 39j "write, rename, close, stat ======================="
3454
3455 test_39k() {
3456         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3457         touch $DIR1/$tfile
3458         sleep 1
3459
3460         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3461         local multipid=$!
3462         local mtime1=`stat -c %Y $DIR1/$tfile`
3463
3464         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3465
3466         kill -USR1 $multipid
3467         wait $multipid || error "multiop close failed"
3468
3469         for (( i=0; i < 2; i++ )) ; do
3470                 local mtime2=`stat -c %Y $DIR1/$tfile`
3471
3472                 [ "$mtime2" = $TEST_39_MTIME ] || \
3473                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3474
3475                 cancel_lru_locks osc
3476                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3477         done
3478 }
3479 run_test 39k "write, utime, close, stat ========================"
3480
3481 # this should be set to future
3482 TEST_39_ATIME=`date -d "1 year" +%s`
3483
3484 test_39l() {
3485         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3486         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3487         local atime_diff=$(do_facet $SINGLEMDS \
3488                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3489         rm -rf $DIR/$tdir
3490         mkdir -p $DIR/$tdir
3491
3492         # test setting directory atime to future
3493         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3494         local atime=$(stat -c %X $DIR/$tdir)
3495         [ "$atime" = $TEST_39_ATIME ] ||
3496                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3497
3498         # test setting directory atime from future to now
3499         local now=$(date +%s)
3500         touch -a -d @$now $DIR/$tdir
3501
3502         atime=$(stat -c %X $DIR/$tdir)
3503         [ "$atime" -eq "$now"  ] ||
3504                 error "atime is not updated from future: $atime, $now"
3505
3506         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3507         sleep 3
3508
3509         # test setting directory atime when now > dir atime + atime_diff
3510         local d1=$(date +%s)
3511         ls $DIR/$tdir
3512         local d2=$(date +%s)
3513         cancel_lru_locks mdc
3514         atime=$(stat -c %X $DIR/$tdir)
3515         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3516                 error "atime is not updated  : $atime, should be $d2"
3517
3518         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3519         sleep 3
3520
3521         # test not setting directory atime when now < dir atime + atime_diff
3522         ls $DIR/$tdir
3523         cancel_lru_locks mdc
3524         atime=$(stat -c %X $DIR/$tdir)
3525         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3526                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3527
3528         do_facet $SINGLEMDS \
3529                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3530 }
3531 run_test 39l "directory atime update ==========================="
3532
3533 test_39m() {
3534         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3535         touch $DIR1/$tfile
3536         sleep 2
3537         local far_past_mtime=$(date -d "May 29 1953" +%s)
3538         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3539
3540         touch -m -d @$far_past_mtime $DIR1/$tfile
3541         touch -a -d @$far_past_atime $DIR1/$tfile
3542
3543         for (( i=0; i < 2; i++ )) ; do
3544                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3545                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3546                         error "atime or mtime set incorrectly"
3547
3548                 cancel_lru_locks osc
3549                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3550         done
3551 }
3552 run_test 39m "test atime and mtime before 1970"
3553
3554 test_39n() { # LU-3832
3555         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3556         local atime_diff=$(do_facet $SINGLEMDS \
3557                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3558         local atime0
3559         local atime1
3560         local atime2
3561
3562         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3563
3564         rm -rf $DIR/$tfile
3565         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3566         atime0=$(stat -c %X $DIR/$tfile)
3567
3568         sleep 5
3569         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3570         atime1=$(stat -c %X $DIR/$tfile)
3571
3572         sleep 5
3573         cancel_lru_locks mdc
3574         cancel_lru_locks osc
3575         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3576         atime2=$(stat -c %X $DIR/$tfile)
3577
3578         do_facet $SINGLEMDS \
3579                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3580
3581         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3582         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3583 }
3584 run_test 39n "check that O_NOATIME is honored"
3585
3586 test_39o() {
3587         TESTDIR=$DIR/$tdir/$tfile
3588         [ -e $TESTDIR ] && rm -rf $TESTDIR
3589         mkdir -p $TESTDIR
3590         cd $TESTDIR
3591         links1=2
3592         ls
3593         mkdir a b
3594         ls
3595         links2=$(stat -c %h .)
3596         [ $(($links1 + 2)) != $links2 ] &&
3597                 error "wrong links count $(($links1 + 2)) != $links2"
3598         rmdir b
3599         links3=$(stat -c %h .)
3600         [ $(($links1 + 1)) != $links3 ] &&
3601                 error "wrong links count $links1 != $links3"
3602         return 0
3603 }
3604 run_test 39o "directory cached attributes updated after create ========"
3605
3606 test_39p() {
3607         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3608         local MDTIDX=1
3609         TESTDIR=$DIR/$tdir/$tfile
3610         [ -e $TESTDIR ] && rm -rf $TESTDIR
3611         test_mkdir -p $TESTDIR
3612         cd $TESTDIR
3613         links1=2
3614         ls
3615         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3616         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3617         ls
3618         links2=$(stat -c %h .)
3619         [ $(($links1 + 2)) != $links2 ] &&
3620                 error "wrong links count $(($links1 + 2)) != $links2"
3621         rmdir remote_dir2
3622         links3=$(stat -c %h .)
3623         [ $(($links1 + 1)) != $links3 ] &&
3624                 error "wrong links count $links1 != $links3"
3625         return 0
3626 }
3627 run_test 39p "remote directory cached attributes updated after create ========"
3628
3629
3630 test_39q() { # LU-8041
3631         local testdir=$DIR/$tdir
3632         mkdir -p $testdir
3633         multiop_bg_pause $testdir D_c || error "multiop failed"
3634         local multipid=$!
3635         cancel_lru_locks mdc
3636         kill -USR1 $multipid
3637         local atime=$(stat -c %X $testdir)
3638         [ "$atime" -ne 0 ] || error "atime is zero"
3639 }
3640 run_test 39q "close won't zero out atime"
3641
3642 test_40() {
3643         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3644         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3645                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3646         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3647                 error "$tfile is not 4096 bytes in size"
3648 }
3649 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3650
3651 test_41() {
3652         # bug 1553
3653         small_write $DIR/f41 18
3654 }
3655 run_test 41 "test small file write + fstat ====================="
3656
3657 count_ost_writes() {
3658         lctl get_param -n osc.*.stats |
3659                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3660                         END { printf("%0.0f", writes) }'
3661 }
3662
3663 # decent default
3664 WRITEBACK_SAVE=500
3665 DIRTY_RATIO_SAVE=40
3666 MAX_DIRTY_RATIO=50
3667 BG_DIRTY_RATIO_SAVE=10
3668 MAX_BG_DIRTY_RATIO=25
3669
3670 start_writeback() {
3671         trap 0
3672         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3673         # dirty_ratio, dirty_background_ratio
3674         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3675                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3676                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3677                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3678         else
3679                 # if file not here, we are a 2.4 kernel
3680                 kill -CONT `pidof kupdated`
3681         fi
3682 }
3683
3684 stop_writeback() {
3685         # setup the trap first, so someone cannot exit the test at the
3686         # exact wrong time and mess up a machine
3687         trap start_writeback EXIT
3688         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3689         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3690                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3691                 sysctl -w vm.dirty_writeback_centisecs=0
3692                 sysctl -w vm.dirty_writeback_centisecs=0
3693                 # save and increase /proc/sys/vm/dirty_ratio
3694                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3695                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3696                 # save and increase /proc/sys/vm/dirty_background_ratio
3697                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3698                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3699         else
3700                 # if file not here, we are a 2.4 kernel
3701                 kill -STOP `pidof kupdated`
3702         fi
3703 }
3704
3705 # ensure that all stripes have some grant before we test client-side cache
3706 setup_test42() {
3707         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3708                 dd if=/dev/zero of=$i bs=4k count=1
3709                 rm $i
3710         done
3711 }
3712
3713 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3714 # file truncation, and file removal.
3715 test_42a() {
3716         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3717         setup_test42
3718         cancel_lru_locks osc
3719         stop_writeback
3720         sync; sleep 1; sync # just to be safe
3721         BEFOREWRITES=`count_ost_writes`
3722         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3723         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3724         AFTERWRITES=`count_ost_writes`
3725         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3726                 error "$BEFOREWRITES < $AFTERWRITES"
3727         start_writeback
3728 }
3729 run_test 42a "ensure that we don't flush on close"
3730
3731 test_42b() {
3732         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3733         setup_test42
3734         cancel_lru_locks osc
3735         stop_writeback
3736         sync
3737         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3738         BEFOREWRITES=$(count_ost_writes)
3739         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3740         AFTERWRITES=$(count_ost_writes)
3741         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3742                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3743         fi
3744         BEFOREWRITES=$(count_ost_writes)
3745         sync || error "sync: $?"
3746         AFTERWRITES=$(count_ost_writes)
3747         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3748                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3749         fi
3750         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3751         start_writeback
3752         return 0
3753 }
3754 run_test 42b "test destroy of file with cached dirty data ======"
3755
3756 # if these tests just want to test the effect of truncation,
3757 # they have to be very careful.  consider:
3758 # - the first open gets a {0,EOF}PR lock
3759 # - the first write conflicts and gets a {0, count-1}PW
3760 # - the rest of the writes are under {count,EOF}PW
3761 # - the open for truncate tries to match a {0,EOF}PR
3762 #   for the filesize and cancels the PWs.
3763 # any number of fixes (don't get {0,EOF} on open, match
3764 # composite locks, do smarter file size management) fix
3765 # this, but for now we want these tests to verify that
3766 # the cancellation with truncate intent works, so we
3767 # start the file with a full-file pw lock to match against
3768 # until the truncate.
3769 trunc_test() {
3770         test=$1
3771         file=$DIR/$test
3772         offset=$2
3773         cancel_lru_locks osc
3774         stop_writeback
3775         # prime the file with 0,EOF PW to match
3776         touch $file
3777         $TRUNCATE $file 0
3778         sync; sync
3779         # now the real test..
3780         dd if=/dev/zero of=$file bs=1024 count=100
3781         BEFOREWRITES=`count_ost_writes`
3782         $TRUNCATE $file $offset
3783         cancel_lru_locks osc
3784         AFTERWRITES=`count_ost_writes`
3785         start_writeback
3786 }
3787
3788 test_42c() {
3789         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3790         trunc_test 42c 1024
3791         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3792             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3793         rm $file
3794 }
3795 run_test 42c "test partial truncate of file with cached dirty data"
3796
3797 test_42d() {
3798         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3799         trunc_test 42d 0
3800         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3801             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3802         rm $file
3803 }
3804 run_test 42d "test complete truncate of file with cached dirty data"
3805
3806 test_42e() { # bug22074
3807         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3808         local TDIR=$DIR/${tdir}e
3809         local pagesz=$(page_size)
3810         local pages=16 # hardcoded 16 pages, don't change it.
3811         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3812         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3813         local max_dirty_mb
3814         local warmup_files
3815
3816         test_mkdir -p $DIR/${tdir}e
3817         $SETSTRIPE -c 1 $TDIR
3818         createmany -o $TDIR/f $files
3819
3820         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3821
3822         # we assume that with $OSTCOUNT files, at least one of them will
3823         # be allocated on OST0.
3824         warmup_files=$((OSTCOUNT * max_dirty_mb))
3825         createmany -o $TDIR/w $warmup_files
3826
3827         # write a large amount of data into one file and sync, to get good
3828         # avail_grant number from OST.
3829         for ((i=0; i<$warmup_files; i++)); do
3830                 idx=$($GETSTRIPE -i $TDIR/w$i)
3831                 [ $idx -ne 0 ] && continue
3832                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3833                 break
3834         done
3835         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3836         sync
3837         $LCTL get_param $proc_osc0/cur_dirty_bytes
3838         $LCTL get_param $proc_osc0/cur_grant_bytes
3839
3840         # create as much dirty pages as we can while not to trigger the actual
3841         # RPCs directly. but depends on the env, VFS may trigger flush during this
3842         # period, hopefully we are good.
3843         for ((i=0; i<$warmup_files; i++)); do
3844                 idx=$($GETSTRIPE -i $TDIR/w$i)
3845                 [ $idx -ne 0 ] && continue
3846                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3847         done
3848         $LCTL get_param $proc_osc0/cur_dirty_bytes
3849         $LCTL get_param $proc_osc0/cur_grant_bytes
3850
3851         # perform the real test
3852         $LCTL set_param $proc_osc0/rpc_stats 0
3853         for ((;i<$files; i++)); do
3854                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3855                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3856         done
3857         sync
3858         $LCTL get_param $proc_osc0/rpc_stats
3859
3860         local percent=0
3861         local have_ppr=false
3862         $LCTL get_param $proc_osc0/rpc_stats |
3863                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3864                         # skip lines until we are at the RPC histogram data
3865                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3866                         $have_ppr || continue
3867
3868                         # we only want the percent stat for < 16 pages
3869                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3870
3871                         percent=$((percent + WPCT))
3872                         if [[ $percent -gt 15 ]]; then
3873                                 error "less than 16-pages write RPCs" \
3874                                       "$percent% > 15%"
3875                                 break
3876                         fi
3877                 done
3878         rm -rf $TDIR
3879 }
3880 run_test 42e "verify sub-RPC writes are not done synchronously"
3881
3882 test_43A() { # was test_43
3883         test_mkdir -p $DIR/$tdir
3884         cp -p /bin/ls $DIR/$tdir/$tfile
3885         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3886         pid=$!
3887         # give multiop a chance to open
3888         sleep 1
3889
3890         $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
3891         kill -USR1 $pid
3892 }
3893 run_test 43A "execution of file opened for write should return -ETXTBSY"
3894
3895 test_43a() {
3896         test_mkdir $DIR/$tdir
3897         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3898                 cp -p multiop $DIR/$tdir/multiop
3899         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3900                 error "multiop open $TMP/$tfile.junk failed"
3901         MULTIOP_PID=$!
3902         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3903         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3904         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3905 }
3906 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3907
3908 test_43b() {
3909         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3910         test_mkdir $DIR/$tdir
3911         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3912                 cp -p multiop $DIR/$tdir/multiop
3913         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3914                 error "multiop open $TMP/$tfile.junk failed"
3915         MULTIOP_PID=$!
3916         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3917         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3918         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3919 }
3920 run_test 43b "truncate of file being executed should return -ETXTBSY"
3921
3922 test_43c() {
3923         local testdir="$DIR/$tdir"
3924         test_mkdir $testdir
3925         cp $SHELL $testdir/
3926         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |
3927                 ( cd $testdir && md5sum -c )
3928 }
3929 run_test 43c "md5sum of copy into lustre"
3930
3931 test_44A() { # was test_44
3932         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
3933         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3934         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3935 }
3936 run_test 44A "zero length read from a sparse stripe"
3937
3938 test_44a() {
3939         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3940                 awk '{ print $2 }')
3941         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3942         [[ $nstripe -gt $OSTCOUNT ]] &&
3943             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3944             return
3945         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3946                 awk '{ print $2 }')
3947         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3948                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3949                         awk '{ print $2 }')
3950         fi
3951
3952         OFFSETS="0 $((stride/2)) $((stride-1))"
3953         for offset in $OFFSETS; do
3954                 for i in $(seq 0 $((nstripe-1))); do
3955                         local GLOBALOFFSETS=""
3956                         # size in Bytes
3957                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3958                         local myfn=$DIR/d44a-$size
3959                         echo "--------writing $myfn at $size"
3960                         ll_sparseness_write $myfn $size ||
3961                                 error "ll_sparseness_write"
3962                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3963                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3964                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3965
3966                         for j in $(seq 0 $((nstripe-1))); do
3967                                 # size in Bytes
3968                                 size=$((((j + $nstripe )*$stride + $offset)))
3969                                 ll_sparseness_write $myfn $size ||
3970                                         error "ll_sparseness_write"
3971                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3972                         done
3973                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3974                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3975                         rm -f $myfn
3976                 done
3977         done
3978 }
3979 run_test 44a "test sparse pwrite ==============================="
3980
3981 dirty_osc_total() {
3982         tot=0
3983         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3984                 tot=$(($tot + $d))
3985         done
3986         echo $tot
3987 }
3988 do_dirty_record() {
3989         before=`dirty_osc_total`
3990         echo executing "\"$*\""
3991         eval $*
3992         after=`dirty_osc_total`
3993         echo before $before, after $after
3994 }
3995 test_45() {
3996         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3997         f="$DIR/f45"
3998         # Obtain grants from OST if it supports it
3999         echo blah > ${f}_grant
4000         stop_writeback
4001         sync
4002         do_dirty_record "echo blah > $f"
4003         [[ $before -eq $after ]] && error "write wasn't cached"
4004         do_dirty_record "> $f"
4005         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
4006         do_dirty_record "echo blah > $f"
4007         [[ $before -eq $after ]] && error "write wasn't cached"
4008         do_dirty_record "sync"
4009         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
4010         do_dirty_record "echo blah > $f"
4011         [[ $before -eq $after ]] && error "write wasn't cached"
4012         do_dirty_record "cancel_lru_locks osc"
4013         [[ $before -gt $after ]] ||
4014                 error "lock cancellation didn't lower dirty count"
4015         start_writeback
4016 }
4017 run_test 45 "osc io page accounting ============================"
4018
4019 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
4020 # test tickles a bug where re-dirtying a page was failing to be mapped to the
4021 # objects offset and an assert hit when an rpc was built with 1023's mapped
4022 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
4023 test_46() {
4024         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4025         f="$DIR/f46"
4026         stop_writeback
4027         sync
4028         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
4029         sync
4030         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
4031         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
4032         sync
4033         start_writeback
4034 }
4035 run_test 46 "dirtying a previously written page ================"
4036
4037 # test_47 is removed "Device nodes check" is moved to test_28
4038
4039 test_48a() { # bug 2399
4040         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
4041         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
4042                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
4043                 return
4044         test_mkdir $DIR/$tdir
4045         cd $DIR/$tdir
4046         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
4047         test_mkdir $DIR/$tdir || error "recreate directory failed"
4048         touch foo || error "'touch foo' failed after recreating cwd"
4049         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
4050         touch .foo || error "'touch .foo' failed after recreating cwd"
4051         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
4052         ls . > /dev/null || error "'ls .' failed after recreating cwd"
4053         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4054         cd . || error "'cd .' failed after recreating cwd"
4055         test_mkdir . && error "'mkdir .' worked after recreating cwd"
4056         rmdir . && error "'rmdir .' worked after recreating cwd"
4057         ln -s . baz || error "'ln -s .' failed after recreating cwd"
4058         cd .. || error "'cd ..' failed after recreating cwd"
4059 }
4060 run_test 48a "Access renamed working dir (should return errors)="
4061
4062 test_48b() { # bug 2399
4063         rm -rf $DIR/$tdir
4064         test_mkdir $DIR/$tdir
4065         cd $DIR/$tdir
4066         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
4067         touch foo && error "'touch foo' worked after removing cwd"
4068         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
4069         touch .foo && error "'touch .foo' worked after removing cwd"
4070         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
4071         ls . > /dev/null && error "'ls .' worked after removing cwd"
4072         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4073         test_mkdir . && error "'mkdir .' worked after removing cwd"
4074         rmdir . && error "'rmdir .' worked after removing cwd"
4075         ln -s . foo && error "'ln -s .' worked after removing cwd"
4076         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
4077 }
4078 run_test 48b "Access removed working dir (should return errors)="
4079
4080 test_48c() { # bug 2350
4081         #lctl set_param debug=-1
4082         #set -vx
4083         rm -rf $DIR/$tdir
4084         test_mkdir -p $DIR/$tdir/dir
4085         cd $DIR/$tdir/dir
4086         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4087         $TRACE touch foo && error "touch foo worked after removing cwd"
4088         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
4089         touch .foo && error "touch .foo worked after removing cwd"
4090         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
4091         $TRACE ls . && error "'ls .' worked after removing cwd"
4092         $TRACE ls .. || error "'ls ..' failed after removing cwd"
4093         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
4094         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
4095         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
4096         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
4097 }
4098 run_test 48c "Access removed working subdir (should return errors)"
4099
4100 test_48d() { # bug 2350
4101         #lctl set_param debug=-1
4102         #set -vx
4103         rm -rf $DIR/$tdir
4104         test_mkdir -p $DIR/$tdir/dir
4105         cd $DIR/$tdir/dir
4106         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4107         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4108         $TRACE touch foo && error "'touch foo' worked after removing parent"
4109         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
4110         touch .foo && error "'touch .foo' worked after removing parent"
4111         test_mkdir .foo && error "mkdir .foo worked after removing parent"
4112         $TRACE ls . && error "'ls .' worked after removing parent"
4113         $TRACE ls .. && error "'ls ..' worked after removing parent"
4114         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
4115         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
4116         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
4117         true
4118 }
4119 run_test 48d "Access removed parent subdir (should return errors)"
4120
4121 test_48e() { # bug 4134
4122         #lctl set_param debug=-1
4123         #set -vx
4124         rm -rf $DIR/$tdir
4125         test_mkdir -p $DIR/$tdir/dir
4126         cd $DIR/$tdir/dir
4127         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4128         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4129         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
4130         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
4131         # On a buggy kernel addition of "touch foo" after cd .. will
4132         # produce kernel oops in lookup_hash_it
4133         touch ../foo && error "'cd ..' worked after recreate parent"
4134         cd $DIR
4135         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
4136 }
4137 run_test 48e "Access to recreated parent subdir (should return errors)"
4138
4139 test_49() { # LU-1030
4140         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4141         remote_ost_nodsh && skip "remote OST with nodsh" && return
4142         # get ost1 size - lustre-OST0000
4143         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
4144                 awk '{ print $4 }')
4145         # write 800M at maximum
4146         [[ $ost1_size -lt 2 ]] && ost1_size=2
4147         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
4148
4149         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
4150         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
4151         local dd_pid=$!
4152
4153         # change max_pages_per_rpc while writing the file
4154         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
4155         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
4156         # loop until dd process exits
4157         while ps ax -opid | grep -wq $dd_pid; do
4158                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
4159                 sleep $((RANDOM % 5 + 1))
4160         done
4161         # restore original max_pages_per_rpc
4162         $LCTL set_param $osc1_mppc=$orig_mppc
4163         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
4164 }
4165 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4166
4167 test_50() {
4168         # bug 1485
4169         test_mkdir $DIR/$tdir
4170         cd $DIR/$tdir
4171         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4172 }
4173 run_test 50 "special situations: /proc symlinks  ==============="
4174
4175 test_51a() {    # was test_51
4176         # bug 1516 - create an empty entry right after ".." then split dir
4177         test_mkdir -c1 $DIR/$tdir
4178         touch $DIR/$tdir/foo
4179         $MCREATE $DIR/$tdir/bar
4180         rm $DIR/$tdir/foo
4181         createmany -m $DIR/$tdir/longfile 201
4182         FNUM=202
4183         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4184                 $MCREATE $DIR/$tdir/longfile$FNUM
4185                 FNUM=$(($FNUM + 1))
4186                 echo -n "+"
4187         done
4188         echo
4189         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4190 }
4191 run_test 51a "special situations: split htree with empty entry =="
4192
4193 cleanup_print_lfs_df () {
4194         trap 0
4195         $LFS df
4196         $LFS df -i
4197 }
4198
4199 test_51b() {
4200         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4201         local dir=$DIR/$tdir
4202
4203         local nrdirs=$((65536 + 100))
4204
4205         # cleanup the directory
4206         rm -fr $dir
4207
4208         test_mkdir -p -c1 $dir
4209
4210         $LFS df
4211         $LFS df -i
4212         local mdtidx=$(printf "%04x" $($LFS getstripe -M $dir))
4213         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4214         [[ $numfree -lt $nrdirs ]] &&
4215                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4216                 return
4217
4218         # need to check free space for the directories as well
4219         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4220         numfree=$(( blkfree / $(fs_inode_ksize) ))
4221         [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)" &&
4222                 return
4223
4224         trap cleanup_print_lfs_df EXIT
4225
4226         # create files
4227         createmany -d $dir/d $nrdirs || {
4228                 unlinkmany $dir/d $nrdirs
4229                 error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
4230         }
4231
4232         # really created :
4233         nrdirs=$(ls -U $dir | wc -l)
4234
4235         # unlink all but 100 subdirectories, then check it still works
4236         local left=100
4237         local delete=$((nrdirs - left))
4238
4239         $LFS df
4240         $LFS df -i
4241
4242         # for ldiskfs the nlink count should be 1, but this is OSD specific
4243         # and so this is listed for informational purposes only
4244         echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
4245         unlinkmany -d $dir/d $delete ||
4246                 error "unlink of first $delete subdirs failed"
4247
4248         echo "nlink between: $(stat -c %h $dir)"
4249         local found=$(ls -U $dir | wc -l)
4250         [ $found -ne $left ] &&
4251                 error "can't find subdirs: found only $found, expected $left"
4252
4253         unlinkmany -d $dir/d $delete $left ||
4254                 error "unlink of second $left subdirs failed"
4255         # regardless of whether the backing filesystem tracks nlink accurately
4256         # or not, the nlink count shouldn't be more than "." and ".." here
4257         local after=$(stat -c %h $dir)
4258         [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
4259                 echo "nlink after: $after"
4260
4261         cleanup_print_lfs_df
4262 }
4263 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
4264
4265 test_51d() {
4266         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4267         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
4268         test_mkdir -p $DIR/$tdir
4269         createmany -o $DIR/$tdir/t- 1000
4270         $GETSTRIPE $DIR/$tdir > $TMP/$tfile
4271         for N in $(seq 0 $((OSTCOUNT - 1))); do
4272                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4273                         END { printf("%0.0f", objs) }' $TMP/$tfile)
4274                 OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
4275                         '($1 == '$N') { objs += 1 } \
4276                         END { printf("%0.0f", objs) }')
4277                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4278         done
4279         unlinkmany $DIR/$tdir/t- 1000
4280
4281         NLAST=0
4282         for N in $(seq 1 $((OSTCOUNT - 1))); do
4283                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4284                         error "OST $N has less objects vs OST $NLAST" \
4285                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4286                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4287                         error "OST $N has less objects vs OST $NLAST" \
4288                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4289
4290                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4291                         error "OST $N has less #0 objects vs OST $NLAST" \
4292                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4293                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4294                         error "OST $N has less #0 objects vs OST $NLAST" \
4295                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4296                 NLAST=$N
4297         done
4298         rm -f $TMP/$tfile
4299 }
4300 run_test 51d "check object distribution"
4301
4302 test_51e() {
4303         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4304                 skip "ldiskfs only test"
4305                 return
4306         fi
4307
4308         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4309         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4310
4311         touch $DIR/$tdir/d0/foo
4312         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4313                 error "file exceed 65000 nlink limit!"
4314         unlinkmany $DIR/$tdir/d0/f- 65001
4315         return 0
4316 }
4317 run_test 51e "check file nlink limit"
4318
4319 test_51f() {
4320         test_mkdir $DIR/$tdir
4321
4322         local max=100000
4323         local ulimit_old=$(ulimit -n)
4324         local spare=20 # number of spare fd's for scripts/libraries, etc.
4325         local mdt=$(lfs getstripe -M $DIR/$tdir)
4326         local numfree=$(lfs df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
4327
4328         echo "MDT$mdt numfree=$numfree, max=$max"
4329         [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
4330         if [ $((numfree + spare)) -gt $ulimit_old ]; then
4331                 while ! ulimit -n $((numfree + spare)); do
4332                         numfree=$((numfree * 3 / 4))
4333                 done
4334                 echo "changed ulimit from $ulimit_old to $((numfree + spare))"
4335         else
4336                 echo "left ulimit at $ulimit_old"
4337         fi
4338
4339         createmany -o -k -t 120 $DIR/$tdir/f $numfree || {
4340                 unlinkmany $DIR/$tdir/f $numfree
4341                 error "create+open $numfree files in $DIR/$tdir failed"
4342         }
4343         ulimit -n $ulimit_old
4344
4345         # if createmany exits at 120s there will be fewer than $numfree files
4346         unlinkmany $DIR/$tdir/f $numfree || true
4347 }
4348 run_test 51f "check many open files limit"
4349
4350 test_52a() {
4351         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4352         test_mkdir -p $DIR/$tdir
4353         touch $DIR/$tdir/foo
4354         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4355         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4356         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4357         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4358         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4359                                         error "link worked"
4360         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4361         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4362         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4363                                                      error "lsattr"
4364         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4365         cp -r $DIR/$tdir $TMP/
4366         rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
4367 }
4368 run_test 52a "append-only flag test (should return errors)"
4369
4370 test_52b() {
4371         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4372         test_mkdir -p $DIR/$tdir
4373         touch $DIR/$tdir/foo
4374         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4375         cat test > $DIR/$tdir/foo && error "cat test worked"
4376         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4377         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4378         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4379                                         error "link worked"
4380         echo foo >> $DIR/$tdir/foo && error "echo worked"
4381         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4382         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4383         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4384         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4385                                                         error "lsattr"
4386         chattr -i $DIR/$tdir/foo || error "chattr failed"
4387
4388         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4389 }
4390 run_test 52b "immutable flag test (should return errors) ======="
4391
4392 test_53() {
4393         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4394         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4395         remote_ost_nodsh && skip "remote OST with nodsh" && return
4396
4397         local param
4398         local param_seq
4399         local ostname
4400         local mds_last
4401         local mds_last_seq
4402         local ost_last
4403         local ost_last_seq
4404         local ost_last_id
4405         local ostnum
4406         local node
4407         local found=false
4408         local support_last_seq=true
4409
4410         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4411                 support_last_seq=false
4412
4413         # only test MDT0000
4414         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4415         local value
4416         for value in $(do_facet $SINGLEMDS \
4417                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4418                 param=$(echo ${value[0]} | cut -d "=" -f1)
4419                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4420
4421                 if $support_last_seq; then
4422                         param_seq=$(echo $param |
4423                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4424                         mds_last_seq=$(do_facet $SINGLEMDS \
4425                                        $LCTL get_param -n $param_seq)
4426                 fi
4427                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4428
4429                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4430                 node=$(facet_active_host ost$((ostnum+1)))
4431                 param="obdfilter.$ostname.last_id"
4432                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4433                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4434                         ost_last_id=$ost_last
4435
4436                         if $support_last_seq; then
4437                                 ost_last_id=$(echo $ost_last |
4438                                               awk -F':' '{print $2}' |
4439                                               sed -e "s/^0x//g")
4440                                 ost_last_seq=$(echo $ost_last |
4441                                                awk -F':' '{print $1}')
4442                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4443                         fi
4444
4445                         if [[ $ost_last_id != $mds_last ]]; then
4446                                 error "$ost_last_id != $mds_last"
4447                         else
4448                                 found=true
4449                                 break
4450                         fi
4451                 done
4452         done
4453         $found || error "can not match last_seq/last_id for $mdtosc"
4454         return 0
4455 }
4456 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4457
4458 test_54a() {
4459         perl -MSocket -e ';' || { skip "no Socket perl module installed" && return; }
4460
4461         $SOCKETSERVER $DIR/socket ||
4462                 error "$SOCKETSERVER $DIR/socket failed: $?"
4463         $SOCKETCLIENT $DIR/socket ||
4464                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4465         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4466 }
4467 run_test 54a "unix domain socket test =========================="
4468
4469 test_54b() {
4470         f="$DIR/f54b"
4471         mknod $f c 1 3
4472         chmod 0666 $f
4473         dd if=/dev/zero of=$f bs=$(page_size) count=1
4474 }
4475 run_test 54b "char device works in lustre ======================"
4476
4477 find_loop_dev() {
4478         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4479         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4480         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4481
4482         for i in $(seq 3 7); do
4483                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4484                 LOOPDEV=$LOOPBASE$i
4485                 LOOPNUM=$i
4486                 break
4487         done
4488 }
4489
4490 cleanup_54c() {
4491         local rc=0
4492         loopdev="$DIR/loop54c"
4493
4494         trap 0
4495         $UMOUNT $DIR/$tdir || rc=$?
4496         losetup -d $loopdev || true
4497         losetup -d $LOOPDEV || true
4498         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4499         return $rc
4500 }
4501
4502 test_54c() {
4503         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4504         loopdev="$DIR/loop54c"
4505
4506         find_loop_dev
4507         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4508         trap cleanup_54c EXIT
4509         mknod $loopdev b 7 $LOOPNUM
4510         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4511         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4512         losetup $loopdev $DIR/$tfile ||
4513                 error "can't set up $loopdev for $DIR/$tfile"
4514         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4515         test_mkdir -p $DIR/$tdir
4516         mount -t ext2 $loopdev $DIR/$tdir ||
4517                 error "error mounting $loopdev on $DIR/$tdir"
4518         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4519                 error "dd write"
4520         df $DIR/$tdir
4521         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4522                 error "dd read"
4523         cleanup_54c
4524 }
4525 run_test 54c "block device works in lustre ====================="
4526
4527 test_54d() {
4528         f="$DIR/f54d"
4529         string="aaaaaa"
4530         mknod $f p
4531         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4532 }
4533 run_test 54d "fifo device works in lustre ======================"
4534
4535 test_54e() {
4536         f="$DIR/f54e"
4537         string="aaaaaa"
4538         cp -aL /dev/console $f
4539         echo $string > $f || error "echo $string to $f failed"
4540 }
4541 run_test 54e "console/tty device works in lustre ======================"
4542
4543 #The test_55 used to be iopen test and it was removed by bz#24037.
4544 #run_test 55 "check iopen_connect_dentry() ======================"
4545
4546 test_56a() {    # was test_56
4547         rm -rf $DIR/$tdir
4548         $SETSTRIPE -d $DIR
4549         test_mkdir -p $DIR/$tdir/dir
4550         NUMFILES=3
4551         NUMFILESx2=$(($NUMFILES * 2))
4552         for i in $(seq 1 $NUMFILES); do
4553                 touch $DIR/$tdir/file$i
4554                 touch $DIR/$tdir/dir/file$i
4555         done
4556
4557         # test lfs getstripe with --recursive
4558         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4559         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4560                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4561         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4562         [[ $FILENUM -eq $NUMFILES ]] ||
4563                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4564         echo "$GETSTRIPE --recursive passed."
4565
4566         # test lfs getstripe with file instead of dir
4567         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4568         [[ $FILENUM -eq 1 ]] ||
4569                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4570         echo "$GETSTRIPE file1 passed."
4571
4572         #test lfs getstripe with --verbose
4573         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4574                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4575                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4576         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4577                 error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4578
4579         #test lfs getstripe with -v prints lmm_fid
4580         [[ $($GETSTRIPE -v $DIR/$tdir | grep -c lmm_fid) -eq $NUMFILES ]] ||
4581                 error "$GETSTRIPE -v $DIR/$tdir: want $NUMFILES lmm_fid: lines"
4582         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_fid) -eq 0 ]] ||
4583                 error "$GETSTRIPE $DIR/$tdir: showed lmm_fid"
4584         echo "$GETSTRIPE --verbose passed."
4585
4586         #check for FID information
4587         local fid1=$($GETSTRIPE --fid $DIR/$tdir/file1)
4588         local fid2=$($GETSTRIPE --verbose $DIR/$tdir/file1 |
4589                        awk '/lmm_fid: / { print $2 }')
4590         local fid3=$($LFS path2fid $DIR/$tdir/file1)
4591         [ "$fid1" != "$fid2" ] &&
4592                 error "getstripe --fid $fid1 != getstripe --verbose $fid2"
4593         [ "$fid1" != "$fid3" ] &&
4594                 error "getstripe --fid $fid1 != lfs path2fid $fid3"
4595         echo "$GETSTRIPE --fid passed."
4596
4597         #test lfs getstripe with --obd
4598         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4599                 grep -q "unknown obduuid" ||
4600                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4601
4602         [[ $OSTCOUNT -lt 2 ]] &&
4603                 skip_env "skipping other $GETSTRIPE --obd test" && return
4604
4605         OSTIDX=1
4606         OBDUUID=$(ostuuid_from_index $OSTIDX)
4607         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4608         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4609         [[ $FOUND -eq $FILENUM ]] ||
4610                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4611         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4612                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4613                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4614                 error "$GETSTRIPE --obd: should not show file on other obd"
4615         echo "$GETSTRIPE --obd passed"
4616 }
4617 run_test 56a "check $GETSTRIPE"
4618
4619 test_56b() {
4620         test_mkdir $DIR/$tdir
4621         NUMDIRS=3
4622         for i in $(seq 1 $NUMDIRS); do
4623                 test_mkdir $DIR/$tdir/dir$i
4624         done
4625
4626         # test lfs getdirstripe default mode is non-recursion, which is
4627         # different from lfs getstripe
4628         dircnt=$($LFS getdirstripe $DIR/$tdir | grep -c lmv_stripe_count)
4629         [[ $dircnt -eq 1 ]] ||
4630                 error "$LFS getdirstripe: found $dircnt, not 1"
4631         dircnt=$($LFS getdirstripe --recursive $DIR/$tdir |
4632                 grep -c lmv_stripe_count)
4633         [[ $dircnt -eq $((NUMDIRS + 1)) ]] ||
4634                 error "$LFS getdirstripe --recursive: found $dircnt, \
4635                         not $((NUMDIRS + 1))"
4636 }
4637 run_test 56b "check $LFS getdirstripe"
4638
4639 test_56c() {
4640         local ost_idx=0
4641         local ost_name=$(ostname_from_index $ost_idx)
4642
4643         local old_status=$(ost_dev_status $ost_idx)
4644         [[ -z "$old_status" ]] ||
4645                 { skip_env "OST $ost_name is in $old_status status"; return 0; }
4646
4647         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
4648         sleep_maxage
4649
4650         local new_status=$(ost_dev_status $ost_idx)
4651         [[ "$new_status" = "D" ]] ||
4652                 error "OST $ost_name is in status of '$new_status', not 'D'"
4653
4654         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
4655         sleep_maxage
4656
4657         new_status=$(ost_dev_status $ost_idx)
4658         [[ -z "$new_status" ]] ||
4659                 error "OST $ost_name is in status of '$new_status', not ''"
4660 }
4661 run_test 56c "check 'lfs df' showing device status"
4662
4663 NUMFILES=3
4664 NUMDIRS=3
4665 setup_56() {
4666         local LOCAL_NUMFILES="$1"
4667         local LOCAL_NUMDIRS="$2"
4668         local MKDIR_PARAMS="$3"
4669         local DIR_STRIPE_PARAMS="$4"
4670
4671         if [ ! -d "$TDIR" ] ; then
4672                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4673                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4674                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4675                         touch $TDIR/file$i
4676                 done
4677                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4678                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4679                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4680                                 touch $TDIR/dir$i/file$j
4681                         done
4682                 done
4683         fi
4684 }
4685
4686 setup_56_special() {
4687         LOCAL_NUMFILES=$1
4688         LOCAL_NUMDIRS=$2
4689         setup_56 $1 $2
4690         if [ ! -e "$TDIR/loop1b" ] ; then
4691                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4692                         mknod $TDIR/loop${i}b b 7 $i
4693                         mknod $TDIR/null${i}c c 1 3
4694                         ln -s $TDIR/file1 $TDIR/link${i}l
4695                 done
4696                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4697                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4698                         mknod $TDIR/dir$i/null${i}c c 1 3
4699                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4700                 done
4701         fi
4702 }
4703
4704 test_56g() {
4705         $SETSTRIPE -d $DIR
4706
4707         TDIR=$DIR/${tdir}g
4708         setup_56 $NUMFILES $NUMDIRS
4709
4710         EXPECTED=$(($NUMDIRS + 2))
4711         # test lfs find with -name
4712         for i in $(seq 1 $NUMFILES) ; do
4713                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4714                 [ $NUMS -eq $EXPECTED ] ||
4715                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4716                               "found $NUMS, expected $EXPECTED"
4717         done
4718 }
4719 run_test 56g "check lfs find -name ============================="
4720
4721 test_56h() {
4722         $SETSTRIPE -d $DIR
4723
4724         TDIR=$DIR/${tdir}g
4725         setup_56 $NUMFILES $NUMDIRS
4726
4727         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4728         # test lfs find with ! -name
4729         for i in $(seq 1 $NUMFILES) ; do
4730                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4731                 [ $NUMS -eq $EXPECTED ] ||
4732                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4733                               "found $NUMS, expected $EXPECTED"
4734         done
4735 }
4736 run_test 56h "check lfs find ! -name ============================="
4737
4738 test_56i() {
4739        tdir=${tdir}i
4740        test_mkdir -p $DIR/$tdir
4741        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4742        CMD="$LFIND -ost $UUID $DIR/$tdir"
4743        OUT=$($CMD)
4744        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4745 }
4746 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4747
4748 test_56j() {
4749         TDIR=$DIR/${tdir}g
4750         setup_56_special $NUMFILES $NUMDIRS
4751
4752         EXPECTED=$((NUMDIRS + 1))
4753         CMD="$LFIND -type d $TDIR"
4754         NUMS=$($CMD | wc -l)
4755         [ $NUMS -eq $EXPECTED ] ||
4756                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4757 }
4758 run_test 56j "check lfs find -type d ============================="
4759
4760 test_56k() {
4761         TDIR=$DIR/${tdir}g
4762         setup_56_special $NUMFILES $NUMDIRS
4763
4764         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4765         CMD="$LFIND -type f $TDIR"
4766         NUMS=$($CMD | wc -l)
4767         [ $NUMS -eq $EXPECTED ] ||
4768                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4769 }
4770 run_test 56k "check lfs find -type f ============================="
4771
4772 test_56l() {
4773         TDIR=$DIR/${tdir}g
4774         setup_56_special $NUMFILES $NUMDIRS
4775
4776         EXPECTED=$((NUMDIRS + NUMFILES))
4777         CMD="$LFIND -type b $TDIR"
4778         NUMS=$($CMD | wc -l)
4779         [ $NUMS -eq $EXPECTED ] ||
4780                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4781 }
4782 run_test 56l "check lfs find -type b ============================="
4783
4784 test_56m() {
4785         TDIR=$DIR/${tdir}g
4786         setup_56_special $NUMFILES $NUMDIRS
4787
4788         EXPECTED=$((NUMDIRS + NUMFILES))
4789         CMD="$LFIND -type c $TDIR"
4790         NUMS=$($CMD | wc -l)
4791         [ $NUMS -eq $EXPECTED ] ||
4792                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4793 }
4794 run_test 56m "check lfs find -type c ============================="
4795
4796 test_56n() {
4797         TDIR=$DIR/${tdir}g
4798         setup_56_special $NUMFILES $NUMDIRS
4799
4800         EXPECTED=$((NUMDIRS + NUMFILES))
4801         CMD="$LFIND -type l $TDIR"
4802         NUMS=$($CMD | wc -l)
4803         [ $NUMS -eq $EXPECTED ] ||
4804                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4805 }
4806 run_test 56n "check lfs find -type l ============================="
4807
4808 test_56o() {
4809         TDIR=$DIR/${tdir}o
4810         setup_56 $NUMFILES $NUMDIRS
4811         utime $TDIR/file1 > /dev/null || error "utime (1)"
4812         utime $TDIR/file2 > /dev/null || error "utime (2)"
4813         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4814         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4815         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4816         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4817
4818         EXPECTED=4
4819         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4820         [ $NUMS -eq $EXPECTED ] || \
4821                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4822
4823         EXPECTED=12
4824         CMD="$LFIND -mtime 0 $TDIR"
4825         NUMS=$($CMD | wc -l)
4826         [ $NUMS -eq $EXPECTED ] ||
4827                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4828 }
4829 run_test 56o "check lfs find -mtime for old files =========================="
4830
4831 test_56p() {
4832         [ $RUNAS_ID -eq $UID ] &&
4833                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4834
4835         TDIR=$DIR/${tdir}p
4836         setup_56 $NUMFILES $NUMDIRS
4837
4838         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4839         EXPECTED=$NUMFILES
4840         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4841         NUMS=$($CMD | wc -l)
4842         [ $NUMS -eq $EXPECTED ] || \
4843                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4844
4845         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4846         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4847         NUMS=$($CMD | wc -l)
4848         [ $NUMS -eq $EXPECTED ] || \
4849                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4850 }
4851 run_test 56p "check lfs find -uid and ! -uid ==============================="
4852
4853 test_56q() {
4854         [ $RUNAS_ID -eq $UID ] &&
4855                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4856
4857         TDIR=$DIR/${tdir}q
4858         setup_56 $NUMFILES $NUMDIRS
4859
4860         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4861
4862         EXPECTED=$NUMFILES
4863         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4864         NUMS=$($CMD | wc -l)
4865         [ $NUMS -eq $EXPECTED ] ||
4866                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4867
4868         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4869         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4870         NUMS=$($CMD | wc -l)
4871         [ $NUMS -eq $EXPECTED ] ||
4872                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4873 }
4874 run_test 56q "check lfs find -gid and ! -gid ==============================="
4875
4876 test_56r() {
4877         TDIR=$DIR/${tdir}r
4878         setup_56 $NUMFILES $NUMDIRS
4879
4880         EXPECTED=12
4881         CMD="$LFIND -size 0 -type f $TDIR"
4882         NUMS=$($CMD | wc -l)
4883         [ $NUMS -eq $EXPECTED ] ||
4884                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4885         EXPECTED=0
4886         CMD="$LFIND ! -size 0 -type f $TDIR"
4887         NUMS=$($CMD | wc -l)
4888         [ $NUMS -eq $EXPECTED ] ||
4889                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4890         echo "test" > $TDIR/$tfile
4891         echo "test2" > $TDIR/$tfile.2 && sync
4892         EXPECTED=1
4893         CMD="$LFIND -size 5 -type f $TDIR"
4894         NUMS=$($CMD | wc -l)
4895         [ $NUMS -eq $EXPECTED ] ||
4896                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4897         EXPECTED=1
4898         CMD="$LFIND -size +5 -type f $TDIR"
4899         NUMS=$($CMD | wc -l)
4900         [ $NUMS -eq $EXPECTED ] ||
4901                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4902         EXPECTED=2
4903         CMD="$LFIND -size +0 -type f $TDIR"
4904         NUMS=$($CMD | wc -l)
4905         [ $NUMS -eq $EXPECTED ] ||
4906                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4907         EXPECTED=2
4908         CMD="$LFIND ! -size -5 -type f $TDIR"
4909         NUMS=$($CMD | wc -l)
4910         [ $NUMS -eq $EXPECTED ] ||
4911                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4912         EXPECTED=12
4913         CMD="$LFIND -size -5 -type f $TDIR"
4914         NUMS=$($CMD | wc -l)
4915         [ $NUMS -eq $EXPECTED ] ||
4916                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4917 }
4918 run_test 56r "check lfs find -size works =========================="
4919
4920 test_56s() { # LU-611
4921         TDIR=$DIR/${tdir}s
4922
4923         #LU-9369
4924         setup_56 0 $NUMDIRS
4925         for i in $(seq 1 $NUMDIRS); do
4926                 $SETSTRIPE -c $((OSTCOUNT + 1)) $TDIR/dir$i/$tfile
4927         done
4928         EXPECTED=$NUMDIRS
4929         CMD="$LFIND -c $OSTCOUNT $TDIR"
4930         NUMS=$($CMD | wc -l)
4931         [ $NUMS -eq $EXPECTED ] || {
4932                 $GETSTRIPE -R $TDIR
4933                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4934         }
4935         rm -rf $TDIR
4936
4937         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4938         if [[ $OSTCOUNT -gt 1 ]]; then
4939                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4940                 ONESTRIPE=4
4941                 EXTRA=4
4942         else
4943                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4944                 EXTRA=0
4945         fi
4946
4947         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4948         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4949         NUMS=$($CMD | wc -l)
4950         [ $NUMS -eq $EXPECTED ] || {
4951                 $GETSTRIPE -R $TDIR
4952                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4953         }
4954
4955         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4956         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4957         NUMS=$($CMD | wc -l)
4958         [ $NUMS -eq $EXPECTED ] || {
4959                 $GETSTRIPE -R $TDIR
4960                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4961         }
4962
4963         EXPECTED=$ONESTRIPE
4964         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4965         NUMS=$($CMD | wc -l)
4966         [ $NUMS -eq $EXPECTED ] || {
4967                 $GETSTRIPE -R $TDIR
4968                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4969         }
4970
4971         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4972         NUMS=$($CMD | wc -l)
4973         [ $NUMS -eq $EXPECTED ] || {
4974                 $GETSTRIPE -R $TDIR
4975                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4976         }
4977
4978         EXPECTED=0
4979         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4980         NUMS=$($CMD | wc -l)
4981         [ $NUMS -eq $EXPECTED ] || {
4982                 $GETSTRIPE -R $TDIR
4983                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4984         }
4985 }
4986 run_test 56s "check lfs find -stripe-count works"
4987
4988 test_56t() { # LU-611
4989         TDIR=$DIR/${tdir}t
4990
4991         #LU-9369
4992         setup_56 0 $NUMDIRS
4993         for i in $(seq 1 $NUMDIRS); do
4994                 $SETSTRIPE -S 4M $TDIR/dir$i/$tfile
4995         done
4996         EXPECTED=$NUMDIRS
4997         CMD="$LFIND -S 4M $TDIR"
4998         NUMS=$($CMD | wc -l)
4999         [ $NUMS -eq $EXPECTED ] || {
5000                 $GETSTRIPE -R $TDIR
5001                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5002         }
5003         rm -rf $TDIR
5004
5005         setup_56 $NUMFILES $NUMDIRS "--stripe-size 512k"
5006
5007         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
5008
5009         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
5010         CMD="$LFIND -stripe-size 512k -type f $TDIR"
5011         NUMS=$($CMD | wc -l)
5012         [ $NUMS -eq $EXPECTED ] ||
5013                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5014
5015         CMD="$LFIND -stripe-size +320k -type f $TDIR"
5016         NUMS=$($CMD | wc -l)
5017         [ $NUMS -eq $EXPECTED ] ||
5018                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5019
5020         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
5021         CMD="$LFIND -stripe-size +200k -type f $TDIR"
5022         NUMS=$($CMD | wc -l)
5023         [ $NUMS -eq $EXPECTED ] ||
5024                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5025
5026         CMD="$LFIND -stripe-size -640k -type f $TDIR"
5027         NUMS=$($CMD | wc -l)
5028         [ $NUMS -eq $EXPECTED ] ||
5029                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5030
5031         EXPECTED=4
5032         CMD="$LFIND -stripe-size 256k -type f $TDIR"
5033         NUMS=$($CMD | wc -l)
5034         [ $NUMS -eq $EXPECTED ] ||
5035                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5036
5037         CMD="$LFIND -stripe-size -320k -type f $TDIR"
5038         NUMS=$($CMD | wc -l)
5039         [ $NUMS -eq $EXPECTED ] ||
5040                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5041
5042         EXPECTED=0
5043         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
5044         NUMS=$($CMD | wc -l)
5045         [ $NUMS -eq $EXPECTED ] ||
5046                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5047 }
5048 run_test 56t "check lfs find -stripe-size works"
5049
5050 test_56u() { # LU-611
5051         TDIR=$DIR/${tdir}u
5052         setup_56 $NUMFILES $NUMDIRS "-i 0"
5053
5054         if [[ $OSTCOUNT -gt 1 ]]; then
5055                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
5056                 ONESTRIPE=4
5057         else
5058                 ONESTRIPE=0
5059         fi
5060
5061         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
5062         CMD="$LFIND -stripe-index 0 -type f $TDIR"
5063         NUMS=$($CMD | wc -l)
5064         [ $NUMS -eq $EXPECTED ] ||
5065                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5066
5067         EXPECTED=$ONESTRIPE
5068         CMD="$LFIND -stripe-index 1 -type f $TDIR"
5069         NUMS=$($CMD | wc -l)
5070         [ $NUMS -eq $EXPECTED ] ||
5071                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5072
5073         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
5074         NUMS=$($CMD | wc -l)
5075         [ $NUMS -eq $EXPECTED ] ||
5076                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5077
5078         EXPECTED=0
5079         # This should produce an error and not return any files
5080         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
5081         NUMS=$($CMD 2>/dev/null | wc -l)
5082         [ $NUMS -eq $EXPECTED ] ||
5083                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5084
5085         if [[ $OSTCOUNT -gt 1 ]]; then
5086                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
5087                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
5088                 NUMS=$($CMD | wc -l)
5089                 [ $NUMS -eq $EXPECTED ] ||
5090                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5091         fi
5092 }
5093 run_test 56u "check lfs find -stripe-index works"
5094
5095 test_56v() {
5096     local MDT_IDX=0
5097
5098     TDIR=$DIR/${tdir}v
5099     rm -rf $TDIR
5100     setup_56 $NUMFILES $NUMDIRS
5101
5102     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
5103     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
5104
5105     for file in $($LFIND -mdt $UUID $TDIR); do
5106         file_mdt_idx=$($GETSTRIPE -M $file)
5107         [ $file_mdt_idx -eq $MDT_IDX ] ||
5108             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
5109     done
5110 }
5111 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
5112
5113 test_56w() {
5114         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5115         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5116         TDIR=$DIR/${tdir}w
5117
5118         rm -rf $TDIR || error "remove $TDIR failed"
5119         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
5120
5121         local stripe_size
5122         stripe_size=$($GETSTRIPE -S -d $TDIR) ||
5123                 error "$GETSTRIPE -S -d $TDIR failed"
5124         stripe_size=${stripe_size%% *}
5125
5126         local file_size=$((stripe_size * OSTCOUNT))
5127         local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
5128         local required_space=$((file_num * file_size))
5129
5130         local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
5131                            head -n1)
5132         [[ $free_space -le $((required_space / 1024)) ]] &&
5133                 skip_env "need $required_space bytes, have $free_space KB" &&
5134                 return
5135
5136         local dd_bs=65536
5137         local dd_count=$((file_size / dd_bs))
5138
5139         # write data into the files
5140         local i
5141         local j
5142         local file
5143         for i in $(seq 1 $NUMFILES); do
5144                 file=$TDIR/file$i
5145                 yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5146                         error "write data into $file failed"
5147         done
5148         for i in $(seq 1 $NUMDIRS); do
5149                 for j in $(seq 1 $NUMFILES); do
5150                         file=$TDIR/dir$i/file$j
5151                         yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5152                                 error "write data into $file failed"
5153                 done
5154         done
5155
5156         # $LFS_MIGRATE will fail if hard link migration is unsupported
5157         if [[ $(lustre_version_code mds1) -gt $(version_code 2.5.55) ]]; then
5158                 createmany -l$TDIR/dir1/file1 $TDIR/dir1/link 200 ||
5159                         error "creating links to $TDIR/dir1/file1 failed"
5160         fi
5161
5162         local expected=-1
5163         [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
5164
5165         # lfs_migrate file
5166         local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
5167         echo "$cmd"
5168         eval $cmd || error "$cmd failed"
5169
5170         check_stripe_count $TDIR/file1 $expected
5171
5172         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
5173         then
5174                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
5175                 # OST 1 if it is on OST 0. This file is small enough to
5176                 # be on only one stripe.
5177                 file=$TDIR/migr_1_ost
5178                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
5179                         error "write data into $file failed"
5180                 local obdidx=$($LFS getstripe -i $file)
5181                 local oldmd5=$(md5sum $file)
5182                 local newobdidx=0
5183                 [[ $obdidx -eq 0 ]] && newobdidx=1
5184                 cmd="$LFS migrate -i $newobdidx $file"
5185                 echo $cmd
5186                 eval $cmd || error "$cmd failed"
5187                 local realobdix=$($LFS getstripe -i $file)
5188                 local newmd5=$(md5sum $file)
5189                 [[ $newobdidx -ne $realobdix ]] &&
5190                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
5191                 [[ "$oldmd5" != "$newmd5" ]] &&
5192                         error "md5sum differ: $oldmd5, $newmd5"
5193         fi
5194
5195     # lfs_migrate dir
5196     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
5197     echo "$cmd"
5198     eval $cmd || error "$cmd failed"
5199
5200     for j in $(seq 1 $NUMFILES); do
5201         check_stripe_count $TDIR/dir1/file$j $expected
5202     done
5203
5204     # lfs_migrate works with lfs find
5205     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
5206          $LFS_MIGRATE -y -c $expected"
5207     echo "$cmd"
5208     eval $cmd || error "$cmd failed"
5209
5210     for i in $(seq 2 $NUMFILES); do
5211         check_stripe_count $TDIR/file$i $expected
5212     done
5213     for i in $(seq 2 $NUMDIRS); do
5214         for j in $(seq 1 $NUMFILES); do
5215             check_stripe_count $TDIR/dir$i/file$j $expected
5216         done
5217     done
5218 }
5219 run_test 56w "check lfs_migrate -c stripe_count works"
5220
5221 test_56x() {
5222         check_swap_layouts_support && return 0
5223         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5224
5225         local dir0=$DIR/$tdir
5226         local ref1=/etc/passwd
5227         local file1=$dir0/file1
5228
5229         test_mkdir $dir0 || error "creating dir $dir0"
5230         $LFS setstripe -c 2 $file1
5231         cp $ref1 $file1
5232         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
5233         stripe=$($LFS getstripe -c $file1)
5234         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5235         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5236
5237         # clean up
5238         rm -f $file1
5239 }
5240 run_test 56x "lfs migration support"
5241
5242 test_56xa() {
5243         check_swap_layouts_support && return 0
5244         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5245
5246         local dir0=$DIR/$tdir/$testnum
5247         test_mkdir -p $dir0 || error "creating dir $dir0"
5248
5249         local ref1=/etc/passwd
5250         local file1=$dir0/file1
5251
5252         $LFS setstripe -c 2 $file1
5253         cp $ref1 $file1
5254         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
5255         local stripe=$($LFS getstripe -c $file1)
5256         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5257         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5258
5259         # clean up
5260         rm -f $file1
5261 }
5262 run_test 56xa "lfs migration --block support"
5263
5264 check_migrate_links() {
5265         local dir="$1"
5266         local file1="$dir/file1"
5267         local begin="$2"
5268         local count="$3"
5269         local total_count=$(($begin + $count - 1))
5270         local symlink_count=10
5271         local uniq_count=10
5272
5273         if [ ! -f "$file1" ]; then
5274                 echo -n "creating initial file..."
5275                 $LFS setstripe -c 1 -S "512k" "$file1" ||
5276                         error "cannot setstripe initial file"
5277                 echo "done"
5278
5279                 echo -n "creating symlinks..."
5280                 for s in $(seq 1 $symlink_count); do
5281                         ln -s "$file1" "$dir/slink$s" ||
5282                                 error "cannot create symlinks"
5283                 done
5284                 echo "done"
5285
5286                 echo -n "creating nonlinked files..."
5287                 createmany -o "$dir/uniq" 1 10 &> /dev/null ||
5288                         error "cannot create nonlinked files"
5289                 echo "done"
5290         fi
5291
5292         # create hard links
5293         if [ ! -f "$dir/file$total_count" ]; then
5294                 echo -n "creating hard links $begin:$total_count..."
5295                 createmany -l"$file1" "$dir/file" "$begin" "$count" &>  \
5296                         /dev/null || error "cannot create hard links"
5297                 echo "done"
5298         fi
5299
5300         echo -n "checking number of hard links listed in xattrs..."
5301         local fid=$($LFS getstripe -F "$file1")
5302         local paths=($($LFS fid2path "$MOUNT" "$fid" 2> /dev/null))
5303
5304         echo "${#paths[*]}"
5305         if [ ${#paths[*]} -lt $total_count -a "$begin" -eq 2  ]; then
5306                         echo "hard link list has unexpected size, skipping test"
5307                         return 0
5308         fi
5309         if [ ${#paths[*]} -ge $total_count -a "$begin" -ne 2  ]; then
5310                         error "link names should exceed xattrs size"
5311         fi
5312
5313         echo -n "migrating files..."
5314         local migrate_out=$($LFS_MIGRATE -y -S '1m' $dir)
5315         local rc=$?
5316         [ $rc -eq 0 ] || error "migrate failed rc = $rc"
5317         echo "done"
5318
5319         # make sure all links have been properly migrated
5320         echo -n "verifying files..."
5321         fid=$($LFS getstripe -F "$file1") ||
5322                 error "cannot get fid for file $file1"
5323         for i in $(seq 2 $total_count); do
5324                 local fid2=$($LFS getstripe -F $dir/file$i)
5325                 [ "$fid2" == "$fid" ] ||
5326                         error "migrated hard link has mismatched FID"
5327         done
5328
5329         # make sure hard links were properly detected, and migration was
5330         # performed only once for the entire link set; nonlinked files should
5331         # also be migrated
5332         local actual=$(grep -c 'done migrate' <<< "$migrate_out")
5333         local expected=$(($uniq_count + 1))
5334         [ "$actual" -eq  "$expected" ] ||
5335                 error "hard links individually migrated ($actual != $expected)"
5336
5337         # make sure the correct number of hard links are present
5338         local hardlinks=$(stat -c '%h' "$file1")
5339         [ $hardlinks -eq $total_count ] ||
5340                 error "num hard links $hardlinks != $total_count"
5341         echo "done"
5342
5343         return 0
5344 }
5345
5346 test_56xb() {
5347         local dir0="$DIR/$tdir"
5348
5349         test_mkdir "$dir0" || error "cannot create dir $dir0"
5350
5351         echo "testing lfs migrate mode when all links fit within xattrs"
5352         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir0" 2 99
5353
5354         echo "testing rsync mode when all links fit within xattrs"
5355         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir0" 2 99
5356
5357         echo "testing lfs migrate mode when all links do not fit within xattrs"
5358         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir0" 101 100
5359
5360         echo "testing rsync mode when all links do not fit within xattrs"
5361         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir0" 101 100
5362
5363         # clean up
5364         rm -rf $dir0
5365 }
5366 run_test 56xb "lfs migration hard link support"
5367
5368 test_56y() {
5369         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
5370                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
5371                 return
5372
5373         local res=""
5374         local dir0=$DIR/$tdir/$testnum
5375         test_mkdir -p $dir0 || error "creating dir $dir0"
5376         local f1=$dir0/file1
5377         local f2=$dir0/file2
5378
5379         touch $f1 || error "creating std file $f1"
5380         $MULTIOP $f2 H2c || error "creating released file $f2"
5381
5382         # a directory can be raid0, so ask only for files
5383         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
5384         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
5385
5386         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
5387         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
5388
5389         # only files can be released, so no need to force file search
5390         res=$($LFIND $dir0 -L released)
5391         [[ $res == $f2 ]] || error "search released: found $res != $f2"
5392
5393         res=$($LFIND $dir0 \! -L released)
5394         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
5395
5396 }
5397 run_test 56y "lfs find -L raid0|released"
5398
5399 test_56z() { # LU-4824
5400         # This checks to make sure 'lfs find' continues after errors
5401         # There are two classes of errors that should be caught:
5402         # - If multiple paths are provided, all should be searched even if one
5403         #   errors out
5404         # - If errors are encountered during the search, it should not terminate
5405         #   early
5406         local i
5407         test_mkdir $DIR/$tdir
5408         for i in d{0..9}; do
5409                 test_mkdir $DIR/$tdir/$i
5410         done
5411         touch $DIR/$tdir/d{0..9}/$tfile
5412         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5413                 error "$LFS find did not return an error"
5414         # Make a directory unsearchable. This should NOT be the last entry in
5415         # directory order.  Arbitrarily pick the 6th entry
5416         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5417         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5418         # The user should be able to see 10 directories and 9 files
5419         [ $count == 19 ] || error "$LFS find did not continue after error"
5420 }
5421 run_test 56z "lfs find should continue after an error"
5422
5423 test_56aa() { # LU-5937
5424         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5425
5426         mkdir $DIR/$tdir
5427         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5428
5429         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5430         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5431
5432         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5433 }
5434 run_test 56aa "lfs find --size under striped dir"
5435
5436 test_57a() {
5437         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5438         # note test will not do anything if MDS is not local
5439         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5440                 skip "ldiskfs only test"
5441                 return
5442         fi
5443
5444         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5445         local MNTDEV="osd*.*MDT*.mntdev"
5446         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5447         [ -z "$DEV" ] && error "can't access $MNTDEV"
5448         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5449                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5450                         error "can't access $DEV"
5451                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5452                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5453                 rm $TMP/t57a.dump
5454         done
5455 }
5456 run_test 57a "verify MDS filesystem created with large inodes =="
5457
5458 test_57b() {
5459         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5460         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5461                 skip "ldiskfs only test"
5462                 return
5463         fi
5464
5465         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5466         local dir=$DIR/$tdir
5467
5468         local FILECOUNT=100
5469         local FILE1=$dir/f1
5470         local FILEN=$dir/f$FILECOUNT
5471
5472         rm -rf $dir || error "removing $dir"
5473         test_mkdir -p -c1 $dir || error "creating $dir"
5474         local mdtidx=$($LFS getstripe -M $dir)
5475         local mdtname=MDT$(printf %04x $mdtidx)
5476         local facet=mds$((mdtidx + 1))
5477
5478         echo "mcreating $FILECOUNT files"
5479         createmany -m $dir/f 1 $FILECOUNT || \
5480                 error "creating files in $dir"
5481
5482         # verify that files do not have EAs yet
5483         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5484         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5485
5486         sync
5487         sleep 1
5488         df $dir  #make sure we get new statfs data
5489         local MDSFREE=$(do_facet $facet \
5490                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5491         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5492         echo "opening files to create objects/EAs"
5493         local FILE
5494         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5495                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5496         done
5497
5498         # verify that files have EAs now
5499         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5500         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5501
5502         sleep 1  #make sure we get new statfs data
5503         df $dir
5504         local MDSFREE2=$(do_facet $facet \
5505                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5506         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5507         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5508                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5509                         error "MDC before $MDCFREE != after $MDCFREE2"
5510                 else
5511                         echo "MDC before $MDCFREE != after $MDCFREE2"
5512                         echo "unable to confirm if MDS has large inodes"
5513                 fi
5514         fi
5515         rm -rf $dir
5516 }
5517 run_test 57b "default LOV EAs are stored inside large inodes ==="
5518
5519 test_58() {
5520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5521         [ -z "$(which wiretest 2>/dev/null)" ] &&
5522                         skip_env "could not find wiretest" && return
5523         wiretest
5524 }
5525 run_test 58 "verify cross-platform wire constants =============="
5526
5527 test_59() {
5528         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5529         echo "touch 130 files"
5530         createmany -o $DIR/f59- 130
5531         echo "rm 130 files"
5532         unlinkmany $DIR/f59- 130
5533         sync
5534         # wait for commitment of removal
5535         wait_delete_completed
5536 }
5537 run_test 59 "verify cancellation of llog records async ========="
5538
5539 TEST60_HEAD="test_60 run $RANDOM"
5540 test_60a() {
5541         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5542         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5543         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5544                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5545                         skip_env "missing subtest run-llog.sh" && return
5546
5547         log "$TEST60_HEAD - from kernel mode"
5548         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5549         do_facet mgs sh run-llog.sh
5550         do_facet mgs $LCTL dk > $TMP/$tfile
5551
5552         # LU-6388: test llog_reader
5553         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5554         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5555         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5556                         skip_env "missing llog_reader" && return
5557         local fstype=$(facet_fstype mgs)
5558         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5559                 skip_env "Only for ldiskfs or zfs type mgs" && return
5560
5561         local mntpt=$(facet_mntpt mgs)
5562         local mgsdev=$(mgsdevname 1)
5563         local fid_list
5564         local fid
5565         local rec_list
5566         local rec
5567         local rec_type
5568         local obj_file
5569         local path
5570         local seq
5571         local oid
5572         local pass=true
5573
5574         #get fid and record list
5575         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5576                 tail -n 4))
5577         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5578                 tail -n 4))
5579         #remount mgs as ldiskfs or zfs type
5580         stop mgs || error "stop mgs failed"
5581         mount_fstype mgs || error "remount mgs failed"
5582         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5583                 fid=${fid_list[i]}
5584                 rec=${rec_list[i]}
5585                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5586                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5587                 oid=$((16#$oid))
5588
5589                 case $fstype in
5590                         ldiskfs )
5591                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5592                         zfs )
5593                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5594                 esac
5595                 echo "obj_file is $obj_file"
5596                 do_facet mgs $llog_reader $obj_file
5597
5598                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5599                         awk '{ print $3 }' | sed -e "s/^type=//g")
5600                 if [ $rec_type != $rec ]; then
5601                         echo "FAILED test_60a wrong record type $rec_type," \
5602                               "should be $rec"
5603                         pass=false
5604                         break
5605                 fi
5606
5607                 #check obj path if record type is LLOG_LOGID_MAGIC
5608                 if [ "$rec" == "1064553b" ]; then
5609                         path=$(do_facet mgs $llog_reader $obj_file |
5610                                 grep "path=" | awk '{ print $NF }' |
5611                                 sed -e "s/^path=//g")
5612                         if [ $obj_file != $mntpt/$path ]; then
5613                                 echo "FAILED test_60a wrong obj path" \
5614                                       "$montpt/$path, should be $obj_file"
5615                                 pass=false
5616                                 break
5617                         fi
5618                 fi
5619         done
5620         rm -f $TMP/$tfile
5621         #restart mgs before "error", otherwise it will block the next test
5622         stop mgs || error "stop mgs failed"
5623         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5624         $pass || error "test failed, see FAILED test_60a messages for specifics"
5625 }
5626 run_test 60a "llog_test run from kernel module and test llog_reader"
5627
5628 test_60b() { # bug 6411
5629         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5630         dmesg > $DIR/$tfile
5631         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
5632                                 /llog.test/ {
5633                                         if (marker)
5634                                                 from_marker++
5635                                         from_begin++
5636                                 }
5637                                 END {
5638                                         if (marker)
5639                                                 print from_marker
5640                                         else
5641                                                 print from_begin
5642                                 }")
5643         [[ $LLOG_COUNT -gt 100 ]] &&
5644                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5645 }
5646 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5647
5648 test_60c() {
5649         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5650         echo "create 5000 files"
5651         createmany -o $DIR/f60c- 5000
5652 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5653         lctl set_param fail_loc=0x80000137
5654         unlinkmany $DIR/f60c- 5000
5655         lctl set_param fail_loc=0
5656 }
5657 run_test 60c "unlink file when mds full"
5658
5659 test_60d() {
5660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5661         SAVEPRINTK=$(lctl get_param -n printk)
5662
5663         # verify "lctl mark" is even working"
5664         MESSAGE="test message ID $RANDOM $$"
5665         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5666         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5667
5668         lctl set_param printk=0 || error "set lnet.printk failed"
5669         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5670         MESSAGE="new test message ID $RANDOM $$"
5671         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5672         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5673         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5674
5675         lctl set_param -n printk="$SAVEPRINTK"
5676 }
5677 run_test 60d "test printk console message masking"
5678
5679 test_60e() {
5680         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5681         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5682         touch $DIR/$tfile
5683 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5684         do_facet mds1 lctl set_param fail_loc=0x15b
5685         rm $DIR/$tfile
5686 }
5687 run_test 60e "no space while new llog is being created"
5688
5689 test_61() {
5690         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5691         f="$DIR/f61"
5692         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5693         cancel_lru_locks osc
5694         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5695         sync
5696 }
5697 run_test 61 "mmap() writes don't make sync hang ================"
5698
5699 # bug 2330 - insufficient obd_match error checking causes LBUG
5700 test_62() {
5701         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5702         f="$DIR/f62"
5703         echo foo > $f
5704         cancel_lru_locks osc
5705         lctl set_param fail_loc=0x405
5706         cat $f && error "cat succeeded, expect -EIO"
5707         lctl set_param fail_loc=0
5708 }
5709 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5710 # match every page all of the time.
5711 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5712
5713 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5714 # Though this test is irrelevant anymore, it helped to reveal some
5715 # other grant bugs (LU-4482), let's keep it.
5716 test_63a() {   # was test_63
5717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5718         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5719         for i in `seq 10` ; do
5720                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5721                 sleep 5
5722                 kill $!
5723                 sleep 1
5724         done
5725
5726         rm -f $DIR/f63 || true
5727 }
5728 run_test 63a "Verify oig_wait interruption does not crash ======="
5729
5730 # bug 2248 - async write errors didn't return to application on sync
5731 # bug 3677 - async write errors left page locked
5732 test_63b() {
5733         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5734         debugsave
5735         lctl set_param debug=-1
5736
5737         # ensure we have a grant to do async writes
5738         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5739         rm $DIR/$tfile
5740
5741         sync    # sync lest earlier test intercept the fail_loc
5742
5743         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5744         lctl set_param fail_loc=0x80000406
5745         $MULTIOP $DIR/$tfile Owy && \
5746                 error "sync didn't return ENOMEM"
5747         sync; sleep 2; sync     # do a real sync this time to flush page
5748         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5749                 error "locked page left in cache after async error" || true
5750         debugrestore
5751 }
5752 run_test 63b "async write errors should be returned to fsync ==="
5753
5754 test_64a () {
5755         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5756         df $DIR
5757         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5758 }
5759 run_test 64a "verify filter grant calculations (in kernel) ====="
5760
5761 test_64b () {
5762         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5763         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5764 }
5765 run_test 64b "check out-of-space detection on client ==========="
5766
5767 test_64c() {
5768         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5769 }
5770 run_test 64c "verify grant shrink ========================------"
5771
5772 # this does exactly what osc_request.c:osc_announce_cached() does in
5773 # order to calculate max amount of grants to ask from server
5774 want_grant() {
5775         local tgt=$1
5776
5777         local page_size=$(get_page_size client)
5778
5779         local nrpages=$($LCTL get_param -n osc.${tgt}.max_pages_per_rpc)
5780         local rpc_in_flight=$($LCTL get_param -n osc.${tgt}.max_rpcs_in_flight)
5781
5782         ((rpc_in_flight ++));
5783         nrpages=$((nrpages * rpc_in_flight))
5784
5785         local dirty_max_pages=$($LCTL get_param -n osc.${tgt}.max_dirty_mb)
5786
5787         dirty_max_pages=$((dirty_max_pages * 1024 * 1024 / page_size))
5788
5789         [[ $dirty_max_pages -gt $nrpages ]] && nrpages=$dirty_max_pages
5790         local undirty=$((nrpages * page_size))
5791
5792         local max_extent_pages
5793         max_extent_pages=$($LCTL get_param osc.${tgt}.import |
5794             grep grant_max_extent_size | awk '{print $2}')
5795         max_extent_pages=$((max_extent_pages / page_size))
5796         local nrextents=$(((nrpages + max_extent_pages - 1) / max_extent_pages))
5797         local grant_extent_tax
5798         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
5799             grep grant_extent_tax | awk '{print $2}')
5800
5801         undirty=$((undirty + nrextents * grant_extent_tax))
5802
5803         echo $undirty
5804 }
5805
5806 # this is size of unit for grant allocation. It should be equal to
5807 # what tgt_grant.c:tgt_grant_chunk() calculates
5808 grant_chunk() {
5809         local tgt=$1
5810         local max_brw_size
5811         local grant_extent_tax
5812
5813         max_brw_size=$($LCTL get_param osc.${tgt}.import |
5814             grep max_brw_size | awk '{print $2}')
5815
5816         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
5817             grep grant_extent_tax | awk '{print $2}')
5818
5819         echo $(((max_brw_size + grant_extent_tax) * 2))
5820 }
5821
5822 test_64d() {
5823         [ $(lustre_version_code ost1) -lt $(version_code 2.10.56) ] &&
5824                 skip "OST < 2.10.55 doesn't limit grants enough" && return 0
5825
5826         local tgt=$($LCTL dl | grep "0000-osc-[^mM]" | awk '{print $4}')
5827
5828         [[ $($LCTL get_param osc.${tgt}.import |
5829                     grep "connect_flags:.*grant_param") ]] || \
5830                         { skip "no grant_param connect flag"; return; }
5831
5832         local olddebug=$($LCTL get_param -n debug 2> /dev/null)
5833
5834         $LCTL set_param debug="$OLDDEBUG" 2> /dev/null || true
5835
5836         local max_cur_granted=$(($(want_grant $tgt) + $(grant_chunk $tgt)))
5837
5838         $SETSTRIPE $DIR/$tfile -i 0 -c 1
5839         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1000 &
5840         ddpid=$!
5841
5842         while true
5843         do
5844                 local cur_grant=$($LCTL get_param -n osc.${tgt}.cur_grant_bytes)
5845                 if [[ $cur_grant -gt $max_cur_granted ]]
5846                 then
5847                         kill $ddpid
5848                         error "cur_grant $cur_grant > $max_cur_granted"
5849                 fi
5850                 kill -0 $ddpid
5851                 [[ $? -ne 0 ]] && break;
5852                 sleep 2
5853         done
5854         $LCTL set_param debug="$olddebug" 2> /dev/null || true
5855 }
5856 run_test 64d "check grant limit exceed"
5857
5858 # bug 1414 - set/get directories' stripe info
5859 test_65a() {
5860         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5861         test_mkdir -p $DIR/$tdir
5862         touch $DIR/$tdir/f1
5863         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5864 }
5865 run_test 65a "directory with no stripe info ===================="
5866
5867 test_65b() {
5868         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5869         test_mkdir -p $DIR/$tdir
5870         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5871
5872         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5873                                                 error "setstripe"
5874         touch $DIR/$tdir/f2
5875         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5876 }
5877 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
5878
5879 test_65c() {
5880         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5881         if [[ $OSTCOUNT -gt 1 ]]; then
5882                 test_mkdir -p $DIR/$tdir
5883                 local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5884
5885                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5886                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5887                 touch $DIR/$tdir/f3
5888                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5889         fi
5890 }
5891 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
5892
5893 test_65d() {
5894         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5895         test_mkdir -p $DIR/$tdir
5896         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
5897         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5898
5899         if [[ $STRIPECOUNT -le 0 ]]; then
5900                 sc=1
5901         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5902 #LOV_MAX_STRIPE_COUNT is 2000
5903                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5904         else
5905                 sc=$(($STRIPECOUNT - 1))
5906         fi
5907         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5908         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5909         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5910                 error "lverify failed"
5911 }
5912 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
5913
5914 test_65e() {
5915         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5916         test_mkdir -p $DIR/$tdir
5917
5918         $SETSTRIPE $DIR/$tdir || error "setstripe"
5919         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5920                                         error "no stripe info failed"
5921         touch $DIR/$tdir/f6
5922         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5923 }
5924 run_test 65e "directory setstripe defaults ======================="
5925
5926 test_65f() {
5927         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5928         test_mkdir -p $DIR/${tdir}f
5929         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5930 }
5931 run_test 65f "dir setstripe permission (should return error) ==="
5932
5933 test_65g() {
5934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5935         test_mkdir -p $DIR/$tdir
5936         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5937
5938         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5939                                                         error "setstripe"
5940         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5941         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5942                 error "delete default stripe failed"
5943 }
5944 run_test 65g "directory setstripe -d ==========================="
5945
5946 test_65h() {
5947         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5948         test_mkdir -p $DIR/$tdir
5949         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5950
5951         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5952                                                         error "setstripe"
5953         test_mkdir -p $DIR/$tdir/dd1
5954         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5955                 error "stripe info inherit failed"
5956 }
5957 run_test 65h "directory stripe info inherit ===================="
5958
5959 test_65i() {
5960         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5961
5962         save_layout_restore_at_exit $MOUNT
5963
5964         # bug6367: set non-default striping on root directory
5965         $LFS setstripe -S 65536 -c -1 $MOUNT || error "error setting stripe"
5966
5967         # bug12836: getstripe on -1 default directory striping
5968         $LFS getstripe $MOUNT || error "getstripe $MOUNT failed"
5969
5970         # bug12836: getstripe -v on -1 default directory striping
5971         $LFS getstripe -v $MOUNT || error "getstripe -v $MOUNT failed"
5972
5973         # bug12836: new find on -1 default directory striping
5974         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5975 }
5976 run_test 65i "various tests to set root directory striping"
5977
5978 test_65j() { # bug6367
5979         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5980
5981         sync; sleep 1
5982
5983         # if we aren't already remounting for each test, do so for this test
5984         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5985                 cleanup || error "failed to unmount"
5986                 setup
5987         fi
5988
5989         save_layout_restore_at_exit $MOUNT
5990
5991         $LFS setstripe -d $MOUNT || error "setstripe failed"
5992 }
5993 run_test 65j "set default striping on root directory (bug 6367)="
5994
5995 test_65k() { # bug11679
5996         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5997         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5998         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5999
6000         local disable_precreate=true
6001         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.8.54) ] &&
6002                 disable_precreate=false
6003
6004         echo "Check OST status: "
6005         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
6006                 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
6007
6008         for OSC in $MDS_OSCS; do
6009                 echo $OSC "is active"
6010                 do_facet $SINGLEMDS lctl --device %$OSC activate
6011         done
6012
6013         for INACTIVE_OSC in $MDS_OSCS; do
6014                 local ost=$(osc_to_ost $INACTIVE_OSC)
6015                 local ostnum=$(do_facet $SINGLEMDS lctl get_param -n \
6016                                lov.*md*.target_obd |
6017                                awk -F: /$ost/'{ print $1 }' | head -n 1)
6018
6019                 mkdir -p $DIR/$tdir
6020                 $SETSTRIPE -i $ostnum -c 1 $DIR/$tdir
6021                 createmany -o $DIR/$tdir/$tfile.$ostnum. 1000
6022
6023                 echo "Deactivate: " $INACTIVE_OSC
6024                 do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
6025
6026                 local count=$(do_facet $SINGLEMDS "lctl get_param -n \
6027                               osp.$ost*MDT0000.create_count")
6028                 local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
6029                                   osp.$ost*MDT0000.max_create_count")
6030                 $disable_precreate &&
6031                         do_facet $SINGLEMDS "lctl set_param -n \
6032                                 osp.$ost*MDT0000.max_create_count=0"
6033
6034                 for idx in $(seq 0 $((OSTCOUNT - 1))); do
6035                         [ -f $DIR/$tdir/$idx ] && continue
6036                         echo "$SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx"
6037                         $SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx ||
6038                                 error "setstripe $idx should succeed"
6039                         rm -f $DIR/$tdir/$idx || error "rm $idx failed"
6040                 done
6041                 unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
6042                 rmdir $DIR/$tdir
6043
6044                 do_facet $SINGLEMDS "lctl set_param -n \
6045                         osp.$ost*MDT0000.max_create_count=$max_count"
6046                 do_facet $SINGLEMDS "lctl set_param -n \
6047                         osp.$ost*MDT0000.create_count=$count"
6048                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
6049                 echo $INACTIVE_OSC "is Activate"
6050
6051                 wait_osc_import_state mds ost$ostnum FULL
6052         done
6053 }
6054 run_test 65k "validate manual striping works properly with deactivated OSCs"
6055
6056 test_65l() { # bug 12836
6057         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6058         test_mkdir -p $DIR/$tdir/test_dir
6059         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
6060         $LFS find -mtime -1 $DIR/$tdir >/dev/null
6061 }
6062 run_test 65l "lfs find on -1 stripe dir ========================"
6063
6064 test_65m() {
6065         local layout=$(save_layout $MOUNT)
6066         $RUNAS $SETSTRIPE -c 2 $MOUNT && {
6067                 restore_layout $MOUNT $layout
6068                 error "setstripe should fail by non-root users"
6069         }
6070         true
6071 }
6072 run_test 65m "normal user can't set filesystem default stripe"
6073
6074 test_65n() {
6075         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.6) ]] ||
6076                 skip "Need MDS version at least 2.10.6"
6077         [[ $PARALLEL != "yes" ]] || skip "skip parallel run"
6078
6079         [[ $OSTCOUNT -ge 2 ]] || skip_env "needs >= 2 OSTs"
6080         which getfattr > /dev/null 2>&1 || skip_env "no getfattr command"
6081         which setfattr > /dev/null 2>&1 || skip_env "no setfattr command"
6082
6083         local root_layout=$(save_layout $MOUNT)
6084         stack_trap "restore_layout $MOUNT $root_layout" EXIT
6085
6086         # new subdirectory under root directory should not inherit
6087         # the default layout from root
6088         local dir1=$MOUNT/$tdir-1
6089         mkdir $dir1 || error "mkdir $dir1 failed"
6090         ! getfattr -n trusted.lov $dir1 &> /dev/null ||
6091                 error "$dir1 shouldn't have LOV EA"
6092
6093         # delete the default layout on root directory
6094         $LFS setstripe -d $MOUNT || error "delete root default layout failed"
6095
6096         local dir2=$MOUNT/$tdir-2
6097         mkdir $dir2 || error "mkdir $dir2 failed"
6098         ! getfattr -n trusted.lov $dir2 &> /dev/null ||
6099                 error "$dir2 shouldn't have LOV EA"
6100
6101         # set a new striping pattern on root directory
6102         local def_stripe_size=$($LFS getstripe -S $MOUNT)
6103         local new_def_stripe_size=$((def_stripe_size * 2))
6104         $LFS setstripe -S $new_def_stripe_size $MOUNT ||
6105                 error "set stripe size on $MOUNT failed"
6106
6107         # new file created in $dir2 should inherit the new stripe size from
6108         # the filesystem default
6109         local file2=$dir2/$tfile-2
6110         touch $file2 || error "touch $file2 failed"
6111
6112         local file2_stripe_size=$($LFS getstripe -S $file2)
6113         [[ $file2_stripe_size -eq $new_def_stripe_size ]] ||
6114                 error "$file2 didn't inherit stripe size $new_def_stripe_size"
6115
6116         local dir3=$MOUNT/$tdir-3
6117         mkdir $dir3 || error "mkdir $dir3 failed"
6118         ! getfattr -n trusted.lov $dir3 &> /dev/null ||
6119                 error "$dir3 shouldn't have LOV EA"
6120
6121         # set OST pool on root directory
6122         local pool=$TESTNAME
6123         pool_add $pool || error "add $pool failed"
6124         pool_add_targets $pool 0 $((OSTCOUNT - 1)) 1 ||
6125                 error "add targets to $pool failed"
6126
6127         $LFS setstripe -p $pool $MOUNT ||
6128                 error "set OST pool on $MOUNT failed"
6129
6130         # new file created in $dir3 should inherit the pool from
6131         # the filesystem default
6132         local file3=$dir3/$tfile-3
6133         touch $file3 || error "touch $file3 failed"
6134
6135         local file3_pool=$($LFS getstripe -p $file3)
6136         [[ "$file3_pool" = "$pool" ]] ||
6137                 error "$file3 didn't inherit OST pool $pool"
6138
6139         local dir4=$MOUNT/$tdir-4
6140         mkdir $dir4 || error "mkdir $dir4 failed"
6141         ! getfattr -n trusted.lov $dir4 &> /dev/null ||
6142                 error "$dir4 shouldn't have LOV EA"
6143
6144         # new file created in $dir4 should inherit the pool from
6145         # the filesystem default
6146         local file4=$dir4/$tfile-4
6147         touch $file4 || error "touch $file4 failed"
6148
6149         local file4_pool=$($LFS getstripe -p $file4)
6150         [[ "$file4_pool" = "$pool" ]] ||
6151                 error "$file4 didn't inherit OST pool $pool"
6152
6153         # new subdirectory under non-root directory should inherit
6154         # the default layout from its parent directory
6155         $LFS setstripe -S $new_def_stripe_size -p $pool $dir4 ||
6156                 error "set directory layout on $dir4 failed"
6157
6158         local dir5=$dir4/$tdir-5
6159         mkdir $dir5 || error "mkdir $dir5 failed"
6160
6161         local dir4_layout=$(get_layout_param $dir4)
6162         local dir5_layout=$(get_layout_param $dir5)
6163         [[ "$dir4_layout" = "$dir5_layout" ]] ||
6164                 error "$dir5 should inherit the default layout from $dir4"
6165 }
6166 run_test 65n "don't inherit default layout from root for new subdirectories"
6167
6168 # bug 2543 - update blocks count on client
6169 test_66() {
6170         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6171         COUNT=${COUNT:-8}
6172         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
6173         sync; sync_all_data; sync; sync_all_data
6174         cancel_lru_locks osc
6175         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
6176         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
6177 }
6178 run_test 66 "update inode blocks count on client ==============="
6179
6180 meminfo() {
6181         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
6182 }
6183
6184 swap_used() {
6185         swapon -s | awk '($1 == "'$1'") { print $4 }'
6186 }
6187
6188 # bug5265, obdfilter oa2dentry return -ENOENT
6189 # #define OBD_FAIL_SRV_ENOENT 0x217
6190 test_69() {
6191         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6192         remote_ost_nodsh && skip "remote OST with nodsh" && return
6193
6194         f="$DIR/$tfile"
6195         $SETSTRIPE -c 1 -i 0 $f
6196
6197         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
6198
6199         do_facet ost1 lctl set_param fail_loc=0x217
6200         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
6201         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
6202
6203         do_facet ost1 lctl set_param fail_loc=0
6204         $DIRECTIO write $f 0 2 || error "write error"
6205
6206         cancel_lru_locks osc
6207         $DIRECTIO read $f 0 1 || error "read error"
6208
6209         do_facet ost1 lctl set_param fail_loc=0x217
6210         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
6211
6212         do_facet ost1 lctl set_param fail_loc=0
6213         rm -f $f
6214 }
6215 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
6216
6217 test_71() {
6218         test_mkdir -p $DIR/$tdir
6219         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
6220         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
6221 }
6222 run_test 71 "Running dbench on lustre (don't segment fault) ===="
6223
6224 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
6225         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6226         [ "$RUNAS_ID" = "$UID" ] &&
6227                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6228
6229         # Check that testing environment is properly set up. Skip if not
6230         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
6231                 skip_env "User $RUNAS_ID does not exist - skipping"
6232                 return 0
6233         }
6234         touch $DIR/$tfile
6235         chmod 777 $DIR/$tfile
6236         chmod ug+s $DIR/$tfile
6237         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
6238                 error "$RUNAS dd $DIR/$tfile failed"
6239         # See if we are still setuid/sgid
6240         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6241                 error "S/gid is not dropped on write"
6242         # Now test that MDS is updated too
6243         cancel_lru_locks mdc
6244         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6245                 error "S/gid is not dropped on MDS"
6246         rm -f $DIR/$tfile
6247 }
6248 run_test 72a "Test that remove suid works properly (bug5695) ===="
6249
6250 test_72b() { # bug 24226 -- keep mode setting when size is not changing
6251         local perm
6252
6253         [ "$RUNAS_ID" = "$UID" ] && \
6254                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6255         [ "$RUNAS_ID" -eq 0 ] && \
6256                 skip_env "RUNAS_ID = 0 -- skipping" && return
6257
6258         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6259         # Check that testing environment is properly set up. Skip if not
6260         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
6261                 skip_env "User $RUNAS_ID does not exist - skipping"
6262                 return 0
6263         }
6264         touch $DIR/${tfile}-f{g,u}
6265         test_mkdir $DIR/${tfile}-dg
6266         test_mkdir $DIR/${tfile}-du
6267         chmod 770 $DIR/${tfile}-{f,d}{g,u}
6268         chmod g+s $DIR/${tfile}-{f,d}g
6269         chmod u+s $DIR/${tfile}-{f,d}u
6270         for perm in 777 2777 4777; do
6271                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
6272                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
6273                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
6274                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
6275         done
6276         true
6277 }
6278 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
6279
6280 # bug 3462 - multiple simultaneous MDC requests
6281 test_73() {
6282         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6283         test_mkdir $DIR/d73-1
6284         test_mkdir $DIR/d73-2
6285         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
6286         pid1=$!
6287
6288         lctl set_param fail_loc=0x80000129
6289         $MULTIOP $DIR/d73-1/f73-2 Oc &
6290         sleep 1
6291         lctl set_param fail_loc=0
6292
6293         $MULTIOP $DIR/d73-2/f73-3 Oc &
6294         pid3=$!
6295
6296         kill -USR1 $pid1
6297         wait $pid1 || return 1
6298
6299         sleep 25
6300
6301         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
6302         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
6303         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
6304
6305         rm -rf $DIR/d73-*
6306 }
6307 run_test 73 "multiple MDC requests (should not deadlock)"
6308
6309 test_74a() { # bug 6149, 6184
6310         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6311         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6312         #
6313         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6314         # will spin in a tight reconnection loop
6315         touch $DIR/f74a
6316         $LCTL set_param fail_loc=0x8000030e
6317         # get any lock that won't be difficult - lookup works.
6318         ls $DIR/f74a
6319         $LCTL set_param fail_loc=0
6320         rm -f $DIR/f74a
6321         true
6322 }
6323 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
6324
6325 test_74b() { # bug 13310
6326         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6327         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6328         #
6329         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6330         # will spin in a tight reconnection loop
6331         $LCTL set_param fail_loc=0x8000030e
6332         # get a "difficult" lock
6333         touch $DIR/f74b
6334         $LCTL set_param fail_loc=0
6335         rm -f $DIR/f74b
6336         true
6337 }
6338 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
6339
6340 test_74c() {
6341         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6342         #define OBD_FAIL_LDLM_NEW_LOCK
6343         $LCTL set_param fail_loc=0x319
6344         touch $DIR/$tfile && error "touch successful"
6345         $LCTL set_param fail_loc=0
6346         true
6347 }
6348 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
6349
6350 num_inodes() {
6351         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
6352 }
6353
6354 test_76() { # Now for bug 20433, added originally in bug 1443
6355         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6356         local CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
6357         cancel_lru_locks osc
6358         BEFORE_INODES=$(num_inodes)
6359         echo "before inodes: $BEFORE_INODES"
6360         local COUNT=1000
6361         [ "$SLOW" = "no" ] && COUNT=100
6362         for i in $(seq $COUNT); do
6363                 touch $DIR/$tfile
6364                 rm -f $DIR/$tfile
6365         done
6366         cancel_lru_locks osc
6367         AFTER_INODES=$(num_inodes)
6368         echo "after inodes: $AFTER_INODES"
6369         local wait=0
6370         while [[ $((AFTER_INODES-1*${CPUS:-1})) -gt $BEFORE_INODES ]]; do
6371                 sleep 2
6372                 AFTER_INODES=$(num_inodes)
6373                 wait=$((wait+2))
6374                 echo "wait $wait seconds inodes: $AFTER_INODES"
6375                 if [ $wait -gt 30 ]; then
6376                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
6377                 fi
6378         done
6379 }
6380 run_test 76 "confirm clients recycle inodes properly ===="
6381
6382
6383 export ORIG_CSUM=""
6384 set_checksums()
6385 {
6386         # Note: in sptlrpc modes which enable its own bulk checksum, the
6387         # original crc32_le bulk checksum will be automatically disabled,
6388         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
6389         # will be checked by sptlrpc code against sptlrpc bulk checksum.
6390         # In this case set_checksums() will not be no-op, because sptlrpc
6391         # bulk checksum will be enabled all through the test.
6392
6393         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
6394         lctl set_param -n osc.*.checksums $1
6395         return 0
6396 }
6397
6398 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
6399                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
6400 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
6401 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
6402 set_checksum_type()
6403 {
6404         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
6405         log "set checksum type to $1"
6406         return 0
6407 }
6408 F77_TMP=$TMP/f77-temp
6409 F77SZ=8
6410 setup_f77() {
6411         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
6412                 error "error writing to $F77_TMP"
6413 }
6414
6415 test_77a() { # bug 10889
6416         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6417         $GSS && skip "could not run with gss" && return
6418         [ ! -f $F77_TMP ] && setup_f77
6419         set_checksums 1
6420         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
6421         set_checksums 0
6422         rm -f $DIR/$tfile
6423 }
6424 run_test 77a "normal checksum read/write operation"
6425
6426 test_77b() { # bug 10889
6427         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6428         $GSS && skip "could not run with gss" && return
6429         [ ! -f $F77_TMP ] && setup_f77
6430         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6431         $LCTL set_param fail_loc=0x80000409
6432         set_checksums 1
6433
6434         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6435                 error "dd error: $?"
6436         $LCTL set_param fail_loc=0
6437
6438         for algo in $CKSUM_TYPES; do
6439                 cancel_lru_locks osc
6440                 set_checksum_type $algo
6441                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6442                 $LCTL set_param fail_loc=0x80000408
6443                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6444                 $LCTL set_param fail_loc=0
6445         done
6446         set_checksums 0
6447         set_checksum_type $ORIG_CSUM_TYPE
6448         rm -f $DIR/$tfile
6449 }
6450 run_test 77b "checksum error on client write, read"
6451
6452 cleanup_77c() {
6453         trap 0
6454         set_checksums 0
6455         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
6456         $check_ost &&
6457                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
6458         [ -n $osc_file_prefix ] && rm -f ${osc_file_prefix}*
6459         $check_ost && [ -n $ost_file_prefix ] &&
6460                 do_facet ost1 rm -f ${ost_file_prefix}\*
6461 }
6462
6463 test_77c() {
6464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6465         $GSS && skip "could not run with gss" && return
6466
6467         local bad1
6468         local osc_file_prefix
6469         local osc_file
6470         local check_ost=false
6471         local ost_file_prefix
6472         local ost_file
6473         local orig_cksum
6474         local dump_cksum
6475         local fid
6476
6477         # ensure corruption will occur on first OSS/OST
6478         $LFS setstripe -i 0 $DIR/$tfile
6479
6480         [ ! -f $F77_TMP ] && setup_f77
6481         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6482                 error "dd write error: $?"
6483         fid=$($LFS path2fid $DIR/$tfile)
6484
6485         if [ $(lustre_version_code ost1) -ge $(version_code 2.9.57) ]
6486         then
6487                 check_ost=true
6488                 ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
6489                 ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
6490         else
6491                 echo "OSS do not support bulk pages dump upon error"
6492         fi
6493
6494         osc_file_prefix=$($LCTL get_param -n debug_path)
6495         osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
6496
6497         trap cleanup_77c EXIT
6498
6499         set_checksums 1
6500         # enable bulk pages dump upon error on Client
6501         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
6502         # enable bulk pages dump upon error on OSS
6503         $check_ost &&
6504                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
6505
6506         # flush Client cache to allow next read to reach OSS
6507         cancel_lru_locks osc
6508
6509         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
6510         $LCTL set_param fail_loc=0x80000408
6511         dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
6512         $LCTL set_param fail_loc=0
6513
6514         rm -f $DIR/$tfile
6515
6516         # check cksum dump on Client
6517         osc_file=$(ls ${osc_file_prefix}*)
6518         [ -n "$osc_file" ] || error "no checksum dump file on Client"
6519         # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
6520         bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
6521         [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
6522         orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
6523                      cksum)
6524         dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
6525         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6526                 error "dump content does not match on Client"
6527
6528         $check_ost || { skip "No need to check cksum dump on OSS"; return 0; }
6529
6530         # check cksum dump on OSS
6531         ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
6532         [ -n "$ost_file" ] || error "no checksum dump file on OSS"
6533         orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
6534         dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
6535         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6536                 error "dump content does not match on OSS"
6537
6538         cleanup_77c
6539 }
6540 run_test 77c "checksum error on client read with debug"
6541
6542 test_77d() { # bug 10889
6543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6544         $GSS && skip "could not run with gss" && return
6545         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6546         $LCTL set_param fail_loc=0x80000409
6547         set_checksums 1
6548         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6549                 error "direct write: rc=$?"
6550         $LCTL set_param fail_loc=0
6551         set_checksums 0
6552
6553         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6554         $LCTL set_param fail_loc=0x80000408
6555         set_checksums 1
6556         cancel_lru_locks osc
6557         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6558                 error "direct read: rc=$?"
6559         $LCTL set_param fail_loc=0
6560         set_checksums 0
6561 }
6562 run_test 77d "checksum error on OST direct write, read"
6563
6564 test_77f() { # bug 10889
6565         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6566         $GSS && skip "could not run with gss" && return
6567         set_checksums 1
6568         for algo in $CKSUM_TYPES; do
6569                 cancel_lru_locks osc
6570                 set_checksum_type $algo
6571                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6572                 $LCTL set_param fail_loc=0x409
6573                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
6574                         error "direct write succeeded"
6575                 $LCTL set_param fail_loc=0
6576         done
6577         set_checksum_type $ORIG_CSUM_TYPE
6578         set_checksums 0
6579 }
6580 run_test 77f "repeat checksum error on write (expect error)"
6581
6582 test_77g() { # bug 10889
6583         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6584         $GSS && skip "could not run with gss" && return
6585         remote_ost_nodsh && skip "remote OST with nodsh" && return
6586
6587         [ ! -f $F77_TMP ] && setup_f77
6588
6589         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
6590         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
6591         do_facet ost1 lctl set_param fail_loc=0x8000021a
6592         set_checksums 1
6593         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
6594                 error "write error: rc=$?"
6595         do_facet ost1 lctl set_param fail_loc=0
6596         set_checksums 0
6597
6598         cancel_lru_locks osc
6599         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
6600         do_facet ost1 lctl set_param fail_loc=0x8000021b
6601         set_checksums 1
6602         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6603         do_facet ost1 lctl set_param fail_loc=0
6604         set_checksums 0
6605 }
6606 run_test 77g "checksum error on OST write, read"
6607
6608 test_77j() { # bug 13805
6609         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6610         $GSS && skip "could not run with gss" && return
6611         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6612         lctl set_param fail_loc=0x40c
6613         remount_client $MOUNT
6614         lctl set_param fail_loc=0
6615         # wait async osc connect to finish and reflect updated state value
6616         local i
6617         for (( i=0; i < OSTCOUNT; i++ )) ; do
6618                 wait_osc_import_state client ost$((i+1)) FULL
6619         done
6620
6621         for VALUE in $(lctl get_param osc.*osc-[^mM]*.checksum_type); do
6622                 PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
6623                 algo=$(lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g')
6624                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6625         done
6626         remount_client $MOUNT
6627 }
6628 run_test 77j "client only supporting ADLER32"
6629
6630 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6631 rm -f $F77_TMP
6632 unset F77_TMP
6633
6634 cleanup_test_78() {
6635         trap 0
6636         rm -f $DIR/$tfile
6637 }
6638
6639 test_78() { # bug 10901
6640         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6641         remote_ost || { skip_env "local OST" && return; }
6642
6643         NSEQ=5
6644         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6645         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6646         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6647         echo "MemTotal: $MEMTOTAL"
6648
6649         # reserve 256MB of memory for the kernel and other running processes,
6650         # and then take 1/2 of the remaining memory for the read/write buffers.
6651         if [ $MEMTOTAL -gt 512 ] ;then
6652                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6653         else
6654                 # for those poor memory-starved high-end clusters...
6655                 MEMTOTAL=$((MEMTOTAL / 2))
6656         fi
6657         echo "Mem to use for directio: $MEMTOTAL"
6658
6659         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6660         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6661         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6662         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6663                 head -n1)
6664         echo "Smallest OST: $SMALLESTOST"
6665         [[ $SMALLESTOST -lt 10240 ]] &&
6666                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6667
6668         trap cleanup_test_78 EXIT
6669
6670         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6671                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6672
6673         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6674         echo "File size: $F78SIZE"
6675         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6676         for i in $(seq 1 $NSEQ); do
6677                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6678                 echo directIO rdwr round $i of $NSEQ
6679                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6680         done
6681
6682         cleanup_test_78
6683 }
6684 run_test 78 "handle large O_DIRECT writes correctly ============"
6685
6686 test_79() { # bug 12743
6687         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6688         wait_delete_completed
6689
6690         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6691         BKFREE=$(calc_osc_kbytes kbytesfree)
6692         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6693
6694         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6695         DFTOTAL=`echo $STRING | cut -d, -f1`
6696         DFUSED=`echo $STRING  | cut -d, -f2`
6697         DFAVAIL=`echo $STRING | cut -d, -f3`
6698         DFFREE=$(($DFTOTAL - $DFUSED))
6699
6700         ALLOWANCE=$((64 * $OSTCOUNT))
6701
6702         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6703            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6704                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6705         fi
6706         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6707            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6708                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6709         fi
6710         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6711            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6712                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6713         fi
6714 }
6715 run_test 79 "df report consistency check ======================="
6716
6717 test_80() { # bug 10718
6718         remote_ost_nodsh && skip "remote OST with nodsh" && return
6719         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6720         # relax strong synchronous semantics for slow backends like ZFS
6721         local soc="obdfilter.*.sync_on_lock_cancel"
6722         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6723         local hosts=
6724         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6725                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6726                           facet_active_host $host; done | sort -u)
6727                 do_nodes $hosts lctl set_param $soc=never
6728         fi
6729
6730         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6731         sync; sleep 1; sync
6732         local BEFORE=`date +%s`
6733         cancel_lru_locks osc
6734         local AFTER=`date +%s`
6735         local DIFF=$((AFTER-BEFORE))
6736         if [ $DIFF -gt 1 ] ; then
6737                 error "elapsed for 1M@1T = $DIFF"
6738         fi
6739
6740         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6741
6742         rm -f $DIR/$tfile
6743 }
6744 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6745
6746 test_81a() { # LU-456
6747         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6748         remote_ost_nodsh && skip "remote OST with nodsh" && return
6749         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6750         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6751         do_facet ost1 lctl set_param fail_loc=0x80000228
6752
6753         # write should trigger a retry and success
6754         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6755         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6756         RC=$?
6757         if [ $RC -ne 0 ] ; then
6758                 error "write should success, but failed for $RC"
6759         fi
6760 }
6761 run_test 81a "OST should retry write when get -ENOSPC ==============="
6762
6763 test_81b() { # LU-456
6764         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6765         remote_ost_nodsh && skip "remote OST with nodsh" && return
6766         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6767         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6768         do_facet ost1 lctl set_param fail_loc=0x228
6769
6770         # write should retry several times and return -ENOSPC finally
6771         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6772         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6773         RC=$?
6774         ENOSPC=28
6775         if [ $RC -ne $ENOSPC ] ; then
6776                 error "dd should fail for -ENOSPC, but succeed."
6777         fi
6778 }
6779 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6780
6781 test_82() { # LU-1031
6782         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6783         local gid1=14091995
6784         local gid2=16022000
6785
6786         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6787         local MULTIPID1=$!
6788         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6789         local MULTIPID2=$!
6790         kill -USR1 $MULTIPID2
6791         sleep 2
6792         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6793                 error "First grouplock does not block second one"
6794         else
6795                 echo "Second grouplock blocks first one"
6796         fi
6797         kill -USR1 $MULTIPID1
6798         wait $MULTIPID1
6799         wait $MULTIPID2
6800 }
6801 run_test 82 "Basic grouplock test ==============================="
6802
6803 test_83() {
6804         local sfile="/boot/System.map-$(uname -r)"
6805         # define OBD_FAIL_LLITE_PTASK_IO_FAIL 0x140d
6806         $LCTL set_param fail_loc=0x140d
6807         cp $sfile $DIR/$tfile || error "write failed"
6808         diff -c $sfile $DIR/$tfile || error "files are different"
6809         $LCTL set_param fail_loc=0
6810         rm -f $DIR/$tfile
6811 }
6812 run_test 83 "Short write in ptask ==============================="
6813
6814 test_99a() {
6815         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6816                 return
6817         test_mkdir -p $DIR/d99cvsroot
6818         chown $RUNAS_ID $DIR/d99cvsroot
6819         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6820         cd $TMP
6821
6822         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6823         cd $oldPWD
6824 }
6825 run_test 99a "cvs init ========================================="
6826
6827 test_99b() {
6828         [ -z "$(which cvs 2>/dev/null)" ] &&
6829                 skip_env "could not find cvs" && return
6830         [ ! -d $DIR/d99cvsroot ] && test_99a
6831         cd /etc/init.d
6832         # some versions of cvs import exit(1) when asked to import links or
6833         # files they can't read.  ignore those files.
6834         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6835                         ! -perm /4 -printf '-I %f\n')
6836         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6837                 d99reposname vtag rtag
6838 }
6839 run_test 99b "cvs import ======================================="
6840
6841 test_99c() {
6842         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6843         [ ! -d $DIR/d99cvsroot ] && test_99b
6844         cd $DIR
6845         test_mkdir -p $DIR/d99reposname
6846         chown $RUNAS_ID $DIR/d99reposname
6847         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6848 }
6849 run_test 99c "cvs checkout ====================================="
6850
6851 test_99d() {
6852         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6853         [ ! -d $DIR/d99cvsroot ] && test_99c
6854         cd $DIR/d99reposname
6855         $RUNAS touch foo99
6856         $RUNAS cvs add -m 'addmsg' foo99
6857 }
6858 run_test 99d "cvs add =========================================="
6859
6860 test_99e() {
6861         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6862         [ ! -d $DIR/d99cvsroot ] && test_99c
6863         cd $DIR/d99reposname
6864         $RUNAS cvs update
6865 }
6866 run_test 99e "cvs update ======================================="
6867
6868 test_99f() {
6869         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6870         [ ! -d $DIR/d99cvsroot ] && test_99d
6871         cd $DIR/d99reposname
6872         $RUNAS cvs commit -m 'nomsg' foo99
6873     rm -fr $DIR/d99cvsroot
6874 }
6875 run_test 99f "cvs commit ======================================="
6876
6877 test_100() {
6878         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6879         [[ "$NETTYPE" =~ tcp ]] ||
6880                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" &&
6881                         return ; }
6882
6883         remote_ost_nodsh && skip "remote OST with nodsh" && return
6884         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6885         remote_servers ||
6886                 { skip "useless for local single node setup" && return; }
6887
6888         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6889                 [ "$PROT" != "tcp" ] && continue
6890                 RPORT=$(echo $REMOTE | cut -d: -f2)
6891                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6892
6893                 rc=0
6894                 LPORT=`echo $LOCAL | cut -d: -f2`
6895                 if [ $LPORT -ge 1024 ]; then
6896                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6897                         netstat -tna
6898                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6899                 fi
6900         done
6901         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6902 }
6903 run_test 100 "check local port using privileged port ==========="
6904
6905 function get_named_value()
6906 {
6907     local tag
6908
6909     tag=$1
6910     while read ;do
6911         line=$REPLY
6912         case $line in
6913         $tag*)
6914             echo $line | sed "s/^$tag[ ]*//"
6915             break
6916             ;;
6917         esac
6918     done
6919 }
6920
6921 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6922                    awk '/^max_cached_mb/ { print $2 }')
6923
6924 cleanup_101a() {
6925         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6926         trap 0
6927 }
6928
6929 test_101a() {
6930         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6931         [ $MDSCOUNT -ge 2 ] && skip "needs < 2 MDTs" && return #LU-4322
6932         local s
6933         local discard
6934         local nreads=10000
6935         local cache_limit=32
6936
6937         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6938         trap cleanup_101a EXIT
6939         $LCTL set_param -n llite.*.read_ahead_stats 0
6940         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6941
6942         #
6943         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6944         #
6945         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6946         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6947
6948         discard=0
6949         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6950                 get_named_value 'read but discarded' | cut -d" " -f1); do
6951                         discard=$(($discard + $s))
6952         done
6953         cleanup_101a
6954
6955         if [[ $(($discard * 10)) -gt $nreads ]]; then
6956                 $LCTL get_param osc.*-osc*.rpc_stats
6957                 $LCTL get_param llite.*.read_ahead_stats
6958                 error "too many ($discard) discarded pages"
6959         fi
6960         rm -f $DIR/$tfile || true
6961 }
6962 run_test 101a "check read-ahead for random reads ================"
6963
6964 setup_test101bc() {
6965         test_mkdir -p $DIR/$tdir
6966         local STRIPE_SIZE=$1
6967         local FILE_LENGTH=$2
6968         STRIPE_OFFSET=0
6969
6970         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6971
6972         local list=$(comma_list $(osts_nodes))
6973         set_osd_param $list '' read_cache_enable 0
6974         set_osd_param $list '' writethrough_cache_enable 0
6975
6976         trap cleanup_test101bc EXIT
6977         # prepare the read-ahead file
6978         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6979
6980         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6981                                 count=$FILE_SIZE_MB 2> /dev/null
6982
6983 }
6984
6985 cleanup_test101bc() {
6986         trap 0
6987         rm -rf $DIR/$tdir
6988         rm -f $DIR/$tfile
6989
6990         local list=$(comma_list $(osts_nodes))
6991         set_osd_param $list '' read_cache_enable 1
6992         set_osd_param $list '' writethrough_cache_enable 1
6993 }
6994
6995 calc_total() {
6996         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6997 }
6998
6999 ra_check_101() {
7000         local READ_SIZE=$1
7001         local STRIPE_SIZE=$2
7002         local FILE_LENGTH=$3
7003         local RA_INC=1048576
7004         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
7005         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
7006                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
7007         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
7008                         get_named_value 'read but discarded' |
7009                         cut -d" " -f1 | calc_total)
7010         if [[ $DISCARD -gt $discard_limit ]]; then
7011                 $LCTL get_param llite.*.read_ahead_stats
7012                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
7013         else
7014                 echo "Read-ahead success for size ${READ_SIZE}"
7015         fi
7016 }
7017
7018 test_101b() {
7019         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7020         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7021         local STRIPE_SIZE=1048576
7022         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
7023         if [ $SLOW == "yes" ]; then
7024                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
7025         else
7026                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
7027         fi
7028
7029         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
7030
7031         # prepare the read-ahead file
7032         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
7033         cancel_lru_locks osc
7034         for BIDX in 2 4 8 16 32 64 128 256
7035         do
7036                 local BSIZE=$((BIDX*4096))
7037                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
7038                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
7039                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
7040                 $LCTL set_param -n llite.*.read_ahead_stats 0
7041                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
7042                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
7043                 cancel_lru_locks osc
7044                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
7045         done
7046         cleanup_test101bc
7047         true
7048 }
7049 run_test 101b "check stride-io mode read-ahead ================="
7050
7051 test_101c() {
7052         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7053         local STRIPE_SIZE=1048576
7054         local FILE_LENGTH=$((STRIPE_SIZE*100))
7055         local nreads=10000
7056         local osc_rpc_stats
7057
7058         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
7059
7060         cancel_lru_locks osc
7061         $LCTL set_param osc.*.rpc_stats 0
7062         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
7063         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
7064                 local stats=$($LCTL get_param -n $osc_rpc_stats)
7065                 local lines=$(echo "$stats" | awk 'END {print NR;}')
7066                 local size
7067
7068                 if [ $lines -le 20 ]; then
7069                         continue
7070                 fi
7071                 for size in 1 2 4 8; do
7072                         local rpc=$(echo "$stats" |
7073                                     awk '($1 == "'$size':") {print $2; exit; }')
7074                         [ $rpc != 0 ] &&
7075                                 error "Small $((size*4))k read IO $rpc !"
7076                 done
7077                 echo "$osc_rpc_stats check passed!"
7078         done
7079         cleanup_test101bc
7080         true
7081 }
7082 run_test 101c "check stripe_size aligned read-ahead ================="
7083
7084 set_read_ahead() {
7085         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
7086         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
7087 }
7088
7089 test_101d() {
7090         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7091         local file=$DIR/$tfile
7092         local sz_MB=${FILESIZE_101d:-500}
7093         local ra_MB=${READAHEAD_MB:-40}
7094
7095         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
7096         [ $free_MB -lt $sz_MB ] &&
7097                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
7098
7099         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
7100         $SETSTRIPE -c -1 $file || error "setstripe failed"
7101
7102         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
7103         echo Cancel LRU locks on lustre client to flush the client cache
7104         cancel_lru_locks osc
7105
7106         echo Disable read-ahead
7107         local old_READAHEAD=$(set_read_ahead 0)
7108
7109         echo Reading the test file $file with read-ahead disabled
7110         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
7111
7112         echo Cancel LRU locks on lustre client to flush the client cache
7113         cancel_lru_locks osc
7114         echo Enable read-ahead with ${ra_MB}MB
7115         set_read_ahead $ra_MB
7116
7117         echo Reading the test file $file with read-ahead enabled
7118         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
7119
7120         echo "read-ahead disabled time read $raOFF"
7121         echo "read-ahead enabled  time read $raON"
7122
7123         set_read_ahead $old_READAHEAD
7124         rm -f $file
7125         wait_delete_completed
7126
7127         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
7128                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
7129 }
7130 run_test 101d "file read with and without read-ahead enabled"
7131
7132 test_101e() {
7133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7134         local file=$DIR/$tfile
7135         local size_KB=500  #KB
7136         local count=100
7137         local bsize=1024
7138
7139         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
7140         local need_KB=$((count * size_KB))
7141         [[ $free_KB -le $need_KB ]] &&
7142                 skip_env "Need free space $need_KB, have $free_KB" && return
7143
7144         echo "Creating $count ${size_KB}K test files"
7145         for ((i = 0; i < $count; i++)); do
7146                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
7147         done
7148
7149         echo "Cancel LRU locks on lustre client to flush the client cache"
7150         cancel_lru_locks osc
7151
7152         echo "Reset readahead stats"
7153         $LCTL set_param -n llite.*.read_ahead_stats 0
7154
7155         for ((i = 0; i < $count; i++)); do
7156                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
7157         done
7158
7159         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
7160                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
7161
7162         for ((i = 0; i < $count; i++)); do
7163                 rm -rf $file.$i 2>/dev/null
7164         done
7165
7166         #10000 means 20% reads are missing in readahead
7167         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
7168 }
7169 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
7170
7171 test_101f() {
7172         which iozone || { skip "no iozone installed" && return; }
7173
7174         local old_debug=$($LCTL get_param debug)
7175         old_debug=${old_debug#*=}
7176         $LCTL set_param debug="reada mmap"
7177
7178         # create a test file
7179         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
7180
7181         echo Cancel LRU locks on lustre client to flush the client cache
7182         cancel_lru_locks osc
7183
7184         echo Reset readahead stats
7185         $LCTL set_param -n llite.*.read_ahead_stats 0
7186
7187         echo mmap read the file with small block size
7188         iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
7189                 > /dev/null 2>&1
7190
7191         echo checking missing pages
7192         $LCTL get_param llite.*.read_ahead_stats
7193         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
7194                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
7195
7196         $LCTL set_param debug="$old_debug"
7197         [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
7198         rm -f $DIR/$tfile
7199 }
7200 run_test 101f "check mmap read performance"
7201
7202 test_101g_brw_size_test() {
7203         local mb=$1
7204         local pages=$((mb * 1048576 / $(page_size)))
7205
7206         $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
7207                 { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
7208         for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
7209                 [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
7210                         return 2
7211         done
7212
7213         $LCTL set_param -n osc.*.rpc_stats=0
7214
7215         # 10 RPCs should be enough for the test
7216         local count=10
7217         dd if=/dev/zero of=$DIR/$tfile bs=${mb}M count=$count ||
7218                 { error "dd write ${mb} MB blocks failed"; return 3; }
7219         cancel_lru_locks osc
7220         dd of=/dev/null if=$DIR/$tfile bs=${mb}M count=$count ||
7221                 { error "dd write ${mb} MB blocks failed"; return 4; }
7222
7223         # calculate number of full-sized read and write RPCs
7224         rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
7225                 sed -n '/pages per rpc/,/^$/p' |
7226                 awk '/'$pages':/ { reads += $2; writes += $6 }; \
7227                 END { print reads,writes }'))
7228         [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
7229                 return 5
7230         [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
7231                 return 6
7232
7233         return 0
7234 }
7235
7236 test_101g() {
7237         local rpcs
7238         local osts=$(get_facets OST)
7239         local list=$(comma_list $(osts_nodes))
7240         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
7241         local brw_size="obdfilter.*.brw_size"
7242         local ostver=$(lustre_version_code ost1)
7243
7244         $LFS setstripe -i 0 -c 1 $DIR/$tfile
7245
7246         local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
7247         if [ $ostver -ge $(version_code 2.8.52) ] ||
7248            [ $ostver -ge $(version_code 2.7.17) -a \
7249              $ostver -lt $(version_code 2.7.50) ]; then
7250                 [ $ostver -ge $(version_code 2.9.52) ] && suffix="M"
7251                 if [[ $orig_mb -lt 16 ]]; then
7252                         save_lustre_params $osts "$brw_size" > $p
7253                         do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
7254                                 error "set 16MB RPC size failed"
7255
7256                         echo "remount client to enable new RPC size"
7257                         remount_client $MOUNT || error "remount_client failed"
7258                 fi
7259
7260                 test_101g_brw_size_test 16 || error "16MB RPC test failed"
7261                 # should be able to set brw_size=12, but no rpc_stats for that
7262                 test_101g_brw_size_test 8 || error "8MB RPC test failed"
7263         fi
7264
7265         test_101g_brw_size_test 4 || error "4MB RPC test failed"
7266
7267         if [[ $orig_mb -lt 16 ]]; then
7268                 restore_lustre_params < $p
7269                 remount_client $MOUNT || error "remount_client restore failed"
7270         fi
7271
7272         rm -f $p $DIR/$tfile
7273 }
7274 run_test 101g "Big bulk(4/16 MiB) readahead"
7275
7276 setup_test102() {
7277         test_mkdir $DIR/$tdir
7278         chown $RUNAS_ID $DIR/$tdir
7279         STRIPE_SIZE=65536
7280         STRIPE_OFFSET=1
7281         STRIPE_COUNT=$OSTCOUNT
7282         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
7283
7284         trap cleanup_test102 EXIT
7285         cd $DIR
7286         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
7287         cd $DIR/$tdir
7288         for num in 1 2 3 4; do
7289                 for count in $(seq 1 $STRIPE_COUNT); do
7290                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
7291                                 local size=`expr $STRIPE_SIZE \* $num`
7292                                 local file=file"$num-$idx-$count"
7293                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
7294                         done
7295                 done
7296         done
7297
7298         cd $DIR
7299         $1 tar cf $TMP/f102.tar $tdir --xattrs
7300 }
7301
7302 cleanup_test102() {
7303         trap 0
7304         rm -f $TMP/f102.tar
7305         rm -rf $DIR/d0.sanity/d102
7306 }
7307
7308 test_102a() {
7309         local testfile=$DIR/$tfile
7310
7311         touch $testfile
7312
7313         [ "$UID" != 0 ] && skip_env "must run as root" && return
7314         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
7315                 skip_env "must have user_xattr" && return
7316
7317         [ -z "$(which setfattr 2>/dev/null)" ] &&
7318                 skip_env "could not find setfattr" && return
7319
7320         echo "set/get xattr..."
7321         setfattr -n trusted.name1 -v value1 $testfile ||
7322                 error "setfattr -n trusted.name1=value1 $testfile failed"
7323         getfattr -n trusted.name1 $testfile 2> /dev/null |
7324           grep "trusted.name1=.value1" ||
7325                 error "$testfile missing trusted.name1=value1"
7326
7327         setfattr -n user.author1 -v author1 $testfile ||
7328                 error "setfattr -n user.author1=author1 $testfile failed"
7329         getfattr -n user.author1 $testfile 2> /dev/null |
7330           grep "user.author1=.author1" ||
7331                 error "$testfile missing trusted.author1=author1"
7332
7333         echo "listxattr..."
7334         setfattr -n trusted.name2 -v value2 $testfile ||
7335                 error "$testfile unable to set trusted.name2"
7336         setfattr -n trusted.name3 -v value3 $testfile ||
7337                 error "$testfile unable to set trusted.name3"
7338         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
7339             grep "trusted.name" | wc -l) -eq 3 ] ||
7340                 error "$testfile missing 3 trusted.name xattrs"
7341
7342         setfattr -n user.author2 -v author2 $testfile ||
7343                 error "$testfile unable to set user.author2"
7344         setfattr -n user.author3 -v author3 $testfile ||
7345                 error "$testfile unable to set user.author3"
7346         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
7347             grep "user.author" | wc -l) -eq 3 ] ||
7348                 error "$testfile missing 3 user.author xattrs"
7349
7350         echo "remove xattr..."
7351         setfattr -x trusted.name1 $testfile ||
7352                 error "$testfile error deleting trusted.name1"
7353         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
7354                 error "$testfile did not delete trusted.name1 xattr"
7355
7356         setfattr -x user.author1 $testfile ||
7357                 error "$testfile error deleting user.author1"
7358         echo "set lustre special xattr ..."
7359         $LFS setstripe -c1 $testfile
7360         local lovea=$(getfattr -n "trusted.lov" -e hex $testfile |
7361                 awk -F "=" '/trusted.lov/ { print $2 }' )
7362         setfattr -n "trusted.lov" -v $lovea $testfile ||
7363                 error "$testfile doesn't ignore setting trusted.lov again"
7364         setfattr -n "trusted.lov" -v "invalid_value" $testfile &&
7365                 error "$testfile allow setting invalid trusted.lov"
7366         rm -f $testfile
7367 }
7368 run_test 102a "user xattr test =================================="
7369
7370 test_102b() {
7371         [ -z "$(which setfattr 2>/dev/null)" ] &&
7372                 skip_env "could not find setfattr" && return
7373
7374         # b10930: get/set/list trusted.lov xattr
7375         echo "get/set/list trusted.lov xattr ..."
7376         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7377         local testfile=$DIR/$tfile
7378         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7379                 error "setstripe failed"
7380         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
7381                 error "getstripe failed"
7382         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
7383                 error "can't get trusted.lov from $testfile"
7384
7385         local testfile2=${testfile}2
7386         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
7387                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
7388
7389         $MCREATE $testfile2
7390         setfattr -n trusted.lov -v $value $testfile2
7391         local stripe_size=$($GETSTRIPE -S $testfile2)
7392         local stripe_count=$($GETSTRIPE -c $testfile2)
7393         [[ $stripe_size -eq 65536 ]] ||
7394                 error "stripe size $stripe_size != 65536"
7395         [[ $stripe_count -eq $STRIPECOUNT ]] ||
7396                 error "stripe count $stripe_count != $STRIPECOUNT"
7397         rm -f $DIR/$tfile
7398 }
7399 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
7400
7401 test_102c() {
7402         [ -z "$(which setfattr 2>/dev/null)" ] &&
7403                 skip_env "could not find setfattr" && return
7404
7405         # b10930: get/set/list lustre.lov xattr
7406         echo "get/set/list lustre.lov xattr ..."
7407         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7408         test_mkdir $DIR/$tdir
7409         chown $RUNAS_ID $DIR/$tdir
7410         local testfile=$DIR/$tdir/$tfile
7411         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7412                 error "setstripe failed"
7413         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
7414                 error "getstripe failed"
7415         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
7416         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
7417
7418         local testfile2=${testfile}2
7419         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
7420                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
7421
7422         $RUNAS $MCREATE $testfile2
7423         $RUNAS setfattr -n lustre.lov -v $value $testfile2
7424         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
7425         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
7426         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
7427         [ $stripe_count -eq $STRIPECOUNT ] ||
7428                 error "stripe count $stripe_count != $STRIPECOUNT"
7429 }
7430 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
7431
7432 compare_stripe_info1() {
7433         local stripe_index_all_zero=true
7434
7435         for num in 1 2 3 4; do
7436                 for count in $(seq 1 $STRIPE_COUNT); do
7437                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
7438                                 local size=$((STRIPE_SIZE * num))
7439                                 local file=file"$num-$offset-$count"
7440                                 stripe_size=$($LFS getstripe -S $PWD/$file)
7441                                 [[ $stripe_size -ne $size ]] &&
7442                                     error "$file: size $stripe_size != $size"
7443                                 stripe_count=$($LFS getstripe -c $PWD/$file)
7444                                 # allow fewer stripes to be created, ORI-601
7445                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
7446                                     error "$file: count $stripe_count != $count"
7447                                 stripe_index=$($LFS getstripe -i $PWD/$file)
7448                                 [[ $stripe_index -ne 0 ]] &&
7449                                         stripe_index_all_zero=false
7450                         done
7451                 done
7452         done
7453         $stripe_index_all_zero &&
7454                 error "all files are being extracted starting from OST index 0"
7455         return 0
7456 }
7457
7458 have_xattrs_include() {
7459         tar --help | grep -q xattrs-include &&
7460                 echo --xattrs-include="lustre.*"
7461 }
7462
7463 test_102d() {
7464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7465         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7466         local xinc=$(have_xattrs_include)
7467         setup_test102
7468         tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $xinc
7469         cd $DIR/$tdir/$tdir
7470         compare_stripe_info1
7471 }
7472 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
7473
7474 test_102f() {
7475         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7476         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7477         local xinc=$(have_xattrs_include)
7478         setup_test102
7479         test_mkdir $DIR/$tdir.restore
7480         cd $DIR
7481         tar cf - --xattrs $tdir | tar xf - \
7482                 -C $DIR/$tdir.restore --xattrs $xinc
7483         cd $DIR/$tdir.restore/$tdir
7484         compare_stripe_info1
7485 }
7486 run_test 102f "tar copy files, not keep osts ==========="
7487
7488 grow_xattr() {
7489         local xsize=${1:-1024}  # in bytes
7490         local file=$DIR/$tfile
7491
7492         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
7493                 skip "must have user_xattr" && return 0
7494         [ -z "$(which setfattr 2>/dev/null)" ] &&
7495                 skip_env "could not find setfattr" && return 0
7496         [ -z "$(which getfattr 2>/dev/null)" ] &&
7497                 skip_env "could not find getfattr" && return 0
7498
7499         touch $file
7500
7501         local value="$(generate_string $xsize)"
7502
7503         local xbig=trusted.big
7504         log "save $xbig on $file"
7505         setfattr -n $xbig -v $value $file ||
7506                 error "saving $xbig on $file failed"
7507
7508         local orig=$(get_xattr_value $xbig $file)
7509         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
7510
7511         local xsml=trusted.sml
7512         log "save $xsml on $file"
7513         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
7514
7515         local new=$(get_xattr_value $xbig $file)
7516         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
7517
7518         log "grow $xsml on $file"
7519         setfattr -n $xsml -v "$value" $file ||
7520                 error "growing $xsml on $file failed"
7521
7522         new=$(get_xattr_value $xbig $file)
7523         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
7524         log "$xbig still valid after growing $xsml"
7525
7526         rm -f $file
7527 }
7528
7529 test_102h() { # bug 15777
7530         grow_xattr 1024
7531 }
7532 run_test 102h "grow xattr from inside inode to external block"
7533
7534 test_102ha() {
7535         large_xattr_enabled || { skip "ea_inode feature disabled" && return; }
7536         grow_xattr $(max_xattr_size)
7537 }
7538 run_test 102ha "grow xattr from inside inode to external inode"
7539
7540 test_102i() { # bug 17038
7541         [ -z "$(which getfattr 2>/dev/null)" ] &&
7542                 skip "could not find getfattr" && return
7543         touch $DIR/$tfile
7544         ln -s $DIR/$tfile $DIR/${tfile}link
7545         getfattr -n trusted.lov $DIR/$tfile ||
7546                 error "lgetxattr on $DIR/$tfile failed"
7547         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
7548                 grep -i "no such attr" ||
7549                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
7550         rm -f $DIR/$tfile $DIR/${tfile}link
7551 }
7552 run_test 102i "lgetxattr test on symbolic link ============"
7553
7554 test_102j() {
7555         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7556         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7557         local xinc=$(have_xattrs_include)
7558         setup_test102 "$RUNAS"
7559         chown $RUNAS_ID $DIR/$tdir
7560         $RUNAS tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $xinc
7561         cd $DIR/$tdir/$tdir
7562         compare_stripe_info1 "$RUNAS"
7563 }
7564 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
7565
7566 test_102k() {
7567         [ -z "$(which setfattr 2>/dev/null)" ] &&
7568                 skip "could not find setfattr" && return
7569         touch $DIR/$tfile
7570         # b22187 just check that does not crash for regular file.
7571         setfattr -n trusted.lov $DIR/$tfile
7572         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
7573         local test_kdir=$DIR/$tdir
7574         test_mkdir $test_kdir
7575         local default_size=`$GETSTRIPE -S $test_kdir`
7576         local default_count=`$GETSTRIPE -c $test_kdir`
7577         local default_offset=`$GETSTRIPE -i $test_kdir`
7578         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
7579                 error 'dir setstripe failed'
7580         setfattr -n trusted.lov $test_kdir
7581         local stripe_size=`$GETSTRIPE -S $test_kdir`
7582         local stripe_count=`$GETSTRIPE -c $test_kdir`
7583         local stripe_offset=`$GETSTRIPE -i $test_kdir`
7584         [ $stripe_size -eq $default_size ] ||
7585                 error "stripe size $stripe_size != $default_size"
7586         [ $stripe_count -eq $default_count ] ||
7587                 error "stripe count $stripe_count != $default_count"
7588         [ $stripe_offset -eq $default_offset ] ||
7589                 error "stripe offset $stripe_offset != $default_offset"
7590         rm -rf $DIR/$tfile $test_kdir
7591 }
7592 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
7593
7594 test_102l() {
7595         [ -z "$(which getfattr 2>/dev/null)" ] &&
7596                 skip "could not find getfattr" && return
7597
7598         # LU-532 trusted. xattr is invisible to non-root
7599         local testfile=$DIR/$tfile
7600
7601         touch $testfile
7602
7603         echo "listxattr as user..."
7604         chown $RUNAS_ID $testfile
7605         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
7606             grep -q "trusted" &&
7607                 error "$testfile trusted xattrs are user visible"
7608
7609         return 0;
7610 }
7611 run_test 102l "listxattr size test =================================="
7612
7613 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
7614         local path=$DIR/$tfile
7615         touch $path
7616
7617         listxattr_size_check $path || error "listattr_size_check $path failed"
7618 }
7619 run_test 102m "Ensure listxattr fails on small bufffer ========"
7620
7621 cleanup_test102
7622
7623 getxattr() { # getxattr path name
7624         # Return the base64 encoding of the value of xattr name on path.
7625         local path=$1
7626         local name=$2
7627
7628         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
7629         # file: $path
7630         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7631         #
7632         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7633
7634         getfattr --absolute-names --encoding=base64 --name=$name $path |
7635                 awk -F= -v name=$name '$1 == name {
7636                         print substr($0, index($0, "=") + 1);
7637         }'
7638 }
7639
7640 test_102n() { # LU-4101 mdt: protect internal xattrs
7641         [ -z "$(which setfattr 2>/dev/null)" ] &&
7642                 skip "could not find setfattr" && return
7643         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
7644         then
7645                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
7646                 return
7647         fi
7648
7649         local file0=$DIR/$tfile.0
7650         local file1=$DIR/$tfile.1
7651         local xattr0=$TMP/$tfile.0
7652         local xattr1=$TMP/$tfile.1
7653         local namelist="lov lma lmv link fid version som hsm"
7654         local name
7655         local value
7656
7657         rm -rf $file0 $file1 $xattr0 $xattr1
7658         touch $file0 $file1
7659
7660         # Get 'before' xattrs of $file1.
7661         getfattr --absolute-names --dump --match=- $file1 > $xattr0
7662
7663         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
7664                 namelist+=" lfsck_namespace"
7665         for name in $namelist; do
7666                 # Try to copy xattr from $file0 to $file1.
7667                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7668
7669                 setfattr --name=trusted.$name --value="$value" $file1 ||
7670                         error "setxattr 'trusted.$name' failed"
7671
7672                 # Try to set a garbage xattr.
7673                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7674
7675                 if [[ x$name == "xlov" ]]; then
7676                         setfattr --name=trusted.lov --value="$value" $file1 &&
7677                         error "setxattr invalid 'trusted.lov' success"
7678                 else
7679                         setfattr --name=trusted.$name --value="$value" $file1 ||
7680                                 error "setxattr invalid 'trusted.$name' failed"
7681                 fi
7682
7683                 # Try to remove the xattr from $file1. We don't care if this
7684                 # appears to succeed or fail, we just don't want there to be
7685                 # any changes or crashes.
7686                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7687         done
7688
7689         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
7690         then
7691                 name="lfsck_ns"
7692                 # Try to copy xattr from $file0 to $file1.
7693                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7694
7695                 setfattr --name=trusted.$name --value="$value" $file1 ||
7696                         error "setxattr 'trusted.$name' failed"
7697
7698                 # Try to set a garbage xattr.
7699                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7700
7701                 setfattr --name=trusted.$name --value="$value" $file1 ||
7702                         error "setxattr 'trusted.$name' failed"
7703
7704                 # Try to remove the xattr from $file1. We don't care if this
7705                 # appears to succeed or fail, we just don't want there to be
7706                 # any changes or crashes.
7707                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7708         fi
7709
7710         # Get 'after' xattrs of file1.
7711         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7712
7713         if ! diff $xattr0 $xattr1; then
7714                 error "before and after xattrs of '$file1' differ"
7715         fi
7716
7717         rm -rf $file0 $file1 $xattr0 $xattr1
7718
7719         return 0
7720 }
7721 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7722
7723 test_102p() { # LU-4703 setxattr did not check ownership
7724         local testfile=$DIR/$tfile
7725
7726         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7727                 skip "MDS needs to be at least 2.5.56" && return
7728
7729         touch $testfile
7730
7731         echo "setfacl as user..."
7732         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7733         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7734
7735         echo "setfattr as user..."
7736         setfacl -m "u:$RUNAS_ID:---" $testfile
7737         $RUNAS setfattr -x system.posix_acl_access $testfile
7738         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7739 }
7740 run_test 102p "check setxattr(2) correctly fails without permission"
7741
7742 test_102q() {
7743         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7744                 skip "MDS needs to be at least 2.6.92" && return
7745         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7746 }
7747 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7748
7749 test_102r() {
7750         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7751                 skip "MDS needs to be at least 2.6.93" && return
7752         touch $DIR/$tfile || error "touch"
7753         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7754         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7755         rm $DIR/$tfile || error "rm"
7756
7757         #normal directory
7758         mkdir -p $DIR/$tdir || error "mkdir"
7759         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7760         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7761         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7762                 error "$testfile error deleting user.author1"
7763         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7764                 grep "user.$(basename $tdir)" &&
7765                 error "$tdir did not delete user.$(basename $tdir)"
7766         rmdir $DIR/$tdir || error "rmdir"
7767
7768         #striped directory
7769         test_mkdir $DIR/$tdir || error "make striped dir"
7770         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7771         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7772         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7773                 error "$testfile error deleting user.author1"
7774         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7775                 grep "user.$(basename $tdir)" &&
7776                 error "$tdir did not delete user.$(basename $tdir)"
7777         rmdir $DIR/$tdir || error "rm striped dir"
7778 }
7779 run_test 102r "set EAs with empty values"
7780
7781 test_102s() {
7782         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.52) ] &&
7783                 skip "MDS needs to be at least 2.11.52"
7784
7785         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
7786
7787         save_lustre_params client "llite.*.xattr_cache" > $save
7788
7789         for cache in 0 1; do
7790                 lctl set_param llite.*.xattr_cache=$cache
7791
7792                 rm -f $DIR/$tfile
7793                 touch $DIR/$tfile || error "touch"
7794                 for prefix in lustre security system trusted user; do
7795                         # Note getxattr() may fail with 'Operation not
7796                         # supported' or 'No such attribute' depending
7797                         # on prefix and cache.
7798                         getfattr -n $prefix.n102s $DIR/$tfile &&
7799                                 error "getxattr '$prefix.n102s' should fail (cache = $cache)"
7800                 done
7801         done
7802
7803         restore_lustre_params < $save
7804 }
7805 run_test 102s "getting nonexistent xattrs should fail"
7806
7807 run_acl_subtest()
7808 {
7809     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7810     return $?
7811 }
7812
7813 test_103a() {
7814         [ "$UID" != 0 ] && skip_env "must run as root" && return
7815         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7816                 skip "must have acl enabled" && return
7817         [ -z "$(which setfacl 2>/dev/null)" ] &&
7818                 skip_env "could not find setfacl" && return
7819         $GSS && skip "could not run under gss" && return
7820         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7821
7822         gpasswd -a daemon bin                           # LU-5641
7823         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7824
7825         declare -a identity_old
7826
7827         for num in $(seq $MDSCOUNT); do
7828                 switch_identity $num true || identity_old[$num]=$?
7829         done
7830
7831         SAVE_UMASK=$(umask)
7832         umask 0022
7833         mkdir -p $DIR/$tdir
7834         cd $DIR/$tdir
7835
7836         echo "performing cp ..."
7837         run_acl_subtest cp || error "run_acl_subtest cp failed"
7838         echo "performing getfacl-noacl..."
7839         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7840         echo "performing misc..."
7841         run_acl_subtest misc || error  "misc test failed"
7842         echo "performing permissions..."
7843         run_acl_subtest permissions || error "permissions failed"
7844         # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
7845         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.8.55) -o \
7846              \( $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6) -a \
7847              $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.29) \) ]
7848         then
7849                 echo "performing permissions xattr..."
7850                 run_acl_subtest permissions_xattr ||
7851                         error "permissions_xattr failed"
7852         fi
7853         echo "performing setfacl..."
7854         run_acl_subtest setfacl || error  "setfacl test failed"
7855
7856         # inheritance test got from HP
7857         echo "performing inheritance..."
7858         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7859         chmod +x make-tree || error "chmod +x failed"
7860         run_acl_subtest inheritance || error "inheritance test failed"
7861         rm -f make-tree
7862
7863         echo "LU-974 ignore umask when acl is enabled..."
7864         run_acl_subtest 974 || error "LU-974 umask test failed"
7865         if [ $MDSCOUNT -ge 2 ]; then
7866                 run_acl_subtest 974_remote ||
7867                         error "LU-974 umask test failed under remote dir"
7868         fi
7869
7870         echo "LU-2561 newly created file is same size as directory..."
7871         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7872                 run_acl_subtest 2561 || error "LU-2561 test failed"
7873         else
7874                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7875         fi
7876
7877         run_acl_subtest 4924 || error "LU-4924 test failed"
7878
7879         cd $SAVE_PWD
7880         umask $SAVE_UMASK
7881
7882         for num in $(seq $MDSCOUNT); do
7883                 if [ "${identity_old[$num]}" = 1 ]; then
7884                         switch_identity $num false || identity_old[$num]=$?
7885                 fi
7886         done
7887 }
7888 run_test 103a "acl test ========================================="
7889
7890 test_103b() {
7891         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7892         local noacl=false
7893         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7894         local mountopts=$MDS_MOUNT_OPTS
7895
7896         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7897                 noacl=true
7898         else
7899                 # stop the MDT
7900                 stop $SINGLEMDS || error "failed to stop MDT."
7901                 # remount the MDT
7902                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7903                         MDS_MOUNT_OPTS="-o noacl"
7904                 else
7905                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7906                 fi
7907                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7908                         error "failed to start MDT."
7909                 MDS_MOUNT_OPTS=$mountopts
7910         fi
7911
7912         touch $DIR/$tfile
7913         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7914
7915         if ! $noacl; then
7916                 # stop the MDT
7917                 stop $SINGLEMDS || error "failed to stop MDT."
7918                 # remount the MDT
7919                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7920                         error "failed to start MDT."
7921         fi
7922
7923         true
7924 }
7925 run_test 103b "MDS mount option 'noacl'"
7926
7927 test_103c() {
7928         mkdir -p $DIR/$tdir
7929         cp -rp $DIR/$tdir $DIR/$tdir.bak
7930
7931         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7932                 error "$DIR/$tdir shouldn't contain default ACL"
7933         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7934                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7935         true
7936 }
7937 run_test 103c "'cp -rp' won't set empty acl"
7938
7939 test_104a() {
7940         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7941         touch $DIR/$tfile
7942         lfs df || error "lfs df failed"
7943         lfs df -ih || error "lfs df -ih failed"
7944         lfs df -h $DIR || error "lfs df -h $DIR failed"
7945         lfs df -i $DIR || error "lfs df -i $DIR failed"
7946         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7947         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7948
7949         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7950         lctl --device %$OSC deactivate
7951         lfs df || error "lfs df with deactivated OSC failed"
7952         lctl --device %$OSC activate
7953         # wait the osc back to normal
7954         wait_osc_import_state client ost FULL
7955
7956         lfs df || error "lfs df with reactivated OSC failed"
7957         rm -f $DIR/$tfile
7958 }
7959 run_test 104a "lfs df [-ih] [path] test ========================="
7960
7961 test_104b() {
7962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7963         [ $RUNAS_ID -eq $UID ] &&
7964                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7965         chmod 666 /dev/obd
7966         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7967                         grep "Permission denied" | wc -l)))
7968         if [ $denied_cnt -ne 0 ]; then
7969                 error "lfs check servers test failed"
7970         fi
7971 }
7972 run_test 104b "$RUNAS lfs check servers test ===================="
7973
7974 test_105a() {
7975         # doesn't work on 2.4 kernels
7976         touch $DIR/$tfile
7977         if $(flock_is_enabled); then
7978                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7979         else
7980                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7981         fi
7982         rm -f $DIR/$tfile
7983 }
7984 run_test 105a "flock when mounted without -o flock test ========"
7985
7986 test_105b() {
7987         touch $DIR/$tfile
7988         if $(flock_is_enabled); then
7989                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7990         else
7991                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7992         fi
7993         rm -f $DIR/$tfile
7994 }
7995 run_test 105b "fcntl when mounted without -o flock test ========"
7996
7997 test_105c() {
7998         touch $DIR/$tfile
7999         if $(flock_is_enabled); then
8000                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
8001         else
8002                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
8003         fi
8004         rm -f $DIR/$tfile
8005 }
8006 run_test 105c "lockf when mounted without -o flock test ========"
8007
8008 test_105d() { # bug 15924
8009         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8010         test_mkdir -p $DIR/$tdir
8011         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
8012         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
8013         $LCTL set_param fail_loc=0x80000315
8014         flocks_test 2 $DIR/$tdir
8015 }
8016 run_test 105d "flock race (should not freeze) ========"
8017
8018 test_105e() { # bug 22660 && 22040
8019         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
8020         touch $DIR/$tfile
8021         flocks_test 3 $DIR/$tfile
8022 }
8023 run_test 105e "Two conflicting flocks from same process ======="
8024
8025 test_106() { #bug 10921
8026         test_mkdir -p $DIR/$tdir
8027         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
8028         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
8029 }
8030 run_test 106 "attempt exec of dir followed by chown of that dir"
8031
8032 test_107() {
8033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8034         CDIR=`pwd`
8035         cd $DIR
8036
8037         local file=core
8038         rm -f $file
8039
8040         local save_pattern=$(sysctl -n kernel.core_pattern)
8041         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
8042         sysctl -w kernel.core_pattern=$file
8043         sysctl -w kernel.core_uses_pid=0
8044
8045         ulimit -c unlimited
8046         sleep 60 &
8047         SLEEPPID=$!
8048
8049         sleep 1
8050
8051         kill -s 11 $SLEEPPID
8052         wait $SLEEPPID
8053         if [ -e $file ]; then
8054                 size=`stat -c%s $file`
8055                 [ $size -eq 0 ] && error "Fail to create core file $file"
8056         else
8057                 error "Fail to create core file $file"
8058         fi
8059         rm -f $file
8060         sysctl -w kernel.core_pattern=$save_pattern
8061         sysctl -w kernel.core_uses_pid=$save_uses_pid
8062         cd $CDIR
8063 }
8064 run_test 107 "Coredump on SIG"
8065
8066 test_110() {
8067         test_mkdir -p $DIR/$tdir
8068         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
8069                 error "mkdir with 255 char failed"
8070         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
8071                 error "mkdir with 256 char should fail, but did not"
8072         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
8073                 error "create with 255 char failed"
8074         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
8075                 error "create with 256 char should fail, but did not"
8076
8077         ls -l $DIR/$tdir
8078         rm -rf $DIR/$tdir
8079 }
8080 run_test 110 "filename length checking"
8081
8082 #
8083 # Purpose: To verify dynamic thread (OSS) creation.
8084 #
8085 test_115() {
8086         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8087         remote_ost_nodsh && skip "remote OST with nodsh" && return
8088
8089         # Lustre does not stop service threads once they are started.
8090         # Reset number of running threads to default.
8091         stopall
8092         setupall
8093
8094         local OSTIO_pre
8095         local save_params="$TMP/sanity-$TESTNAME.parameters"
8096
8097         # Get ll_ost_io count before I/O
8098         OSTIO_pre=$(do_facet ost1 \
8099                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
8100         # Exit if lustre is not running (ll_ost_io not running).
8101         [ -z "$OSTIO_pre" ] && error "no OSS threads"
8102
8103         echo "Starting with $OSTIO_pre threads"
8104         local thread_max=$((OSTIO_pre * 2))
8105         local rpc_in_flight=$((thread_max * 2))
8106         # Number of I/O Process proposed to be started.
8107         local nfiles
8108         local facets=$(get_facets OST)
8109
8110         save_lustre_params client \
8111                 "osc.*OST*.max_rpcs_in_flight" > $save_params
8112         save_lustre_params $facets \
8113                 "ost.OSS.ost_io.threads_max" >> $save_params
8114
8115         # Set in_flight to $rpc_in_flight
8116         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
8117                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
8118         nfiles=${rpc_in_flight}
8119         # Set ost thread_max to $thread_max
8120         do_facet ost1 \
8121                 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
8122
8123         # 5 Minutes should be sufficient for max number of OSS
8124         # threads(thread_max) to be created.
8125         local timeout=300
8126
8127         # Start I/O.
8128         local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
8129         mkdir -p $DIR/$tdir
8130         for i in $(seq $nfiles); do
8131                 local file=$DIR/$tdir/${tfile}-$i
8132                 $LFS setstripe -c -1 -i 0 $file
8133                 ($WTL $file $timeout)&
8134         done
8135
8136         # I/O Started - Wait for thread_started to reach thread_max or report
8137         # error if thread_started is more than thread_max.
8138         echo "Waiting for thread_started to reach thread_max"
8139         local thread_started=0
8140         local end_time=$((SECONDS + timeout))
8141
8142         while [ $SECONDS -le $end_time ] ; do
8143                 echo -n "."
8144                 # Get ost i/o thread_started count.
8145                 thread_started=$(do_facet ost1 \
8146                         "$LCTL get_param \
8147                         ost.OSS.ost_io.threads_started | cut -d= -f2")
8148                 # Break out if thread_started is equal/greater than thread_max
8149                 if [[ $thread_started -ge $thread_max ]]; then
8150                         echo ll_ost_io thread_started $thread_started, \
8151                                 equal/greater than thread_max $thread_max
8152                         break
8153                 fi
8154                 sleep 1
8155         done
8156
8157         # Cleanup - We have the numbers, Kill i/o jobs if running.
8158         jobcount=($(jobs -p))
8159         for i in $(seq 0 $((${#jobcount[@]}-1)))
8160         do
8161                 kill -9 ${jobcount[$i]}
8162                 if [ $? -ne 0 ] ; then
8163                         echo Warning: \
8164                         Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
8165                 fi
8166         done
8167
8168         # Cleanup files left by WTL binary.
8169         for i in $(seq $nfiles); do
8170                 local file=$DIR/$tdir/${tfile}-$i
8171                 rm -rf $file
8172                 if [ $? -ne 0 ] ; then
8173                         echo "Warning: Failed to delete file $file"
8174                 fi
8175         done
8176
8177         restore_lustre_params <$save_params
8178         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
8179
8180         # Error out if no new thread has started or Thread started is greater
8181         # than thread max.
8182         if [[ $thread_started -le $OSTIO_pre ||
8183                         $thread_started -gt $thread_max ]]; then
8184                 error "ll_ost_io: thread_started $thread_started" \
8185                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
8186                       "No new thread started or thread started greater " \
8187                       "than thread_max."
8188         fi
8189 }
8190 run_test 115 "verify dynamic thread creation===================="
8191
8192 free_min_max () {
8193         wait_delete_completed
8194         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
8195         echo "OST kbytes available: ${AVAIL[@]}"
8196         MAXV=${AVAIL[0]}
8197         MAXI=0
8198         MINV=${AVAIL[0]}
8199         MINI=0
8200         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
8201                 #echo OST $i: ${AVAIL[i]}kb
8202                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
8203                         MAXV=${AVAIL[i]}
8204                         MAXI=$i
8205                 fi
8206                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
8207                         MINV=${AVAIL[i]}
8208                         MINI=$i
8209                 fi
8210         done
8211         echo "Min free space: OST $MINI: $MINV"
8212         echo "Max free space: OST $MAXI: $MAXV"
8213 }
8214
8215 test_116a() { # was previously test_116()
8216         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8217         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8218
8219         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
8220
8221         echo -n "Free space priority "
8222         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
8223                 head -n1
8224         declare -a AVAIL
8225         free_min_max
8226
8227         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
8228         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
8229                 && return
8230         trap simple_cleanup_common EXIT
8231
8232
8233         # Check if we need to generate uneven OSTs
8234         test_mkdir -p $DIR/$tdir/OST${MINI}
8235         local FILL=$((MINV / 4))
8236         local DIFF=$((MAXV - MINV))
8237         local DIFF2=$((DIFF * 100 / MINV))
8238
8239         local threshold=$(do_facet $SINGLEMDS \
8240                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
8241         threshold=${threshold%%%}
8242         echo -n "Check for uneven OSTs: "
8243         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
8244
8245         if [[ $DIFF2 -gt $threshold ]]; then
8246                 echo "ok"
8247                 echo "Don't need to fill OST$MINI"
8248         else
8249                 # generate uneven OSTs. Write 2% over the QOS threshold value
8250                 echo "no"
8251                 DIFF=$((threshold - DIFF2 + 2))
8252                 DIFF2=$((MINV * DIFF / 100))
8253                 echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
8254                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
8255                         error "setstripe failed"
8256                 DIFF=$((DIFF2 / 2048))
8257                 i=0
8258                 while [ $i -lt $DIFF ]; do
8259                         i=$((i + 1))
8260                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
8261                                 bs=2M count=1 2>/dev/null
8262                         echo -n .
8263                 done
8264                 echo .
8265                 sync
8266                 sleep_maxage
8267                 free_min_max
8268         fi
8269
8270         DIFF=$((MAXV - MINV))
8271         DIFF2=$((DIFF * 100 / MINV))
8272         echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
8273         if [ $DIFF2 -gt $threshold ]; then
8274                 echo "ok"
8275         else
8276                 echo "failed - QOS mode won't be used"
8277                 skip "QOS imbalance criteria not met"
8278                 simple_cleanup_common
8279                 return
8280         fi
8281
8282         MINI1=$MINI
8283         MINV1=$MINV
8284         MAXI1=$MAXI
8285         MAXV1=$MAXV
8286
8287         # now fill using QOS
8288         $SETSTRIPE -c 1 $DIR/$tdir
8289         FILL=$((FILL / 200))
8290         if [ $FILL -gt 600 ]; then
8291                 FILL=600
8292         fi
8293         echo "writing $FILL files to QOS-assigned OSTs"
8294         i=0
8295         while [ $i -lt $FILL ]; do
8296                 i=$((i + 1))
8297                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
8298                         count=1 2>/dev/null
8299                 echo -n .
8300         done
8301         echo "wrote $i 200k files"
8302         sync
8303         sleep_maxage
8304
8305         echo "Note: free space may not be updated, so measurements might be off"
8306         free_min_max
8307         DIFF2=$((MAXV - MINV))
8308         echo "free space delta: orig $DIFF final $DIFF2"
8309         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
8310         DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
8311         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
8312         DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
8313         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
8314         if [[ $DIFF -gt 0 ]]; then
8315                 FILL=$((DIFF2 * 100 / DIFF - 100))
8316                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
8317         fi
8318
8319         # Figure out which files were written where
8320         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
8321                awk '/'$MINI1': / {print $2; exit}')
8322         echo $UUID
8323         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
8324         echo "$MINC files created on smaller OST $MINI1"
8325         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
8326                awk '/'$MAXI1': / {print $2; exit}')
8327         echo $UUID
8328         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
8329         echo "$MAXC files created on larger OST $MAXI1"
8330         if [[ $MINC -gt 0 ]]; then
8331                 FILL=$((MAXC * 100 / MINC - 100))
8332                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
8333         fi
8334         [[ $MAXC -gt $MINC ]] ||
8335                 error_ignore LU-9 "stripe QOS didn't balance free space"
8336         simple_cleanup_common
8337 }
8338 run_test 116a "stripe QOS: free space balance ==================="
8339
8340 test_116b() { # LU-2093
8341         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8342         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8343
8344 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
8345         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
8346                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
8347         [ -z "$old_rr" ] && skip "no QOS" && return 0
8348         do_facet $SINGLEMDS lctl set_param \
8349                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
8350         mkdir -p $DIR/$tdir
8351         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
8352         createmany -o $DIR/$tdir/f- 20 || error "can't create"
8353         do_facet $SINGLEMDS lctl set_param fail_loc=0
8354         rm -rf $DIR/$tdir
8355         do_facet $SINGLEMDS lctl set_param \
8356                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
8357 }
8358 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
8359
8360 test_117() # bug 10891
8361 {
8362         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8363         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
8364         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
8365         lctl set_param fail_loc=0x21e
8366         > $DIR/$tfile || error "truncate failed"
8367         lctl set_param fail_loc=0
8368         echo "Truncate succeeded."
8369         rm -f $DIR/$tfile
8370 }
8371 run_test 117 "verify osd extend =========="
8372
8373 NO_SLOW_RESENDCOUNT=4
8374 export OLD_RESENDCOUNT=""
8375 set_resend_count () {
8376         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
8377         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
8378         lctl set_param -n $PROC_RESENDCOUNT $1
8379         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
8380 }
8381
8382 # for reduce test_118* time (b=14842)
8383 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8384
8385 # Reset async IO behavior after error case
8386 reset_async() {
8387         FILE=$DIR/reset_async
8388
8389         # Ensure all OSCs are cleared
8390         $SETSTRIPE -c -1 $FILE
8391         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
8392         sync
8393         rm $FILE
8394 }
8395
8396 test_118a() #bug 11710
8397 {
8398         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8399         reset_async
8400
8401         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8402         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8403         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8404
8405         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8406                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8407                 return 1;
8408         fi
8409         rm -f $DIR/$tfile
8410 }
8411 run_test 118a "verify O_SYNC works =========="
8412
8413 test_118b()
8414 {
8415         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8416         remote_ost_nodsh && skip "remote OST with nodsh" && return
8417
8418         reset_async
8419
8420         #define OBD_FAIL_SRV_ENOENT 0x217
8421         set_nodes_failloc "$(osts_nodes)" 0x217
8422         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8423         RC=$?
8424         set_nodes_failloc "$(osts_nodes)" 0
8425         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8426         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8427                     grep -c writeback)
8428
8429         if [[ $RC -eq 0 ]]; then
8430                 error "Must return error due to dropped pages, rc=$RC"
8431                 return 1;
8432         fi
8433
8434         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8435                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8436                 return 1;
8437         fi
8438
8439         echo "Dirty pages not leaked on ENOENT"
8440
8441         # Due to the above error the OSC will issue all RPCs syncronously
8442         # until a subsequent RPC completes successfully without error.
8443         $MULTIOP $DIR/$tfile Ow4096yc
8444         rm -f $DIR/$tfile
8445
8446         return 0
8447 }
8448 run_test 118b "Reclaim dirty pages on fatal error =========="
8449
8450 test_118c()
8451 {
8452         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8453
8454         # for 118c, restore the original resend count, LU-1940
8455         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
8456                                 set_resend_count $OLD_RESENDCOUNT
8457         remote_ost_nodsh && skip "remote OST with nodsh" && return
8458
8459         reset_async
8460
8461         #define OBD_FAIL_OST_EROFS               0x216
8462         set_nodes_failloc "$(osts_nodes)" 0x216
8463
8464         # multiop should block due to fsync until pages are written
8465         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8466         MULTIPID=$!
8467         sleep 1
8468
8469         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8470                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8471         fi
8472
8473         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8474                     grep -c writeback)
8475         if [[ $WRITEBACK -eq 0 ]]; then
8476                 error "No page in writeback, writeback=$WRITEBACK"
8477         fi
8478
8479         set_nodes_failloc "$(osts_nodes)" 0
8480         wait $MULTIPID
8481         RC=$?
8482         if [[ $RC -ne 0 ]]; then
8483                 error "Multiop fsync failed, rc=$RC"
8484         fi
8485
8486         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8487         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8488                     grep -c writeback)
8489         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8490                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8491         fi
8492
8493         rm -f $DIR/$tfile
8494         echo "Dirty pages flushed via fsync on EROFS"
8495         return 0
8496 }
8497 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
8498
8499 # continue to use small resend count to reduce test_118* time (b=14842)
8500 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8501
8502 test_118d()
8503 {
8504         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8505         remote_ost_nodsh && skip "remote OST with nodsh" && return
8506
8507         reset_async
8508
8509         #define OBD_FAIL_OST_BRW_PAUSE_BULK
8510         set_nodes_failloc "$(osts_nodes)" 0x214
8511         # multiop should block due to fsync until pages are written
8512         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8513         MULTIPID=$!
8514         sleep 1
8515
8516         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8517                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8518         fi
8519
8520         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8521                     grep -c writeback)
8522         if [[ $WRITEBACK -eq 0 ]]; then
8523                 error "No page in writeback, writeback=$WRITEBACK"
8524         fi
8525
8526         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
8527         set_nodes_failloc "$(osts_nodes)" 0
8528
8529         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8530         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8531                     grep -c writeback)
8532         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8533                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8534         fi
8535
8536         rm -f $DIR/$tfile
8537         echo "Dirty pages gaurenteed flushed via fsync"
8538         return 0
8539 }
8540 run_test 118d "Fsync validation inject a delay of the bulk =========="
8541
8542 test_118f() {
8543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8544         reset_async
8545
8546         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
8547         lctl set_param fail_loc=0x8000040a
8548
8549         # Should simulate EINVAL error which is fatal
8550         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8551         RC=$?
8552         if [[ $RC -eq 0 ]]; then
8553                 error "Must return error due to dropped pages, rc=$RC"
8554         fi
8555
8556         lctl set_param fail_loc=0x0
8557
8558         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8559         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8560         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8561                     grep -c writeback)
8562         if [[ $LOCKED -ne 0 ]]; then
8563                 error "Locked pages remain in cache, locked=$LOCKED"
8564         fi
8565
8566         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8567                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8568         fi
8569
8570         rm -f $DIR/$tfile
8571         echo "No pages locked after fsync"
8572
8573         reset_async
8574         return 0
8575 }
8576 run_test 118f "Simulate unrecoverable OSC side error =========="
8577
8578 test_118g() {
8579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8580         reset_async
8581
8582         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
8583         lctl set_param fail_loc=0x406
8584
8585         # simulate local -ENOMEM
8586         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8587         RC=$?
8588
8589         lctl set_param fail_loc=0
8590         if [[ $RC -eq 0 ]]; then
8591                 error "Must return error due to dropped pages, rc=$RC"
8592         fi
8593
8594         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8595         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8596         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8597                         grep -c writeback)
8598         if [[ $LOCKED -ne 0 ]]; then
8599                 error "Locked pages remain in cache, locked=$LOCKED"
8600         fi
8601
8602         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8603                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8604         fi
8605
8606         rm -f $DIR/$tfile
8607         echo "No pages locked after fsync"
8608
8609         reset_async
8610         return 0
8611 }
8612 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
8613
8614 test_118h() {
8615         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8616         remote_ost_nodsh && skip "remote OST with nodsh" && return
8617
8618         reset_async
8619
8620         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8621         set_nodes_failloc "$(osts_nodes)" 0x20e
8622         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8623         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8624         RC=$?
8625
8626         set_nodes_failloc "$(osts_nodes)" 0
8627         if [[ $RC -eq 0 ]]; then
8628                 error "Must return error due to dropped pages, rc=$RC"
8629         fi
8630
8631         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8632         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8633         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8634                     grep -c writeback)
8635         if [[ $LOCKED -ne 0 ]]; then
8636                 error "Locked pages remain in cache, locked=$LOCKED"
8637         fi
8638
8639         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8640                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8641         fi
8642
8643         rm -f $DIR/$tfile
8644         echo "No pages locked after fsync"
8645
8646         return 0
8647 }
8648 run_test 118h "Verify timeout in handling recoverables errors  =========="
8649
8650 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8651
8652 test_118i() {
8653         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8654         remote_ost_nodsh && skip "remote OST with nodsh" && return
8655
8656         reset_async
8657
8658         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8659         set_nodes_failloc "$(osts_nodes)" 0x20e
8660
8661         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8662         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8663         PID=$!
8664         sleep 5
8665         set_nodes_failloc "$(osts_nodes)" 0
8666
8667         wait $PID
8668         RC=$?
8669         if [[ $RC -ne 0 ]]; then
8670                 error "got error, but should be not, rc=$RC"
8671         fi
8672
8673         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8674         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8675         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8676         if [[ $LOCKED -ne 0 ]]; then
8677                 error "Locked pages remain in cache, locked=$LOCKED"
8678         fi
8679
8680         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8681                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8682         fi
8683
8684         rm -f $DIR/$tfile
8685         echo "No pages locked after fsync"
8686
8687         return 0
8688 }
8689 run_test 118i "Fix error before timeout in recoverable error  =========="
8690
8691 [ "$SLOW" = "no" ] && set_resend_count 4
8692
8693 test_118j() {
8694         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8695         remote_ost_nodsh && skip "remote OST with nodsh" && return
8696
8697         reset_async
8698
8699         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
8700         set_nodes_failloc "$(osts_nodes)" 0x220
8701
8702         # return -EIO from OST
8703         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8704         RC=$?
8705         set_nodes_failloc "$(osts_nodes)" 0x0
8706         if [[ $RC -eq 0 ]]; then
8707                 error "Must return error due to dropped pages, rc=$RC"
8708         fi
8709
8710         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8711         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8712         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8713         if [[ $LOCKED -ne 0 ]]; then
8714                 error "Locked pages remain in cache, locked=$LOCKED"
8715         fi
8716
8717         # in recoverable error on OST we want resend and stay until it finished
8718         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8719                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8720         fi
8721
8722         rm -f $DIR/$tfile
8723         echo "No pages locked after fsync"
8724
8725         return 0
8726 }
8727 run_test 118j "Simulate unrecoverable OST side error =========="
8728
8729 test_118k()
8730 {
8731         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8732         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
8733
8734         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8735         set_nodes_failloc "$(osts_nodes)" 0x20e
8736         test_mkdir -p $DIR/$tdir
8737
8738         for ((i=0;i<10;i++)); do
8739                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
8740                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
8741                 SLEEPPID=$!
8742                 sleep 0.500s
8743                 kill $SLEEPPID
8744                 wait $SLEEPPID
8745         done
8746
8747         set_nodes_failloc "$(osts_nodes)" 0
8748         rm -rf $DIR/$tdir
8749 }
8750 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
8751
8752 test_118l()
8753 {
8754         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8755         # LU-646
8756         test_mkdir -p $DIR/$tdir
8757         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
8758         rm -rf $DIR/$tdir
8759 }
8760 run_test 118l "fsync dir ========="
8761
8762 test_118m() # LU-3066
8763 {
8764         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8765         test_mkdir -p $DIR/$tdir
8766         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
8767         rm -rf $DIR/$tdir
8768 }
8769 run_test 118m "fdatasync dir ========="
8770
8771 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8772
8773 test_119a() # bug 11737
8774 {
8775         BSIZE=$((512 * 1024))
8776         directio write $DIR/$tfile 0 1 $BSIZE
8777         # We ask to read two blocks, which is more than a file size.
8778         # directio will indicate an error when requested and actual
8779         # sizes aren't equeal (a normal situation in this case) and
8780         # print actual read amount.
8781         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
8782         if [ "$NOB" != "$BSIZE" ]; then
8783                 error "read $NOB bytes instead of $BSIZE"
8784         fi
8785         rm -f $DIR/$tfile
8786 }
8787 run_test 119a "Short directIO read must return actual read amount"
8788
8789 test_119b() # bug 11737
8790 {
8791         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
8792
8793         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
8794         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
8795         sync
8796         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
8797                 error "direct read failed"
8798         rm -f $DIR/$tfile
8799 }
8800 run_test 119b "Sparse directIO read must return actual read amount"
8801
8802 test_119c() # bug 13099
8803 {
8804         BSIZE=1048576
8805         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
8806         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
8807         rm -f $DIR/$tfile
8808 }
8809 run_test 119c "Testing for direct read hitting hole"
8810
8811 test_119d() # bug 15950
8812 {
8813         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8814         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
8815         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
8816         BSIZE=1048576
8817         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
8818         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
8819         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
8820         lctl set_param fail_loc=0x40d
8821         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
8822         pid_dio=$!
8823         sleep 1
8824         cat $DIR/$tfile > /dev/null &
8825         lctl set_param fail_loc=0
8826         pid_reads=$!
8827         wait $pid_dio
8828         log "the DIO writes have completed, now wait for the reads (should not block very long)"
8829         sleep 2
8830         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8831         error "the read rpcs have not completed in 2s"
8832         rm -f $DIR/$tfile
8833         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8834 }
8835 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8836
8837 test_120a() {
8838         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8839         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8840         test_mkdir -p $DIR/$tdir
8841         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8842                skip "no early lock cancel on server" && return 0
8843
8844         lru_resize_disable mdc
8845         lru_resize_disable osc
8846         cancel_lru_locks mdc
8847         # asynchronous object destroy at MDT could cause bl ast to client
8848         cancel_lru_locks osc
8849
8850         stat $DIR/$tdir > /dev/null
8851         can1=$(do_facet $SINGLEMDS \
8852                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8853                awk '/ldlm_cancel/ {print $2}')
8854         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8855                awk '/ldlm_bl_callback/ {print $2}')
8856         test_mkdir -c1 $DIR/$tdir/d1
8857         can2=$(do_facet $SINGLEMDS \
8858                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8859                awk '/ldlm_cancel/ {print $2}')
8860         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8861                awk '/ldlm_bl_callback/ {print $2}')
8862         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8863         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8864         lru_resize_enable mdc
8865         lru_resize_enable osc
8866 }
8867 run_test 120a "Early Lock Cancel: mkdir test"
8868
8869 test_120b() {
8870         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8871         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8872         test_mkdir $DIR/$tdir
8873         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8874                skip "no early lock cancel on server" && return 0
8875         lru_resize_disable mdc
8876         lru_resize_disable osc
8877         cancel_lru_locks mdc
8878         stat $DIR/$tdir > /dev/null
8879         can1=$(do_facet $SINGLEMDS \
8880                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8881                awk '/ldlm_cancel/ {print $2}')
8882         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8883                awk '/ldlm_bl_callback/ {print $2}')
8884         touch $DIR/$tdir/f1
8885         can2=$(do_facet $SINGLEMDS \
8886                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8887                awk '/ldlm_cancel/ {print $2}')
8888         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8889                awk '/ldlm_bl_callback/ {print $2}')
8890         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8891         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8892         lru_resize_enable mdc
8893         lru_resize_enable osc
8894 }
8895 run_test 120b "Early Lock Cancel: create test"
8896
8897 test_120c() {
8898         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8899         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8900         test_mkdir -c1 $DIR/$tdir
8901         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8902                skip "no early lock cancel on server" && return 0
8903         lru_resize_disable mdc
8904         lru_resize_disable osc
8905         test_mkdir -p -c1 $DIR/$tdir/d1
8906         test_mkdir -p -c1 $DIR/$tdir/d2
8907         touch $DIR/$tdir/d1/f1
8908         cancel_lru_locks mdc
8909         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8910         can1=$(do_facet $SINGLEMDS \
8911                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8912                awk '/ldlm_cancel/ {print $2}')
8913         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8914                awk '/ldlm_bl_callback/ {print $2}')
8915         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8916         can2=$(do_facet $SINGLEMDS \
8917                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8918                awk '/ldlm_cancel/ {print $2}')
8919         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8920                awk '/ldlm_bl_callback/ {print $2}')
8921         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8922         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8923         lru_resize_enable mdc
8924         lru_resize_enable osc
8925 }
8926 run_test 120c "Early Lock Cancel: link test"
8927
8928 test_120d() {
8929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8930         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8931         test_mkdir -p -c1 $DIR/$tdir
8932         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8933                skip "no early lock cancel on server" && return 0
8934         lru_resize_disable mdc
8935         lru_resize_disable osc
8936         touch $DIR/$tdir
8937         cancel_lru_locks mdc
8938         stat $DIR/$tdir > /dev/null
8939         can1=$(do_facet $SINGLEMDS \
8940                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8941                awk '/ldlm_cancel/ {print $2}')
8942         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8943                awk '/ldlm_bl_callback/ {print $2}')
8944         chmod a+x $DIR/$tdir
8945         can2=$(do_facet $SINGLEMDS \
8946                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8947                awk '/ldlm_cancel/ {print $2}')
8948         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8949                awk '/ldlm_bl_callback/ {print $2}')
8950         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8951         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8952         lru_resize_enable mdc
8953         lru_resize_enable osc
8954 }
8955 run_test 120d "Early Lock Cancel: setattr test"
8956
8957 test_120e() {
8958         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8959         ! $($LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_can) &&
8960                 skip "no early lock cancel on server" && return 0
8961         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8962         local dlmtrace_set=false
8963
8964         test_mkdir -p -c1 $DIR/$tdir
8965         lru_resize_disable mdc
8966         lru_resize_disable osc
8967         ! $LCTL get_param debug | grep -q dlmtrace &&
8968                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
8969         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8970         cancel_lru_locks mdc
8971         cancel_lru_locks osc
8972         dd if=$DIR/$tdir/f1 of=/dev/null
8973         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8974         # XXX client can not do early lock cancel of OST lock
8975         # during unlink (LU-4206), so cancel osc lock now.
8976         sleep 2
8977         cancel_lru_locks osc
8978         can1=$(do_facet $SINGLEMDS \
8979                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8980                awk '/ldlm_cancel/ {print $2}')
8981         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8982                awk '/ldlm_bl_callback/ {print $2}')
8983         unlink $DIR/$tdir/f1
8984         sleep 5
8985         can2=$(do_facet $SINGLEMDS \
8986                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8987                awk '/ldlm_cancel/ {print $2}')
8988         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8989                awk '/ldlm_bl_callback/ {print $2}')
8990         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
8991                 $LCTL dk $TMP/cancel.debug.txt
8992         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
8993                 $LCTL dk $TMP/blocking.debug.txt
8994         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
8995         lru_resize_enable mdc
8996         lru_resize_enable osc
8997 }
8998 run_test 120e "Early Lock Cancel: unlink test"
8999
9000 test_120f() {
9001         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9002         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
9003                skip "no early lock cancel on server" && return 0
9004         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9005         test_mkdir -p -c1 $DIR/$tdir
9006         lru_resize_disable mdc
9007         lru_resize_disable osc
9008         test_mkdir -p -c1 $DIR/$tdir/d1
9009         test_mkdir -p -c1 $DIR/$tdir/d2
9010         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
9011         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
9012         cancel_lru_locks mdc
9013         cancel_lru_locks osc
9014         dd if=$DIR/$tdir/d1/f1 of=/dev/null
9015         dd if=$DIR/$tdir/d2/f2 of=/dev/null
9016         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
9017         # XXX client can not do early lock cancel of OST lock
9018         # during rename (LU-4206), so cancel osc lock now.
9019         sleep 2
9020         cancel_lru_locks osc
9021         can1=$(do_facet $SINGLEMDS \
9022                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9023                awk '/ldlm_cancel/ {print $2}')
9024         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9025                awk '/ldlm_bl_callback/ {print $2}')
9026         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
9027         sleep 5
9028         can2=$(do_facet $SINGLEMDS \
9029                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9030                awk '/ldlm_cancel/ {print $2}')
9031         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9032                awk '/ldlm_bl_callback/ {print $2}')
9033         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9034         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9035         lru_resize_enable mdc
9036         lru_resize_enable osc
9037 }
9038 run_test 120f "Early Lock Cancel: rename test"
9039
9040 test_120g() {
9041         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9042         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
9043                skip "no early lock cancel on server" && return 0
9044         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9045         lru_resize_disable mdc
9046         lru_resize_disable osc
9047         count=10000
9048         echo create $count files
9049         test_mkdir -p $DIR/$tdir
9050         cancel_lru_locks mdc
9051         cancel_lru_locks osc
9052         t0=`date +%s`
9053
9054         can0=$(do_facet $SINGLEMDS \
9055                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9056                awk '/ldlm_cancel/ {print $2}')
9057         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9058                awk '/ldlm_bl_callback/ {print $2}')
9059         createmany -o $DIR/$tdir/f $count
9060         sync
9061         can1=$(do_facet $SINGLEMDS \
9062                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9063                awk '/ldlm_cancel/ {print $2}')
9064         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9065                awk '/ldlm_bl_callback/ {print $2}')
9066         t1=$(date +%s)
9067         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
9068         echo rm $count files
9069         rm -r $DIR/$tdir
9070         sync
9071         can2=$(do_facet $SINGLEMDS \
9072                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9073                awk '/ldlm_cancel/ {print $2}')
9074         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9075                awk '/ldlm_bl_callback/ {print $2}')
9076         t2=$(date +%s)
9077         echo total: $count removes in $((t2-t1))
9078         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
9079         sleep 2
9080         # wait for commitment of removal
9081         lru_resize_enable mdc
9082         lru_resize_enable osc
9083 }
9084 run_test 120g "Early Lock Cancel: performance test"
9085
9086 test_121() { #bug #10589
9087         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9088         rm -rf $DIR/$tfile
9089         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
9090 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
9091         lctl set_param fail_loc=0x310
9092         cancel_lru_locks osc > /dev/null
9093         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
9094         lctl set_param fail_loc=0
9095         [[ $reads -eq $writes ]] ||
9096                 error "read $reads blocks, must be $writes blocks"
9097 }
9098 run_test 121 "read cancel race ========="
9099
9100 test_123a() { # was test 123, statahead(bug 11401)
9101         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9102         SLOWOK=0
9103         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
9104             log "testing on UP system. Performance may be not as good as expected."
9105                         SLOWOK=1
9106         fi
9107
9108         rm -rf $DIR/$tdir
9109         test_mkdir -p $DIR/$tdir
9110         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
9111         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
9112         MULT=10
9113         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
9114                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
9115
9116                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
9117                 lctl set_param -n llite.*.statahead_max 0
9118                 lctl get_param llite.*.statahead_max
9119                 cancel_lru_locks mdc
9120                 cancel_lru_locks osc
9121                 stime=`date +%s`
9122                 time ls -l $DIR/$tdir | wc -l
9123                 etime=`date +%s`
9124                 delta=$((etime - stime))
9125                 log "ls $i files without statahead: $delta sec"
9126                 lctl set_param llite.*.statahead_max=$max
9127
9128                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
9129                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
9130                 cancel_lru_locks mdc
9131                 cancel_lru_locks osc
9132                 stime=`date +%s`
9133                 time ls -l $DIR/$tdir | wc -l
9134                 etime=`date +%s`
9135                 delta_sa=$((etime - stime))
9136                 log "ls $i files with statahead: $delta_sa sec"
9137                 lctl get_param -n llite.*.statahead_stats
9138                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
9139
9140                 [[ $swrong -lt $ewrong ]] &&
9141                         log "statahead was stopped, maybe too many locks held!"
9142                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
9143
9144                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
9145                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
9146                     lctl set_param -n llite.*.statahead_max 0
9147                     lctl get_param llite.*.statahead_max
9148                     cancel_lru_locks mdc
9149                     cancel_lru_locks osc
9150                     stime=`date +%s`
9151                     time ls -l $DIR/$tdir | wc -l
9152                     etime=`date +%s`
9153                     delta=$((etime - stime))
9154                     log "ls $i files again without statahead: $delta sec"
9155                     lctl set_param llite.*.statahead_max=$max
9156                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
9157                         if [  $SLOWOK -eq 0 ]; then
9158                                 error "ls $i files is slower with statahead!"
9159                         else
9160                                 log "ls $i files is slower with statahead!"
9161                         fi
9162                         break
9163                     fi
9164                 fi
9165
9166                 [ $delta -gt 20 ] && break
9167                 [ $delta -gt 8 ] && MULT=$((50 / delta))
9168                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
9169         done
9170         log "ls done"
9171
9172         stime=`date +%s`
9173         rm -r $DIR/$tdir
9174         sync
9175         etime=`date +%s`
9176         delta=$((etime - stime))
9177         log "rm -r $DIR/$tdir/: $delta seconds"
9178         log "rm done"
9179         lctl get_param -n llite.*.statahead_stats
9180 }
9181 run_test 123a "verify statahead work"
9182
9183 test_123b () { # statahead(bug 15027)
9184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9185         test_mkdir -p $DIR/$tdir
9186         createmany -o $DIR/$tdir/$tfile-%d 1000
9187
9188         cancel_lru_locks mdc
9189         cancel_lru_locks osc
9190
9191 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
9192         lctl set_param fail_loc=0x80000803
9193         ls -lR $DIR/$tdir > /dev/null
9194         log "ls done"
9195         lctl set_param fail_loc=0x0
9196         lctl get_param -n llite.*.statahead_stats
9197         rm -r $DIR/$tdir
9198         sync
9199
9200 }
9201 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
9202
9203 test_124a() {
9204         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9205         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
9206                 skip "no lru resize on server" && return 0
9207         local NR=2000
9208         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9209
9210         log "create $NR files at $DIR/$tdir"
9211         createmany -o $DIR/$tdir/f $NR ||
9212                 error "failed to create $NR files in $DIR/$tdir"
9213
9214         cancel_lru_locks mdc
9215         ls -l $DIR/$tdir > /dev/null
9216
9217         local NSDIR=""
9218         local LRU_SIZE=0
9219         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
9220                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
9221                 LRU_SIZE=$($LCTL get_param -n $PARAM)
9222                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
9223                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
9224                         log "NSDIR=$NSDIR"
9225                         log "NS=$(basename $NSDIR)"
9226                         break
9227                 fi
9228         done
9229
9230         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
9231                 skip "Not enough cached locks created!"
9232                 return 0
9233         fi
9234         log "LRU=$LRU_SIZE"
9235
9236         local SLEEP=30
9237
9238         # We know that lru resize allows one client to hold $LIMIT locks
9239         # for 10h. After that locks begin to be killed by client.
9240         local MAX_HRS=10
9241         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
9242         log "LIMIT=$LIMIT"
9243         if [ $LIMIT -lt $LRU_SIZE ]; then
9244             skip "Limit is too small $LIMIT"
9245             return 0
9246         fi
9247
9248         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
9249         # killing locks. Some time was spent for creating locks. This means
9250         # that up to the moment of sleep finish we must have killed some of
9251         # them (10-100 locks). This depends on how fast ther were created.
9252         # Many of them were touched in almost the same moment and thus will
9253         # be killed in groups.
9254         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
9255
9256         # Use $LRU_SIZE_B here to take into account real number of locks
9257         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
9258         local LRU_SIZE_B=$LRU_SIZE
9259         log "LVF=$LVF"
9260         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
9261         log "OLD_LVF=$OLD_LVF"
9262         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
9263
9264         # Let's make sure that we really have some margin. Client checks
9265         # cached locks every 10 sec.
9266         SLEEP=$((SLEEP+20))
9267         log "Sleep ${SLEEP} sec"
9268         local SEC=0
9269         while ((SEC<$SLEEP)); do
9270                 echo -n "..."
9271                 sleep 5
9272                 SEC=$((SEC+5))
9273                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
9274                 echo -n "$LRU_SIZE"
9275         done
9276         echo ""
9277         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
9278         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
9279
9280         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
9281                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
9282                 unlinkmany $DIR/$tdir/f $NR
9283                 return
9284         }
9285
9286         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
9287         log "unlink $NR files at $DIR/$tdir"
9288         unlinkmany $DIR/$tdir/f $NR
9289 }
9290 run_test 124a "lru resize ======================================="
9291
9292 get_max_pool_limit()
9293 {
9294         local limit=$($LCTL get_param \
9295                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
9296         local max=0
9297         for l in $limit; do
9298                 if [[ $l -gt $max ]]; then
9299                         max=$l
9300                 fi
9301         done
9302         echo $max
9303 }
9304
9305 test_124b() {
9306         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9307         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
9308                 skip "no lru resize on server" && return 0
9309
9310         LIMIT=$(get_max_pool_limit)
9311
9312         NR=$(($(default_lru_size)*20))
9313         if [[ $NR -gt $LIMIT ]]; then
9314                 log "Limit lock number by $LIMIT locks"
9315                 NR=$LIMIT
9316         fi
9317
9318         IFree=$(mdsrate_inodes_available)
9319         if [ $IFree -lt $NR ]; then
9320                 log "Limit lock number by $IFree inodes"
9321                 NR=$IFree
9322         fi
9323
9324         lru_resize_disable mdc
9325         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
9326                 error "failed to create $DIR/$tdir/disable_lru_resize"
9327
9328         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
9329         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
9330         cancel_lru_locks mdc
9331         stime=`date +%s`
9332         PID=""
9333         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9334         PID="$PID $!"
9335         sleep 2
9336         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9337         PID="$PID $!"
9338         sleep 2
9339         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9340         PID="$PID $!"
9341         wait $PID
9342         etime=`date +%s`
9343         nolruresize_delta=$((etime-stime))
9344         log "ls -la time: $nolruresize_delta seconds"
9345         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9346         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
9347
9348         lru_resize_enable mdc
9349         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
9350                 error "failed to create $DIR/$tdir/enable_lru_resize"
9351
9352         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
9353         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
9354         cancel_lru_locks mdc
9355         stime=`date +%s`
9356         PID=""
9357         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9358         PID="$PID $!"
9359         sleep 2
9360         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9361         PID="$PID $!"
9362         sleep 2
9363         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9364         PID="$PID $!"
9365         wait $PID
9366         etime=`date +%s`
9367         lruresize_delta=$((etime-stime))
9368         log "ls -la time: $lruresize_delta seconds"
9369         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9370
9371         if [ $lruresize_delta -gt $nolruresize_delta ]; then
9372                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
9373         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
9374                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
9375         else
9376                 log "lru resize performs the same with no lru resize"
9377         fi
9378         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
9379 }
9380 run_test 124b "lru resize (performance test) ======================="
9381
9382 test_124c() {
9383         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9384         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
9385                 skip "no lru resize on server" && return 0
9386
9387         # cache ununsed locks on client
9388         local nr=100
9389         cancel_lru_locks mdc
9390         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9391         createmany -o $DIR/$tdir/f $nr ||
9392                 error "failed to create $nr files in $DIR/$tdir"
9393         ls -l $DIR/$tdir > /dev/null
9394
9395         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9396         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9397         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
9398         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
9399         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
9400
9401         # set lru_max_age to 1 sec
9402         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
9403         echo "sleep $((recalc_p * 2)) seconds..."
9404         sleep $((recalc_p * 2))
9405
9406         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
9407         # restore lru_max_age
9408         $LCTL set_param -n $nsdir.lru_max_age $max_age
9409         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
9410         unlinkmany $DIR/$tdir/f $nr
9411 }
9412 run_test 124c "LRUR cancel very aged locks"
9413
9414 test_125() { # 13358
9415         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
9416         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
9417         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9418         test_mkdir -p $DIR/d125 || error "mkdir failed"
9419         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
9420         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
9421         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
9422 }
9423 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
9424
9425 test_126() { # bug 12829/13455
9426         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
9427         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
9428         $GSS && skip "must run as gss disabled" && return
9429
9430         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
9431         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
9432         rm -f $DIR/$tfile
9433         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
9434 }
9435 run_test 126 "check that the fsgid provided by the client is taken into account"
9436
9437 test_127a() { # bug 15521
9438         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9439         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
9440         $LCTL set_param osc.*.stats=0
9441         FSIZE=$((2048 * 1024))
9442         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9443         cancel_lru_locks osc
9444         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
9445
9446         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
9447         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9448                 echo "got $COUNT $NAME"
9449                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
9450                 eval $NAME=$COUNT || error "Wrong proc format"
9451
9452                 case $NAME in
9453                         read_bytes|write_bytes)
9454                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
9455                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
9456                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
9457                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
9458                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
9459                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
9460                                 error "sumsquare is too small: $SUMSQ"
9461                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
9462                                 error "sumsquare is too big: $SUMSQ"
9463                         ;;
9464                         *) ;;
9465                 esac
9466         done < $DIR/${tfile}.tmp
9467
9468         #check that we actually got some stats
9469         [ "$read_bytes" ] || error "Missing read_bytes stats"
9470         [ "$write_bytes" ] || error "Missing write_bytes stats"
9471         [ "$read_bytes" != 0 ] || error "no read done"
9472         [ "$write_bytes" != 0 ] || error "no write done"
9473 }
9474 run_test 127a "verify the client stats are sane"
9475
9476 test_127b() { # bug LU-333
9477         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9478         $LCTL set_param llite.*.stats=0
9479         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
9480         # perform 2 reads and writes so MAX is different from SUM.
9481         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9482         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9483         cancel_lru_locks osc
9484         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9485         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9486
9487         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
9488         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9489                 echo "got $COUNT $NAME"
9490                 eval $NAME=$COUNT || error "Wrong proc format"
9491
9492         case $NAME in
9493                 read_bytes)
9494                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9495                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9496                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9497                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9498                         ;;
9499                 write_bytes)
9500                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9501                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9502                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9503                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9504                         ;;
9505                         *) ;;
9506                 esac
9507         done < $TMP/${tfile}.tmp
9508
9509         #check that we actually got some stats
9510         [ "$read_bytes" ] || error "Missing read_bytes stats"
9511         [ "$write_bytes" ] || error "Missing write_bytes stats"
9512         [ "$read_bytes" != 0 ] || error "no read done"
9513         [ "$write_bytes" != 0 ] || error "no write done"
9514
9515         rm -f $TMP/${tfile}.tmp
9516 }
9517 run_test 127b "verify the llite client stats are sane"
9518
9519 test_128() { # bug 15212
9520         touch $DIR/$tfile
9521         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
9522                 find $DIR/$tfile
9523                 find $DIR/$tfile
9524         EOF
9525
9526         result=$(grep error $TMP/$tfile.log)
9527         rm -f $DIR/$tfile $TMP/$tfile.log
9528         [ -z "$result" ] ||
9529                 error "consecutive find's under interactive lfs failed"
9530 }
9531 run_test 128 "interactive lfs for 2 consecutive find's"
9532
9533 set_dir_limits () {
9534         local mntdev
9535         local canondev
9536         local node
9537
9538         local ldproc=/proc/fs/ldiskfs
9539         local facets=$(get_facets MDS)
9540
9541         for facet in ${facets//,/ }; do
9542                 canondev=$(ldiskfs_canon \
9543                            *.$(convert_facet2label $facet).mntdev $facet)
9544                 do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
9545                         ldproc=/sys/fs/ldiskfs
9546                 do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
9547                 do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
9548         done
9549 }
9550
9551 check_mds_dmesg() {
9552         local facets=$(get_facets MDS)
9553         for facet in ${facets//,/ }; do
9554                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
9555         done
9556         return 1
9557 }
9558
9559 test_129() {
9560         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.56) ]] ||
9561                 { skip "Need MDS version with at least 2.5.56"; return 0; }
9562
9563         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9564         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
9565                 skip "ldiskfs only test"
9566                 return
9567         fi
9568         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9569         local ENOSPC=28
9570         local EFBIG=27
9571         local has_warning=false
9572
9573         rm -rf $DIR/$tdir
9574         mkdir -p $DIR/$tdir
9575
9576         # block size of mds1
9577         local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
9578         set_dir_limits $maxsize $maxsize
9579         local dirsize=$(stat -c%s "$DIR/$tdir")
9580         local nfiles=0
9581         while [[ $dirsize -le $maxsize ]]; do
9582                 $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
9583                 rc=$?
9584                 if ! $has_warning; then
9585                         check_mds_dmesg '"is approaching"' && has_warning=true
9586                 fi
9587                 # check two errors:
9588                 # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
9589                 # EFBIG for previous versions included in ldiskfs series
9590                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
9591                         set_dir_limits 0 0
9592                         echo "return code $rc received as expected"
9593
9594                         createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
9595                                 error_exit "create failed w/o dir size limit"
9596
9597                         check_mds_dmesg '"has reached"' ||
9598                                 error_exit "reached message should be output"
9599
9600                         [ $has_warning = "false" ] &&
9601                                 error_exit "warning message should be output"
9602
9603                         dirsize=$(stat -c%s "$DIR/$tdir")
9604
9605                         [[ $dirsize -ge $maxsize ]] && return 0
9606                         error_exit "current dir size $dirsize, " \
9607                                    "previous limit $maxsize"
9608                 elif [ $rc -ne 0 ]; then
9609                         set_dir_limits 0 0
9610                         error_exit "return $rc received instead of expected " \
9611                                    "$EFBIG or $ENOSPC, files in dir $dirsize"
9612                 fi
9613                 nfiles=$((nfiles + 1))
9614                 dirsize=$(stat -c%s "$DIR/$tdir")
9615         done
9616
9617         set_dir_limits 0 0
9618         error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
9619 }
9620 run_test 129 "test directory size limit ========================"
9621
9622 OLDIFS="$IFS"
9623 cleanup_130() {
9624         trap 0
9625         IFS="$OLDIFS"
9626 }
9627
9628 test_130a() {
9629         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9630         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9631                 return
9632
9633         trap cleanup_130 EXIT RETURN
9634
9635         local fm_file=$DIR/$tfile
9636         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
9637         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
9638                 error "dd failed for $fm_file"
9639
9640         # LU-1795: test filefrag/FIEMAP once, even if unsupported
9641         filefrag -ves $fm_file
9642         RC=$?
9643         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9644                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9645         [ $RC != 0 ] && error "filefrag $fm_file failed"
9646
9647         filefrag_op=$(filefrag -ve $fm_file |
9648                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9649         lun=$($GETSTRIPE -i $fm_file)
9650
9651         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
9652         IFS=$'\n'
9653         tot_len=0
9654         for line in $filefrag_op
9655         do
9656                 frag_lun=`echo $line | cut -d: -f5`
9657                 ext_len=`echo $line | cut -d: -f4`
9658                 if (( $frag_lun != $lun )); then
9659                         cleanup_130
9660                         error "FIEMAP on 1-stripe file($fm_file) failed"
9661                         return
9662                 fi
9663                 (( tot_len += ext_len ))
9664         done
9665
9666         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
9667                 cleanup_130
9668                 error "FIEMAP on 1-stripe file($fm_file) failed;"
9669                 return
9670         fi
9671
9672         cleanup_130
9673
9674         echo "FIEMAP on single striped file succeeded"
9675 }
9676 run_test 130a "FIEMAP (1-stripe file)"
9677
9678 test_130b() {
9679         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
9680
9681         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9682         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9683                 return
9684
9685         trap cleanup_130 EXIT RETURN
9686
9687         local fm_file=$DIR/$tfile
9688         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9689                         error "setstripe on $fm_file"
9690         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9691                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9692
9693         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
9694                 error "dd failed on $fm_file"
9695
9696         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9697         filefrag_op=$(filefrag -ve $fm_file |
9698                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9699
9700         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9701                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9702
9703         IFS=$'\n'
9704         tot_len=0
9705         num_luns=1
9706         for line in $filefrag_op
9707         do
9708                 frag_lun=$(echo $line | cut -d: -f5 |
9709                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9710                 ext_len=$(echo $line | cut -d: -f4)
9711                 if (( $frag_lun != $last_lun )); then
9712                         if (( tot_len != 1024 )); then
9713                                 cleanup_130
9714                                 error "FIEMAP on $fm_file failed; returned " \
9715                                 "len $tot_len for OST $last_lun instead of 1024"
9716                                 return
9717                         else
9718                                 (( num_luns += 1 ))
9719                                 tot_len=0
9720                         fi
9721                 fi
9722                 (( tot_len += ext_len ))
9723                 last_lun=$frag_lun
9724         done
9725         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
9726                 cleanup_130
9727                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9728                         "luns or wrong len for OST $last_lun"
9729                 return
9730         fi
9731
9732         cleanup_130
9733
9734         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
9735 }
9736 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
9737
9738 test_130c() {
9739         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9740
9741         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9742         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9743                 return
9744
9745         trap cleanup_130 EXIT RETURN
9746
9747         local fm_file=$DIR/$tfile
9748         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
9749         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9750                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9751
9752         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
9753                         error "dd failed on $fm_file"
9754
9755         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9756         filefrag_op=$(filefrag -ve $fm_file |
9757                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9758
9759         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9760                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9761
9762         IFS=$'\n'
9763         tot_len=0
9764         num_luns=1
9765         for line in $filefrag_op
9766         do
9767                 frag_lun=$(echo $line | cut -d: -f5 |
9768                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9769                 ext_len=$(echo $line | cut -d: -f4)
9770                 if (( $frag_lun != $last_lun )); then
9771                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
9772                         if (( logical != 512 )); then
9773                                 cleanup_130
9774                                 error "FIEMAP on $fm_file failed; returned " \
9775                                 "logical start for lun $logical instead of 512"
9776                                 return
9777                         fi
9778                         if (( tot_len != 512 )); then
9779                                 cleanup_130
9780                                 error "FIEMAP on $fm_file failed; returned " \
9781                                 "len $tot_len for OST $last_lun instead of 1024"
9782                                 return
9783                         else
9784                                 (( num_luns += 1 ))
9785                                 tot_len=0
9786                         fi
9787                 fi
9788                 (( tot_len += ext_len ))
9789                 last_lun=$frag_lun
9790         done
9791         if (( num_luns != 2 || tot_len != 512 )); then
9792                 cleanup_130
9793                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9794                         "luns or wrong len for OST $last_lun"
9795                 return
9796         fi
9797
9798         cleanup_130
9799
9800         echo "FIEMAP on 2-stripe file with hole succeeded"
9801 }
9802 run_test 130c "FIEMAP (2-stripe file with hole)"
9803
9804 test_130d() {
9805         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
9806
9807         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9808         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9809                 return
9810
9811         trap cleanup_130 EXIT RETURN
9812
9813         local fm_file=$DIR/$tfile
9814         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9815                         error "setstripe on $fm_file"
9816         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9817                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9818
9819         local actual_stripe_count=$($GETSTRIPE -c $fm_file)
9820         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripe_count ||
9821                 error "dd failed on $fm_file"
9822
9823         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9824         filefrag_op=$(filefrag -ve $fm_file |
9825                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9826
9827         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9828                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9829
9830         IFS=$'\n'
9831         tot_len=0
9832         num_luns=1
9833         for line in $filefrag_op
9834         do
9835                 frag_lun=$(echo $line | cut -d: -f5 |
9836                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9837                 ext_len=$(echo $line | cut -d: -f4)
9838                 if (( $frag_lun != $last_lun )); then
9839                         if (( tot_len != 1024 )); then
9840                                 cleanup_130
9841                                 error "FIEMAP on $fm_file failed; returned " \
9842                                 "len $tot_len for OST $last_lun instead of 1024"
9843                                 return
9844                         else
9845                                 (( num_luns += 1 ))
9846                                 tot_len=0
9847                         fi
9848                 fi
9849                 (( tot_len += ext_len ))
9850                 last_lun=$frag_lun
9851         done
9852         if (( num_luns != actual_stripe_count || tot_len != 1024 )); then
9853                 cleanup_130
9854                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9855                         "luns or wrong len for OST $last_lun"
9856                 return
9857         fi
9858
9859         cleanup_130
9860
9861         echo "FIEMAP on N-stripe file succeeded"
9862 }
9863 run_test 130d "FIEMAP (N-stripe file)"
9864
9865 test_130e() {
9866         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9867
9868         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9869         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9870
9871         trap cleanup_130 EXIT RETURN
9872
9873         local fm_file=$DIR/$tfile
9874         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9875         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9876                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9877
9878         NUM_BLKS=512
9879         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9880         for ((i = 0; i < $NUM_BLKS; i++))
9881         do
9882                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9883         done
9884
9885         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9886         filefrag_op=$(filefrag -ve $fm_file |
9887                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9888
9889         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9890                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9891
9892         IFS=$'\n'
9893         tot_len=0
9894         num_luns=1
9895         for line in $filefrag_op
9896         do
9897                 frag_lun=$(echo $line | cut -d: -f5 |
9898                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9899                 ext_len=$(echo $line | cut -d: -f4)
9900                 if (( $frag_lun != $last_lun )); then
9901                         if (( tot_len != $EXPECTED_LEN )); then
9902                                 cleanup_130
9903                                 error "FIEMAP on $fm_file failed; returned " \
9904                                 "len $tot_len for OST $last_lun instead " \
9905                                 "of $EXPECTED_LEN"
9906                                 return
9907                         else
9908                                 (( num_luns += 1 ))
9909                                 tot_len=0
9910                         fi
9911                 fi
9912                 (( tot_len += ext_len ))
9913                 last_lun=$frag_lun
9914         done
9915         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9916                 cleanup_130
9917                 error "FIEMAP on $fm_file failed; returned wrong number " \
9918                         "of luns or wrong len for OST $last_lun"
9919                 return
9920         fi
9921
9922         cleanup_130
9923
9924         echo "FIEMAP with continuation calls succeeded"
9925 }
9926 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9927
9928 # Test for writev/readv
9929 test_131a() {
9930         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
9931                 error "writev test failed"
9932         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 ||
9933                 error "readv failed"
9934         rm -f $DIR/$tfile
9935 }
9936 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9937
9938 test_131b() {
9939         local fsize=$((524288 + 1048576 + 1572864))
9940         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 &&
9941                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9942                         error "append writev test failed"
9943
9944         ((fsize += 1572864 + 1048576))
9945         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 &&
9946                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9947                         error "append writev test failed"
9948         rm -f $DIR/$tfile
9949 }
9950 run_test 131b "test append writev"
9951
9952 test_131c() {
9953         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9954         error "NOT PASS"
9955 }
9956 run_test 131c "test read/write on file w/o objects"
9957
9958 test_131d() {
9959         rwv -f $DIR/$tfile -w -n 1 1572864
9960         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9961         if [ "$NOB" != 1572864 ]; then
9962                 error "Short read filed: read $NOB bytes instead of 1572864"
9963         fi
9964         rm -f $DIR/$tfile
9965 }
9966 run_test 131d "test short read"
9967
9968 test_131e() {
9969         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9970         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9971         error "read hitting hole failed"
9972         rm -f $DIR/$tfile
9973 }
9974 run_test 131e "test read hitting hole"
9975
9976 check_stats() {
9977         local facet=$1
9978         local op=$2
9979         local want=${3:-0}
9980         local res
9981
9982         case $facet in
9983         mds*) res=$(do_facet $facet \
9984                    $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
9985                  ;;
9986         ost*) res=$(do_facet $facet \
9987                    $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
9988                  ;;
9989         *) error "Wrong facet '$facet'" ;;
9990         esac
9991         echo $res
9992         [ "$res" ] || error "The counter for $op on $facet was not incremented"
9993         # if the argument $3 is zero, it means any stat increment is ok.
9994         if [[ $want -gt 0 ]]; then
9995                 local count=$(echo $res | awk '{ print $2 }')
9996                 [[ $count -ne $want ]] &&
9997                         error "The $op counter on $facet is $count, not $want"
9998         fi
9999 }
10000
10001 test_133a() {
10002         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10003         remote_ost_nodsh && skip "remote OST with nodsh" && return
10004         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10005
10006         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
10007                 { skip "MDS doesn't support rename stats"; return; }
10008         local testdir=$DIR/${tdir}/stats_testdir
10009         mkdir -p $DIR/${tdir}
10010
10011         # clear stats.
10012         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10013         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10014
10015         # verify mdt stats first.
10016         mkdir ${testdir} || error "mkdir failed"
10017         check_stats $SINGLEMDS "mkdir" 1
10018         touch ${testdir}/${tfile} || error "touch failed"
10019         check_stats $SINGLEMDS "open" 1
10020         check_stats $SINGLEMDS "close" 1
10021         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ] && {
10022                 mknod ${testdir}/${tfile}-pipe p || error "mknod failed"
10023                 check_stats $SINGLEMDS "mknod" 2
10024         }
10025         rm -f ${testdir}/${tfile}-pipe || error "pipe remove failed"
10026         check_stats $SINGLEMDS "unlink" 1
10027         rm -f ${testdir}/${tfile} || error "file remove failed"
10028         check_stats $SINGLEMDS "unlink" 2
10029
10030         # remove working dir and check mdt stats again.
10031         rmdir ${testdir} || error "rmdir failed"
10032         check_stats $SINGLEMDS "rmdir" 1
10033
10034         local testdir1=$DIR/${tdir}/stats_testdir1
10035         mkdir -p ${testdir}
10036         mkdir -p ${testdir1}
10037         touch ${testdir1}/test1
10038         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
10039         check_stats $SINGLEMDS "crossdir_rename" 1
10040
10041         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
10042         check_stats $SINGLEMDS "samedir_rename" 1
10043
10044         rm -rf $DIR/${tdir}
10045 }
10046 run_test 133a "Verifying MDT stats ========================================"
10047
10048 test_133b() {
10049         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10050         remote_ost_nodsh && skip "remote OST with nodsh" && return
10051         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10052         local testdir=$DIR/${tdir}/stats_testdir
10053         mkdir -p ${testdir} || error "mkdir failed"
10054         touch ${testdir}/${tfile} || error "touch failed"
10055         cancel_lru_locks mdc
10056
10057         # clear stats.
10058         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10059         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10060
10061         # extra mdt stats verification.
10062         chmod 444 ${testdir}/${tfile} || error "chmod failed"
10063         check_stats $SINGLEMDS "setattr" 1
10064         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10065         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
10066         then            # LU-1740
10067                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
10068                 check_stats $SINGLEMDS "getattr" 1
10069         fi
10070         $LFS df || error "lfs failed"
10071         check_stats $SINGLEMDS "statfs" 1
10072
10073         rm -rf $DIR/${tdir}
10074 }
10075 run_test 133b "Verifying extra MDT stats =================================="
10076
10077 test_133c() {
10078         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10079         remote_ost_nodsh && skip "remote OST with nodsh" && return
10080         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10081         local testdir=$DIR/${tdir}/stats_testdir
10082         test_mkdir -p ${testdir} || error "mkdir failed"
10083
10084         # verify obdfilter stats.
10085         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
10086         sync
10087         cancel_lru_locks osc
10088         wait_delete_completed
10089
10090         # clear stats.
10091         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10092         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10093
10094         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
10095         sync
10096         cancel_lru_locks osc
10097         check_stats ost1 "write" 1
10098
10099         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
10100         check_stats ost1 "read" 1
10101
10102         > ${testdir}/${tfile} || error "truncate failed"
10103         check_stats ost1 "punch" 1
10104
10105         rm -f ${testdir}/${tfile} || error "file remove failed"
10106         wait_delete_completed
10107         check_stats ost1 "destroy" 1
10108
10109         rm -rf $DIR/${tdir}
10110 }
10111 run_test 133c "Verifying OST stats ========================================"
10112
10113 order_2() {
10114         local value=$1
10115         local orig=$value
10116         local order=1
10117
10118         while [ $value -ge 2 ]; do
10119                 order=$((order*2))
10120                 value=$((value/2))
10121         done
10122
10123         if [ $orig -gt $order ]; then
10124                 order=$((order*2))
10125         fi
10126         echo $order
10127 }
10128
10129 size_in_KMGT() {
10130     local value=$1
10131     local size=('K' 'M' 'G' 'T');
10132     local i=0
10133     local size_string=$value
10134
10135     while [ $value -ge 1024 ]; do
10136         if [ $i -gt 3 ]; then
10137             #T is the biggest unit we get here, if that is bigger,
10138             #just return XXXT
10139             size_string=${value}T
10140             break
10141         fi
10142         value=$((value >> 10))
10143         if [ $value -lt 1024 ]; then
10144             size_string=${value}${size[$i]}
10145             break
10146         fi
10147         i=$((i + 1))
10148     done
10149
10150     echo $size_string
10151 }
10152
10153 get_rename_size() {
10154         local size=$1
10155         local context=${2:-.}
10156         local sample=$(do_facet $SINGLEMDS $LCTL \
10157                 get_param mdt.$FSNAME-MDT0000.rename_stats |
10158                 grep -A1 $context |
10159                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
10160         echo $sample
10161 }
10162
10163 test_133d() {
10164         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10165         remote_ost_nodsh && skip "remote OST with nodsh" && return
10166         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10167         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
10168         { skip "MDS doesn't support rename stats"; return; }
10169
10170         local testdir1=$DIR/${tdir}/stats_testdir1
10171         local testdir2=$DIR/${tdir}/stats_testdir2
10172         mkdir -p $DIR/${tdir}
10173
10174         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
10175
10176         lfs mkdir -i 0 -c 1 ${testdir1} || error "mkdir failed"
10177         lfs mkdir -i 0 -c 1 ${testdir2} || error "mkdir failed"
10178
10179         createmany -o $testdir1/test 512 || error "createmany failed"
10180
10181         # check samedir rename size
10182         mv ${testdir1}/test0 ${testdir1}/test_0
10183
10184         local testdir1_size=$(ls -l $DIR/${tdir} |
10185                 awk '/stats_testdir1/ {print $5}')
10186         local testdir2_size=$(ls -l $DIR/${tdir} |
10187                 awk '/stats_testdir2/ {print $5}')
10188
10189         testdir1_size=$(order_2 $testdir1_size)
10190         testdir2_size=$(order_2 $testdir2_size)
10191
10192         testdir1_size=$(size_in_KMGT $testdir1_size)
10193         testdir2_size=$(size_in_KMGT $testdir2_size)
10194
10195         echo "source rename dir size: ${testdir1_size}"
10196         echo "target rename dir size: ${testdir2_size}"
10197
10198         local cmd="do_facet $SINGLEMDS $LCTL "
10199         cmd+="get_param mdt.$FSNAME-MDT0000.rename_stats"
10200
10201         eval $cmd || error "$cmd failed"
10202         local samedir=$($cmd | grep 'same_dir')
10203         local same_sample=$(get_rename_size $testdir1_size)
10204         [ -z "$samedir" ] && error "samedir_rename_size count error"
10205         [[ $same_sample -eq 1 ]] ||
10206                 error "samedir_rename_size error $same_sample"
10207         echo "Check same dir rename stats success"
10208
10209         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
10210
10211         # check crossdir rename size
10212         mv ${testdir1}/test_0 ${testdir2}/test_0
10213
10214         testdir1_size=$(ls -l $DIR/${tdir} |
10215                 awk '/stats_testdir1/ {print $5}')
10216         testdir2_size=$(ls -l $DIR/${tdir} |
10217                 awk '/stats_testdir2/ {print $5}')
10218
10219         testdir1_size=$(order_2 $testdir1_size)
10220         testdir2_size=$(order_2 $testdir2_size)
10221
10222         testdir1_size=$(size_in_KMGT $testdir1_size)
10223         testdir2_size=$(size_in_KMGT $testdir2_size)
10224
10225         echo "source rename dir size: ${testdir1_size}"
10226         echo "target rename dir size: ${testdir2_size}"
10227
10228         eval $cmd || error "$cmd failed"
10229         local crossdir=$($cmd | grep 'crossdir')
10230         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
10231         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
10232         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
10233         [[ $src_sample -eq 1 ]] ||
10234                 error "crossdir_rename_size error $src_sample"
10235         [[ $tgt_sample -eq 1 ]] ||
10236                 error "crossdir_rename_size error $tgt_sample"
10237         echo "Check cross dir rename stats success"
10238         rm -rf $DIR/${tdir}
10239 }
10240 run_test 133d "Verifying rename_stats ========================================"
10241
10242 test_133e() {
10243         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10244         remote_ost_nodsh && skip "remote OST with nodsh" && return
10245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10246         local testdir=$DIR/${tdir}/stats_testdir
10247         local ctr f0 f1 bs=32768 count=42 sum
10248
10249         mkdir -p ${testdir} || error "mkdir failed"
10250
10251         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
10252
10253         for ctr in {write,read}_bytes; do
10254                 sync
10255                 cancel_lru_locks osc
10256
10257                 do_facet ost1 $LCTL set_param -n \
10258                         "obdfilter.*.exports.clear=clear"
10259
10260                 if [ $ctr = write_bytes ]; then
10261                         f0=/dev/zero
10262                         f1=${testdir}/${tfile}
10263                 else
10264                         f0=${testdir}/${tfile}
10265                         f1=/dev/null
10266                 fi
10267
10268                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
10269                         error "dd failed"
10270                 sync
10271                 cancel_lru_locks osc
10272
10273                 sum=$(do_facet ost1 $LCTL get_param \
10274                         "obdfilter.*.exports.*.stats" |
10275                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
10276                                 $1 == ctr { sum += $7 }
10277                                 END { printf("%0.0f", sum) }')
10278
10279                 if ((sum != bs * count)); then
10280                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
10281                 fi
10282         done
10283
10284         rm -rf $DIR/${tdir}
10285 }
10286 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
10287
10288 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
10289
10290 test_133f() {
10291         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10292         remote_ost_nodsh && skip "remote OST with nodsh" && return
10293         # First without trusting modes.
10294         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
10295         echo "proc_dirs='$proc_dirs'"
10296         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
10297         find $proc_dirs -exec cat '{}' \; &> /dev/null
10298
10299         # Second verifying readability.
10300         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
10301
10302         # eventually, this can also be replaced with "lctl get_param -R",
10303         # but not until that option is always available on the server
10304         local facet
10305         for facet in mds1 ost1; do
10306                 local facet_proc_dirs=$(do_facet $facet \
10307                                         \\\ls -d $proc_regexp 2>/dev/null)
10308                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10309                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10310                 do_facet $facet find $facet_proc_dirs \
10311                         ! -name req_history \
10312                         -exec cat '{}' \\\; &> /dev/null
10313
10314                 do_facet $facet find $facet_proc_dirs \
10315                         ! -name req_history \
10316                         -type f \
10317                         -exec cat '{}' \\\; &> /dev/null ||
10318                                 error "proc file read failed"
10319         done
10320 }
10321 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
10322
10323 test_133g() {
10324         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10325         remote_ost_nodsh && skip "remote OST with nodsh" && return
10326         # Second verifying writability.
10327         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
10328         echo "proc_dirs='$proc_dirs'"
10329         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
10330         find $proc_dirs \
10331                 -type f \
10332                 -not -name force_lbug \
10333                 -not -name changelog_mask \
10334                 -exec badarea_io '{}' \; &> /dev/null ||
10335                 error "find $proc_dirs failed"
10336
10337         local facet
10338         for facet in mds1 ost1; do
10339                 [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
10340                         skip "Too old lustre on $facet" && continue
10341                 local facet_proc_dirs=$(do_facet $facet \
10342                                         \\\ls -d $proc_regexp 2> /dev/null)
10343                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10344                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10345                 do_facet $facet find $facet_proc_dirs \
10346                         -type f \
10347                         -not -name force_lbug \
10348                         -not -name changelog_mask \
10349                         -exec badarea_io '{}' \\\; &> /dev/null ||
10350                                 error "$facet find $facet_proc_dirs failed"
10351         done
10352
10353         # remount the FS in case writes/reads /proc break the FS
10354         cleanup || error "failed to unmount"
10355         setup || error "failed to setup"
10356         true
10357 }
10358 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
10359
10360 test_133h() {
10361         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10362         remote_ost_nodsh && skip "remote OST with nodsh" && return
10363         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.54) ]] &&
10364                 skip "Need MDS version at least 2.9.54" && return
10365
10366         local facet
10367         for facet in client mds1 ost1; do
10368                 local facet_proc_dirs=$(do_facet $facet \
10369                                         \\\ls -d $proc_regexp 2> /dev/null)
10370                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10371                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10372                 # Get the list of files that are missing the terminating newline
10373                 local missing=($(do_facet $facet \
10374                         find ${facet_proc_dirs} -type f \|              \
10375                                 while read F\; do                       \
10376                                         awk -v FS='\v' -v RS='\v\v'     \
10377                                         "'END { if(NR>0 &&              \
10378                                         \\\$NF !~ /.*\\\n\$/)           \
10379                                                 print FILENAME}'"       \
10380                                         '\$F'\;                         \
10381                                 done 2>/dev/null))
10382                 [ ${#missing[*]} -eq 0 ] ||
10383                         error "files do not end with newline: ${missing[*]}"
10384         done
10385 }
10386 run_test 133h "Proc files should end with newlines"
10387
10388 test_134a() {
10389         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10390         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10391                 skip "Need MDS version at least 2.7.54" && return
10392
10393         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10394         cancel_lru_locks mdc
10395
10396         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
10397         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10398         [ $unused -eq 0 ] || error "$unused locks are not cleared"
10399
10400         local nr=1000
10401         createmany -o $DIR/$tdir/f $nr ||
10402                 error "failed to create $nr files in $DIR/$tdir"
10403         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10404
10405         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
10406         do_facet mds1 $LCTL set_param fail_loc=0x327
10407         do_facet mds1 $LCTL set_param fail_val=500
10408         touch $DIR/$tdir/m
10409
10410         echo "sleep 10 seconds ..."
10411         sleep 10
10412         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
10413
10414         do_facet mds1 $LCTL set_param fail_loc=0
10415         do_facet mds1 $LCTL set_param fail_val=0
10416         [ $lck_cnt -lt $unused ] ||
10417                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
10418
10419         rm $DIR/$tdir/m
10420         unlinkmany $DIR/$tdir/f $nr
10421 }
10422 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
10423
10424 test_134b() {
10425         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10426         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10427                 skip "Need MDS version at least 2.7.54" && return
10428
10429         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10430         cancel_lru_locks mdc
10431
10432         local low_wm=$(do_facet mds1 $LCTL get_param -n \
10433                         ldlm.lock_reclaim_threshold_mb)
10434         # disable reclaim temporarily
10435         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
10436
10437         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
10438         do_facet mds1 $LCTL set_param fail_loc=0x328
10439         do_facet mds1 $LCTL set_param fail_val=500
10440
10441         $LCTL set_param debug=+trace
10442
10443         local nr=600
10444         createmany -o $DIR/$tdir/f $nr &
10445         local create_pid=$!
10446
10447         echo "Sleep $TIMEOUT seconds ..."
10448         sleep $TIMEOUT
10449         if ! ps -p $create_pid  > /dev/null 2>&1; then
10450                 do_facet mds1 $LCTL set_param fail_loc=0
10451                 do_facet mds1 $LCTL set_param fail_val=0
10452                 do_facet mds1 $LCTL set_param \
10453                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
10454                 error "createmany finished incorrectly!"
10455         fi
10456         do_facet mds1 $LCTL set_param fail_loc=0
10457         do_facet mds1 $LCTL set_param fail_val=0
10458         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
10459         wait $create_pid || return 1
10460
10461         unlinkmany $DIR/$tdir/f $nr
10462 }
10463 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
10464
10465 test_140() { #bug-17379
10466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10467         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
10468         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
10469         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
10470
10471         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
10472         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
10473         local i=0
10474         while i=`expr $i + 1`; do
10475                 test_mkdir -p $i || error "Creating dir $i"
10476                 cd $i || error "Changing to $i"
10477                 ln -s ../stat stat || error "Creating stat symlink"
10478                 # Read the symlink until ELOOP present,
10479                 # not LBUGing the system is considered success,
10480                 # we didn't overrun the stack.
10481                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
10482                 [ $ret -ne 0 ] && {
10483                         if [ $ret -eq 40 ]; then
10484                                 break  # -ELOOP
10485                         else
10486                                 error "Open stat symlink"
10487                                 return
10488                         fi
10489                 }
10490         done
10491         i=`expr $i - 1`
10492         echo "The symlink depth = $i"
10493         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
10494                                         error "Invalid symlink depth"
10495
10496         # Test recursive symlink
10497         ln -s symlink_self symlink_self
10498         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
10499         echo "open symlink_self returns $ret"
10500         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
10501 }
10502 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
10503
10504 test_150() {
10505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10506         local TF="$TMP/$tfile"
10507
10508         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10509         cp $TF $DIR/$tfile
10510         cancel_lru_locks osc
10511         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
10512         remount_client $MOUNT
10513         df -P $MOUNT
10514         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
10515
10516         $TRUNCATE $TF 6000
10517         $TRUNCATE $DIR/$tfile 6000
10518         cancel_lru_locks osc
10519         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
10520
10521         echo "12345" >>$TF
10522         echo "12345" >>$DIR/$tfile
10523         cancel_lru_locks osc
10524         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
10525
10526         echo "12345" >>$TF
10527         echo "12345" >>$DIR/$tfile
10528         cancel_lru_locks osc
10529         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
10530
10531         rm -f $TF
10532         true
10533 }
10534 run_test 150 "truncate/append tests"
10535
10536 #LU-2902 roc_hit was not able to read all values from lproc
10537 function roc_hit_init() {
10538         local list=$(comma_list $(osts_nodes))
10539         local dir=$DIR/$tdir-check
10540         local file=$dir/file
10541         local BEFORE
10542         local AFTER
10543         local idx
10544
10545         test_mkdir -p $dir
10546         #use setstripe to do a write to every ost
10547         for i in $(seq 0 $((OSTCOUNT-1))); do
10548                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
10549                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
10550                 idx=$(printf %04x $i)
10551                 BEFORE=$(get_osd_param $list *OST*$idx stats |
10552                         awk '$1 == "cache_access" {sum += $7}
10553                                 END { printf("%0.0f", sum) }')
10554
10555                 cancel_lru_locks osc
10556                 cat $file >/dev/null
10557
10558                 AFTER=$(get_osd_param $list *OST*$idx stats |
10559                         awk '$1 == "cache_access" {sum += $7}
10560                                 END { printf("%0.0f", sum) }')
10561
10562                 echo BEFORE:$BEFORE AFTER:$AFTER
10563                 if ! let "AFTER - BEFORE == 4"; then
10564                         rm -rf $dir
10565                         error "roc_hit is not safe to use"
10566                 fi
10567                 rm $file
10568         done
10569
10570         rm -rf $dir
10571 }
10572
10573 function roc_hit() {
10574         local list=$(comma_list $(osts_nodes))
10575         echo $(get_osd_param $list '' stats |
10576                 awk '$1 == "cache_hit" {sum += $7}
10577                         END { printf("%0.0f", sum) }')
10578 }
10579
10580 function set_cache() {
10581         local on=1
10582
10583         if [ "$2" == "off" ]; then
10584                 on=0;
10585         fi
10586         local list=$(comma_list $(osts_nodes))
10587         set_osd_param $list '' $1_cache_enable $on
10588
10589         cancel_lru_locks osc
10590 }
10591
10592 test_151() {
10593         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10594         remote_ost_nodsh && skip "remote OST with nodsh" && return
10595
10596         local CPAGES=3
10597         local list=$(comma_list $(osts_nodes))
10598
10599         # check whether obdfilter is cache capable at all
10600         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
10601                 echo "not cache-capable obdfilter"
10602                 return 0
10603         fi
10604
10605         # check cache is enabled on all obdfilters
10606         if get_osd_param $list '' read_cache_enable | grep 0; then
10607                 echo "oss cache is disabled"
10608                 return 0
10609         fi
10610
10611         set_osd_param $list '' writethrough_cache_enable 1
10612
10613         # check write cache is enabled on all obdfilters
10614         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
10615                 echo "oss write cache is NOT enabled"
10616                 return 0
10617         fi
10618
10619         roc_hit_init
10620
10621         #define OBD_FAIL_OBD_NO_LRU  0x609
10622         do_nodes $list $LCTL set_param fail_loc=0x609
10623
10624         # pages should be in the case right after write
10625         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
10626                 error "dd failed"
10627
10628         local BEFORE=$(roc_hit)
10629         cancel_lru_locks osc
10630         cat $DIR/$tfile >/dev/null
10631         local AFTER=$(roc_hit)
10632
10633         do_nodes $list $LCTL set_param fail_loc=0
10634
10635         if ! let "AFTER - BEFORE == CPAGES"; then
10636                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10637         fi
10638
10639         # the following read invalidates the cache
10640         cancel_lru_locks osc
10641         set_osd_param $list '' read_cache_enable 0
10642         cat $DIR/$tfile >/dev/null
10643
10644         # now data shouldn't be found in the cache
10645         BEFORE=$(roc_hit)
10646         cancel_lru_locks osc
10647         cat $DIR/$tfile >/dev/null
10648         AFTER=$(roc_hit)
10649         if let "AFTER - BEFORE != 0"; then
10650                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10651         fi
10652
10653         set_osd_param $list '' read_cache_enable 1
10654         rm -f $DIR/$tfile
10655 }
10656 run_test 151 "test cache on oss and controls ==============================="
10657
10658 test_152() {
10659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10660         local TF="$TMP/$tfile"
10661
10662         # simulate ENOMEM during write
10663 #define OBD_FAIL_OST_NOMEM      0x226
10664         lctl set_param fail_loc=0x80000226
10665         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10666         cp $TF $DIR/$tfile
10667         sync || error "sync failed"
10668         lctl set_param fail_loc=0
10669
10670         # discard client's cache
10671         cancel_lru_locks osc
10672
10673         # simulate ENOMEM during read
10674         lctl set_param fail_loc=0x80000226
10675         cmp $TF $DIR/$tfile || error "cmp failed"
10676         lctl set_param fail_loc=0
10677
10678         rm -f $TF
10679 }
10680 run_test 152 "test read/write with enomem ============================"
10681
10682 test_153() {
10683         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
10684 }
10685 run_test 153 "test if fdatasync does not crash ======================="
10686
10687 dot_lustre_fid_permission_check() {
10688         local fid=$1
10689         local ffid=$MOUNT/.lustre/fid/$fid
10690         local test_dir=$2
10691
10692         echo "stat fid $fid"
10693         stat $ffid > /dev/null || error "stat $ffid failed."
10694         echo "touch fid $fid"
10695         touch $ffid || error "touch $ffid failed."
10696         echo "write to fid $fid"
10697         cat /etc/hosts > $ffid || error "write $ffid failed."
10698         echo "read fid $fid"
10699         diff /etc/hosts $ffid || error "read $ffid failed."
10700         echo "append write to fid $fid"
10701         cat /etc/hosts >> $ffid || error "append write $ffid failed."
10702         echo "rename fid $fid"
10703         mv $ffid $test_dir/$tfile.1 &&
10704                 error "rename $ffid to $tfile.1 should fail."
10705         touch $test_dir/$tfile.1
10706         mv $test_dir/$tfile.1 $ffid &&
10707                 error "rename $tfile.1 to $ffid should fail."
10708         rm -f $test_dir/$tfile.1
10709         echo "truncate fid $fid"
10710         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
10711         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
10712                 echo "link fid $fid"
10713                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
10714         fi
10715         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
10716                 echo "setfacl fid $fid"
10717                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
10718                 echo "getfacl fid $fid"
10719                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
10720         fi
10721         echo "unlink fid $fid"
10722         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
10723         echo "mknod fid $fid"
10724         mknod $ffid c 1 3 && error "mknod $ffid should fail."
10725
10726         fid=[0xf00000400:0x1:0x0]
10727         ffid=$MOUNT/.lustre/fid/$fid
10728
10729         echo "stat non-exist fid $fid"
10730         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
10731         echo "write to non-exist fid $fid"
10732         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
10733         echo "link new fid $fid"
10734         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
10735
10736         mkdir -p $test_dir/$tdir
10737         touch $test_dir/$tdir/$tfile
10738         fid=$($LFS path2fid $test_dir/$tdir)
10739         rc=$?
10740         [ $rc -ne 0 ] &&
10741                 error "error: could not get fid for $test_dir/$dir/$tfile."
10742
10743         ffid=$MOUNT/.lustre/fid/$fid
10744
10745         echo "ls $fid"
10746         ls $ffid > /dev/null || error "ls $ffid failed."
10747         echo "touch $fid/$tfile.1"
10748         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
10749
10750         echo "touch $MOUNT/.lustre/fid/$tfile"
10751         touch $MOUNT/.lustre/fid/$tfile && \
10752                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
10753
10754         echo "setxattr to $MOUNT/.lustre/fid"
10755         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
10756
10757         echo "listxattr for $MOUNT/.lustre/fid"
10758         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
10759
10760         echo "delxattr from $MOUNT/.lustre/fid"
10761         setfattr -x trusted.name1 $MOUNT/.lustre/fid
10762
10763         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
10764         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
10765                 error "touch invalid fid should fail."
10766
10767         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
10768         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
10769                 error "touch non-normal fid should fail."
10770
10771         echo "rename $tdir to $MOUNT/.lustre/fid"
10772         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
10773                 error "rename to $MOUNT/.lustre/fid should fail."
10774
10775         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
10776         then            # LU-3547
10777                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
10778                 local new_obf_mode=777
10779
10780                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
10781                 chmod $new_obf_mode $DIR/.lustre/fid ||
10782                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
10783
10784                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
10785                 [ $obf_mode -eq $new_obf_mode ] ||
10786                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
10787
10788                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
10789                 chmod $old_obf_mode $DIR/.lustre/fid ||
10790                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
10791         fi
10792
10793         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
10794         fid=$($LFS path2fid $test_dir/$tfile-2)
10795
10796         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
10797         then # LU-5424
10798                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
10799                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
10800                         error "create lov data thru .lustre failed"
10801         fi
10802         echo "cp /etc/passwd $test_dir/$tfile-2"
10803         cp /etc/passwd $test_dir/$tfile-2 ||
10804                 error "copy to $test_dir/$tfile-2 failed."
10805         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
10806         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
10807                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
10808
10809         rm -rf $test_dir/tfile.lnk
10810         rm -rf $test_dir/$tfile-2
10811 }
10812
10813 test_154A() {
10814         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10815                 skip "Need MDS version at least 2.4.1" && return
10816
10817         local tf=$DIR/$tfile
10818         touch $tf
10819
10820         local fid=$($LFS path2fid $tf)
10821         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
10822
10823         # check that we get the same pathname back
10824         local found=$($LFS fid2path $MOUNT "$fid")
10825         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
10826         [ "$found" == "$tf" ] ||
10827                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
10828 }
10829 run_test 154A "lfs path2fid and fid2path basic checks"
10830
10831 test_154B() {
10832         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10833                 skip "Need MDS version at least 2.4.1" && return
10834
10835         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
10836         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
10837         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
10838         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
10839
10840         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
10841         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
10842
10843         # check that we get the same pathname
10844         echo "PFID: $PFID, name: $name"
10845         local FOUND=$($LFS fid2path $MOUNT "$PFID")
10846         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
10847         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
10848                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
10849
10850         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
10851 }
10852 run_test 154B "verify the ll_decode_linkea tool"
10853
10854 test_154a() {
10855         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10856         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10857                 { skip "Need MDS version at least 2.2.51"; return 0; }
10858         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
10859         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10860
10861         cp /etc/hosts $DIR/$tfile
10862
10863         fid=$($LFS path2fid $DIR/$tfile)
10864         rc=$?
10865         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
10866
10867         dot_lustre_fid_permission_check "$fid" $DIR ||
10868                 error "dot lustre permission check $fid failed"
10869
10870         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
10871
10872         touch $MOUNT/.lustre/file &&
10873                 error "creation is not allowed under .lustre"
10874
10875         mkdir $MOUNT/.lustre/dir &&
10876                 error "mkdir is not allowed under .lustre"
10877
10878         rm -rf $DIR/$tfile
10879 }
10880 run_test 154a "Open-by-FID"
10881
10882 test_154b() {
10883         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10884         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10885                 { skip "Need MDS version at least 2.2.51"; return 0; }
10886         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10887
10888         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10889
10890         local remote_dir=$DIR/$tdir/remote_dir
10891         local MDTIDX=1
10892         local rc=0
10893
10894         mkdir -p $DIR/$tdir
10895         $LFS mkdir -i $MDTIDX $remote_dir ||
10896                 error "create remote directory failed"
10897
10898         cp /etc/hosts $remote_dir/$tfile
10899
10900         fid=$($LFS path2fid $remote_dir/$tfile)
10901         rc=$?
10902         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
10903
10904         dot_lustre_fid_permission_check "$fid" $remote_dir ||
10905                 error "dot lustre permission check $fid failed"
10906         rm -rf $DIR/$tdir
10907 }
10908 run_test 154b "Open-by-FID for remote directory"
10909
10910 test_154c() {
10911         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10912                 skip "Need MDS version at least 2.4.1" && return
10913
10914         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
10915         local FID1=$($LFS path2fid $DIR/$tfile.1)
10916         local FID2=$($LFS path2fid $DIR/$tfile.2)
10917         local FID3=$($LFS path2fid $DIR/$tfile.3)
10918
10919         local N=1
10920         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
10921                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
10922                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
10923                 local want=FID$N
10924                 [ "$FID" = "${!want}" ] ||
10925                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
10926                 N=$((N + 1))
10927         done
10928
10929         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10930         do
10931                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10932                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10933                 N=$((N + 1))
10934         done
10935 }
10936 run_test 154c "lfs path2fid and fid2path multiple arguments"
10937
10938 test_154d() {
10939         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10940         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10941                 skip "Need MDS version at least 2.5.53" && return
10942
10943         if remote_mds; then
10944                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10945         else
10946                 nid="0@lo"
10947         fi
10948         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10949         local fd
10950         local cmd
10951
10952         rm -f $DIR/$tfile
10953         touch $DIR/$tfile
10954
10955         local fid=$($LFS path2fid $DIR/$tfile)
10956         # Open the file
10957         fd=$(free_fd)
10958         cmd="exec $fd<$DIR/$tfile"
10959         eval $cmd
10960         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10961         echo "$fid_list" | grep "$fid"
10962         rc=$?
10963
10964         cmd="exec $fd>/dev/null"
10965         eval $cmd
10966         if [ $rc -ne 0 ]; then
10967                 error "FID $fid not found in open files list $fid_list"
10968         fi
10969 }
10970 run_test 154d "Verify open file fid"
10971
10972 test_154e()
10973 {
10974         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10975                 skip "Need MDS version at least 2.6.50" && return
10976
10977         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10978                 error ".lustre returned by readdir"
10979         fi
10980 }
10981 run_test 154e ".lustre is not returned by readdir"
10982
10983 test_154f() {
10984         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10985         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10986         test_mkdir -p -c1 $DIR/$tdir/d
10987         # test dirs inherit from its stripe
10988         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10989         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10990         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10991         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10992         touch $DIR/f
10993
10994         # get fid of parents
10995         local FID0=$($LFS path2fid $DIR/$tdir/d)
10996         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10997         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10998         local FID3=$($LFS path2fid $DIR)
10999
11000         # check that path2fid --parents returns expected <parent_fid>/name
11001         # 1) test for a directory (single parent)
11002         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
11003         [ "$parent" == "$FID0/foo1" ] ||
11004                 error "expected parent: $FID0/foo1, got: $parent"
11005
11006         # 2) test for a file with nlink > 1 (multiple parents)
11007         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
11008         echo "$parent" | grep -F "$FID1/$tfile" ||
11009                 error "$FID1/$tfile not returned in parent list"
11010         echo "$parent" | grep -F "$FID2/link" ||
11011                 error "$FID2/link not returned in parent list"
11012
11013         # 3) get parent by fid
11014         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
11015         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11016         echo "$parent" | grep -F "$FID1/$tfile" ||
11017                 error "$FID1/$tfile not returned in parent list (by fid)"
11018         echo "$parent" | grep -F "$FID2/link" ||
11019                 error "$FID2/link not returned in parent list (by fid)"
11020
11021         # 4) test for entry in root directory
11022         parent=$($LFS path2fid --parents $DIR/f)
11023         echo "$parent" | grep -F "$FID3/f" ||
11024                 error "$FID3/f not returned in parent list"
11025
11026         # 5) test it on root directory
11027         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
11028                 error "$MOUNT should not have parents"
11029
11030         # enable xattr caching and check that linkea is correctly updated
11031         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
11032         save_lustre_params client "llite.*.xattr_cache" > $save
11033         lctl set_param llite.*.xattr_cache 1
11034
11035         # 6.1) linkea update on rename
11036         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
11037
11038         # get parents by fid
11039         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11040         # foo1 should no longer be returned in parent list
11041         echo "$parent" | grep -F "$FID1" &&
11042                 error "$FID1 should no longer be in parent list"
11043         # the new path should appear
11044         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
11045                 error "$FID2/$tfile.moved is not in parent list"
11046
11047         # 6.2) linkea update on unlink
11048         rm -f $DIR/$tdir/d/foo2/link
11049         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11050         # foo2/link should no longer be returned in parent list
11051         echo "$parent" | grep -F "$FID2/link" &&
11052                 error "$FID2/link should no longer be in parent list"
11053         true
11054
11055         rm -f $DIR/f
11056         restore_lustre_params < $save
11057         rm -f $save
11058 }
11059 run_test 154f "get parent fids by reading link ea"
11060
11061 test_154g()
11062 {
11063         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) && \
11064            $(lustre_version_code client) -gt $(version_code 2.6.99) ]] ||
11065                 { skip "Need MDS version at least 2.6.92"; return 0; }
11066         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
11067
11068         mkdir -p $DIR/$tdir
11069         llapi_fid_test -d $DIR/$tdir
11070 }
11071 run_test 154g "various llapi FID tests"
11072
11073 test_155_small_load() {
11074     local temp=$TMP/$tfile
11075     local file=$DIR/$tfile
11076
11077     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
11078         error "dd of=$temp bs=6096 count=1 failed"
11079     cp $temp $file
11080     cancel_lru_locks osc
11081     cmp $temp $file || error "$temp $file differ"
11082
11083     $TRUNCATE $temp 6000
11084     $TRUNCATE $file 6000
11085     cmp $temp $file || error "$temp $file differ (truncate1)"
11086
11087     echo "12345" >>$temp
11088     echo "12345" >>$file
11089     cmp $temp $file || error "$temp $file differ (append1)"
11090
11091     echo "12345" >>$temp
11092     echo "12345" >>$file
11093     cmp $temp $file || error "$temp $file differ (append2)"
11094
11095     rm -f $temp $file
11096     true
11097 }
11098
11099 test_155_big_load() {
11100     remote_ost_nodsh && skip "remote OST with nodsh" && return
11101     local temp=$TMP/$tfile
11102     local file=$DIR/$tfile
11103
11104     free_min_max
11105     local cache_size=$(do_facet ost$((MAXI+1)) \
11106         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
11107     local large_file_size=$((cache_size * 2))
11108
11109     echo "OSS cache size: $cache_size KB"
11110     echo "Large file size: $large_file_size KB"
11111
11112     [ $MAXV -le $large_file_size ] && \
11113         skip_env "max available OST size needs > $large_file_size KB" && \
11114         return 0
11115
11116     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
11117
11118     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
11119         error "dd of=$temp bs=$large_file_size count=1k failed"
11120     cp $temp $file
11121     ls -lh $temp $file
11122     cancel_lru_locks osc
11123     cmp $temp $file || error "$temp $file differ"
11124
11125     rm -f $temp $file
11126     true
11127 }
11128
11129 save_writethrough() {
11130         local facets=$(get_facets OST)
11131
11132         save_lustre_params $facets "obdfilter.*.writethrough_cache_enable" > $1
11133         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" >> $1
11134 }
11135
11136 test_155a() {
11137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11138         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11139         save_writethrough $p
11140
11141         set_cache read on
11142         set_cache writethrough on
11143         test_155_small_load
11144         restore_lustre_params < $p
11145         rm -f $p
11146 }
11147 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
11148
11149 test_155b() {
11150         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11151         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11152         save_writethrough $p
11153
11154         set_cache read on
11155         set_cache writethrough off
11156         test_155_small_load
11157         restore_lustre_params < $p
11158         rm -f $p
11159 }
11160 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
11161
11162 test_155c() {
11163         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11164         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11165         save_writethrough $p
11166
11167         set_cache read off
11168         set_cache writethrough on
11169         test_155_small_load
11170         restore_lustre_params < $p
11171         rm -f $p
11172 }
11173 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
11174
11175 test_155d() {
11176         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11177         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11178         save_writethrough $p
11179
11180         set_cache read off
11181         set_cache writethrough off
11182         test_155_small_load
11183         restore_lustre_params < $p
11184         rm -f $p
11185 }
11186 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
11187
11188 test_155e() {
11189         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11190         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11191         save_writethrough $p
11192
11193         set_cache read on
11194         set_cache writethrough on
11195         test_155_big_load
11196         restore_lustre_params < $p
11197         rm -f $p
11198 }
11199 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
11200
11201 test_155f() {
11202         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11203         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11204         save_writethrough $p
11205
11206         set_cache read on
11207         set_cache writethrough off
11208         test_155_big_load
11209         restore_lustre_params < $p
11210         rm -f $p
11211 }
11212 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
11213
11214 test_155g() {
11215         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11216         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11217         save_writethrough $p
11218
11219         set_cache read off
11220         set_cache writethrough on
11221         test_155_big_load
11222         restore_lustre_params < $p
11223         rm -f $p
11224 }
11225 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
11226
11227 test_155h() {
11228         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11229         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11230         save_writethrough $p
11231
11232         set_cache read off
11233         set_cache writethrough off
11234         test_155_big_load
11235         restore_lustre_params < $p
11236         rm -f $p
11237 }
11238 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
11239
11240 test_156() {
11241         remote_ost_nodsh && skip "remote OST with nodsh" && return
11242         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11243         local CPAGES=3
11244         local BEFORE
11245         local AFTER
11246         local file="$DIR/$tfile"
11247         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11248
11249         [ "$(facet_fstype ost1)" = "zfs" -a \
11250            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
11251                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
11252                 return
11253
11254         save_writethrough $p
11255         roc_hit_init
11256
11257         log "Turn on read and write cache"
11258         set_cache read on
11259         set_cache writethrough on
11260
11261         log "Write data and read it back."
11262         log "Read should be satisfied from the cache."
11263         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11264         BEFORE=$(roc_hit)
11265         cancel_lru_locks osc
11266         cat $file >/dev/null
11267         AFTER=$(roc_hit)
11268         if ! let "AFTER - BEFORE == CPAGES"; then
11269                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11270         else
11271                 log "cache hits:: before: $BEFORE, after: $AFTER"
11272         fi
11273
11274         log "Read again; it should be satisfied from the cache."
11275         BEFORE=$AFTER
11276         cancel_lru_locks osc
11277         cat $file >/dev/null
11278         AFTER=$(roc_hit)
11279         if ! let "AFTER - BEFORE == CPAGES"; then
11280                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11281         else
11282                 log "cache hits:: before: $BEFORE, after: $AFTER"
11283         fi
11284
11285         log "Turn off the read cache and turn on the write cache"
11286         set_cache read off
11287         set_cache writethrough on
11288
11289         log "Read again; it should be satisfied from the cache."
11290         BEFORE=$(roc_hit)
11291         cancel_lru_locks osc
11292         cat $file >/dev/null
11293         AFTER=$(roc_hit)
11294         if ! let "AFTER - BEFORE == CPAGES"; then
11295                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11296         else
11297                 log "cache hits:: before: $BEFORE, after: $AFTER"
11298         fi
11299
11300         log "Read again; it should not be satisfied from the cache."
11301         BEFORE=$AFTER
11302         cancel_lru_locks osc
11303         cat $file >/dev/null
11304         AFTER=$(roc_hit)
11305         if ! let "AFTER - BEFORE == 0"; then
11306                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11307         else
11308                 log "cache hits:: before: $BEFORE, after: $AFTER"
11309         fi
11310
11311         log "Write data and read it back."
11312         log "Read should be satisfied from the cache."
11313         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11314         BEFORE=$(roc_hit)
11315         cancel_lru_locks osc
11316         cat $file >/dev/null
11317         AFTER=$(roc_hit)
11318         if ! let "AFTER - BEFORE == CPAGES"; then
11319                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11320         else
11321                 log "cache hits:: before: $BEFORE, after: $AFTER"
11322         fi
11323
11324         log "Read again; it should not be satisfied from the cache."
11325         BEFORE=$AFTER
11326         cancel_lru_locks osc
11327         cat $file >/dev/null
11328         AFTER=$(roc_hit)
11329         if ! let "AFTER - BEFORE == 0"; then
11330                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11331         else
11332                 log "cache hits:: before: $BEFORE, after: $AFTER"
11333         fi
11334
11335         log "Turn off read and write cache"
11336         set_cache read off
11337         set_cache writethrough off
11338
11339         log "Write data and read it back"
11340         log "It should not be satisfied from the cache."
11341         rm -f $file
11342         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11343         cancel_lru_locks osc
11344         BEFORE=$(roc_hit)
11345         cat $file >/dev/null
11346         AFTER=$(roc_hit)
11347         if ! let "AFTER - BEFORE == 0"; then
11348                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
11349         else
11350                 log "cache hits:: before: $BEFORE, after: $AFTER"
11351         fi
11352
11353         log "Turn on the read cache and turn off the write cache"
11354         set_cache read on
11355         set_cache writethrough off
11356
11357         log "Write data and read it back"
11358         log "It should not be satisfied from the cache."
11359         rm -f $file
11360         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11361         BEFORE=$(roc_hit)
11362         cancel_lru_locks osc
11363         cat $file >/dev/null
11364         AFTER=$(roc_hit)
11365         if ! let "AFTER - BEFORE == 0"; then
11366                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
11367         else
11368                 log "cache hits:: before: $BEFORE, after: $AFTER"
11369         fi
11370
11371         log "Read again; it should be satisfied from the cache."
11372         BEFORE=$(roc_hit)
11373         cancel_lru_locks osc
11374         cat $file >/dev/null
11375         AFTER=$(roc_hit)
11376         if ! let "AFTER - BEFORE == CPAGES"; then
11377                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11378         else
11379                 log "cache hits:: before: $BEFORE, after: $AFTER"
11380         fi
11381
11382         rm -f $file
11383         restore_lustre_params < $p
11384         rm -f $p
11385 }
11386 run_test 156 "Verification of tunables"
11387
11388 #Changelogs
11389 cleanup_changelog () {
11390         trap 0
11391         echo "Deregistering changelog client $CL_USER"
11392         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
11393 }
11394
11395 err17935 () {
11396         if [[ $MDSCOUNT -gt 1 ]]; then
11397                 error_ignore bz17935 $*
11398         else
11399                 error $*
11400         fi
11401 }
11402
11403 changelog_chmask()
11404 {
11405         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11406
11407         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
11408
11409         if [ $MASK -eq 1 ]; then
11410                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
11411         else
11412                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
11413         fi
11414 }
11415
11416 changelog_extract_field() {
11417         local mdt=$1
11418         local cltype=$2
11419         local file=$3
11420         local identifier=$4
11421
11422         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
11423                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
11424                 tail -1
11425 }
11426
11427 test_160a() {
11428         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11429         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11430         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11431                 { skip "Need MDS version at least 2.2.0"; return; }
11432
11433         local CL_USERS="mdd.$MDT0.changelog_users"
11434         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11435         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11436                 changelog_register -n)
11437         echo "Registered as changelog user $CL_USER"
11438         trap cleanup_changelog EXIT
11439         $GET_CL_USERS | grep -q $CL_USER ||
11440                 error "User $CL_USER not found in changelog_users"
11441
11442         # change something
11443         test_mkdir -p $DIR/$tdir/pics/2008/zachy
11444         touch $DIR/$tdir/pics/2008/zachy/timestamp
11445         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
11446         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
11447         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
11448         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
11449         rm $DIR/$tdir/pics/desktop.jpg
11450
11451         $LFS changelog $MDT0 | tail -5
11452
11453         echo "verifying changelog mask"
11454         changelog_chmask "MKDIR"
11455         changelog_chmask "CLOSE"
11456
11457         test_mkdir -p $DIR/$tdir/pics/zach/sofia
11458         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11459
11460         changelog_chmask "MKDIR"
11461         changelog_chmask "CLOSE"
11462
11463         test_mkdir -p $DIR/$tdir/pics/2008/sofia
11464         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11465
11466         $LFS changelog $MDT0
11467         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
11468         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
11469         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
11470         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
11471
11472         # verify contents
11473         echo "verifying target fid"
11474         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
11475         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
11476         [ "$fidc" == "$fidf" ] ||
11477                 err17935 "fid in changelog $fidc != file fid $fidf"
11478         echo "verifying parent fid"
11479         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
11480         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
11481         [ "$fidc" == "$fidf" ] ||
11482                 err17935 "pfid in changelog $fidc != dir fid $fidf"
11483
11484         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11485         $LFS changelog_clear $MDT0 $CL_USER $(($USER_REC1 + 5))
11486         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11487         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
11488         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
11489                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
11490
11491         MIN_REC=$($GET_CL_USERS |
11492                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
11493         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
11494         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
11495         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
11496                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
11497
11498         # LU-3446 changelog index reset on MDT restart
11499         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11500         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11501         $LFS changelog_clear $MDT0 $CL_USER 0
11502         stop $SINGLEMDS || error "Fail to stop MDT."
11503         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11504         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11505         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
11506         [ $CUR_REC1 == $CUR_REC2 ] ||
11507                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
11508
11509         echo "verifying user deregister"
11510         cleanup_changelog
11511         $GET_CL_USERS | grep -q $CL_USER &&
11512                 error "User $CL_USER still in changelog_users"
11513
11514         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
11515         if [ $CL_USER -eq 0 ]; then
11516                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11517                 touch $DIR/$tdir/chloe
11518                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11519                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
11520                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
11521         else
11522                 echo "$CL_USER other changelog users; can't verify off"
11523         fi
11524 }
11525 run_test 160a "changelog sanity"
11526
11527 test_160b() { # LU-3587
11528         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11529         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11530         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11531                 { skip "Need MDS version at least 2.2.0"; return; }
11532
11533         local CL_USERS="mdd.$MDT0.changelog_users"
11534         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11535         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11536                 changelog_register -n)
11537         echo "Registered as changelog user $CL_USER"
11538         trap cleanup_changelog EXIT
11539         $GET_CL_USERS | grep -q $CL_USER ||
11540                 error "User $CL_USER not found in changelog_users"
11541
11542         local LONGNAME1=$(str_repeat a 255)
11543         local LONGNAME2=$(str_repeat b 255)
11544
11545         cd $DIR
11546         echo "creating very long named file"
11547         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
11548         echo "moving very long named file"
11549         mv $LONGNAME1 $LONGNAME2
11550
11551         $LFS changelog $MDT0 | grep RENME
11552         rm -f $LONGNAME2
11553         cleanup_changelog
11554 }
11555 run_test 160b "Verify that very long rename doesn't crash in changelog"
11556
11557 test_160c() {
11558         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11559
11560         local rc=0
11561         local server_version=$(lustre_version_code $SINGLEMDS)
11562
11563         [[ $server_version -gt $(version_code 2.5.57) ]] ||
11564                 [[ $server_version -gt $(version_code 2.5.1) &&
11565                    $server_version -lt $(version_code 2.5.50) ]] ||
11566                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
11567         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11568
11569         # Registration step
11570         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11571                 changelog_register -n)
11572         trap cleanup_changelog EXIT
11573
11574         rm -rf $DIR/$tdir
11575         mkdir -p $DIR/$tdir
11576         $MCREATE $DIR/$tdir/foo_160c
11577         changelog_chmask "TRUNC"
11578         $TRUNCATE $DIR/$tdir/foo_160c 200
11579         changelog_chmask "TRUNC"
11580         $TRUNCATE $DIR/$tdir/foo_160c 199
11581         $LFS changelog $MDT0
11582         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
11583         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
11584         $LFS changelog_clear $MDT0 $CL_USER 0
11585
11586         # Deregistration step
11587         cleanup_changelog
11588 }
11589 run_test 160c "verify that changelog log catch the truncate event"
11590
11591 test_160d() {
11592         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11593         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11594
11595         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
11596                 skip "lustre < 2.11.56 does not support migrate -m "
11597
11598         local server_version=$(lustre_version_code mds1)
11599         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11600
11601         [[ $server_version -ge $(version_code 2.7.60) ]] ||
11602                 { skip "Need MDS version at least 2.7.60+"; return; }
11603         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11604
11605         # Registration step
11606         CL_USER=$(do_facet mds1 $LCTL --device $MDT0 \
11607                 changelog_register -n)
11608
11609         trap cleanup_changelog EXIT
11610         mkdir -p $DIR/$tdir/migrate_dir
11611         $LFS changelog_clear $MDT0 $CL_USER 0
11612
11613         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
11614         $LFS changelog $MDT0
11615         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
11616         $LFS changelog_clear $MDT0 $CL_USER 0
11617         [ $MIGRATES -eq 1 ] ||
11618                 error "MIGRATE changelog mask count $MIGRATES != 1"
11619
11620         # Deregistration step
11621         cleanup_changelog
11622 }
11623 run_test 160d "verify that changelog log catch the migrate event"
11624
11625 test_160e() {
11626         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11627
11628         # Create a user
11629         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11630                 changelog_register -n)
11631         echo "Registered as changelog user $CL_USER"
11632         trap cleanup_changelog EXIT
11633
11634         # Delete a future user (expect fail)
11635         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister cl77
11636         local rc=$?
11637
11638         if [ $rc -eq 0 ]; then
11639                 error "Deleted non-existant user cl77"
11640         elif [ $rc -ne 2 ]; then
11641                 error "changelog_deregister failed with $rc, " \
11642                         "expected 2 (ENOENT)"
11643         fi
11644
11645         # Clear to a bad index (1 billion should be safe)
11646         $LFS changelog_clear $MDT0 $CL_USER 1000000000
11647         rc=$?
11648
11649         if [ $rc -eq 0 ]; then
11650                 error "Successfully cleared to invalid CL index"
11651         elif [ $rc -ne 22 ]; then
11652                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
11653         fi
11654 }
11655 run_test 160e "changelog negative testing"
11656
11657 test_161a() {
11658         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11659         test_mkdir -p -c1 $DIR/$tdir
11660         cp /etc/hosts $DIR/$tdir/$tfile
11661         test_mkdir -c1 $DIR/$tdir/foo1
11662         test_mkdir -c1 $DIR/$tdir/foo2
11663         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
11664         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
11665         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
11666         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
11667         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
11668         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11669                 $LFS fid2path $DIR $FID
11670                 err17935 "bad link ea"
11671         fi
11672     # middle
11673     rm $DIR/$tdir/foo2/zachary
11674     # last
11675     rm $DIR/$tdir/foo2/thor
11676     # first
11677     rm $DIR/$tdir/$tfile
11678     # rename
11679     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
11680     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
11681         then
11682         $LFS fid2path $DIR $FID
11683         err17935 "bad link rename"
11684     fi
11685     rm $DIR/$tdir/foo2/maggie
11686
11687         # overflow the EA
11688         local longname=filename_avg_len_is_thirty_two_
11689         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
11690                 error "failed to hardlink many files"
11691         links=$($LFS fid2path $DIR $FID | wc -l)
11692         echo -n "${links}/1000 links in link EA"
11693         [[ $links -gt 60 ]] ||
11694                 err17935 "expected at least 60 links in link EA"
11695         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
11696                 error "failed to unlink many hardlinks"
11697 }
11698 run_test 161a "link ea sanity"
11699
11700 test_161b() {
11701         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11702         [ $MDSCOUNT -lt 2 ] && skip "skipping remote directory test" && return
11703         local MDTIDX=1
11704         local remote_dir=$DIR/$tdir/remote_dir
11705
11706         mkdir -p $DIR/$tdir
11707         $LFS mkdir -i $MDTIDX $remote_dir ||
11708                 error "create remote directory failed"
11709
11710         cp /etc/hosts $remote_dir/$tfile
11711         mkdir -p $remote_dir/foo1
11712         mkdir -p $remote_dir/foo2
11713         ln $remote_dir/$tfile $remote_dir/foo1/sofia
11714         ln $remote_dir/$tfile $remote_dir/foo2/zachary
11715         ln $remote_dir/$tfile $remote_dir/foo1/luna
11716         ln $remote_dir/$tfile $remote_dir/foo2/thor
11717
11718         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
11719                      tr -d ']')
11720         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11721                 $LFS fid2path $DIR $FID
11722                 err17935 "bad link ea"
11723         fi
11724         # middle
11725         rm $remote_dir/foo2/zachary
11726         # last
11727         rm $remote_dir/foo2/thor
11728         # first
11729         rm $remote_dir/$tfile
11730         # rename
11731         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
11732         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
11733         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
11734                 $LFS fid2path $DIR $FID
11735                 err17935 "bad link rename"
11736         fi
11737         rm $remote_dir/foo2/maggie
11738
11739         # overflow the EA
11740         local longname=filename_avg_len_is_thirty_two_
11741         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
11742                 error "failed to hardlink many files"
11743         links=$($LFS fid2path $DIR $FID | wc -l)
11744         echo -n "${links}/1000 links in link EA"
11745         [[ ${links} -gt 60 ]] ||
11746                 err17935 "expected at least 60 links in link EA"
11747         unlinkmany $remote_dir/foo2/$longname 1000 ||
11748         error "failed to unlink many hardlinks"
11749 }
11750 run_test 161b "link ea sanity under remote directory"
11751
11752 test_161c() {
11753         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11754         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11755         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
11756                 skip "Need MDS version at least 2.1.5" && return
11757
11758         # define CLF_RENAME_LAST 0x0001
11759         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
11760         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11761                 changelog_register -n)
11762
11763         trap cleanup_changelog EXIT
11764         rm -rf $DIR/$tdir
11765         mkdir -p $DIR/$tdir
11766         touch $DIR/$tdir/foo_161c
11767         touch $DIR/$tdir/bar_161c
11768         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11769         $LFS changelog $MDT0 | grep RENME
11770         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
11771                 cut -f5 -d' ')
11772         $LFS changelog_clear $MDT0 $CL_USER 0
11773         if [ x$flags != "x0x1" ]; then
11774                 error "flag $flags is not 0x1"
11775         fi
11776         echo "rename overwrite a target having nlink = 1," \
11777                 "changelog record has flags of $flags"
11778
11779         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
11780         touch $DIR/$tdir/foo_161c
11781         touch $DIR/$tdir/bar_161c
11782         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11783         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11784         $LFS changelog $MDT0 | grep RENME
11785         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11786         $LFS changelog_clear $MDT0 $CL_USER 0
11787         if [ x$flags != "x0x0" ]; then
11788                 error "flag $flags is not 0x0"
11789         fi
11790         echo "rename overwrite a target having nlink > 1," \
11791                 "changelog record has flags of $flags"
11792
11793         # rename doesn't overwrite a target (changelog flag 0x0)
11794         touch $DIR/$tdir/foo_161c
11795         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
11796         $LFS changelog $MDT0 | grep RENME
11797         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11798         $LFS changelog_clear $MDT0 $CL_USER 0
11799         if [ x$flags != "x0x0" ]; then
11800                 error "flag $flags is not 0x0"
11801         fi
11802         echo "rename doesn't overwrite a target," \
11803                 "changelog record has flags of $flags"
11804
11805         # define CLF_UNLINK_LAST 0x0001
11806         # unlink a file having nlink = 1 (changelog flag 0x1)
11807         rm -f $DIR/$tdir/foo2_161c
11808         $LFS changelog $MDT0 | grep UNLNK
11809         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11810         $LFS changelog_clear $MDT0 $CL_USER 0
11811         if [ x$flags != "x0x1" ]; then
11812                 error "flag $flags is not 0x1"
11813         fi
11814         echo "unlink a file having nlink = 1," \
11815                 "changelog record has flags of $flags"
11816
11817         # unlink a file having nlink > 1 (changelog flag 0x0)
11818         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11819         rm -f $DIR/$tdir/foobar_161c
11820         $LFS changelog $MDT0 | grep UNLNK
11821         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11822         $LFS changelog_clear $MDT0 $CL_USER 0
11823         if [ x$flags != "x0x0" ]; then
11824                 error "flag $flags is not 0x0"
11825         fi
11826         echo "unlink a file having nlink > 1," \
11827                 "changelog record has flags of $flags"
11828         cleanup_changelog
11829 }
11830 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
11831
11832 test_161d() {
11833         local user
11834         local pid
11835         local fid
11836
11837         # cleanup previous run
11838         rm -rf $DIR/$tdir/$tfile
11839
11840         user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11841                 changelog_register -n)
11842         [[ $? -eq 0 ]] || error "changelog_register failed"
11843
11844         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
11845         # interfer with $MOUNT/.lustre/fid/ access
11846         mkdir $DIR/$tdir
11847         [[ $? -eq 0 ]] || error "mkdir failed"
11848
11849         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
11850         $LCTL set_param fail_loc=0x8000140c
11851         # 5s pause
11852         $LCTL set_param fail_val=5
11853
11854         # create file
11855         echo foofoo > $DIR/$tdir/$tfile &
11856         pid=$!
11857
11858         # wait for create to be delayed
11859         sleep 2
11860
11861         ps -p $pid
11862         [[ $? -eq 0 ]] || error "create should be blocked"
11863
11864         local tempfile=$(mktemp)
11865         fid=$(changelog_extract_field $MDT0 "CREAT" "$tfile" "t=")
11866         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
11867         # some delay may occur during ChangeLog publishing and file read just
11868         # above, that could allow file write to happen finally
11869         [[ -s $tempfile ]] && echo "file should be empty"
11870
11871         $LCTL set_param fail_loc=0
11872
11873         wait $pid
11874         [[ $? -eq 0 ]] || error "create failed"
11875
11876         $LFS changelog_clear $MDT0 $user 0
11877         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $user
11878 }
11879 run_test 161d "create with concurrent .lustre/fid access"
11880
11881 check_path() {
11882     local expected=$1
11883     shift
11884     local fid=$2
11885
11886     local path=$(${LFS} fid2path $*)
11887     # Remove the '//' indicating a remote directory
11888     path=$(echo $path | sed 's#//#/#g')
11889     RC=$?
11890
11891     if [ $RC -ne 0 ]; then
11892         err17935 "path looked up of $expected failed. Error $RC"
11893         return $RC
11894     elif [ "${path}" != "${expected}" ]; then
11895         err17935 "path looked up \"${path}\" instead of \"${expected}\""
11896         return 2
11897     fi
11898     echo "fid $fid resolves to path $path (expected $expected)"
11899 }
11900
11901 test_162a() { # was test_162
11902         # Make changes to filesystem
11903         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11904         test_mkdir -p -c1 $DIR/$tdir/d2
11905         touch $DIR/$tdir/d2/$tfile
11906         touch $DIR/$tdir/d2/x1
11907         touch $DIR/$tdir/d2/x2
11908         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
11909         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
11910         # regular file
11911         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
11912         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
11913                 error "check path $tdir/d2/$tfile failed"
11914
11915         # softlink
11916         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
11917         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
11918         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
11919                 error "check path $tdir/d2/p/q/r/slink failed"
11920
11921         # softlink to wrong file
11922         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
11923         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
11924         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
11925                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
11926
11927         # hardlink
11928         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
11929         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
11930         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
11931         # fid2path dir/fsname should both work
11932         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
11933                 error "check path $tdir/d2/a/b/c/new_file failed"
11934         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
11935                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
11936
11937         # hardlink count: check that there are 2 links
11938         # Doesnt work with CMD yet: 17935
11939         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
11940                 err17935 "expected 2 links"
11941
11942         # hardlink indexing: remove the first link
11943         rm $DIR/$tdir/d2/p/q/r/hlink
11944         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
11945                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
11946
11947         return 0
11948 }
11949 run_test 162a "path lookup sanity"
11950
11951 test_162b() {
11952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11953         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11954
11955         mkdir $DIR/$tdir
11956         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
11957                                 error "create striped dir failed"
11958
11959         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
11960                                         tail -n 1 | awk '{print $2}')
11961         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
11962
11963         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
11964         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
11965
11966         # regular file
11967         for ((i=0;i<5;i++)); do
11968                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
11969                         error "get fid for f$i failed"
11970                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
11971                         error "check path $tdir/striped_dir/f$i failed"
11972
11973                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
11974                         error "get fid for d$i failed"
11975                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
11976                         error "check path $tdir/striped_dir/d$i failed"
11977         done
11978
11979         return 0
11980 }
11981 run_test 162b "striped directory path lookup sanity"
11982
11983 # LU-4239: Verify fid2path works with paths 100 or more directories deep
11984 test_162c() {
11985         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
11986                 skip "Need MDS version at least 2.7.51" && return
11987         test_mkdir $DIR/$tdir.local
11988         test_mkdir $DIR/$tdir.remote
11989         local lpath=$tdir.local
11990         local rpath=$tdir.remote
11991
11992         for ((i = 0; i <= 101; i++)); do
11993                 lpath="$lpath/$i"
11994                 mkdir $DIR/$lpath
11995                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
11996                         error "get fid for local directory $DIR/$lpath failed"
11997                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
11998                         error "check path for local directory $DIR/$lpath failed"
11999
12000                 rpath="$rpath/$i"
12001                 test_mkdir $DIR/$rpath
12002                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
12003                         error "get fid for remote directory $DIR/$rpath failed"
12004                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
12005                         error "check path for remote directory $DIR/$rpath failed"
12006         done
12007
12008         return 0
12009 }
12010 run_test 162c "fid2path works with paths 100 or more directories deep"
12011
12012 test_169() {
12013         # do directio so as not to populate the page cache
12014         log "creating a 10 Mb file"
12015         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12016         log "starting reads"
12017         dd if=$DIR/$tfile of=/dev/null bs=4096 &
12018         log "truncating the file"
12019         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12020         log "killing dd"
12021         kill %+ || true # reads might have finished
12022         echo "wait until dd is finished"
12023         wait
12024         log "removing the temporary file"
12025         rm -rf $DIR/$tfile || error "tmp file removal failed"
12026 }
12027 run_test 169 "parallel read and truncate should not deadlock"
12028
12029 test_170() {
12030         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12031         $LCTL clear     # bug 18514
12032         $LCTL debug_daemon start $TMP/${tfile}_log_good
12033         touch $DIR/$tfile
12034         $LCTL debug_daemon stop
12035         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
12036                error "sed failed to read log_good"
12037
12038         $LCTL debug_daemon start $TMP/${tfile}_log_good
12039         rm -rf $DIR/$tfile
12040         $LCTL debug_daemon stop
12041
12042         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
12043                error "lctl df log_bad failed"
12044
12045         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
12046         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
12047
12048         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
12049         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
12050
12051         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
12052                 error "bad_line good_line1 good_line2 are empty"
12053
12054         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
12055         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
12056         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
12057
12058         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
12059         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
12060         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
12061
12062         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
12063                 error "bad_line_new good_line_new are empty"
12064
12065         local expected_good=$((good_line1 + good_line2*2))
12066
12067         rm -f $TMP/${tfile}*
12068         # LU-231, short malformed line may not be counted into bad lines
12069         if [ $bad_line -ne $bad_line_new ] &&
12070                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
12071                 error "expected $bad_line bad lines, but got $bad_line_new"
12072                 return 1
12073         fi
12074
12075         if [ $expected_good -ne $good_line_new ]; then
12076                 error "expected $expected_good good lines, but got $good_line_new"
12077                 return 2
12078         fi
12079         true
12080 }
12081 run_test 170 "test lctl df to handle corrupted log ====================="
12082
12083 test_171() { # bug20592
12084         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12085 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
12086         $LCTL set_param fail_loc=0x50e
12087         $LCTL set_param fail_val=3000
12088         multiop_bg_pause $DIR/$tfile O_s || true
12089         local MULTIPID=$!
12090         kill -USR1 $MULTIPID
12091         # cause log dump
12092         sleep 3
12093         wait $MULTIPID
12094         if dmesg | grep "recursive fault"; then
12095                 error "caught a recursive fault"
12096         fi
12097         $LCTL set_param fail_loc=0
12098         true
12099 }
12100 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
12101
12102 # it would be good to share it with obdfilter-survey/iokit-libecho code
12103 setup_obdecho_osc () {
12104         local rc=0
12105         local ost_nid=$1
12106         local obdfilter_name=$2
12107         echo "Creating new osc for $obdfilter_name on $ost_nid"
12108         # make sure we can find loopback nid
12109         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
12110
12111         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
12112                            ${obdfilter_name}_osc_UUID || rc=2; }
12113         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
12114                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
12115         return $rc
12116 }
12117
12118 cleanup_obdecho_osc () {
12119         local obdfilter_name=$1
12120         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
12121         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
12122         return 0
12123 }
12124
12125 obdecho_test() {
12126         local OBD=$1
12127         local node=$2
12128         local pages=${3:-64}
12129         local rc=0
12130         local id
12131
12132         local count=10
12133         local obd_size=$(get_obd_size $node $OBD)
12134         local page_size=$(get_page_size $node)
12135         if [[ -n "$obd_size" ]]; then
12136                 local new_count=$((obd_size / (pages * page_size / 1024)))
12137                 [[ $new_count -ge $count ]] || count=$new_count
12138         fi
12139
12140         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
12141         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
12142                            rc=2; }
12143         if [ $rc -eq 0 ]; then
12144             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
12145             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
12146         fi
12147         echo "New object id is $id"
12148         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
12149                            rc=4; }
12150         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
12151                            "test_brw $count w v $pages $id" || rc=4; }
12152         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
12153                            rc=4; }
12154         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
12155                                         "cleanup" || rc=5; }
12156         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
12157                                         "detach" || rc=6; }
12158         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
12159         return $rc
12160 }
12161
12162 test_180a() {
12163         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12164         remote_ost_nodsh && skip "remote OST with nodsh" && return
12165         local rc=0
12166         local rmmod_local=0
12167
12168         if ! module_loaded obdecho; then
12169             load_module obdecho/obdecho
12170             rmmod_local=1
12171         fi
12172
12173         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
12174         local host=$(lctl get_param -n osc.$osc.import |
12175                              awk '/current_connection:/ {print $2}' )
12176         local target=$(lctl get_param -n osc.$osc.import |
12177                              awk '/target:/ {print $2}' )
12178         target=${target%_UUID}
12179
12180         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
12181         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
12182         [[ -n $target ]] && cleanup_obdecho_osc $target
12183         [ $rmmod_local -eq 1 ] && rmmod obdecho
12184         return $rc
12185 }
12186 run_test 180a "test obdecho on osc"
12187
12188 test_180b() {
12189         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12190         remote_ost_nodsh && skip "remote OST with nodsh" && return
12191         local rc=0
12192         local rmmod_remote=0
12193
12194         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
12195                 rmmod_remote=true || error "failed to load module obdecho"
12196         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
12197         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
12198         $rmmod_remote && do_facet ost1 "rmmod obdecho"
12199         return $rc
12200 }
12201 run_test 180b "test obdecho directly on obdfilter"
12202
12203 test_180c() { # LU-2598
12204         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12205         remote_ost_nodsh && skip "remote OST with nodsh" && return
12206         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
12207                 skip "Need MDS version at least 2.4.0" && return
12208
12209         local rc=0
12210         local rmmod_remote=false
12211         local pages=16384 # 64MB bulk I/O RPC size
12212         local target
12213
12214         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
12215                 rmmod_remote=true || error "failed to load module obdecho"
12216
12217         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
12218                 head -n1)
12219         if [ -n "$target" ]; then
12220                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
12221         else
12222                 echo "there is no obdfilter target on ost1"
12223                 rc=2
12224         fi
12225         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
12226         return $rc
12227 }
12228 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
12229
12230 test_181() { # bug 22177
12231         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12232         # create enough files to index the directory
12233         createmany -o $DIR/$tdir/foobar 4000
12234         # print attributes for debug purpose
12235         lsattr -d .
12236         # open dir
12237         multiop_bg_pause $DIR/$tdir D_Sc || return 1
12238         MULTIPID=$!
12239         # remove the files & current working dir
12240         unlinkmany $DIR/$tdir/foobar 4000
12241         rmdir $DIR/$tdir
12242         kill -USR1 $MULTIPID
12243         wait $MULTIPID
12244         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
12245         return 0
12246 }
12247 run_test 181 "Test open-unlinked dir ========================"
12248
12249 test_182() {
12250         local fcount=1000
12251         local tcount=10
12252
12253         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12254
12255         $LCTL set_param mdc.*.rpc_stats=clear
12256
12257         for (( i = 0; i < $tcount; i++ )) ; do
12258                 mkdir $DIR/$tdir/$i
12259         done
12260
12261         for (( i = 0; i < $tcount; i++ )) ; do
12262                 createmany -o $DIR/$tdir/$i/f- $fcount &
12263         done
12264         wait
12265
12266         for (( i = 0; i < $tcount; i++ )) ; do
12267                 unlinkmany $DIR/$tdir/$i/f- $fcount &
12268         done
12269         wait
12270
12271         $LCTL get_param mdc.*.rpc_stats
12272
12273         rm -rf $DIR/$tdir
12274 }
12275 run_test 182 "Test parallel modify metadata operations ================"
12276
12277 test_183() { # LU-2275
12278         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12279         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
12280                 skip "Need MDS version at least 2.3.56" && return
12281
12282         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12283         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12284         echo aaa > $DIR/$tdir/$tfile
12285
12286 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
12287         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
12288
12289         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
12290         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
12291
12292         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
12293
12294         # Flush negative dentry cache
12295         touch $DIR/$tdir/$tfile
12296
12297         # We are not checking for any leaked references here, they'll
12298         # become evident next time we do cleanup with module unload.
12299         rm -rf $DIR/$tdir
12300 }
12301 run_test 183 "No crash or request leak in case of strange dispositions ========"
12302
12303 # test suite 184 is for LU-2016, LU-2017
12304 test_184a() {
12305         check_swap_layouts_support && return 0
12306
12307         dir0=$DIR/$tdir/$testnum
12308         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
12309         ref1=/etc/passwd
12310         ref2=/etc/group
12311         file1=$dir0/f1
12312         file2=$dir0/f2
12313         $SETSTRIPE -c1 $file1
12314         cp $ref1 $file1
12315         $SETSTRIPE -c2 $file2
12316         cp $ref2 $file2
12317         gen1=$($GETSTRIPE -g $file1)
12318         gen2=$($GETSTRIPE -g $file2)
12319
12320         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
12321         gen=$($GETSTRIPE -g $file1)
12322         [[ $gen1 != $gen ]] ||
12323                 "Layout generation on $file1 does not change"
12324         gen=$($GETSTRIPE -g $file2)
12325         [[ $gen2 != $gen ]] ||
12326                 "Layout generation on $file2 does not change"
12327
12328         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
12329         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12330 }
12331 run_test 184a "Basic layout swap"
12332
12333 test_184b() {
12334         check_swap_layouts_support && return 0
12335
12336         dir0=$DIR/$tdir/$testnum
12337         mkdir -p $dir0 || error "creating dir $dir0"
12338         file1=$dir0/f1
12339         file2=$dir0/f2
12340         file3=$dir0/f3
12341         dir1=$dir0/d1
12342         dir2=$dir0/d2
12343         mkdir $dir1 $dir2
12344         $SETSTRIPE -c1 $file1
12345         $SETSTRIPE -c2 $file2
12346         $SETSTRIPE -c1 $file3
12347         chown $RUNAS_ID $file3
12348         gen1=$($GETSTRIPE -g $file1)
12349         gen2=$($GETSTRIPE -g $file2)
12350
12351         $LFS swap_layouts $dir1 $dir2 &&
12352                 error "swap of directories layouts should fail"
12353         $LFS swap_layouts $dir1 $file1 &&
12354                 error "swap of directory and file layouts should fail"
12355         $RUNAS $LFS swap_layouts $file1 $file2 &&
12356                 error "swap of file we cannot write should fail"
12357         $LFS swap_layouts $file1 $file3 &&
12358                 error "swap of file with different owner should fail"
12359         /bin/true # to clear error code
12360 }
12361 run_test 184b "Forbidden layout swap (will generate errors)"
12362
12363 test_184c() {
12364         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
12365         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n" && return
12366         check_swap_layouts_support && return 0
12367
12368         local dir0=$DIR/$tdir/$testnum
12369         mkdir -p $dir0 || error "creating dir $dir0"
12370
12371         local ref1=$dir0/ref1
12372         local ref2=$dir0/ref2
12373         local file1=$dir0/file1
12374         local file2=$dir0/file2
12375         # create a file large enough for the concurrent test
12376         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
12377         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
12378         echo "ref file size: ref1($(stat -c %s $ref1))," \
12379              "ref2($(stat -c %s $ref2))"
12380
12381         cp $ref2 $file2
12382         dd if=$ref1 of=$file1 bs=16k &
12383         local DD_PID=$!
12384
12385         # Make sure dd starts to copy file
12386         while [ ! -f $file1 ]; do sleep 0.1; done
12387
12388         $LFS swap_layouts $file1 $file2
12389         local rc=$?
12390         wait $DD_PID
12391         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
12392         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
12393
12394         # how many bytes copied before swapping layout
12395         local copied=$(stat -c %s $file2)
12396         local remaining=$(stat -c %s $ref1)
12397         remaining=$((remaining - copied))
12398         echo "Copied $copied bytes before swapping layout..."
12399
12400         cmp -n $copied $file1 $ref2 | grep differ &&
12401                 error "Content mismatch [0, $copied) of ref2 and file1"
12402         cmp -n $copied $file2 $ref1 ||
12403                 error "Content mismatch [0, $copied) of ref1 and file2"
12404         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
12405                 error "Content mismatch [$copied, EOF) of ref1 and file1"
12406
12407         # clean up
12408         rm -f $ref1 $ref2 $file1 $file2
12409 }
12410 run_test 184c "Concurrent write and layout swap"
12411
12412 test_184d() {
12413         check_swap_layouts_support && return 0
12414         [ -z "$(which getfattr 2>/dev/null)" ] &&
12415                 skip "no getfattr command" && return 0
12416
12417         local file1=$DIR/$tdir/$tfile-1
12418         local file2=$DIR/$tdir/$tfile-2
12419         local file3=$DIR/$tdir/$tfile-3
12420         local lovea1
12421         local lovea2
12422
12423         mkdir -p $DIR/$tdir
12424         touch $file1 || error "create $file1 failed"
12425         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12426                 error "create $file2 failed"
12427         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12428                 error "create $file3 failed"
12429         lovea1=$(get_layout_param $file1)
12430
12431         $LFS swap_layouts $file2 $file3 ||
12432                 error "swap $file2 $file3 layouts failed"
12433         $LFS swap_layouts $file1 $file2 ||
12434                 error "swap $file1 $file2 layouts failed"
12435
12436         lovea2=$(get_layout_param $file2)
12437         echo "$lovea1"
12438         echo "$lovea2"
12439         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
12440
12441         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12442         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
12443 }
12444 run_test 184d "allow stripeless layouts swap"
12445
12446 test_184e() {
12447         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
12448                 { skip "Need MDS version at least 2.6.94"; return 0; }
12449         check_swap_layouts_support && return 0
12450         [ -z "$(which getfattr 2>/dev/null)" ] &&
12451                 skip "no getfattr command" && return 0
12452
12453         local file1=$DIR/$tdir/$tfile-1
12454         local file2=$DIR/$tdir/$tfile-2
12455         local file3=$DIR/$tdir/$tfile-3
12456         local lovea
12457
12458         mkdir -p $DIR/$tdir
12459         touch $file1 || error "create $file1 failed"
12460         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12461                 error "create $file2 failed"
12462         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12463                 error "create $file3 failed"
12464
12465         $LFS swap_layouts $file1 $file2 ||
12466                 error "swap $file1 $file2 layouts failed"
12467
12468         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12469         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
12470
12471         echo 123 > $file1 || error "Should be able to write into $file1"
12472
12473         $LFS swap_layouts $file1 $file3 ||
12474                 error "swap $file1 $file3 layouts failed"
12475
12476         echo 123 > $file1 || error "Should be able to write into $file1"
12477
12478         rm -rf $file1 $file2 $file3
12479 }
12480 run_test 184e "Recreate layout after stripeless layout swaps"
12481
12482 test_185() { # LU-2441
12483         # LU-3553 - no volatile file support in old servers
12484         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
12485                 { skip "Need MDS version at least 2.3.60"; return 0; }
12486
12487         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12488         touch $DIR/$tdir/spoo
12489         local mtime1=$(stat -c "%Y" $DIR/$tdir)
12490         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
12491                 error "cannot create/write a volatile file"
12492         [ "$FILESET" == "" ] &&
12493         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
12494                 error "FID is still valid after close"
12495
12496         multiop_bg_pause $DIR/$tdir vVw4096_c
12497         local multi_pid=$!
12498
12499         local OLD_IFS=$IFS
12500         IFS=":"
12501         local fidv=($fid)
12502         IFS=$OLD_IFS
12503         # assume that the next FID for this client is sequential, since stdout
12504         # is unfortunately eaten by multiop_bg_pause
12505         local n=$((${fidv[1]} + 1))
12506         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
12507         if [ "$FILESET" == "" ]; then
12508                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
12509                         error "FID is missing before close"
12510         fi
12511         kill -USR1 $multi_pid
12512         # 1 second delay, so if mtime change we will see it
12513         sleep 1
12514         local mtime2=$(stat -c "%Y" $DIR/$tdir)
12515         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
12516 }
12517 run_test 185 "Volatile file support"
12518
12519 test_187a() {
12520         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12521         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12522                 skip "Need MDS version at least 2.3.0" && return
12523
12524         local dir0=$DIR/$tdir/$testnum
12525         mkdir -p $dir0 || error "creating dir $dir0"
12526
12527         local file=$dir0/file1
12528         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
12529         local dv1=$($LFS data_version $file)
12530         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
12531         local dv2=$($LFS data_version $file)
12532         [[ $dv1 != $dv2 ]] ||
12533                 error "data version did not change on write $dv1 == $dv2"
12534
12535         # clean up
12536         rm -f $file1
12537 }
12538 run_test 187a "Test data version change"
12539
12540 test_187b() {
12541         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12542         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12543                 skip "Need MDS version at least 2.3.0" && return
12544
12545         local dir0=$DIR/$tdir/$testnum
12546         mkdir -p $dir0 || error "creating dir $dir0"
12547
12548         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
12549         [[ ${DV[0]} != ${DV[1]} ]] ||
12550                 error "data version did not change on write"\
12551                       " ${DV[0]} == ${DV[1]}"
12552
12553         # clean up
12554         rm -f $file1
12555 }
12556 run_test 187b "Test data version change on volatile file"
12557
12558 test_200() {
12559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12560         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12561         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
12562
12563         local POOL=${POOL:-cea1}
12564         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
12565         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
12566         # Pool OST targets
12567         local first_ost=0
12568         local last_ost=$(($OSTCOUNT - 1))
12569         local ost_step=2
12570         local ost_list=$(seq $first_ost $ost_step $last_ost)
12571         local ost_range="$first_ost $last_ost $ost_step"
12572         local test_path=$POOL_ROOT/$POOL_DIR_NAME
12573         local file_dir=$POOL_ROOT/file_tst
12574         local subdir=$test_path/subdir
12575         local rc=0
12576
12577         if ! combined_mgs_mds ; then
12578                 mount_mgs_client
12579         fi
12580
12581         while : ; do
12582                 # former test_200a test_200b
12583                 pool_add $POOL                          || { rc=$? ; break; }
12584                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
12585                 # former test_200c test_200d
12586                 mkdir -p $test_path
12587                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
12588                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
12589                 mkdir -p $subdir
12590                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
12591                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
12592                                                         || { rc=$? ; break; }
12593                 # former test_200e test_200f
12594                 local files=$((OSTCOUNT*3))
12595                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
12596                                                         || { rc=$? ; break; }
12597                 pool_create_files $POOL $file_dir $files "$ost_list" \
12598                                                         || { rc=$? ; break; }
12599                 # former test_200g test_200h
12600                 pool_lfs_df $POOL                       || { rc=$? ; break; }
12601                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
12602
12603                 # former test_201a test_201b test_201c
12604                 pool_remove_first_target $POOL          || { rc=$? ; break; }
12605
12606                 local f=$test_path/$tfile
12607                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
12608                 pool_remove $POOL $f                    || { rc=$? ; break; }
12609                 break
12610         done
12611
12612         destroy_test_pools
12613
12614         if ! combined_mgs_mds ; then
12615                 umount_mgs_client
12616         fi
12617         return $rc
12618 }
12619 run_test 200 "OST pools"
12620
12621 # usage: default_attr <count | size | offset>
12622 default_attr() {
12623         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
12624 }
12625
12626 # usage: check_default_stripe_attr
12627 check_default_stripe_attr() {
12628         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
12629         case $1 in
12630         --stripe-count|-c)
12631                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
12632         --stripe-size|-S)
12633                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
12634         --stripe-index|-i)
12635                 EXPECTED=-1;;
12636         *)
12637                 error "unknown getstripe attr '$1'"
12638         esac
12639
12640         [ $ACTUAL != $EXPECTED ] &&
12641                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
12642 }
12643
12644 test_204a() {
12645         test_mkdir -p $DIR/$tdir
12646         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
12647
12648         check_default_stripe_attr --stripe-count
12649         check_default_stripe_attr --stripe-size
12650         check_default_stripe_attr --stripe-index
12651
12652         return 0
12653 }
12654 run_test 204a "Print default stripe attributes ================="
12655
12656 test_204b() {
12657         test_mkdir -p $DIR/$tdir
12658         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12659
12660         check_default_stripe_attr --stripe-size
12661         check_default_stripe_attr --stripe-index
12662
12663         return 0
12664 }
12665 run_test 204b "Print default stripe size and offset  ==========="
12666
12667 test_204c() {
12668         test_mkdir -p $DIR/$tdir
12669         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12670
12671         check_default_stripe_attr --stripe-count
12672         check_default_stripe_attr --stripe-index
12673
12674         return 0
12675 }
12676 run_test 204c "Print default stripe count and offset ==========="
12677
12678 test_204d() {
12679         test_mkdir -p $DIR/$tdir
12680         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12681
12682         check_default_stripe_attr --stripe-count
12683         check_default_stripe_attr --stripe-size
12684
12685         return 0
12686 }
12687 run_test 204d "Print default stripe count and size ============="
12688
12689 test_204e() {
12690         test_mkdir -p $DIR/$tdir
12691         $SETSTRIPE -d $DIR/$tdir
12692
12693         check_default_stripe_attr --stripe-count --raw
12694         check_default_stripe_attr --stripe-size --raw
12695         check_default_stripe_attr --stripe-index --raw
12696
12697         return 0
12698 }
12699 run_test 204e "Print raw stripe attributes ================="
12700
12701 test_204f() {
12702         test_mkdir -p $DIR/$tdir
12703         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12704
12705         check_default_stripe_attr --stripe-size --raw
12706         check_default_stripe_attr --stripe-index --raw
12707
12708         return 0
12709 }
12710 run_test 204f "Print raw stripe size and offset  ==========="
12711
12712 test_204g() {
12713         test_mkdir -p $DIR/$tdir
12714         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12715
12716         check_default_stripe_attr --stripe-count --raw
12717         check_default_stripe_attr --stripe-index --raw
12718
12719         return 0
12720 }
12721 run_test 204g "Print raw stripe count and offset ==========="
12722
12723 test_204h() {
12724         test_mkdir -p $DIR/$tdir
12725         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12726
12727         check_default_stripe_attr --stripe-count --raw
12728         check_default_stripe_attr --stripe-size --raw
12729
12730         return 0
12731 }
12732 run_test 204h "Print raw stripe count and size ============="
12733
12734 # Figure out which job scheduler is being used, if any,
12735 # or use a fake one
12736 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
12737         JOBENV=SLURM_JOB_ID
12738 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
12739         JOBENV=LSB_JOBID
12740 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
12741         JOBENV=PBS_JOBID
12742 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
12743         JOBENV=LOADL_STEP_ID
12744 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
12745         JOBENV=JOB_ID
12746 else
12747         $LCTL list_param jobid_name > /dev/null 2>&1
12748         if [ $? -eq 0 ]; then
12749                 JOBENV=nodelocal
12750         else
12751                 JOBENV=FAKE_JOBID
12752         fi
12753 fi
12754
12755 verify_jobstats() {
12756         local cmd=($1)
12757         shift
12758         local facets="$@"
12759
12760 # we don't really need to clear the stats for this test to work, since each
12761 # command has a unique jobid, but it makes debugging easier if needed.
12762 #       for facet in $facets; do
12763 #               local dev=$(convert_facet2label $facet)
12764 #               # clear old jobstats
12765 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
12766 #       done
12767
12768         # use a new JobID for each test, or we might see an old one
12769         [ "$JOBENV" = "FAKE_JOBID" ] &&
12770                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12771
12772         JOBVAL=${!JOBENV}
12773
12774         [ "$JOBENV" = "nodelocal" ] && {
12775                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12776                 $LCTL set_param jobid_name=$FAKE_JOBID
12777                 JOBVAL=$FAKE_JOBID
12778         }
12779
12780         log "Test: ${cmd[*]}"
12781         log "Using JobID environment variable $JOBENV=$JOBVAL"
12782
12783         if [ $JOBENV = "FAKE_JOBID" ]; then
12784                 FAKE_JOBID=$JOBVAL ${cmd[*]}
12785         else
12786                 ${cmd[*]}
12787         fi
12788
12789         # all files are created on OST0000
12790         for facet in $facets; do
12791                 local stats="*.$(convert_facet2label $facet).job_stats"
12792                 if [ $(do_facet $facet lctl get_param $stats |
12793                        grep -c $JOBVAL) -ne 1 ]; then
12794                         do_facet $facet lctl get_param $stats
12795                         error "No jobstats for $JOBVAL found on $facet::$stats"
12796                 fi
12797         done
12798 }
12799
12800 jobstats_set() {
12801         trap 0
12802         NEW_JOBENV=${1:-$OLD_JOBENV}
12803         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
12804         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
12805 }
12806
12807 cleanup_205() {
12808         trap 0
12809         do_facet $SINGLEMDS \
12810                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
12811         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
12812         cleanup_changelog
12813 }
12814
12815 test_205() { # Job stats
12816         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.1) ]] ||
12817                 { skip "Need MDS version with at least 2.7.1"; return 0; }
12818
12819         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12820         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12821         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12822         remote_ost_nodsh && skip "remote OST with nodsh" && return
12823
12824         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
12825                 skip "Server doesn't support jobstats" && return 0
12826         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
12827
12828         OLD_JOBENV=$($LCTL get_param -n jobid_var)
12829         if [ $OLD_JOBENV != $JOBENV ]; then
12830                 jobstats_set $JOBENV
12831                 trap cleanup_205 EXIT
12832         fi
12833
12834         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
12835         echo "Registered as changelog user $CL_USER"
12836
12837         OLD_INTERVAL=$(do_facet $SINGLEMDS \
12838                        lctl get_param -n mdt.*.job_cleanup_interval)
12839         local interval_new=5
12840         do_facet $SINGLEMDS \
12841                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
12842         local start=$SECONDS
12843
12844         local cmd
12845         # mkdir
12846         cmd="mkdir $DIR/$tdir"
12847         verify_jobstats "$cmd" "$SINGLEMDS"
12848         # rmdir
12849         cmd="rmdir $DIR/$tdir"
12850         verify_jobstats "$cmd" "$SINGLEMDS"
12851         # mkdir on secondary MDT
12852         if [ $MDSCOUNT -gt 1 ]; then
12853                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
12854                 verify_jobstats "$cmd" "mds2"
12855         fi
12856         # mknod
12857         cmd="mknod $DIR/$tfile c 1 3"
12858         verify_jobstats "$cmd" "$SINGLEMDS"
12859         # unlink
12860         cmd="rm -f $DIR/$tfile"
12861         verify_jobstats "$cmd" "$SINGLEMDS"
12862         # create all files on OST0000 so verify_jobstats can find OST stats
12863         # open & close
12864         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
12865         verify_jobstats "$cmd" "$SINGLEMDS"
12866         # setattr
12867         cmd="touch $DIR/$tfile"
12868         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12869         # write
12870         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
12871         verify_jobstats "$cmd" "ost1"
12872         # read
12873         cancel_lru_locks osc
12874         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
12875         verify_jobstats "$cmd" "ost1"
12876         # truncate
12877         cmd="$TRUNCATE $DIR/$tfile 0"
12878         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12879         # rename
12880         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
12881         verify_jobstats "$cmd" "$SINGLEMDS"
12882         # jobstats expiry - sleep until old stats should be expired
12883         local left=$((interval_new + 5 - (SECONDS - start)))
12884         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
12885                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
12886                         "0" $left
12887         cmd="mkdir $DIR/$tdir.expire"
12888         verify_jobstats "$cmd" "$SINGLEMDS"
12889         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
12890             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
12891
12892         # Ensure that jobid are present in changelog (if supported by MDS)
12893         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
12894         then
12895                 $LFS changelog $MDT0 | tail -9
12896                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
12897                 [ $jobids -eq 9 ] ||
12898                         error "Wrong changelog jobid count $jobids != 9"
12899
12900                 # LU-5862
12901                 JOBENV="disable"
12902                 jobstats_set $JOBENV
12903                 touch $DIR/$tfile
12904                 $LFS changelog $MDT0 | tail -1
12905                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
12906                 [ $jobids -eq 0 ] ||
12907                         error "Unexpected jobids when jobid_var=$JOBENV"
12908         fi
12909
12910         cleanup_205
12911 }
12912 run_test 205 "Verify job stats"
12913
12914 # LU-1480, LU-1773 and LU-1657
12915 test_206() {
12916         mkdir -p $DIR/$tdir
12917         $SETSTRIPE -c -1 $DIR/$tdir
12918 #define OBD_FAIL_LOV_INIT 0x1403
12919         $LCTL set_param fail_loc=0xa0001403
12920         $LCTL set_param fail_val=1
12921         touch $DIR/$tdir/$tfile || true
12922 }
12923 run_test 206 "fail lov_init_raid0() doesn't lbug"
12924
12925 test_207a() {
12926         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12927         local fsz=`stat -c %s $DIR/$tfile`
12928         cancel_lru_locks mdc
12929
12930         # do not return layout in getattr intent
12931 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
12932         $LCTL set_param fail_loc=0x170
12933         local sz=`stat -c %s $DIR/$tfile`
12934
12935         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
12936
12937         rm -rf $DIR/$tfile
12938 }
12939 run_test 207a "can refresh layout at glimpse"
12940
12941 test_207b() {
12942         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12943         local cksum=`md5sum $DIR/$tfile`
12944         local fsz=`stat -c %s $DIR/$tfile`
12945         cancel_lru_locks mdc
12946         cancel_lru_locks osc
12947
12948         # do not return layout in getattr intent
12949 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
12950         $LCTL set_param fail_loc=0x171
12951
12952         # it will refresh layout after the file is opened but before read issues
12953         echo checksum is "$cksum"
12954         echo "$cksum" |md5sum -c --quiet || error "file differs"
12955
12956         rm -rf $DIR/$tfile
12957 }
12958 run_test 207b "can refresh layout at open"
12959
12960 test_208() {
12961         # FIXME: in this test suite, only RD lease is used. This is okay
12962         # for now as only exclusive open is supported. After generic lease
12963         # is done, this test suite should be revised. - Jinshan
12964
12965         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12966         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
12967                 { skip "Need MDS version at least 2.4.52"; return 0; }
12968
12969         echo "==== test 1: verify get lease work"
12970         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
12971
12972         echo "==== test 2: verify lease can be broken by upcoming open"
12973         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12974         local PID=$!
12975         sleep 1
12976
12977         $MULTIOP $DIR/$tfile oO_RDONLY:c
12978         kill -USR1 $PID && wait $PID || error "break lease error"
12979
12980         echo "==== test 3: verify lease can't be granted if an open already exists"
12981         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
12982         local PID=$!
12983         sleep 1
12984
12985         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
12986         kill -USR1 $PID && wait $PID || error "open file error"
12987
12988         echo "==== test 4: lease can sustain over recovery"
12989         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
12990         PID=$!
12991         sleep 1
12992
12993         fail mds1
12994
12995         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
12996
12997         echo "==== test 5: lease broken can't be regained by replay"
12998         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12999         PID=$!
13000         sleep 1
13001
13002         # open file to break lease and then recovery
13003         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
13004         fail mds1
13005
13006         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
13007
13008         rm -f $DIR/$tfile
13009 }
13010 run_test 208 "Exclusive open"
13011
13012 test_209() {
13013         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
13014                 skip_env "must have disp_stripe" && return
13015
13016         touch $DIR/$tfile
13017         sync; sleep 5; sync;
13018
13019         echo 3 > /proc/sys/vm/drop_caches
13020         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
13021
13022         # open/close 500 times
13023         for i in $(seq 500); do
13024                 cat $DIR/$tfile
13025         done
13026
13027         echo 3 > /proc/sys/vm/drop_caches
13028         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
13029
13030         echo "before: $req_before, after: $req_after"
13031         [ $((req_after - req_before)) -ge 300 ] &&
13032                 error "open/close requests are not freed"
13033         return 0
13034 }
13035 run_test 209 "read-only open/close requests should be freed promptly"
13036
13037 test_212() {
13038         size=`date +%s`
13039         size=$((size % 8192 + 1))
13040         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
13041         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
13042         rm -f $DIR/f212 $DIR/f212.xyz
13043 }
13044 run_test 212 "Sendfile test ============================================"
13045
13046 test_213() {
13047         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
13048         cancel_lru_locks osc
13049         lctl set_param fail_loc=0x8000040f
13050         # generate a read lock
13051         cat $DIR/$tfile > /dev/null
13052         # write to the file, it will try to cancel the above read lock.
13053         cat /etc/hosts >> $DIR/$tfile
13054 }
13055 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
13056
13057 test_214() { # for bug 20133
13058         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
13059         for (( i=0; i < 340; i++ )) ; do
13060                 touch $DIR/$tdir/d214c/a$i
13061         done
13062
13063         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
13064         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
13065         ls $DIR/d214c || error "ls $DIR/d214c failed"
13066         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
13067         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
13068 }
13069 run_test 214 "hash-indexed directory test - bug 20133"
13070
13071 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
13072 create_lnet_proc_files() {
13073         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
13074         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
13075
13076         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
13077         rm -f "$TMP/lnet_$1.sys_tmp"
13078 }
13079
13080 # counterpart of create_lnet_proc_files
13081 remove_lnet_proc_files() {
13082         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
13083 }
13084
13085 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
13086 # 3rd arg as regexp for body
13087 check_lnet_proc_stats() {
13088         local l=$(cat "$TMP/lnet_$1" |wc -l)
13089         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
13090
13091         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
13092 }
13093
13094 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
13095 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
13096 # optional and can be regexp for 2nd line (lnet.routes case)
13097 check_lnet_proc_entry() {
13098         local blp=2          # blp stands for 'position of 1st line of body'
13099         [ -z "$5" ] || blp=3 # lnet.routes case
13100
13101         local l=$(cat "$TMP/lnet_$1" |wc -l)
13102         # subtracting one from $blp because the body can be empty
13103         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
13104
13105         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
13106                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
13107
13108         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
13109                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
13110
13111         # bail out if any unexpected line happened
13112         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
13113         [ "$?" != 0 ] || error "$2 misformatted"
13114 }
13115
13116 test_215() { # for bugs 18102, 21079, 21517
13117         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13118         local N='(0|[1-9][0-9]*)'       # non-negative numeric
13119         local P='[1-9][0-9]*'           # positive numeric
13120         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
13121         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
13122         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
13123         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
13124
13125         local L1 # regexp for 1st line
13126         local L2 # regexp for 2nd line (optional)
13127         local BR # regexp for the rest (body)
13128
13129         # lnet.stats should look as 11 space-separated non-negative numerics
13130         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
13131         create_lnet_proc_files "stats"
13132         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
13133         remove_lnet_proc_files "stats"
13134
13135         # lnet.routes should look like this:
13136         # Routing disabled/enabled
13137         # net hops priority state router
13138         # where net is a string like tcp0, hops > 0, priority >= 0,
13139         # state is up/down,
13140         # router is a string like 192.168.1.1@tcp2
13141         L1="^Routing (disabled|enabled)$"
13142         L2="^net +hops +priority +state +router$"
13143         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
13144         create_lnet_proc_files "routes"
13145         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
13146         remove_lnet_proc_files "routes"
13147
13148         # lnet.routers should look like this:
13149         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
13150         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
13151         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
13152         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
13153         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
13154         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
13155         create_lnet_proc_files "routers"
13156         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
13157         remove_lnet_proc_files "routers"
13158
13159         # lnet.peers should look like this:
13160         # nid refs state last max rtr min tx min queue
13161         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
13162         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
13163         # numeric (0 or >0 or <0), queue >= 0.
13164         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
13165         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
13166         create_lnet_proc_files "peers"
13167         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
13168         remove_lnet_proc_files "peers"
13169
13170         # lnet.buffers  should look like this:
13171         # pages count credits min
13172         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
13173         L1="^pages +count +credits +min$"
13174         BR="^ +$N +$N +$I +$I$"
13175         create_lnet_proc_files "buffers"
13176         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
13177         remove_lnet_proc_files "buffers"
13178
13179         # lnet.nis should look like this:
13180         # nid status alive refs peer rtr max tx min
13181         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
13182         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
13183         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
13184         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
13185         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
13186         create_lnet_proc_files "nis"
13187         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
13188         remove_lnet_proc_files "nis"
13189
13190         # can we successfully write to lnet.stats?
13191         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
13192         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
13193 }
13194 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
13195
13196 test_216() { # bug 20317
13197         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13198         remote_ost_nodsh && skip "remote OST with nodsh" && return
13199
13200         local node
13201         local facets=$(get_facets OST)
13202         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13203
13204         save_lustre_params client "osc.*.contention_seconds" > $p
13205         save_lustre_params $facets \
13206                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
13207         save_lustre_params $facets \
13208                 "ldlm.namespaces.filter-*.contended_locks" >> $p
13209         save_lustre_params $facets \
13210                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
13211         clear_stats osc.*.osc_stats
13212
13213         # agressive lockless i/o settings
13214         do_nodes $(comma_list $(osts_nodes)) \
13215                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
13216                         ldlm.namespaces.filter-*.contended_locks=0 \
13217                         ldlm.namespaces.filter-*.contention_seconds=60"
13218         lctl set_param -n osc.*.contention_seconds=60
13219
13220         $DIRECTIO write $DIR/$tfile 0 10 4096
13221         $CHECKSTAT -s 40960 $DIR/$tfile
13222
13223         # disable lockless i/o
13224         do_nodes $(comma_list $(osts_nodes)) \
13225                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
13226                         ldlm.namespaces.filter-*.contended_locks=32 \
13227                         ldlm.namespaces.filter-*.contention_seconds=0"
13228         lctl set_param -n osc.*.contention_seconds=0
13229         clear_stats osc.*.osc_stats
13230
13231         dd if=/dev/zero of=$DIR/$tfile count=0
13232         $CHECKSTAT -s 0 $DIR/$tfile
13233
13234         restore_lustre_params <$p
13235         rm -f $p
13236         rm $DIR/$tfile
13237 }
13238 run_test 216 "check lockless direct write updates file size and kms correctly"
13239
13240 test_217() { # bug 22430
13241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13242         local node
13243         local nid
13244
13245         for node in $(nodes_list); do
13246                 nid=$(host_nids_address $node $NETTYPE)
13247                 if [[ $nid = *-* ]] ; then
13248                         echo "lctl ping $(h2nettype $nid)"
13249                         lctl ping $(h2nettype $nid)
13250                 else
13251                         echo "skipping $node (no hyphen detected)"
13252                 fi
13253         done
13254 }
13255 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
13256
13257 test_218() {
13258        # do directio so as not to populate the page cache
13259        log "creating a 10 Mb file"
13260        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
13261        log "starting reads"
13262        dd if=$DIR/$tfile of=/dev/null bs=4096 &
13263        log "truncating the file"
13264        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
13265        log "killing dd"
13266        kill %+ || true # reads might have finished
13267        echo "wait until dd is finished"
13268        wait
13269        log "removing the temporary file"
13270        rm -rf $DIR/$tfile || error "tmp file removal failed"
13271 }
13272 run_test 218 "parallel read and truncate should not deadlock ======================="
13273
13274 test_219() {
13275         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13276         # write one partial page
13277         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
13278         # set no grant so vvp_io_commit_write will do sync write
13279         $LCTL set_param fail_loc=0x411
13280         # write a full page at the end of file
13281         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
13282
13283         $LCTL set_param fail_loc=0
13284         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
13285         $LCTL set_param fail_loc=0x411
13286         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
13287
13288         # LU-4201
13289         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
13290         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
13291 }
13292 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
13293
13294 test_220() { #LU-325
13295         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13296         remote_ost_nodsh && skip "remote OST with nodsh" && return
13297         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13298         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
13299         local OSTIDX=0
13300
13301         # create on MDT0000 so the last_id and next_id are correct
13302         mkdir $DIR/$tdir
13303         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
13304         OST=${OST%_UUID}
13305
13306         # on the mdt's osc
13307         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
13308         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
13309                         osc.$mdtosc_proc1.prealloc_last_id)
13310         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
13311                         osc.$mdtosc_proc1.prealloc_next_id)
13312
13313         $LFS df -i
13314
13315         if ! combined_mgs_mds ; then
13316                 mount_mgs_client
13317         fi
13318
13319         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
13320         #define OBD_FAIL_OST_ENOINO              0x229
13321         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
13322         create_pool $FSNAME.$TESTNAME || return 1
13323         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
13324
13325         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
13326
13327         MDSOBJS=$((last_id - next_id))
13328         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
13329
13330         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
13331         echo "OST still has $count kbytes free"
13332
13333         echo "create $MDSOBJS files @next_id..."
13334         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
13335
13336         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
13337                         osc.$mdtosc_proc1.prealloc_last_id)
13338         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
13339                         osc.$mdtosc_proc1.prealloc_next_id)
13340
13341         echo "after creation, last_id=$last_id2, next_id=$next_id2"
13342         $LFS df -i
13343
13344         echo "cleanup..."
13345
13346         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
13347         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
13348
13349         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST ||
13350                 error "$LCTL pool_remove $FSNAME.$TESTNAME $OST failed"
13351         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
13352                 error "$LCTL pool_destroy $FSNAME.$TESTNAME failed"
13353         echo "unlink $MDSOBJS files @$next_id..."
13354         unlinkmany $DIR/$tdir/f $MDSOBJS || error "unlinkmany failed"
13355
13356         if ! combined_mgs_mds ; then
13357                 umount_mgs_client
13358         fi
13359 }
13360 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
13361
13362 test_221() {
13363         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13364         dd if=`which date` of=$MOUNT/date oflag=sync
13365         chmod +x $MOUNT/date
13366
13367         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
13368         $LCTL set_param fail_loc=0x80001401
13369
13370         $MOUNT/date > /dev/null
13371         rm -f $MOUNT/date
13372 }
13373 run_test 221 "make sure fault and truncate race to not cause OOM"
13374
13375 test_222a () {
13376         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13377        rm -rf $DIR/$tdir
13378        test_mkdir -p $DIR/$tdir
13379        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
13380        createmany -o $DIR/$tdir/$tfile 10
13381        cancel_lru_locks mdc
13382        cancel_lru_locks osc
13383        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
13384        $LCTL set_param fail_loc=0x31a
13385        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
13386        $LCTL set_param fail_loc=0
13387        rm -r $DIR/$tdir
13388 }
13389 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
13390
13391 test_222b () {
13392         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13393         rm -rf $DIR/$tdir
13394         test_mkdir -p $DIR/$tdir
13395         $SETSTRIPE -c 1 -i 0 $DIR/$tdir
13396         createmany -o $DIR/$tdir/$tfile 10
13397         cancel_lru_locks mdc
13398         cancel_lru_locks osc
13399         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
13400         $LCTL set_param fail_loc=0x31a
13401         rm -r $DIR/$tdir || error "AGL for rmdir failed"
13402         $LCTL set_param fail_loc=0
13403 }
13404 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
13405
13406 test_223 () {
13407         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13408        rm -rf $DIR/$tdir
13409        test_mkdir -p $DIR/$tdir
13410        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
13411        createmany -o $DIR/$tdir/$tfile 10
13412        cancel_lru_locks mdc
13413        cancel_lru_locks osc
13414        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
13415        $LCTL set_param fail_loc=0x31b
13416        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
13417        $LCTL set_param fail_loc=0
13418        rm -r $DIR/$tdir
13419 }
13420 run_test 223 "osc reenqueue if without AGL lock granted ======================="
13421
13422 test_224a() { # LU-1039, MRP-303
13423         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13424         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
13425         $LCTL set_param fail_loc=0x508
13426         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
13427         $LCTL set_param fail_loc=0
13428         df $DIR
13429 }
13430 run_test 224a "Don't panic on bulk IO failure"
13431
13432 test_224b() { # LU-1039, MRP-303
13433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13434         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
13435         cancel_lru_locks osc
13436         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
13437         $LCTL set_param fail_loc=0x515
13438         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
13439         $LCTL set_param fail_loc=0
13440         df $DIR
13441 }
13442 run_test 224b "Don't panic on bulk IO failure"
13443
13444 test_224c() { # LU-6441
13445         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13446         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13447
13448         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13449         save_writethrough $p
13450         set_cache writethrough on
13451
13452         local pages_per_rpc=$($LCTL get_param \
13453                                 osc.*.max_pages_per_rpc)
13454         local at_max=$($LCTL get_param -n at_max)
13455         local timeout=$($LCTL get_param -n timeout)
13456         local test_at="$LCTL get_param -n at_max"
13457         local param_at="$FSNAME.sys.at_max"
13458         local test_timeout="$LCTL get_param -n timeout"
13459         local param_timeout="$FSNAME.sys.timeout"
13460
13461         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
13462
13463         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
13464                 error "conf_param at_max=0 failed"
13465         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
13466                 error "conf_param timeout=5 failed"
13467
13468         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
13469         do_facet ost1 $LCTL set_param fail_loc=0x520
13470         $LFS setstripe -c 1 -i 0 $DIR/$tfile
13471         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
13472         sync
13473         do_facet ost1 $LCTL set_param fail_loc=0
13474
13475         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
13476                 error "conf_param at_max=$at_max failed"
13477         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
13478                 $timeout || error "conf_param timeout=$timeout failed"
13479
13480         $LCTL set_param -n $pages_per_rpc
13481         restore_lustre_params < $p
13482         rm -f $p
13483 }
13484 run_test 224c "Don't hang if one of md lost during large bulk RPC"
13485
13486 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
13487 test_225a () {
13488         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13489         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13490         if [ -z ${MDSSURVEY} ]; then
13491               skip_env "mds-survey not found" && return
13492         fi
13493
13494         [ $MDSCOUNT -ge 2 ] &&
13495                 skip "skipping now for more than one MDT" && return
13496
13497        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13498             { skip "Need MDS version at least 2.2.51"; return; }
13499
13500        local mds=$(facet_host $SINGLEMDS)
13501        local target=$(do_nodes $mds 'lctl dl' | \
13502                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13503
13504        local cmd1="file_count=1000 thrhi=4"
13505        local cmd2="dir_count=2 layer=mdd stripe_count=0"
13506        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13507        local cmd="$cmd1 $cmd2 $cmd3"
13508
13509        rm -f ${TMP}/mds_survey*
13510        echo + $cmd
13511        eval $cmd || error "mds-survey with zero-stripe failed"
13512        cat ${TMP}/mds_survey*
13513        rm -f ${TMP}/mds_survey*
13514 }
13515 run_test 225a "Metadata survey sanity with zero-stripe"
13516
13517 test_225b () {
13518         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13519         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13520         if [ -z ${MDSSURVEY} ]; then
13521               skip_env "mds-survey not found" && return
13522         fi
13523         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13524             { skip "Need MDS version at least 2.2.51"; return; }
13525
13526         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
13527               skip_env "Need to mount OST to test" && return
13528         fi
13529
13530        local mds=$(facet_host $SINGLEMDS)
13531        local target=$(do_nodes $mds 'lctl dl' | \
13532                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13533
13534        local cmd1="file_count=1000 thrhi=4"
13535        local cmd2="dir_count=2 layer=mdd stripe_count=1"
13536        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13537        local cmd="$cmd1 $cmd2 $cmd3"
13538
13539        rm -f ${TMP}/mds_survey*
13540        echo + $cmd
13541        eval $cmd || error "mds-survey with stripe_count failed"
13542        cat ${TMP}/mds_survey*
13543        rm -f ${TMP}/mds_survey*
13544 }
13545 run_test 225b "Metadata survey sanity with stripe_count = 1"
13546
13547 mcreate_path2fid () {
13548         local mode=$1
13549         local major=$2
13550         local minor=$3
13551         local name=$4
13552         local desc=$5
13553         local path=$DIR/$tdir/$name
13554         local fid
13555         local rc
13556         local fid_path
13557
13558         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
13559                 error "cannot create $desc"
13560
13561         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
13562         rc=$?
13563         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
13564
13565         fid_path=$($LFS fid2path $MOUNT $fid)
13566         rc=$?
13567         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
13568
13569         [ "$path" == "$fid_path" ] ||
13570                 error "fid2path returned $fid_path, expected $path"
13571
13572         echo "pass with $path and $fid"
13573 }
13574
13575 test_226a () {
13576         rm -rf $DIR/$tdir
13577         mkdir -p $DIR/$tdir
13578
13579         mcreate_path2fid 0010666 0 0 fifo "FIFO"
13580         mcreate_path2fid 0020666 1 3 null "character special file (null)"
13581         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
13582         mcreate_path2fid 0040666 0 0 dir "directory"
13583         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
13584         mcreate_path2fid 0100666 0 0 file "regular file"
13585         mcreate_path2fid 0120666 0 0 link "symbolic link"
13586         mcreate_path2fid 0140666 0 0 sock "socket"
13587 }
13588 run_test 226a "call path2fid and fid2path on files of all type"
13589
13590 test_226b () {
13591         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13592         rm -rf $DIR/$tdir
13593         local MDTIDX=1
13594
13595         mkdir -p $DIR/$tdir
13596         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
13597                 error "create remote directory failed"
13598         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
13599         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
13600                                 "character special file (null)"
13601         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
13602                                 "character special file (no device)"
13603         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
13604         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
13605                                 "block special file (loop)"
13606         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
13607         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
13608         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
13609 }
13610 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
13611
13612 # LU-1299 Executing or running ldd on a truncated executable does not
13613 # cause an out-of-memory condition.
13614 test_227() {
13615         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13616         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
13617         dd if=$(which date) of=$MOUNT/date bs=1k count=1
13618         chmod +x $MOUNT/date
13619
13620         $MOUNT/date > /dev/null
13621         ldd $MOUNT/date > /dev/null
13622         rm -f $MOUNT/date
13623 }
13624 run_test 227 "running truncated executable does not cause OOM"
13625
13626 # LU-1512 try to reuse idle OI blocks
13627 test_228a() {
13628         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13629         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13630         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13631                 skip "ldiskfs only test" && return
13632
13633         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13634         local myDIR=$DIR/$tdir
13635
13636         mkdir -p $myDIR
13637         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13638         $LCTL set_param fail_loc=0x80001002
13639         createmany -o $myDIR/t- 10000
13640         $LCTL set_param fail_loc=0
13641         # The guard is current the largest FID holder
13642         touch $myDIR/guard
13643         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13644                     tr -d '[')
13645         local IDX=$(($SEQ % 64))
13646
13647         do_facet $SINGLEMDS sync
13648         # Make sure journal flushed.
13649         sleep 6
13650         local blk1=$(do_facet $SINGLEMDS \
13651                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13652                      grep Blockcount | awk '{print $4}')
13653
13654         # Remove old files, some OI blocks will become idle.
13655         unlinkmany $myDIR/t- 10000
13656         # Create new files, idle OI blocks should be reused.
13657         createmany -o $myDIR/t- 2000
13658         do_facet $SINGLEMDS sync
13659         # Make sure journal flushed.
13660         sleep 6
13661         local blk2=$(do_facet $SINGLEMDS \
13662                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13663                      grep Blockcount | awk '{print $4}')
13664
13665         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13666 }
13667 run_test 228a "try to reuse idle OI blocks"
13668
13669 test_228b() {
13670         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13671         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13672         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13673                 skip "ldiskfs only test" && return
13674
13675         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13676         local myDIR=$DIR/$tdir
13677
13678         mkdir -p $myDIR
13679         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13680         $LCTL set_param fail_loc=0x80001002
13681         createmany -o $myDIR/t- 10000
13682         $LCTL set_param fail_loc=0
13683         # The guard is current the largest FID holder
13684         touch $myDIR/guard
13685         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13686                     tr -d '[')
13687         local IDX=$(($SEQ % 64))
13688
13689         do_facet $SINGLEMDS sync
13690         # Make sure journal flushed.
13691         sleep 6
13692         local blk1=$(do_facet $SINGLEMDS \
13693                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13694                      grep Blockcount | awk '{print $4}')
13695
13696         # Remove old files, some OI blocks will become idle.
13697         unlinkmany $myDIR/t- 10000
13698
13699         # stop the MDT
13700         stop $SINGLEMDS || error "Fail to stop MDT."
13701         # remount the MDT
13702         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
13703
13704         df $MOUNT || error "Fail to df."
13705         # Create new files, idle OI blocks should be reused.
13706         createmany -o $myDIR/t- 2000
13707         do_facet $SINGLEMDS sync
13708         # Make sure journal flushed.
13709         sleep 6
13710         local blk2=$(do_facet $SINGLEMDS \
13711                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13712                      grep Blockcount | awk '{print $4}')
13713
13714         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13715 }
13716 run_test 228b "idle OI blocks can be reused after MDT restart"
13717
13718 #LU-1881
13719 test_228c() {
13720         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13721         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13722         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13723                 skip "ldiskfs only test" && return
13724
13725         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13726         local myDIR=$DIR/$tdir
13727
13728         mkdir -p $myDIR
13729         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13730         $LCTL set_param fail_loc=0x80001002
13731         # 20000 files can guarantee there are index nodes in the OI file
13732         createmany -o $myDIR/t- 20000
13733         $LCTL set_param fail_loc=0
13734         # The guard is current the largest FID holder
13735         touch $myDIR/guard
13736         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13737                     tr -d '[')
13738         local IDX=$(($SEQ % 64))
13739
13740         do_facet $SINGLEMDS sync
13741         # Make sure journal flushed.
13742         sleep 6
13743         local blk1=$(do_facet $SINGLEMDS \
13744                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13745                      grep Blockcount | awk '{print $4}')
13746
13747         # Remove old files, some OI blocks will become idle.
13748         unlinkmany $myDIR/t- 20000
13749         rm -f $myDIR/guard
13750         # The OI file should become empty now
13751
13752         # Create new files, idle OI blocks should be reused.
13753         createmany -o $myDIR/t- 2000
13754         do_facet $SINGLEMDS sync
13755         # Make sure journal flushed.
13756         sleep 6
13757         local blk2=$(do_facet $SINGLEMDS \
13758                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13759                      grep Blockcount | awk '{print $4}')
13760
13761         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13762 }
13763 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
13764
13765 test_229() { # LU-2482, LU-3448
13766         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
13767                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
13768                 return
13769         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13770         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
13771
13772         rm -f $DIR/$tfile
13773
13774         # Create a file with a released layout and stripe count 2.
13775         $MULTIOP $DIR/$tfile H2c ||
13776                 error "failed to create file with released layout"
13777
13778         $GETSTRIPE -v $DIR/$tfile
13779
13780         local pattern=$($GETSTRIPE -L $DIR/$tfile)
13781         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
13782
13783         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
13784         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
13785         stat $DIR/$tfile || error "failed to stat released file"
13786
13787         chown $RUNAS_ID $DIR/$tfile ||
13788                 error "chown $RUNAS_ID $DIR/$tfile failed"
13789
13790         chgrp $RUNAS_ID $DIR/$tfile ||
13791                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
13792
13793         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
13794         rm $DIR/$tfile || error "failed to remove released file"
13795 }
13796 run_test 229 "getstripe/stat/rm/attr changes work on released files"
13797
13798 test_230a() {
13799         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13800         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13801         local MDTIDX=1
13802
13803         test_mkdir $DIR/$tdir
13804         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
13805         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
13806         [ $mdt_idx -ne 0 ] &&
13807                 error "create local directory on wrong MDT $mdt_idx"
13808
13809         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
13810                         error "create remote directory failed"
13811         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
13812         [ $mdt_idx -ne $MDTIDX ] &&
13813                 error "create remote directory on wrong MDT $mdt_idx"
13814
13815         createmany -o $DIR/$tdir/test_230/t- 10 ||
13816                 error "create files on remote directory failed"
13817         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
13818         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
13819         rm -r $DIR/$tdir || error "unlink remote directory failed"
13820 }
13821 run_test 230a "Create remote directory and files under the remote directory"
13822
13823 test_230b() {
13824         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13825         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13826         local MDTIDX=1
13827         local mdt_index
13828         local i
13829         local file
13830         local pid
13831         local stripe_count
13832         local migrate_dir=$DIR/$tdir/migrate_dir
13833         local other_dir=$DIR/$tdir/other_dir
13834
13835         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
13836                 skip "lustre < 2.11.56 does not support migrate -m "
13837
13838         test_mkdir $DIR/$tdir
13839         test_mkdir -i0 -c1 $migrate_dir
13840         test_mkdir -i0 -c1 $other_dir
13841         for ((i=0; i<10; i++)); do
13842                 mkdir -p $migrate_dir/dir_${i}
13843                 createmany -o $migrate_dir/dir_${i}/f 10 ||
13844                         error "create files under remote dir failed $i"
13845         done
13846
13847         cp /etc/passwd $migrate_dir/$tfile
13848         cp /etc/passwd $other_dir/$tfile
13849         chattr +SAD $migrate_dir
13850         chattr +SAD $migrate_dir/$tfile
13851
13852         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13853         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13854         local old_dir_mode=$(stat -c%f $migrate_dir)
13855         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
13856
13857         mkdir -p $migrate_dir/dir_default_stripe2
13858         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
13859         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
13860
13861         mkdir -p $other_dir
13862         ln $migrate_dir/$tfile $other_dir/luna
13863         ln $migrate_dir/$tfile $migrate_dir/sofia
13864         ln $other_dir/$tfile $migrate_dir/david
13865         ln -s $migrate_dir/$tfile $other_dir/zachary
13866         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
13867         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
13868
13869         $LFS migrate -m $MDTIDX $migrate_dir ||
13870                 error "fails on migrating remote dir to MDT1"
13871
13872         echo "migratate to MDT1, then checking.."
13873         for ((i = 0; i < 10; i++)); do
13874                 for file in $(find $migrate_dir/dir_${i}); do
13875                         mdt_index=$($LFS getstripe -M $file)
13876                         [ $mdt_index == $MDTIDX ] ||
13877                                 error "$file is not on MDT${MDTIDX}"
13878                 done
13879         done
13880
13881         # the multiple link file should still in MDT0
13882         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
13883         [ $mdt_index == 0 ] ||
13884                 error "$file is not on MDT${MDTIDX}"
13885
13886         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13887         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13888                 error " expect $old_dir_flag get $new_dir_flag"
13889
13890         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13891         [ "$old_file_flag" = "$new_file_flag" ] ||
13892                 error " expect $old_file_flag get $new_file_flag"
13893
13894         local new_dir_mode=$(stat -c%f $migrate_dir)
13895         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13896                 error "expect mode $old_dir_mode get $new_dir_mode"
13897
13898         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13899         [ "$old_file_mode" = "$new_file_mode" ] ||
13900                 error "expect mode $old_file_mode get $new_file_mode"
13901
13902         diff /etc/passwd $migrate_dir/$tfile ||
13903                 error "$tfile different after migration"
13904
13905         diff /etc/passwd $other_dir/luna ||
13906                 error "luna different after migration"
13907
13908         diff /etc/passwd $migrate_dir/sofia ||
13909                 error "sofia different after migration"
13910
13911         diff /etc/passwd $migrate_dir/david ||
13912                 error "david different after migration"
13913
13914         diff /etc/passwd $other_dir/zachary ||
13915                 error "zachary different after migration"
13916
13917         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13918                 error "${tfile}_ln different after migration"
13919
13920         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13921                 error "${tfile}_ln_other different after migration"
13922
13923         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
13924         [ $stripe_count = 2 ] ||
13925                 error "dir strpe_count $d != 2 after migration."
13926
13927         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
13928         [ $stripe_count = 2 ] ||
13929                 error "file strpe_count $d != 2 after migration."
13930
13931         #migrate back to MDT0
13932         MDTIDX=0
13933
13934         $LFS migrate -m $MDTIDX $migrate_dir ||
13935                 error "fails on migrating remote dir to MDT0"
13936
13937         echo "migrate back to MDT0, checking.."
13938         for file in $(find $migrate_dir); do
13939                 mdt_index=$($LFS getstripe -M $file)
13940                 [ $mdt_index == $MDTIDX ] ||
13941                         error "$file is not on MDT${MDTIDX}"
13942         done
13943
13944         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13945         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13946                 error " expect $old_dir_flag get $new_dir_flag"
13947
13948         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13949         [ "$old_file_flag" = "$new_file_flag" ] ||
13950                 error " expect $old_file_flag get $new_file_flag"
13951
13952         local new_dir_mode=$(stat -c%f $migrate_dir)
13953         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13954                 error "expect mode $old_dir_mode get $new_dir_mode"
13955
13956         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13957         [ "$old_file_mode" = "$new_file_mode" ] ||
13958                 error "expect mode $old_file_mode get $new_file_mode"
13959
13960         diff /etc/passwd ${migrate_dir}/$tfile ||
13961                 error "$tfile different after migration"
13962
13963         diff /etc/passwd ${other_dir}/luna ||
13964                 error "luna different after migration"
13965
13966         diff /etc/passwd ${migrate_dir}/sofia ||
13967                 error "sofia different after migration"
13968
13969         diff /etc/passwd ${other_dir}/zachary ||
13970                 error "zachary different after migration"
13971
13972         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13973                 error "${tfile}_ln different after migration"
13974
13975         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13976                 error "${tfile}_ln_other different after migration"
13977
13978         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
13979         [ $stripe_count = 2 ] ||
13980                 error "dir strpe_count $d != 2 after migration."
13981
13982         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
13983         [ $stripe_count = 2 ] ||
13984                 error "file strpe_count $d != 2 after migration."
13985
13986         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13987 }
13988 run_test 230b "migrate directory"
13989
13990 test_230c() {
13991         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13992         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13993         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13994         local MDTIDX=1
13995         local mdt_index
13996         local file
13997         local migrate_dir=$DIR/$tdir/migrate_dir
13998
13999         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
14000                 skip "lustre < 2.11.56 does not support migrate -m "
14001
14002         #If migrating directory fails in the middle, all entries of
14003         #the directory is still accessiable.
14004         test_mkdir $DIR/$tdir
14005         test_mkdir -i0 -c1 $migrate_dir
14006         stat $migrate_dir
14007         createmany -o $migrate_dir/f 10 ||
14008                 error "create files under ${migrate_dir} failed"
14009
14010         #failed after migrating 5 entries
14011         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
14012         do_facet mds1 lctl set_param fail_loc=0x20001801
14013         do_facet mds1 lctl  set_param fail_val=5
14014         local t=$(ls $migrate_dir | wc -l)
14015         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
14016                 error "migrate should fail after 5 entries"
14017
14018         mkdir $migrate_dir/dir &&
14019                 error "mkdir succeeds under migrating directory"
14020         touch $migrate_dir/file &&
14021                 error "touch file succeeds under migrating directory"
14022
14023         local u=$(ls $migrate_dir | wc -l)
14024         [ "$u" == "$t" ] || error "$u != $t during migration"
14025
14026         for file in $(find $migrate_dir); do
14027                 stat $file || error "stat $file failed"
14028         done
14029
14030         do_facet mds1 lctl set_param fail_loc=0
14031         do_facet mds1 lctl set_param fail_val=0
14032
14033         $LFS migrate -m $MDTIDX $migrate_dir ||
14034                 error "migrate open files should failed with open files"
14035
14036         echo "Finish migration, then checking.."
14037         for file in $(find $migrate_dir); do
14038                 mdt_index=$($LFS getstripe -M $file)
14039                 [ $mdt_index == $MDTIDX ] ||
14040                         error "$file is not on MDT${MDTIDX}"
14041         done
14042
14043         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14044 }
14045 run_test 230c "check directory accessiblity if migration is failed"
14046
14047 test_230d() {
14048         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14049         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14050         local MDTIDX=1
14051         local mdt_index
14052         local migrate_dir=$DIR/$tdir/migrate_dir
14053         local i
14054         local j
14055
14056         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
14057                 skip "lustre < 2.11.56 does not support migrate -m "
14058
14059         test_mkdir $DIR/$tdir
14060         test_mkdir -i0 -c1 $migrate_dir
14061
14062         for ((i=0; i<100; i++)); do
14063                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
14064                 createmany -o $migrate_dir/dir_${i}/f 100 ||
14065                         error "create files under remote dir failed $i"
14066         done
14067
14068         $LFS migrate -m $MDTIDX $migrate_dir ||
14069                 error "migrate remote dir error"
14070
14071         echo "Finish migration, then checking.."
14072         for file in $(find $migrate_dir); do
14073                 mdt_index=$($LFS getstripe -M $file)
14074                 [ $mdt_index == $MDTIDX ] ||
14075                         error "$file is not on MDT${MDTIDX}"
14076         done
14077
14078         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14079 }
14080 run_test 230d "check migrate big directory"
14081
14082 test_230e() {
14083         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14084         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14085         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
14086                 skip "lustre < 2.11.56 does not support migrate -m "
14087
14088         local i
14089         local j
14090         local a_fid
14091         local b_fid
14092
14093         mkdir -p $DIR/$tdir
14094         mkdir $DIR/$tdir/migrate_dir
14095         mkdir $DIR/$tdir/other_dir
14096         touch $DIR/$tdir/migrate_dir/a
14097         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
14098         ls $DIR/$tdir/other_dir
14099
14100         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
14101                 error "migrate dir fails"
14102
14103         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
14104         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
14105
14106         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14107         [ $mdt_index == 0 ] || error "a is not on MDT0"
14108
14109         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
14110                 error "migrate dir fails"
14111
14112         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
14113         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
14114
14115         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14116         [ $mdt_index == 1 ] || error "a is not on MDT1"
14117
14118         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
14119         [ $mdt_index == 1 ] || error "b is not on MDT1"
14120
14121         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
14122         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
14123
14124         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
14125
14126         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14127 }
14128 run_test 230e "migrate mulitple local link files"
14129
14130 test_230f() {
14131         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14132         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14133         local a_fid
14134         local ln_fid
14135
14136         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
14137                 skip "lustre < 2.11.56 does not support migrate -m "
14138
14139         mkdir -p $DIR/$tdir
14140         mkdir $DIR/$tdir/migrate_dir
14141         $LFS mkdir -i1 $DIR/$tdir/other_dir
14142         touch $DIR/$tdir/migrate_dir/a
14143         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
14144         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
14145         ls $DIR/$tdir/other_dir
14146
14147         # a should be migrated to MDT1, since no other links on MDT0
14148         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
14149                 error "#1 migrate dir fails"
14150         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
14151         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
14152         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14153         [ $mdt_index == 1 ] || error "a is not on MDT1"
14154
14155         # a should stay on MDT1, because it is a mulitple link file
14156         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
14157                 error "#2 migrate dir fails"
14158         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14159         [ $mdt_index == 1 ] || error "a is not on MDT1"
14160
14161         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
14162                 error "#3 migrate dir fails"
14163
14164         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
14165         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
14166         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
14167
14168         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
14169         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
14170
14171         # a should be migrated to MDT0, since no other links on MDT1
14172         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
14173                 error "#4 migrate dir fails"
14174         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14175         [ $mdt_index == 0 ] || error "a is not on MDT0"
14176
14177         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14178 }
14179 run_test 230f "migrate mulitple remote link files"
14180
14181 test_230g() {
14182         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14183         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14184
14185         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
14186                 skip "lustre < 2.11.56 does not support migrate -m "
14187
14188         mkdir -p $DIR/$tdir/migrate_dir
14189
14190         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
14191                 error "migrating dir to non-exist MDT succeeds"
14192         true
14193 }
14194 run_test 230g "migrate dir to non-exist MDT"
14195
14196 test_230h() {
14197         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14198         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14199         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
14200                 skip "lustre < 2.11.56 does not support migrate -m "
14201
14202         local mdt_index
14203
14204         mkdir -p $DIR/$tdir/migrate_dir
14205
14206         $LFS migrate -m1 $DIR &&
14207                 error "migrating mountpoint1 should fail"
14208
14209         $LFS migrate -m1 $DIR/$tdir/.. &&
14210                 error "migrating mountpoint2 should fail"
14211
14212         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
14213                 error "migrating $tdir fail"
14214
14215         mdt_index=$($LFS getstripe -M $DIR/$tdir)
14216         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
14217
14218         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
14219         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
14220
14221 }
14222 run_test 230h "migrate .. and root"
14223
14224 test_230i() {
14225         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14226         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14227
14228         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
14229                 skip "lustre < 2.11.56 does not support migrate -m "
14230
14231         mkdir -p $DIR/$tdir/migrate_dir
14232
14233         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
14234                 error "migration fails with a tailing slash"
14235
14236         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
14237                 error "migration fails with two tailing slashes"
14238 }
14239 run_test 230i "lfs migrate -m tolerates trailing slashes"
14240
14241 test_231a()
14242 {
14243         # For simplicity this test assumes that max_pages_per_rpc
14244         # is the same across all OSCs
14245         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
14246         local bulk_size=$((max_pages * 4096))
14247         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
14248                                        head -n 1)
14249
14250         mkdir -p $DIR/$tdir
14251         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
14252                 error "failed to set stripe with -S ${brw_size}M option"
14253
14254         # clear the OSC stats
14255         $LCTL set_param osc.*.stats=0 &>/dev/null
14256         stop_writeback
14257
14258         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
14259         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
14260                 oflag=direct &>/dev/null || error "dd failed"
14261
14262         sync; sleep 1; sync # just to be safe
14263         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
14264         if [ x$nrpcs != "x1" ]; then
14265                 $LCTL get_param osc.*.stats
14266                 error "found $nrpcs ost_write RPCs, not 1 as expected"
14267         fi
14268
14269         start_writeback
14270         # Drop the OSC cache, otherwise we will read from it
14271         cancel_lru_locks osc
14272
14273         # clear the OSC stats
14274         $LCTL set_param osc.*.stats=0 &>/dev/null
14275
14276         # Client reads $bulk_size.
14277         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
14278                 iflag=direct &>/dev/null || error "dd failed"
14279
14280         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
14281         if [ x$nrpcs != "x1" ]; then
14282                 $LCTL get_param osc.*.stats
14283                 error "found $nrpcs ost_read RPCs, not 1 as expected"
14284         fi
14285 }
14286 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
14287
14288 test_231b() {
14289         mkdir -p $DIR/$tdir
14290         local i
14291         for i in {0..1023}; do
14292                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
14293                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
14294                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
14295         done
14296         sync
14297 }
14298 run_test 231b "must not assert on fully utilized OST request buffer"
14299
14300 test_232() {
14301         mkdir -p $DIR/$tdir
14302         #define OBD_FAIL_LDLM_OST_LVB            0x31c
14303         $LCTL set_param fail_loc=0x31c
14304
14305         # ignore dd failure
14306         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
14307
14308         $LCTL set_param fail_loc=0
14309         umount_client $MOUNT || error "umount failed"
14310         mount_client $MOUNT || error "mount failed"
14311 }
14312 run_test 232 "failed lock should not block umount"
14313
14314 test_233a() {
14315         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
14316         { skip "Need MDS version at least 2.3.64"; return; }
14317         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
14318
14319         local fid=$($LFS path2fid $MOUNT)
14320         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
14321                 error "cannot access $MOUNT using its FID '$fid'"
14322 }
14323 run_test 233a "checking that OBF of the FS root succeeds"
14324
14325 test_233b() {
14326         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
14327         { skip "Need MDS version at least 2.5.90"; return; }
14328         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
14329
14330         local fid=$($LFS path2fid $MOUNT/.lustre)
14331         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
14332                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
14333
14334         fid=$($LFS path2fid $MOUNT/.lustre/fid)
14335         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
14336                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
14337 }
14338 run_test 233b "checking that OBF of the FS .lustre succeeds"
14339
14340 test_234() {
14341         local p="$TMP/sanityN-$TESTNAME.parameters"
14342         save_lustre_params client "llite.*.xattr_cache" > $p
14343         lctl set_param llite.*.xattr_cache 1 ||
14344                 { skip "xattr cache is not supported"; return 0; }
14345
14346         mkdir -p $DIR/$tdir || error "mkdir failed"
14347         touch $DIR/$tdir/$tfile || error "touch failed"
14348         # OBD_FAIL_LLITE_XATTR_ENOMEM
14349         $LCTL set_param fail_loc=0x1405
14350         # output of the form: attr 2 4 44 3 fc13 x86_64
14351         V=($(IFS=".-" rpm -q attr))
14352         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
14353               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
14354                 # attr pre-2.4.44-7 had a bug with rc
14355                 # LU-3703 - SLES 11 and FC13 clients have older attr
14356                 getfattr -n user.attr $DIR/$tdir/$tfile &&
14357                         error "getfattr should have failed with ENOMEM"
14358         else
14359                 skip "LU-3703: attr version $(getfattr --version) too old"
14360         fi
14361         $LCTL set_param fail_loc=0x0
14362         rm -rf $DIR/$tdir
14363
14364         restore_lustre_params < $p
14365         rm -f $p
14366 }
14367 run_test 234 "xattr cache should not crash on ENOMEM"
14368
14369 test_235() {
14370         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
14371                 skip "Need MDS version at least 2.4.52" && return
14372         flock_deadlock $DIR/$tfile
14373         local RC=$?
14374         case $RC in
14375                 0)
14376                 ;;
14377                 124) error "process hangs on a deadlock"
14378                 ;;
14379                 *) error "error executing flock_deadlock $DIR/$tfile"
14380                 ;;
14381         esac
14382 }
14383 run_test 235 "LU-1715: flock deadlock detection does not work properly"
14384
14385 #LU-2935
14386 test_236() {
14387         check_swap_layouts_support && return 0
14388         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
14389
14390         local ref1=/etc/passwd
14391         local ref2=/etc/group
14392         local file1=$DIR/$tdir/f1
14393         local file2=$DIR/$tdir/f2
14394
14395         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
14396         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
14397         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
14398         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
14399         local fd=$(free_fd)
14400         local cmd="exec $fd<>$file2"
14401         eval $cmd
14402         rm $file2
14403         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
14404                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
14405         cmd="exec $fd>&-"
14406         eval $cmd
14407         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
14408
14409         #cleanup
14410         rm -rf $DIR/$tdir
14411 }
14412 run_test 236 "Layout swap on open unlinked file"
14413
14414 # test to verify file handle related system calls
14415 # (name_to_handle_at/open_by_handle_at)
14416 # The new system calls are supported in glibc >= 2.14.
14417
14418 test_237() {
14419         echo "Test file_handle syscalls" > $DIR/$tfile ||
14420                 error "write failed"
14421         check_fhandle_syscalls $DIR/$tfile ||
14422                 error "check_fhandle_syscalls failed"
14423 }
14424 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
14425
14426 # LU-4659 linkea consistency
14427 test_238() {
14428         local server_version=$(lustre_version_code $SINGLEMDS)
14429
14430         [[ $server_version -gt $(version_code 2.5.57) ]] ||
14431                 [[ $server_version -gt $(version_code 2.5.1) &&
14432                    $server_version -lt $(version_code 2.5.50) ]] ||
14433                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
14434
14435         touch $DIR/$tfile
14436         ln $DIR/$tfile $DIR/$tfile.lnk
14437         touch $DIR/$tfile.new
14438         mv $DIR/$tfile.new $DIR/$tfile
14439         local fid1=$($LFS path2fid $DIR/$tfile)
14440         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
14441         local path1=$($LFS fid2path $FSNAME "$fid1")
14442         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
14443         local path2=$($LFS fid2path $FSNAME "$fid2")
14444         [ $tfile.lnk == $path2 ] ||
14445                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
14446         rm -f $DIR/$tfile*
14447 }
14448 run_test 238 "Verify linkea consistency"
14449
14450 test_239() {
14451         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
14452                 skip "Need MDS version at least 2.5.60" && return
14453         local list=$(comma_list $(mdts_nodes))
14454
14455         mkdir -p $DIR/$tdir
14456         createmany -o $DIR/$tdir/f- 5000
14457         unlinkmany $DIR/$tdir/f- 5000
14458         [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.1) ] &&
14459                 do_nodes $list "lctl set_param -n osp.*.force_sync=1"
14460         changes=$(do_nodes $list "lctl get_param -n osp.*MDT*.sync_changes \
14461                         osp.*MDT*.sync_in_flight" | calc_sum)
14462         [ "$changes" -eq 0 ] || error "$changes not synced"
14463 }
14464 run_test 239 "osp_sync test"
14465
14466 test_239a() { #LU-5297
14467         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14468         touch $DIR/$tfile
14469         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
14470         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
14471         chgrp $RUNAS_GID $DIR/$tfile
14472         wait_delete_completed
14473 }
14474 run_test 239a "process invalid osp sync record correctly"
14475
14476 test_239b() { #LU-5297
14477         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14478         touch $DIR/$tfile1
14479         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
14480         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
14481         chgrp $RUNAS_GID $DIR/$tfile1
14482         wait_delete_completed
14483         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
14484         touch $DIR/$tfile2
14485         chgrp $RUNAS_GID $DIR/$tfile2
14486         wait_delete_completed
14487 }
14488 run_test 239b "process osp sync record with ENOMEM error correctly"
14489
14490 test_240() {
14491         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14492         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14493
14494         mkdir -p $DIR/$tdir
14495
14496         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
14497                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
14498         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
14499                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
14500
14501         umount_client $MOUNT || error "umount failed"
14502         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
14503         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
14504         mount_client $MOUNT || error "failed to mount client"
14505
14506         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
14507         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
14508 }
14509 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
14510
14511 test_241_bio() {
14512         for LOOP in $(seq $1); do
14513                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
14514                 cancel_lru_locks osc || true
14515         done
14516 }
14517
14518 test_241_dio() {
14519         for LOOP in $(seq $1); do
14520                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
14521                                                 iflag=direct 2>/dev/null
14522         done
14523 }
14524
14525 test_241a() { # was test_241
14526         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14527         ls -la $DIR/$tfile
14528         cancel_lru_locks osc
14529         test_241_bio 1000 &
14530         PID=$!
14531         test_241_dio 1000
14532         wait $PID
14533 }
14534 run_test 241a "bio vs dio"
14535
14536 test_241b() {
14537         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14538         ls -la $DIR/$tfile
14539         test_241_dio 1000 &
14540         PID=$!
14541         test_241_dio 1000
14542         wait $PID
14543 }
14544 run_test 241b "dio vs dio"
14545
14546 test_242() {
14547         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14548         mkdir -p $DIR/$tdir
14549         touch $DIR/$tdir/$tfile
14550
14551         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
14552         do_facet mds1 lctl set_param fail_loc=0x105
14553         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
14554
14555         do_facet mds1 lctl set_param fail_loc=0
14556         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
14557 }
14558 run_test 242 "mdt_readpage failure should not cause directory unreadable"
14559
14560 test_243()
14561 {
14562         test_mkdir -p $DIR/$tdir
14563         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
14564 }
14565 run_test 243 "various group lock tests"
14566
14567 test_244()
14568 {
14569         test_mkdir -p $DIR/$tdir
14570         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
14571         sendfile_grouplock $DIR/$tdir/$tfile || \
14572                 error "sendfile+grouplock failed"
14573         rm -rf $DIR/$tdir
14574 }
14575 run_test 244 "sendfile with group lock tests"
14576
14577 test_245() {
14578         local flagname="multi_mod_rpcs"
14579         local connect_data_name="max_mod_rpcs"
14580         local out
14581
14582         # check if multiple modify RPCs flag is set
14583         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
14584                 grep "connect_flags:")
14585         echo "$out"
14586
14587         echo "$out" | grep -qw $flagname
14588         if [ $? -ne 0 ]; then
14589                 echo "connect flag $flagname is not set"
14590                 return
14591         fi
14592
14593         # check if multiple modify RPCs data is set
14594         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
14595         echo "$out"
14596
14597         echo "$out" | grep -qw $connect_data_name ||
14598                 error "import should have connect data $connect_data_name"
14599 }
14600 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
14601
14602 test_246() { # LU-7371
14603         remote_ost_nodsh && skip "remote OST with nodsh" && return
14604         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
14605                 skip "Need OST version >= 2.7.62" && return 0
14606         do_facet ost1 $LCTL set_param fail_val=4095
14607 #define OBD_FAIL_OST_READ_SIZE          0x234
14608         do_facet ost1 $LCTL set_param fail_loc=0x234
14609         $LFS setstripe $DIR/$tfile -i 0 -c 1
14610         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
14611         cancel_lru_locks $FSNAME-OST0000
14612         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
14613 }
14614 run_test 246 "Read file of size 4095 should return right length"
14615
14616 test_247a() {
14617         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14618                 grep -q subtree ||
14619                 { skip "Fileset feature is not supported"; return; }
14620
14621         local submount=${MOUNT}_$tdir
14622
14623         mkdir $MOUNT/$tdir
14624         mkdir -p $submount || error "mkdir $submount failed"
14625         FILESET="$FILESET/$tdir" mount_client $submount ||
14626                 error "mount $submount failed"
14627         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
14628         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
14629                 error "read $MOUNT/$tdir/$tfile failed"
14630         umount_client $submount || error "umount $submount failed"
14631         rmdir $submount
14632 }
14633 run_test 247a "mount subdir as fileset"
14634
14635 test_247b() {
14636         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14637                 { skip "Fileset feature is not supported"; return; }
14638
14639         local submount=${MOUNT}_$tdir
14640
14641         rm -rf $MOUNT/$tdir
14642         mkdir -p $submount || error "mkdir $submount failed"
14643         SKIP_FILESET=1
14644         FILESET="$FILESET/$tdir" mount_client $submount &&
14645                 error "mount $submount should fail"
14646         rmdir $submount
14647 }
14648 run_test 247b "mount subdir that dose not exist"
14649
14650 test_247c() {
14651         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14652                 { skip "Fileset feature is not supported"; return; }
14653
14654         local submount=${MOUNT}_$tdir
14655
14656         mkdir -p $MOUNT/$tdir/dir1
14657         mkdir -p $submount || error "mkdir $submount failed"
14658         FILESET="$FILESET/$tdir" mount_client $submount ||
14659                 error "mount $submount failed"
14660         local fid=$($LFS path2fid $MOUNT/)
14661         $LFS fid2path $submount $fid && error "fid2path should fail"
14662         umount_client $submount || error "umount $submount failed"
14663         rmdir $submount
14664 }
14665 run_test 247c "running fid2path outside root"
14666
14667 test_247d() {
14668         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14669                 { skip "Fileset feature is not supported"; return; }
14670
14671         local submount=${MOUNT}_$tdir
14672
14673         mkdir -p $MOUNT/$tdir/dir1
14674         mkdir -p $submount || error "mkdir $submount failed"
14675         FILESET="$FILESET/$tdir" mount_client $submount ||
14676                 error "mount $submount failed"
14677         local fid=$($LFS path2fid $submount/dir1)
14678         $LFS fid2path $submount $fid || error "fid2path should succeed"
14679         umount_client $submount || error "umount $submount failed"
14680         rmdir $submount
14681 }
14682 run_test 247d "running fid2path inside root"
14683
14684 # LU-8037
14685 test_247e() {
14686         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14687                 grep -q subtree ||
14688                 { skip "Fileset feature is not supported"; return; }
14689
14690         local submount=${MOUNT}_$tdir
14691
14692         mkdir $MOUNT/$tdir
14693         mkdir -p $submount || error "mkdir $submount failed"
14694         FILESET="$FILESET/.." mount_client $submount &&
14695                 error "mount $submount should fail"
14696         rmdir $submount
14697 }
14698 run_test 247e "mount .. as fileset"
14699
14700 test_248() {
14701         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
14702         [ -z "$fast_read_sav" ] && skip "no fast read support" && return
14703
14704         # create a large file for fast read verification
14705         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
14706
14707         # make sure the file is created correctly
14708         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
14709                 { rm -f $DIR/$tfile; skip "file creation error" && return; }
14710
14711         echo "Test 1: verify that fast read is 4 times faster on cache read"
14712
14713         # small read with fast read enabled
14714         $LCTL set_param -n llite.*.fast_read=1
14715         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14716                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
14717                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
14718         # small read with fast read disabled
14719         $LCTL set_param -n llite.*.fast_read=0
14720         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14721                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
14722                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
14723
14724         # verify that fast read is 4 times faster for cache read
14725         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
14726                 error_not_in_vm "fast read was not 4 times faster: " \
14727                            "$t_fast vs $t_slow"
14728
14729         echo "Test 2: verify the performance between big and small read"
14730         $LCTL set_param -n llite.*.fast_read=1
14731
14732         # 1k non-cache read
14733         cancel_lru_locks osc
14734         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14735                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
14736                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
14737
14738         # 1M non-cache read
14739         cancel_lru_locks osc
14740         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14741                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
14742                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
14743
14744         # verify that big IO is not 4 times faster than small IO
14745         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
14746                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
14747
14748         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
14749         rm -f $DIR/$tfile
14750 }
14751 run_test 248 "fast read verification"
14752
14753 test_249() { # LU-7890
14754         rm -f $DIR/$tfile
14755         $SETSTRIPE -c 1 $DIR/$tfile
14756
14757         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
14758         skip "Need at least version 2.8.54"
14759
14760         # Offset 2T == 4k * 512M
14761         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
14762                 error "dd to 2T offset failed"
14763 }
14764 run_test 249 "Write above 2T file size"
14765
14766 test_250() {
14767         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
14768          && skip "no 16TB file size limit on ZFS" && return
14769
14770         $SETSTRIPE -c 1 $DIR/$tfile
14771         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
14772         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
14773         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
14774         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
14775                 conv=notrunc,fsync && error "append succeeded"
14776         return 0
14777 }
14778 run_test 250 "Write above 16T limit"
14779
14780 test_251() {
14781         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
14782
14783         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
14784         #Skip once - writing the first stripe will succeed
14785         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14786         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
14787                 error "short write happened"
14788
14789         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14790         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
14791                 error "short read happened"
14792
14793         rm -f $DIR/$tfile
14794 }
14795 run_test 251 "Handling short read and write correctly"
14796
14797 test_252() {
14798         local tgt
14799         local dev
14800         local out
14801         local uuid
14802         local num
14803         local gen
14804
14805         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14806         remote_ost_nodsh && skip "remote OST with nodsh" && return
14807         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
14808              "$(facet_fstype mds1)" != "ldiskfs" ]; then
14809                 skip "ldiskfs only test"
14810                 return
14811         fi
14812
14813         # check lr_reader on OST0000
14814         tgt=ost1
14815         dev=$(facet_device $tgt)
14816         out=$(do_facet $tgt $LR_READER $dev)
14817         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14818         echo "$out"
14819         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
14820         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
14821                 error "Invalid uuid returned by $LR_READER on target $tgt"
14822         echo -e "uuid returned by $LR_READER is '$uuid'\n"
14823
14824         # check lr_reader -c on MDT0000
14825         tgt=mds1
14826         dev=$(facet_device $tgt)
14827         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
14828                 echo "$LR_READER does not support additional options"
14829                 return 0
14830         fi
14831         out=$(do_facet $tgt $LR_READER -c $dev)
14832         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14833         echo "$out"
14834         num=$(echo "$out" | grep -c "mdtlov")
14835         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
14836                 error "Invalid number of mdtlov clients returned by $LR_READER"
14837         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
14838
14839         # check lr_reader -cr on MDT0000
14840         out=$(do_facet $tgt $LR_READER -cr $dev)
14841         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14842         echo "$out"
14843         echo "$out" | grep -q "^reply_data:$" ||
14844                 error "$LR_READER should have returned 'reply_data' section"
14845         num=$(echo "$out" | grep -c "client_generation")
14846         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
14847 }
14848 run_test 252 "check lr_reader tool"
14849
14850 test_253_fill_ost() {
14851         local size_mb #how many MB should we write to pass watermark
14852         local lwm=$3  #low watermark
14853         local free_10mb #10% of free space
14854
14855         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14856         size_mb=$((free_kb / 1024 - lwm))
14857         free_10mb=$((free_kb / 10240))
14858         #If 10% of free space cross low watermark use it
14859         if (( free_10mb > size_mb )); then
14860                 size_mb=$free_10mb
14861         else
14862                 #At least we need to store 1.1 of difference between
14863                 #free space and low watermark
14864                 size_mb=$((size_mb + size_mb / 10))
14865         fi
14866         if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
14867                 dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
14868                          oflag=append conv=notrunc
14869         fi
14870
14871         sleep_maxage
14872
14873         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14874         echo "OST still has $((free_kb / 1024)) mbytes free"
14875 }
14876
14877 test_253() {
14878         local ostidx=0
14879         local rc=0
14880
14881         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14882         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14883         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
14884
14885         local ost_name=$($LFS osts |
14886                 sed -n 's/^'$ostidx': \(.*\)_UUID .*/\1/p')
14887         # on the mdt's osc
14888         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
14889         do_facet $SINGLEMDS $LCTL get_param -n \
14890                 osp.$mdtosc_proc1.reserved_mb_high ||
14891                 { skip  "remote MDS does not support reserved_mb_high" &&
14892                   return; }
14893
14894         rm -rf $DIR/$tdir
14895         wait_mds_ost_sync
14896         wait_delete_completed
14897         mkdir $DIR/$tdir
14898
14899         local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
14900                         osp.$mdtosc_proc1.reserved_mb_high)
14901         local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
14902                         osp.$mdtosc_proc1.reserved_mb_low)
14903         echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
14904
14905         if ! combined_mgs_mds ; then
14906                 mount_mgs_client
14907         fi
14908         create_pool $FSNAME.$TESTNAME || error "Pool creation failed"
14909         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
14910                 error "Adding $ost_name to pool failed"
14911
14912         # Wait for client to see a OST at pool
14913         wait_update $HOSTNAME "$LCTL get_param -n
14914                 lov.$FSNAME-*.pools.$TESTNAME | sort -u |
14915                 grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
14916                 error "Client can not see the pool"
14917         $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
14918                 error "Setstripe failed"
14919
14920         dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
14921         local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
14922         echo "OST still has $((blocks/1024)) mbytes free"
14923
14924         local new_lwm=$((blocks/1024-10))
14925         do_facet $SINGLEMDS $LCTL set_param \
14926                         osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
14927         do_facet $SINGLEMDS $LCTL set_param \
14928                         osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
14929
14930         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14931
14932         #First enospc could execute orphan deletion so repeat.
14933         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14934
14935         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14936                         osp.$mdtosc_proc1.prealloc_status)
14937         echo "prealloc_status $oa_status"
14938
14939         dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
14940                 error "File creation should fail"
14941         #object allocation was stopped, but we still able to append files
14942         dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
14943                 error "Append failed"
14944         rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
14945
14946         wait_delete_completed
14947
14948         sleep_maxage
14949
14950         for i in $(seq 10 12); do
14951                 dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
14952                         error "File creation failed after rm";
14953         done
14954
14955         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14956                         osp.$mdtosc_proc1.prealloc_status)
14957         echo "prealloc_status $oa_status"
14958
14959         if (( oa_status != 0 )); then
14960                 error "Object allocation still disable after rm"
14961         fi
14962         do_facet $SINGLEMDS $LCTL set_param \
14963                         osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
14964         do_facet $SINGLEMDS $LCTL set_param \
14965                         osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
14966
14967
14968         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
14969                 error "Remove $ost_name from pool failed"
14970         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
14971                 error "Pool destroy fialed"
14972
14973         if ! combined_mgs_mds ; then
14974                 umount_mgs_client
14975         fi
14976 }
14977 run_test 253 "Check object allocation limit"
14978
14979 test_254() {
14980         local cl_user
14981
14982         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14983         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14984         do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
14985                 { skip "MDS does not support changelog_size" && return; }
14986
14987         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
14988         echo "Registered as changelog user $cl_user"
14989
14990         $LFS changelog_clear $MDT0 $cl_user 0
14991
14992         local size1=$(do_facet mds1 \
14993                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14994         echo "Changelog size $size1"
14995
14996         rm -rf $DIR/$tdir
14997         $LFS mkdir -i 0 $DIR/$tdir
14998         # change something
14999         mkdir -p $DIR/$tdir/pics/2008/zachy
15000         touch $DIR/$tdir/pics/2008/zachy/timestamp
15001         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
15002         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
15003         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
15004         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
15005         rm $DIR/$tdir/pics/desktop.jpg
15006
15007         local size2=$(do_facet mds1 \
15008                       $LCTL get_param -n mdd.$MDT0.changelog_size)
15009         echo "Changelog size after work $size2"
15010
15011         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
15012
15013         if (( size2 <= size1 )); then
15014                 error "Changelog size after work should be greater than original"
15015         fi
15016         return 0
15017 }
15018 run_test 254 "Check changelog size"
15019
15020 ladvise_no_type()
15021 {
15022         local type=$1
15023         local file=$2
15024
15025         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
15026                 awk -F: '{print $2}' | grep $type > /dev/null
15027         if [ $? -ne 0 ]; then
15028                 return 0
15029         fi
15030         return 1
15031 }
15032
15033 ladvise_no_ioctl()
15034 {
15035         local file=$1
15036
15037         lfs ladvise -a willread $file > /dev/null 2>&1
15038         if [ $? -eq 0 ]; then
15039                 return 1
15040         fi
15041
15042         lfs ladvise -a willread $file 2>&1 |
15043                 grep "Inappropriate ioctl for device" > /dev/null
15044         if [ $? -eq 0 ]; then
15045                 return 0
15046         fi
15047         return 1
15048 }
15049
15050 percent() {
15051         bc <<<"scale=2; ($1 - $2) * 100 / $2"
15052 }
15053
15054 # run a random read IO workload
15055 # usage: random_read_iops <filename> <filesize> <iosize>
15056 random_read_iops() {
15057         local file=$1
15058         local fsize=$2
15059         local iosize=${3:-4096}
15060
15061         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
15062                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
15063 }
15064
15065 drop_file_oss_cache() {
15066         local file="$1"
15067         local nodes="$2"
15068
15069         $LFS ladvise -a dontneed $file 2>/dev/null ||
15070                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
15071 }
15072
15073 ladvise_willread_performance()
15074 {
15075         local repeat=10
15076         local average_origin=0
15077         local average_cache=0
15078         local average_ladvise=0
15079
15080         for ((i = 1; i <= $repeat; i++)); do
15081                 echo "Iter $i/$repeat: reading without willread hint"
15082                 cancel_lru_locks osc
15083                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
15084                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
15085                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
15086                 average_origin=$(bc <<<"$average_origin + $speed_origin")
15087
15088                 cancel_lru_locks osc
15089                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
15090                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
15091                 average_cache=$(bc <<<"$average_cache + $speed_cache")
15092
15093                 cancel_lru_locks osc
15094                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
15095                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
15096                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
15097                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
15098                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
15099         done
15100         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
15101         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
15102         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
15103
15104         speedup_cache=$(percent $average_cache $average_origin)
15105         speedup_ladvise=$(percent $average_ladvise $average_origin)
15106
15107         echo "Average uncached read: $average_origin"
15108         echo "Average speedup with OSS cached read: " \
15109                 "$average_cache = +$speedup_cache%"
15110         echo "Average speedup with ladvise willread: " \
15111                 "$average_ladvise = +$speedup_ladvise%"
15112
15113         local lowest_speedup=20
15114         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
15115                 echo "Speedup with OSS cached read less than $lowest_speedup%, " \
15116                         "got $average_cache%. Skipping ladvise willread check."
15117                 return 0
15118         fi
15119
15120         # the test won't work on ZFS until it supports 'ladvise dontneed', but
15121         # it is still good to run until then to exercise 'ladvise willread'
15122         ! $LFS ladvise -a dontneed $DIR/$tfile &&
15123                 [ "$(facet_fstype ost1)" = "zfs" ] &&
15124                 echo "osd-zfs does not support dontneed or drop_caches" &&
15125                 return 0
15126
15127         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
15128         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
15129                 error_not_in_vm "Speedup with willread is less than " \
15130                         "$lowest_speedup%, got $average_ladvise%"
15131 }
15132
15133 test_255a() {
15134         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
15135                 skip "lustre < 2.8.54 does not support ladvise " && return
15136         remote_ost_nodsh && skip "remote OST with nodsh" && return
15137
15138         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
15139
15140         ladvise_no_type willread $DIR/$tfile &&
15141                 skip "willread ladvise is not supported" && return
15142
15143         ladvise_no_ioctl $DIR/$tfile &&
15144                 skip "ladvise ioctl is not supported" && return
15145
15146         local size_mb=100
15147         local size=$((size_mb * 1048576))
15148         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
15149                 error "dd to $DIR/$tfile failed"
15150
15151         lfs ladvise -a willread $DIR/$tfile ||
15152                 error "Ladvise failed with no range argument"
15153
15154         lfs ladvise -a willread -s 0 $DIR/$tfile ||
15155                 error "Ladvise failed with no -l or -e argument"
15156
15157         lfs ladvise -a willread -e 1 $DIR/$tfile ||
15158                 error "Ladvise failed with only -e argument"
15159
15160         lfs ladvise -a willread -l 1 $DIR/$tfile ||
15161                 error "Ladvise failed with only -l argument"
15162
15163         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
15164                 error "End offset should not be smaller than start offset"
15165
15166         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
15167                 error "End offset should not be equal to start offset"
15168
15169         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
15170                 error "Ladvise failed with overflowing -s argument"
15171
15172         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
15173                 error "Ladvise failed with overflowing -e argument"
15174
15175         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
15176                 error "Ladvise failed with overflowing -l argument"
15177
15178         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
15179                 error "Ladvise succeeded with conflicting -l and -e arguments"
15180
15181         echo "Synchronous ladvise should wait"
15182         local delay=4
15183 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
15184         do_nodes $(comma_list $(osts_nodes)) \
15185                 $LCTL set_param fail_val=$delay fail_loc=0x237
15186
15187         local start_ts=$SECONDS
15188         lfs ladvise -a willread $DIR/$tfile ||
15189                 error "Ladvise failed with no range argument"
15190         local end_ts=$SECONDS
15191         local inteval_ts=$((end_ts - start_ts))
15192
15193         if [ $inteval_ts -lt $(($delay - 1)) ]; then
15194                 error "Synchronous advice didn't wait reply"
15195         fi
15196
15197         echo "Asynchronous ladvise shouldn't wait"
15198         local start_ts=$SECONDS
15199         lfs ladvise -a willread -b $DIR/$tfile ||
15200                 error "Ladvise failed with no range argument"
15201         local end_ts=$SECONDS
15202         local inteval_ts=$((end_ts - start_ts))
15203
15204         if [ $inteval_ts -gt $(($delay / 2)) ]; then
15205                 error "Asynchronous advice blocked"
15206         fi
15207
15208         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
15209         ladvise_willread_performance
15210 }
15211 run_test 255a "check 'lfs ladvise -a willread'"
15212
15213 facet_meminfo() {
15214         local facet=$1
15215         local info=$2
15216
15217         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
15218 }
15219
15220 test_255b() {
15221         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
15222                 skip "lustre < 2.8.54 does not support ladvise " && return
15223         remote_ost_nodsh && skip "remote OST with nodsh" && return
15224
15225         lfs setstripe -c 1 -i 0 $DIR/$tfile
15226
15227         ladvise_no_type dontneed $DIR/$tfile &&
15228                 skip "dontneed ladvise is not supported" && return
15229
15230         ladvise_no_ioctl $DIR/$tfile &&
15231                 skip "ladvise ioctl is not supported" && return
15232
15233         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
15234                 skip "lustre < 2.8.54 does not support ladvise" && return
15235
15236         ! $LFS ladvise -a dontneed $DIR/$tfile &&
15237                 [ "$(facet_fstype ost1)" = "zfs" ] &&
15238                 skip "zfs-osd does not support 'ladvise dontneed'" && return
15239
15240         local size_mb=100
15241         local size=$((size_mb * 1048576))
15242         # In order to prevent disturbance of other processes, only check 3/4
15243         # of the memory usage
15244         local kibibytes=$((size_mb * 1024 * 3 / 4))
15245
15246         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
15247                 error "dd to $DIR/$tfile failed"
15248
15249         local total=$(facet_meminfo ost1 MemTotal)
15250         echo "Total memory: $total KiB"
15251
15252         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
15253         local before_read=$(facet_meminfo ost1 Cached)
15254         echo "Cache used before read: $before_read KiB"
15255
15256         lfs ladvise -a willread $DIR/$tfile ||
15257                 error "Ladvise willread failed"
15258         local after_read=$(facet_meminfo ost1 Cached)
15259         echo "Cache used after read: $after_read KiB"
15260
15261         lfs ladvise -a dontneed $DIR/$tfile ||
15262                 error "Ladvise dontneed again failed"
15263         local no_read=$(facet_meminfo ost1 Cached)
15264         echo "Cache used after dontneed ladvise: $no_read KiB"
15265
15266         if [ $total -lt $((before_read + kibibytes)) ]; then
15267                 echo "Memory is too small, abort checking"
15268                 return 0
15269         fi
15270
15271         if [ $((before_read + kibibytes)) -gt $after_read ]; then
15272                 error "Ladvise willread should use more memory" \
15273                         "than $kibibytes KiB"
15274         fi
15275
15276         if [ $((no_read + kibibytes)) -gt $after_read ]; then
15277                 error "Ladvise dontneed should release more memory" \
15278                         "than $kibibytes KiB"
15279         fi
15280 }
15281 run_test 255b "check 'lfs ladvise -a dontneed'"
15282
15283 test_256() {
15284         local cl_user
15285         local cat_sl
15286         local mdt_dev
15287
15288         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15289         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15290         [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
15291                 skip "ldiskfs only test" && return
15292
15293         mdt_dev=$(mdsdevname 1)
15294         echo $mdt_dev
15295         cl_user=$(do_facet mds1 \
15296         "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
15297         if [[ -n $cl_user ]]; then
15298                 skip "active changelog user"
15299                 return
15300         fi
15301
15302         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
15303         echo "Registered as changelog user $cl_user"
15304
15305         rm -rf $DIR/$tdir
15306         mkdir -p $DIR/$tdir
15307
15308         $LFS changelog_clear $MDT0 $cl_user 0
15309
15310         # change something
15311         touch $DIR/$tdir/{1..10}
15312
15313         # stop the MDT
15314         stop mds1 || error "Fail to stop MDT."
15315
15316         # remount the MDT
15317         start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
15318
15319         #after mount new plainllog is used
15320         touch $DIR/$tdir/{11..19}
15321         local TEMP256FILE=$(mktemp TEMP256XXXXXX)
15322         cat_sl=$(do_facet mds1 \
15323         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
15324          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
15325         rm $TEMP256FILE
15326
15327         if (( cat_sl != 2 )); then
15328                 do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
15329                 error "Changelog catalog has wrong number of slots $cat_sl"
15330         fi
15331
15332         $LFS changelog_clear $MDT0 $cl_user 0
15333
15334         TEMP256FILE=$(mktemp TEMP256XXXXXX)
15335         cat_sl=$(do_facet mds1 \
15336         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
15337          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
15338         rm $TEMP256FILE
15339
15340         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
15341
15342         if (( cat_sl == 2 )); then
15343                 error "Empty plain llog was not deleted from changelog catalog"
15344         fi
15345         if (( cat_sl != 1 )); then
15346                 error "Active plain llog shouldn\`t be deleted from catalog"
15347         fi
15348 }
15349 run_test 256 "Check llog delete for empty and not full state"
15350
15351 test_257() {
15352         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15353         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
15354                 skip "Need MDS version at least 2.8.55" && return
15355
15356         test_mkdir -p $DIR/$tdir
15357
15358         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
15359                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
15360         stat $DIR/$tdir
15361
15362 #define OBD_FAIL_MDS_XATTR_REP                  0x161
15363         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
15364         local facet=mds$((mdtidx + 1))
15365         set_nodes_failloc $(facet_active_host $facet) 0x80000161
15366         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
15367
15368         stop $facet || error "stop MDS failed"
15369         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
15370                 error "start MDS fail"
15371 }
15372 run_test 257 "xattr locks are not lost"
15373
15374 # Verify we take the i_mutex when security requires it
15375 test_258a() {
15376 #define OBD_FAIL_IMUTEX_SEC 0x141c
15377         $LCTL set_param fail_loc=0x141c
15378         touch $DIR/$tfile
15379         chmod u+s $DIR/$tfile
15380         chmod a+rwx $DIR/$tfile
15381         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
15382         RC=$?
15383         if [ $RC -ne 0 ]; then
15384                 error "error, failed to take i_mutex, rc=$?"
15385         fi
15386         rm -f $DIR/$tfile
15387 }
15388 run_test 258a
15389
15390 # Verify we do NOT take the i_mutex in the normal case
15391 test_258b() {
15392 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
15393         $LCTL set_param fail_loc=0x141d
15394         touch $DIR/$tfile
15395         chmod a+rwx $DIR
15396         chmod a+rw $DIR/$tfile
15397         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
15398         RC=$?
15399         if [ $RC -ne 0 ]; then
15400                 error "error, took i_mutex unnecessarily, rc=$?"
15401         fi
15402         rm -f $DIR/$tfile
15403
15404 }
15405 run_test 258b "verify i_mutex security behavior"
15406
15407 test_260() {
15408 #define OBD_FAIL_MDC_CLOSE               0x806
15409         $LCTL set_param fail_loc=0x80000806
15410         touch $DIR/$tfile
15411
15412 }
15413 run_test 260 "Check mdc_close fail"
15414
15415 test_275() {
15416         remote_ost_nodsh && skip "remote OST with nodsh" && return
15417         [ $(lustre_version_code ost1) -lt $(version_code 2.10.1) ] &&
15418                 skip "Need OST version >= 2.10.1" && return 0
15419
15420         local file=$DIR/$tfile
15421         local oss
15422
15423         oss=$(comma_list $(osts_nodes))
15424
15425         dd if=/dev/urandom of=$file bs=1M count=2 ||
15426                 error "failed to create a file"
15427         cancel_lru_locks osc
15428
15429         #lock 1
15430         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
15431                 error "failed to read a file"
15432
15433 #define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
15434         $LCTL set_param fail_loc=0x8000031f
15435
15436         cancel_lru_locks osc &
15437         sleep 1
15438
15439 #define OBD_FAIL_LDLM_PROLONG_PAUSE      0x32b
15440         do_nodes $oss $LCTL set_param fail_loc=0x8000032b
15441         #IO takes another lock, but matches the PENDING one
15442         #and places it to the IO RPC
15443         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
15444                 error "failed to read a file with PENDING lock"
15445 }
15446 run_test 275 "Read on a canceled duplicate lock"
15447
15448 test_276() {
15449         remote_ost_nodsh && skip "remote OST with nodsh" && return
15450         local pid
15451
15452         do_facet ost1 "(while true; do \
15453                 $LCTL get_param obdfilter.*.filesfree > /dev/null 2>&1; \
15454                 done) & pid=\\\$!; echo \\\$pid > $TMP/sanity_276_pid" &
15455         pid=$!
15456
15457         for LOOP in $(seq 20); do
15458                 stop ost1
15459                 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
15460         done
15461         kill -9 $pid
15462         do_facet ost1 "pid=\\\$(cat $TMP/sanity_276_pid); kill -9 \\\$pid; \
15463                 rm $TMP/sanity_276_pid"
15464 }
15465 run_test 276 "Race between mount and obd_statfs"
15466
15467 cleanup_test_300() {
15468         trap 0
15469         umask $SAVE_UMASK
15470 }
15471 test_striped_dir() {
15472         local mdt_index=$1
15473         local stripe_count
15474         local stripe_index
15475
15476         mkdir -p $DIR/$tdir
15477
15478         SAVE_UMASK=$(umask)
15479         trap cleanup_test_300 RETURN EXIT
15480
15481         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
15482                                                 $DIR/$tdir/striped_dir ||
15483                 error "set striped dir error"
15484
15485         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
15486         [ "$mode" = "755" ] || error "expect 755 got $mode"
15487
15488         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
15489                 error "getdirstripe failed"
15490         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
15491         if [ "$stripe_count" != "2" ]; then
15492                 error "1:stripe_count is $stripe_count, expect 2"
15493         fi
15494         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
15495         if [ "$stripe_count" != "2" ]; then
15496                 error "2:stripe_count is $stripe_count, expect 2"
15497         fi
15498
15499         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
15500         if [ "$stripe_index" != "$mdt_index" ]; then
15501                 error "stripe_index is $stripe_index, expect $mdt_index"
15502         fi
15503
15504         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15505                 error "nlink error after create striped dir"
15506
15507         mkdir $DIR/$tdir/striped_dir/a
15508         mkdir $DIR/$tdir/striped_dir/b
15509
15510         stat $DIR/$tdir/striped_dir/a ||
15511                 error "create dir under striped dir failed"
15512         stat $DIR/$tdir/striped_dir/b ||
15513                 error "create dir under striped dir failed"
15514
15515         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
15516                 error "nlink error after mkdir"
15517
15518         rmdir $DIR/$tdir/striped_dir/a
15519         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
15520                 error "nlink error after rmdir"
15521
15522         rmdir $DIR/$tdir/striped_dir/b
15523         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15524                 error "nlink error after rmdir"
15525
15526         chattr +i $DIR/$tdir/striped_dir
15527         createmany -o $DIR/$tdir/striped_dir/f 10 &&
15528                 error "immutable flags not working under striped dir!"
15529         chattr -i $DIR/$tdir/striped_dir
15530
15531         rmdir $DIR/$tdir/striped_dir ||
15532                 error "rmdir striped dir error"
15533
15534         cleanup_test_300
15535
15536         true
15537 }
15538
15539 test_300a() {
15540         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15541                 skip "skipped for lustre < 2.7.0" && return
15542         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15543         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15544
15545         test_striped_dir 0 || error "failed on striped dir on MDT0"
15546         test_striped_dir 1 || error "failed on striped dir on MDT0"
15547 }
15548 run_test 300a "basic striped dir sanity test"
15549
15550 test_300b() {
15551         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15552                 skip "skipped for lustre < 2.7.0" && return
15553         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15554         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15555         local i
15556         local mtime1
15557         local mtime2
15558         local mtime3
15559
15560         test_mkdir $DIR/$tdir || error "mkdir fail"
15561         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15562                 error "set striped dir error"
15563         for ((i=0; i<10; i++)); do
15564                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
15565                 sleep 1
15566                 touch $DIR/$tdir/striped_dir/file_$i ||
15567                                         error "touch error $i"
15568                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
15569                 [ $mtime1 -eq $mtime2 ] &&
15570                         error "mtime not change after create"
15571                 sleep 1
15572                 rm -f $DIR/$tdir/striped_dir/file_$i ||
15573                                         error "unlink error $i"
15574                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
15575                 [ $mtime2 -eq $mtime3 ] &&
15576                         error "mtime did not change after unlink"
15577         done
15578         true
15579 }
15580 run_test 300b "check ctime/mtime for striped dir"
15581
15582 test_300c() {
15583         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15584                 skip "skipped for lustre < 2.7.0" && return
15585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15586         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15587         local file_count
15588
15589         mkdir -p $DIR/$tdir
15590         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
15591                 error "set striped dir error"
15592
15593         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
15594                 error "chown striped dir failed"
15595
15596         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
15597                 error "create 5k files failed"
15598
15599         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
15600
15601         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
15602
15603         rm -rf $DIR/$tdir
15604 }
15605 run_test 300c "chown && check ls under striped directory"
15606
15607 test_300d() {
15608         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15609                 skip "skipped for lustre < 2.7.0" && return
15610         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15611         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15612         local stripe_count
15613         local file
15614
15615         mkdir -p $DIR/$tdir
15616         $SETSTRIPE -c 2 $DIR/$tdir
15617
15618         #local striped directory
15619         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15620                 error "set striped dir error"
15621         createmany -o $DIR/$tdir/striped_dir/f 10 ||
15622                 error "create 10 files failed"
15623
15624         #remote striped directory
15625         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
15626                 error "set striped dir error"
15627         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
15628                 error "create 10 files failed"
15629
15630         for file in $(find $DIR/$tdir); do
15631                 stripe_count=$($GETSTRIPE -c $file)
15632                 [ $stripe_count -eq 2 ] ||
15633                         error "wrong stripe $stripe_count for $file"
15634         done
15635
15636         rm -rf $DIR/$tdir
15637 }
15638 run_test 300d "check default stripe under striped directory"
15639
15640 test_300e() {
15641         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15642                 skip "Need MDS version at least 2.7.55" && return
15643         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15644         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15645         local stripe_count
15646         local file
15647
15648         mkdir -p $DIR/$tdir
15649
15650         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15651                 error "set striped dir error"
15652
15653         touch $DIR/$tdir/striped_dir/a
15654         touch $DIR/$tdir/striped_dir/b
15655         touch $DIR/$tdir/striped_dir/c
15656
15657         mkdir $DIR/$tdir/striped_dir/dir_a
15658         mkdir $DIR/$tdir/striped_dir/dir_b
15659         mkdir $DIR/$tdir/striped_dir/dir_c
15660
15661         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
15662                 error "set striped adir under striped dir error"
15663
15664         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
15665                 error "set striped bdir under striped dir error"
15666
15667         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
15668                 error "set striped cdir under striped dir error"
15669
15670         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
15671                 error "rename dir under striped dir fails"
15672
15673         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
15674                 error "rename dir under different stripes fails"
15675
15676         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
15677                 error "rename file under striped dir should succeed"
15678
15679         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
15680                 error "rename dir under striped dir should succeed"
15681
15682         rm -rf $DIR/$tdir
15683 }
15684 run_test 300e "check rename under striped directory"
15685
15686 test_300f() {
15687         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15688                 skip "Need MDS version at least 2.7.55" && return
15689         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15690         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15691         local stripe_count
15692         local file
15693
15694         rm -rf $DIR/$tdir
15695         mkdir -p $DIR/$tdir
15696
15697         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15698                 error "set striped dir error"
15699
15700         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
15701                 error "set striped dir error"
15702
15703         touch $DIR/$tdir/striped_dir/a
15704         mkdir $DIR/$tdir/striped_dir/dir_a
15705         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
15706                 error "create striped dir under striped dir fails"
15707
15708         touch $DIR/$tdir/striped_dir1/b
15709         mkdir $DIR/$tdir/striped_dir1/dir_b
15710         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
15711                 error "create striped dir under striped dir fails"
15712
15713         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
15714                 error "rename dir under different striped dir should fail"
15715
15716         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
15717                 error "rename striped dir under diff striped dir should fail"
15718
15719         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
15720                 error "rename file under diff striped dirs fails"
15721
15722         rm -rf $DIR/$tdir
15723 }
15724 run_test 300f "check rename cross striped directory"
15725
15726 test_300_check_default_striped_dir()
15727 {
15728         local dirname=$1
15729         local default_count=$2
15730         local default_index=$3
15731         local stripe_count
15732         local stripe_index
15733         local dir_stripe_index
15734         local dir
15735
15736         echo "checking $dirname $default_count $default_index"
15737         $LFS setdirstripe -D -c $default_count -i $default_index \
15738                                 -t all_char $DIR/$tdir/$dirname ||
15739                 error "set default stripe on striped dir error"
15740         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
15741         [ $stripe_count -eq $default_count ] ||
15742                 error "expect $default_count get $stripe_count for $dirname"
15743
15744         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
15745         [ $stripe_index -eq $default_index ] ||
15746                 error "expect $default_index get $stripe_index for $dirname"
15747
15748         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
15749                                                 error "create dirs failed"
15750
15751         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
15752         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
15753         for dir in $(find $DIR/$tdir/$dirname/*); do
15754                 stripe_count=$($LFS getdirstripe -c $dir)
15755                 [ $stripe_count -eq $default_count ] ||
15756                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
15757                 error "stripe count $default_count != $stripe_count for $dir"
15758
15759                 stripe_index=$($LFS getdirstripe -i $dir)
15760                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
15761                         error "$stripe_index != $default_index for $dir"
15762
15763                 #check default stripe
15764                 stripe_count=$($LFS getdirstripe -D -c $dir)
15765                 [ $stripe_count -eq $default_count ] ||
15766                 error "default count $default_count != $stripe_count for $dir"
15767
15768                 stripe_index=$($LFS getdirstripe -D -i $dir)
15769                 [ $stripe_index -eq $default_index ] ||
15770                 error "default index $default_index != $stripe_index for $dir"
15771         done
15772         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
15773 }
15774
15775 test_300g() {
15776         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15777                 skip "Need MDS version at least 2.7.55" && return
15778         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15779         local dir
15780         local stripe_count
15781         local stripe_index
15782
15783         mkdir $DIR/$tdir
15784         mkdir $DIR/$tdir/normal_dir
15785
15786         #Checking when client cache stripe index
15787         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
15788         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
15789                 error "create striped_dir failed"
15790
15791         mkdir $DIR/$tdir/striped_dir/dir1 ||
15792                 error "create dir1 fails"
15793         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
15794         [ $stripe_index -eq 1 ] ||
15795                 error "dir1 expect 1 got $stripe_index"
15796
15797         $LFS setdirstripe -i2 $DIR/$tdir/striped_dir/dir2 ||
15798                 error "create dir2 fails"
15799         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir2)
15800         [ $stripe_index -eq 2 ] ||
15801                 error "dir2 expect 2 got $stripe_index"
15802
15803         #check default stripe count/stripe index
15804         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
15805         test_300_check_default_striped_dir normal_dir 1 0
15806         test_300_check_default_striped_dir normal_dir 2 1
15807         test_300_check_default_striped_dir normal_dir 2 -1
15808
15809         #delete default stripe information
15810         echo "delete default stripeEA"
15811         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
15812                 error "set default stripe on striped dir error"
15813
15814         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
15815         for dir in $(find $DIR/$tdir/normal_dir/*); do
15816                 stripe_count=$($LFS getdirstripe -c $dir)
15817                 [ $stripe_count -eq 0 ] ||
15818                         error "expect 1 get $stripe_count for $dir"
15819                 stripe_index=$($LFS getdirstripe -i $dir)
15820                 [ $stripe_index -eq 0 ] ||
15821                         error "expect 0 get $stripe_index for $dir"
15822         done
15823 }
15824 run_test 300g "check default striped directory for normal directory"
15825
15826 test_300h() {
15827         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15828                 skip "Need MDS version at least 2.7.55" && return
15829         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15830         local dir
15831         local stripe_count
15832
15833         mkdir $DIR/$tdir
15834         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
15835                                         $DIR/$tdir/striped_dir ||
15836                 error "set striped dir error"
15837
15838         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
15839         test_300_check_default_striped_dir striped_dir 1 0
15840         test_300_check_default_striped_dir striped_dir 2 1
15841         test_300_check_default_striped_dir striped_dir 2 -1
15842
15843         #delete default stripe information
15844         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
15845                 error "set default stripe on striped dir error"
15846
15847         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
15848         for dir in $(find $DIR/$tdir/striped_dir/*); do
15849                 stripe_count=$($LFS getdirstripe -c $dir)
15850                 [ $stripe_count -eq 0 ] ||
15851                         error "expect 1 get $stripe_count for $dir"
15852         done
15853 }
15854 run_test 300h "check default striped directory for striped directory"
15855
15856 test_300i() {
15857         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15858                 skip "Need MDS version at least 2.7.55" && return
15859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15860         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15861         local stripe_count
15862         local file
15863
15864         mkdir $DIR/$tdir
15865
15866         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15867                 error "set striped dir error"
15868
15869         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15870                 error "create files under striped dir failed"
15871
15872         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
15873                 error "set striped hashdir error"
15874
15875         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
15876                 error "create dir0 under hash dir failed"
15877         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
15878                 error "create dir1 under hash dir failed"
15879
15880         # unfortunately, we need to umount to clear dir layout cache for now
15881         # once we fully implement dir layout, we can drop this
15882         umount_client $MOUNT || error "umount failed"
15883         mount_client $MOUNT || error "mount failed"
15884
15885         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
15886         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
15887         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
15888
15889         #set the stripe to be unknown hash type
15890         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
15891         $LCTL set_param fail_loc=0x1901
15892         for ((i = 0; i < 10; i++)); do
15893                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
15894                         error "stat f-$i failed"
15895                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
15896         done
15897
15898         touch $DIR/$tdir/striped_dir/f0 &&
15899                 error "create under striped dir with unknown hash should fail"
15900
15901         $LCTL set_param fail_loc=0
15902
15903         umount_client $MOUNT || error "umount failed"
15904         mount_client $MOUNT || error "mount failed"
15905
15906         return 0
15907 }
15908 run_test 300i "client handle unknown hash type striped directory"
15909
15910 test_300j() {
15911         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15912         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15913                 skip "Need MDS version at least 2.7.55" && return
15914         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15915         local stripe_count
15916         local file
15917
15918         mkdir $DIR/$tdir
15919
15920         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
15921         $LCTL set_param fail_loc=0x1702
15922         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15923                 error "set striped dir error"
15924
15925         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15926                 error "create files under striped dir failed"
15927
15928         $LCTL set_param fail_loc=0
15929
15930         rm -rf $DIR/$tdir || error "unlink striped dir fails"
15931
15932         return 0
15933 }
15934 run_test 300j "test large update record"
15935
15936 test_300k() {
15937         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15938                 skip "Need MDS version at least 2.7.55" && return
15939         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15940         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15941         local stripe_count
15942         local file
15943
15944         mkdir $DIR/$tdir
15945
15946         #define OBD_FAIL_LARGE_STRIPE   0x1703
15947         $LCTL set_param fail_loc=0x1703
15948         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
15949                 error "set striped dir error"
15950         $LCTL set_param fail_loc=0
15951
15952         $LFS getdirstripe $DIR/$tdir/striped_dir ||
15953                 error "getstripeddir fails"
15954         rm -rf $DIR/$tdir/striped_dir ||
15955                 error "unlink striped dir fails"
15956
15957         return 0
15958 }
15959 run_test 300k "test large striped directory"
15960
15961 test_300l() {
15962         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15963                 skip "Need MDS version at least 2.7.55" && return
15964         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15965         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15966         local stripe_index
15967
15968         test_mkdir -p $DIR/$tdir/striped_dir
15969         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
15970                         error "chown $RUNAS_ID failed"
15971         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
15972                 error "set default striped dir failed"
15973
15974         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
15975         $LCTL set_param fail_loc=0x80000158
15976         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
15977
15978         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
15979         [ $stripe_index -eq 1 ] ||
15980                 error "expect 1 get $stripe_index for $dir"
15981 }
15982 run_test 300l "non-root user to create dir under striped dir with stale layout"
15983
15984 test_300m() {
15985         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15986                 skip "Need MDS version at least 2.7.55" && return
15987         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15988         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
15989
15990         mkdir -p $DIR/$tdir/striped_dir
15991         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
15992                 error "set default stripes dir error"
15993
15994         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
15995
15996         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
15997         [ $stripe_count -eq 0 ] ||
15998                         error "expect 0 get $stripe_count for a"
15999
16000         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
16001                 error "set default stripes dir error"
16002
16003         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
16004
16005         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
16006         [ $stripe_count -eq 0 ] ||
16007                         error "expect 0 get $stripe_count for b"
16008
16009         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
16010                 error "set default stripes dir error"
16011
16012         mkdir $DIR/$tdir/striped_dir/c &&
16013                 error "default stripe_index is invalid, mkdir c should fails"
16014
16015         rm -rf $DIR/$tdir || error "rmdir fails"
16016 }
16017 run_test 300m "setstriped directory on single MDT FS"
16018
16019 cleanup_300n() {
16020         local list=$(comma_list $(mdts_nodes))
16021
16022         trap 0
16023         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
16024 }
16025
16026 test_300n() {
16027         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16028                 skip "Need MDS version at least 2.7.55" && return
16029         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16030         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16031         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16032
16033         local stripe_index
16034         local list=$(comma_list $(mdts_nodes))
16035
16036         trap cleanup_300n RETURN EXIT
16037         mkdir -p $DIR/$tdir
16038         chmod 777 $DIR/$tdir
16039         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
16040                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
16041                 error "create striped dir succeeds with gid=0"
16042
16043         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
16044         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
16045                 error "create striped dir fails with gid=-1"
16046
16047         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
16048         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
16049                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
16050                 error "set default striped dir succeeds with gid=0"
16051
16052
16053         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
16054         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
16055                 error "set default striped dir fails with gid=-1"
16056
16057
16058         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
16059         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
16060                                         error "create test_dir fails"
16061         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
16062                                         error "create test_dir1 fails"
16063         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
16064                                         error "create test_dir2 fails"
16065         cleanup_300n
16066 }
16067 run_test 300n "non-root user to create dir under striped dir with default EA"
16068
16069 test_300o() {
16070         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16071                 skip "Need MDS version at least 2.7.55" && return
16072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16073         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16074         local numfree1
16075         local numfree2
16076
16077         mkdir -p $DIR/$tdir
16078
16079         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
16080         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
16081         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
16082                 skip "not enough free inodes $numfree1 $numfree2"
16083                 return
16084         fi
16085
16086         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
16087         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
16088         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
16089                 skip "not enough free space $numfree1 $numfree2"
16090                 return
16091         fi
16092
16093         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
16094                 error "setdirstripe fails"
16095
16096         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
16097                 error "create dirs fails"
16098
16099         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
16100         ls $DIR/$tdir/striped_dir > /dev/null ||
16101                 error "ls striped dir fails"
16102         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
16103                 error "unlink big striped dir fails"
16104 }
16105 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
16106
16107 test_300p() {
16108         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16109         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16110         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16111
16112         mkdir -p $DIR/$tdir
16113
16114         #define OBD_FAIL_OUT_ENOSPC     0x1704
16115         do_facet mds2 lctl set_param fail_loc=0x80001704
16116         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
16117                         error "create striped directory should fail"
16118
16119         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
16120
16121         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
16122         true
16123 }
16124 run_test 300p "create striped directory without space"
16125
16126 test_300q() {
16127         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16128         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16129
16130         local fd=$(free_fd)
16131         local cmd="exec $fd<$tdir"
16132         cd $DIR
16133         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
16134         eval $cmd
16135         cmd="exec $fd<&-"
16136         trap "eval $cmd" EXIT
16137         cd $tdir || error "cd $tdir fails"
16138         rmdir  ../$tdir || error "rmdir $tdir fails"
16139         mkdir local_dir && error "create dir succeeds"
16140         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
16141         eval $cmd
16142         return 0
16143 }
16144 run_test 300q "create remote directory under orphan directory"
16145
16146 test_300r() {
16147         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16148                 skip "Need MDS version at least 2.7.55" && return
16149         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16150
16151         mkdir $DIR/$tdir
16152
16153         $LFS setdirstripe -i 0 -c -1 $DIR/$tdir/striped_dir ||
16154                 error "set striped dir error"
16155
16156         $LFS getdirstripe $DIR/$tdir/striped_dir ||
16157                 error "getstripeddir fails"
16158
16159         local stripe_count
16160         stripe_count=$($LFS getdirstripe $DIR/$tdir/striped_dir |
16161                       awk '/lmv_stripe_count:/ { print $2 }')
16162
16163         [ $MDSCOUNT -ne $stripe_count ] &&
16164                 error "wrong stripe count $stripe_count expected $MDSCOUNT"
16165
16166         rm -rf $DIR/$tdir/striped_dir ||
16167                 error "unlink striped dir fails"
16168 }
16169 run_test 300r "test -1 striped directory"
16170
16171 prepare_remote_file() {
16172         mkdir $DIR/$tdir/src_dir ||
16173                 error "create remote source failed"
16174
16175         cp /etc/hosts $DIR/$tdir/src_dir/a || error
16176         touch $DIR/$tdir/src_dir/a
16177
16178         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
16179                 error "create remote target dir failed"
16180
16181         touch $DIR/$tdir/tgt_dir/b
16182
16183         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
16184                 error "rename dir cross MDT failed!"
16185
16186         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
16187                 error "src_child still exists after rename"
16188
16189         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
16190                 error "missing file(a) after rename"
16191
16192         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
16193                 error "diff after rename"
16194 }
16195
16196 test_310a() {
16197         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
16198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16199         local remote_file=$DIR/$tdir/tgt_dir/b
16200
16201         mkdir -p $DIR/$tdir
16202
16203         prepare_remote_file || error "prepare remote file failed"
16204
16205         #open-unlink file
16206         $OPENUNLINK $remote_file $remote_file || error
16207         $CHECKSTAT -a $remote_file || error
16208 }
16209 run_test 310a "open unlink remote file"
16210
16211 test_310b() {
16212         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
16213         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16214         local remote_file=$DIR/$tdir/tgt_dir/b
16215
16216         mkdir -p $DIR/$tdir
16217
16218         prepare_remote_file || error "prepare remote file failed"
16219
16220         ln $remote_file $DIR/$tfile || error "link failed for remote file"
16221         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
16222         $CHECKSTAT -t file $remote_file || error "check file failed"
16223 }
16224 run_test 310b "unlink remote file with multiple links while open"
16225
16226 test_310c() {
16227         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
16228         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16229         local remote_file=$DIR/$tdir/tgt_dir/b
16230
16231         mkdir -p $DIR/$tdir
16232
16233         prepare_remote_file || error "prepare remote file failed"
16234
16235         ln $remote_file $DIR/$tfile || error "link failed for remote file"
16236         multiop_bg_pause $remote_file O_uc ||
16237                         error "mulitop failed for remote file"
16238         MULTIPID=$!
16239         $MULTIOP $DIR/$tfile Ouc
16240         kill -USR1 $MULTIPID
16241         wait $MULTIPID
16242 }
16243 run_test 310c "open-unlink remote file with multiple links"
16244
16245 #LU-4825
16246 test_311() {
16247         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
16248         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.54) ] &&
16249                 skip "lustre < 2.8.54 does not contain LU-4825 fix" && return
16250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16251         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16252
16253         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
16254         local mdts=$(comma_list $(mdts_nodes))
16255
16256         mkdir -p $DIR/$tdir
16257         $SETSTRIPE -i 0 -c 1 $DIR/$tdir
16258         createmany -o $DIR/$tdir/$tfile. 1000
16259
16260         # statfs data is not real time, let's just calculate it
16261         old_iused=$((old_iused + 1000))
16262
16263         local count=$(do_facet $SINGLEMDS "$LCTL get_param -n \
16264                         osp.*OST0000*MDT0000.create_count")
16265         local max_count=$(do_facet $SINGLEMDS "$LCTL get_param -n \
16266                                 osp.*OST0000*MDT0000.max_create_count")
16267         do_nodes $mdts "$LCTL set_param -n osp.*OST0000*.max_create_count=0"
16268
16269         $SETSTRIPE -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
16270         local index=$($GETSTRIPE -i $DIR/$tdir/$tfile)
16271         [ $index -ne 0 ] || error "$tfile stripe index is 0"
16272
16273         unlinkmany $DIR/$tdir/$tfile. 1000
16274
16275         do_nodes $mdts "$LCTL set_param -n \
16276                         osp.*OST0000*.max_create_count=$max_count"
16277         [ $(lustre_version_code $facet) -lt $(version_code 2.11.56) ] &&
16278                 do_nodes $mdts "$LCTL set_param -n \
16279                                 osp.*OST0000*.create_count=$count"
16280         do_nodes $mdts "$LCTL get_param osp.*OST0000*.create_count" |
16281                         grep "=0" && error "create_count is zero"
16282
16283         local new_iused
16284         for i in $(seq 120); do
16285                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
16286                 # system may be too busy to destroy all objs in time, use
16287                 # a somewhat small value to not fail autotest
16288                 [ $((old_iused - new_iused)) -gt 400 ] && break
16289                 sleep 1
16290         done
16291
16292         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
16293         [ $((old_iused - new_iused)) -gt 400 ] ||
16294                 error "objs not destroyed after unlink"
16295 }
16296 run_test 311 "disable OSP precreate, and unlink should destroy objs"
16297
16298 zfs_oid_to_objid()
16299 {
16300         local ost=$1
16301         local objid=$2
16302
16303         local vdevdir=$(dirname $(facet_vdevice $ost))
16304         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
16305         local zfs_zapid=$(do_facet $ost $cmd |
16306                           grep -w "/O/0/d$((objid%32))" -C 5 |
16307                           awk '/Object/{getline; print $1}')
16308         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
16309                           awk "/$objid = /"'{printf $3}')
16310
16311         echo $zfs_objid
16312 }
16313
16314 zfs_object_blksz() {
16315         local ost=$1
16316         local objid=$2
16317
16318         local vdevdir=$(dirname $(facet_vdevice $ost))
16319         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
16320         local blksz=$(do_facet $ost $cmd $objid |
16321                       awk '/dblk/{getline; printf $4}')
16322
16323         case "${blksz: -1}" in
16324                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
16325                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
16326                 *) ;;
16327         esac
16328
16329         echo $blksz
16330 }
16331
16332 test_312() { # LU-4856
16333         remote_ost_nodsh && skip "remote OST with nodsh" && return
16334
16335         [ $(facet_fstype ost1) = "zfs" ] ||
16336                 { skip "the test only applies to zfs" && return; }
16337
16338         local max_blksz=$(do_facet ost1 \
16339                           $ZFS get -p recordsize $(facet_device ost1) |
16340                           awk '!/VALUE/{print $3}')
16341         local min_blksz=$(getconf PAGE_SIZE)
16342
16343         # to make life a little bit easier
16344         $LFS mkdir -c 1 -i 0 $DIR/$tdir
16345         $LFS setstripe -c 1 -i 0 $DIR/$tdir
16346
16347         local tf=$DIR/$tdir/$tfile
16348         touch $tf
16349         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
16350
16351         # Get ZFS object id
16352         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
16353
16354         # block size change by sequential over write
16355         local blksz
16356         for ((bs=$min_blksz; bs <= max_blksz; bs <<= 2)); do
16357                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
16358
16359                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
16360                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
16361         done
16362         rm -f $tf
16363
16364         # block size change by sequential append write
16365         dd if=/dev/zero of=$tf bs=$min_blksz count=1 oflag=sync conv=notrunc
16366         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
16367         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
16368
16369         for ((count = 1; count < $((max_blksz / min_blksz)); count *= 2)); do
16370                 dd if=/dev/zero of=$tf bs=$min_blksz count=$count seek=$count \
16371                         oflag=sync conv=notrunc
16372
16373                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
16374                 [ $blksz -eq $((2 * count * min_blksz)) ] ||
16375                         error "blksz error, actual $blksz, "    \
16376                                 "expected: 2 * $count * $min_blksz"
16377         done
16378         rm -f $tf
16379
16380         # random write
16381         touch $tf
16382         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
16383         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
16384
16385         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
16386         blksz=$(zfs_object_blksz ost1 $zfs_objid)
16387         [ $blksz -eq $min_blksz ] ||
16388                 error "blksz error: $blksz, expected: $min_blksz"
16389
16390         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
16391         blksz=$(zfs_object_blksz ost1 $zfs_objid)
16392         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
16393
16394         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
16395         blksz=$(zfs_object_blksz ost1 $zfs_objid)
16396         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
16397 }
16398 run_test 312 "make sure ZFS adjusts its block size by write pattern"
16399
16400 test_313() {
16401         remote_ost_nodsh && skip "remote OST with nodsh" && return
16402
16403         local file=$DIR/$tfile
16404         rm -f $file
16405         $SETSTRIPE -c 1 -i 0 $file || error "setstripe failed"
16406
16407         # define OBD_FAIL_TGT_RCVD_EIO           0x720
16408         do_facet ost1 "$LCTL set_param fail_loc=0x720"
16409         dd if=/dev/zero of=$file bs=4096 oflag=direct count=1 &&
16410                 error "write should failed"
16411         do_facet ost1 "$LCTL set_param fail_loc=0"
16412         rm -f $file
16413 }
16414 run_test 313 "io should fail after last_rcvd update fail"
16415
16416 test_314() {
16417         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
16418
16419         $SETSTRIPE -c 2 -i 0 $DIR/$tfile || error "setstripe failed"
16420         do_facet ost1 "$LCTL set_param fail_loc=0x720"
16421         rm -f $DIR/$tfile
16422         wait_delete_completed
16423         do_facet ost1 "$LCTL set_param fail_loc=0"
16424 }
16425 run_test 314 "OSP shouldn't fail after last_rcvd update failure"
16426
16427 test_315() { # LU-618
16428         local file=$DIR/$tfile
16429         rm -f $file
16430
16431         $MULTIOP $file oO_CREAT:O_DIRECT:O_RDWR:w4096000c
16432         $MULTIOP $file oO_RDONLY:r4096000_c &
16433         PID=$!
16434
16435         sleep 2
16436
16437         local rbytes=$(awk '/read_bytes/ { print $2 }' /proc/$PID/io)
16438         kill -USR1 $PID
16439
16440         [ $rbytes -gt 4000000 ] || error "read is not accounted ($rbytes)"
16441         rm -f $file
16442 }
16443 run_test 315 "read should be accounted"
16444
16445 test_fake_rw() {
16446         local read_write=$1
16447         if [ "$read_write" = "write" ]; then
16448                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
16449         elif [ "$read_write" = "read" ]; then
16450                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
16451         else
16452                 error "argument error"
16453         fi
16454
16455         # turn off debug for performance testing
16456         local saved_debug=$($LCTL get_param -n debug)
16457         $LCTL set_param debug=0
16458
16459         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
16460
16461         # get ost1 size - lustre-OST0000
16462         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
16463         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
16464         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
16465
16466         if [ "$read_write" = "read" ]; then
16467                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
16468         fi
16469
16470         local start_time=$(date +%s.%N)
16471         $dd_cmd bs=1M count=$blocks oflag=sync ||
16472                 error "real dd $read_write error"
16473         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
16474
16475         if [ "$read_write" = "write" ]; then
16476                 rm -f $DIR/$tfile
16477         fi
16478
16479         # define OBD_FAIL_OST_FAKE_RW           0x238
16480         do_facet ost1 $LCTL set_param fail_loc=0x238
16481
16482         local start_time=$(date +%s.%N)
16483         $dd_cmd bs=1M count=$blocks oflag=sync ||
16484                 error "fake dd $read_write error"
16485         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
16486
16487         if [ "$read_write" = "write" ]; then
16488                 # verify file size
16489                 cancel_lru_locks osc
16490                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
16491                         error "$tfile size not $blocks MB"
16492         fi
16493         do_facet ost1 $LCTL set_param fail_loc=0
16494
16495         echo "fake $read_write $duration_fake vs. normal $read_write" \
16496                 "$duration in seconds"
16497         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
16498                 error_not_in_vm "fake write is slower"
16499
16500         $LCTL set_param -n debug="$saved_debug"
16501         rm -f $DIR/$tfile
16502 }
16503 test_399a() { # LU-7655 for OST fake write
16504         remote_ost_nodsh && skip "remote OST with nodsh" && return
16505
16506         test_fake_rw write
16507 }
16508 run_test 399a "fake write should not be slower than normal write"
16509
16510 test_399b() { # LU-8726 for OST fake read
16511         remote_ost_nodsh && skip "remote OST with nodsh" && return
16512
16513         if [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
16514                 skip "ldiskfs only test" && return 0
16515         fi
16516         test_fake_rw read
16517 }
16518 run_test 399b "fake read should not be slower than normal read"
16519
16520 test_400a() { # LU-1606, was conf-sanity test_74
16521         local extra_flags=''
16522         local out=$TMP/$tfile
16523         local prefix=/usr/include/lustre
16524         local prog
16525
16526         if ! which $CC > /dev/null 2>&1; then
16527                 skip_env "$CC is not installed"
16528                 return 0
16529         fi
16530
16531         if ! [[ -d $prefix ]]; then
16532                 # Assume we're running in tree and fixup the include path.
16533                 extra_flags+=" -I$LUSTRE/../libcfs/include"
16534                 extra_flags+=" -I$LUSTRE/include"
16535                 extra_flags+=" -L$LUSTRE/utils"
16536         fi
16537
16538         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
16539                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
16540                         error "client api broken"
16541         done
16542         rm -f $out
16543 }
16544 run_test 400a "Lustre client api program can compile and link"
16545
16546 test_400b() { # LU-1606, LU-5011
16547         local header
16548         local out=$TMP/$tfile
16549         local prefix=/usr/include/lustre
16550
16551         # We use a hard coded prefix so that this test will not fail
16552         # when run in tree. There are headers in lustre/include/lustre/
16553         # that are not packaged (like lustre_idl.h) and have more
16554         # complicated include dependencies (like config.h and lnet/types.h).
16555         # Since this test about correct packaging we just skip them when
16556         # they don't exist (see below) rather than try to fixup cppflags.
16557
16558         if ! which $CC > /dev/null 2>&1; then
16559                 skip_env "$CC is not installed"
16560                 return 0
16561         fi
16562
16563         for header in $prefix/*.h; do
16564                 if ! [[ -f "$header" ]]; then
16565                         continue
16566                 fi
16567
16568                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
16569                         continue # liblustreapi.h is deprecated.
16570                 fi
16571
16572                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
16573                         error "cannot compile '$header'"
16574         done
16575         rm -f $out
16576 }
16577 run_test 400b "packaged headers can be compiled"
16578
16579 test_401a() { #LU-7437
16580         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
16581         [ -n "$printf_arg" ] && skip_env "find does not support -printf" &&
16582                 return
16583         #count the number of parameters by "list_param -R"
16584         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
16585         #count the number of parameters by listing proc files
16586         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
16587         echo "proc_dirs='$proc_dirs'"
16588         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
16589         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
16590                       sort -u | wc -l)
16591
16592         [ $params -eq $procs ] ||
16593                 error "found $params parameters vs. $procs proc files"
16594
16595         # test the list_param -D option only returns directories
16596         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
16597         #count the number of parameters by listing proc directories
16598         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
16599                 sort -u | wc -l)
16600
16601         [ $params -eq $procs ] ||
16602                 error "found $params parameters vs. $procs proc files"
16603 }
16604 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
16605
16606 test_401b() {
16607         local save=$($LCTL get_param -n jobid_var)
16608         local tmp=testing
16609
16610         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
16611                 error "no error returned when setting bad parameters"
16612
16613         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
16614         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
16615
16616         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
16617         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
16618         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
16619 }
16620 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
16621
16622 test_401c() {
16623         local jobid_var_old=$($LCTL get_param -n jobid_var)
16624         local jobid_var_new
16625
16626         $LCTL set_param jobid_var= &&
16627                 error "no error returned for 'set_param a='"
16628
16629         jobid_var_new=$($LCTL get_param -n jobid_var)
16630         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16631                 error "jobid_var was changed by setting without value"
16632
16633         $LCTL set_param jobid_var &&
16634                 error "no error returned for 'set_param a'"
16635
16636         jobid_var_new=$($LCTL get_param -n jobid_var)
16637         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16638                 error "jobid_var was changed by setting without value"
16639 }
16640 run_test 401c "Verify 'lctl set_param' without value fails in either format."
16641
16642 test_401d() {
16643         local jobid_var_old=$($LCTL get_param -n jobid_var)
16644         local jobid_var_new
16645         local new_value="foo=bar"
16646
16647         $LCTL set_param jobid_var=$new_value ||
16648                 error "'set_param a=b' did not accept a value containing '='"
16649
16650         jobid_var_new=$($LCTL get_param -n jobid_var)
16651         [[ "$jobid_var_new" == "$new_value" ]] ||
16652                 error "'set_param a=b' failed on a value containing '='"
16653
16654         # Reset the jobid_var to test the other format
16655         $LCTL set_param jobid_var=$jobid_var_old
16656         jobid_var_new=$($LCTL get_param -n jobid_var)
16657         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16658                 error "failed to reset jobid_var"
16659
16660         $LCTL set_param jobid_var $new_value ||
16661                 error "'set_param a b' did not accept a value containing '='"
16662
16663         jobid_var_new=$($LCTL get_param -n jobid_var)
16664         [[ "$jobid_var_new" == "$new_value" ]] ||
16665                 error "'set_param a b' failed on a value containing '='"
16666
16667         $LCTL set_param jobid_var $jobid_var_old
16668         jobid_var_new=$($LCTL get_param -n jobid_var)
16669         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16670                 error "failed to reset jobid_var"
16671 }
16672 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
16673
16674 test_402() {
16675         local server_version=$(lustre_version_code $SINGLEMDS)
16676         [[ $server_version -ge $(version_code 2.7.66) ]] ||
16677         [[ $server_version -ge $(version_code 2.7.18.4) &&
16678                 $server_version -lt $(version_code 2.7.50) ]] ||
16679         [[ $server_version -ge $(version_code 2.7.2) &&
16680                 $server_version -lt $(version_code 2.7.11) ]] ||
16681                 { skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+";
16682                         return; }
16683         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16684         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
16685 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
16686         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
16687         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
16688                 echo "Touch failed - OK"
16689 }
16690 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
16691
16692 test_403() {
16693         local file1=$DIR/$tfile.1
16694         local file2=$DIR/$tfile.2
16695         local tfile=$TMP/$tfile
16696
16697         rm -f $file1 $file2 $tfile
16698
16699         touch $file1
16700         ln $file1 $file2
16701
16702         # 30 sec OBD_TIMEOUT in ll_getattr()
16703         # right before populating st_nlink
16704         $LCTL set_param fail_loc=0x80001409
16705         stat -c %h $file1 > $tfile &
16706
16707         # create an alias, drop all locks and reclaim the dentry
16708         < $file2
16709         cancel_lru_locks mdc
16710         cancel_lru_locks osc
16711         sysctl -w vm.drop_caches=2
16712
16713         wait
16714
16715         [ `cat $tfile` -gt 0 ] || error "wrong nlink count: `cat $tfile`"
16716
16717         rm -f $tfile $file1 $file2
16718 }
16719 run_test 403 "i_nlink should not drop to zero due to aliasing"
16720
16721 test_404() { # LU-6601
16722         local server_version=$(lustre_version_code $SINGLEMDS)
16723         [[ $server_version -ge $(version_code 2.8.53) ]] ||
16724                 { skip "Need server version newer than 2.8.52"; return 0; }
16725
16726         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16727         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
16728                 awk '/osp .*-osc-MDT/ { print $4}')
16729
16730         local osp
16731         for osp in $mosps; do
16732                 echo "Deactivate: " $osp
16733                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
16734                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16735                         awk -vp=$osp '$4 == p { print $2 }')
16736                 [ $stat = IN ] || {
16737                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16738                         error "deactivate error"
16739                 }
16740                 echo "Activate: " $osp
16741                 do_facet $SINGLEMDS $LCTL --device %$osp activate
16742                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16743                         awk -vp=$osp '$4 == p { print $2 }')
16744                 [ $stat = UP ] || {
16745                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16746                         error "activate error"
16747                 }
16748         done
16749 }
16750 run_test 404 "validate manual {de}activated works properly for OSPs"
16751
16752 test_405() {
16753         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) -o \
16754         [ $(lustre_version_code client) -lt $(version_code 2.6.99) ] &&
16755                 skip "Layout swap lock is not supported" && return
16756
16757         check_swap_layouts_support && return 0
16758
16759         test_mkdir -p $DIR/$tdir
16760         swap_lock_test -d $DIR/$tdir ||
16761                 error "One layout swap locked test failed"
16762 }
16763 run_test 405 "Various layout swap lock tests"
16764
16765 test_406() {
16766         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16767         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
16768         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
16769         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16770         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.50) ] &&
16771                 skip "Need MDS version at least 2.8.50" && return
16772
16773         local def_stripe_size=$($LFS getstripe -S $MOUNT)
16774         local test_pool=$TESTNAME
16775
16776         if ! combined_mgs_mds ; then
16777                 mount_mgs_client
16778         fi
16779         pool_add $test_pool || error "pool_add failed"
16780         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
16781                 error "pool_add_targets failed"
16782
16783         save_layout_restore_at_exit $MOUNT
16784
16785         # parent set default stripe count only, child will stripe from both
16786         # parent and fs default
16787         $LFS setstripe -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
16788                 error "setstripe $MOUNT failed"
16789         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
16790         $LFS setstripe -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
16791         for i in $(seq 10); do
16792                 local f=$DIR/$tdir/$tfile.$i
16793                 touch $f || error "touch failed"
16794                 local count=$($LFS getstripe -c $f)
16795                 [ $count -eq $OSTCOUNT ] ||
16796                         error "$f stripe count $count != $OSTCOUNT"
16797                 local offset=$($LFS getstripe -i $f)
16798                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
16799                 local size=$($LFS getstripe -S $f)
16800                 [ $size -eq $((def_stripe_size * 2)) ] ||
16801                         error "$f stripe size $size != $((def_stripe_size * 2))"
16802                 local pool=$($LFS getstripe -p $f)
16803                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
16804         done
16805
16806         # change fs default striping, delete parent default striping, now child
16807         # will stripe from new fs default striping only
16808         $LFS setstripe -c 1 -S $def_stripe_size -i 0 $MOUNT ||
16809                 error "change $MOUNT default stripe failed"
16810         $LFS setstripe -c 0 $DIR/$tdir ||
16811                 error "delete $tdir default stripe failed"
16812         for i in $(seq 11 20); do
16813                 local f=$DIR/$tdir/$tfile.$i
16814                 touch $f || error "touch $f failed"
16815                 local count=$($LFS getstripe -c $f)
16816                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
16817                 local offset=$($LFS getstripe -i $f)
16818                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
16819                 local size=$($LFS getstripe -S $f)
16820                 [ $size -eq $def_stripe_size ] ||
16821                         error "$f stripe size $size != $def_stripe_size"
16822                 local pool=$($LFS getstripe -p $f)
16823                 [ $pool == $test_pool ] || error "$f pool $pool isn't set"
16824         done
16825
16826         unlinkmany $DIR/$tdir/$tfile. 1 20
16827
16828         local f=$DIR/$tdir/$tfile
16829         pool_remove_all_targets $test_pool $f
16830         pool_remove $test_pool $f
16831
16832         if ! combined_mgs_mds ; then
16833                 umount_mgs_client
16834         fi
16835 }
16836 run_test 406 "DNE support fs default striping"
16837
16838 test_407() {
16839         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16840         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
16841                 skip "Need MDS version at least 2.8.55" && return
16842         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16843
16844         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
16845                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
16846         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
16847                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
16848         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
16849
16850         #define OBD_FAIL_DT_TXN_STOP    0x2019
16851         for idx in $(seq $MDSCOUNT); do
16852                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
16853         done
16854         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
16855         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
16856                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
16857         true
16858 }
16859 run_test 407 "transaction fail should cause operation fail"
16860
16861 test_408() {
16862         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
16863
16864         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
16865         lctl set_param fail_loc=0x8000040a
16866         # let ll_prepare_partial_page() fail
16867         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
16868
16869         rm -f $DIR/$tfile
16870
16871         # create at least 100 unused inodes so that
16872         # shrink_icache_memory(0) should not return 0
16873         touch $DIR/$tfile-{0..100}
16874         rm -f $DIR/$tfile-{0..100}
16875         sync
16876
16877         echo 2 > /proc/sys/vm/drop_caches
16878 }
16879 run_test 408 "drop_caches should not hang due to page leaks"
16880
16881 test_409()
16882 {
16883         [ $MDSCOUNT -lt 2 ] &&
16884                 skip "We need at least 2 MDTs for this test" && return
16885
16886         check_mount_and_prep
16887
16888         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
16889         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
16890         touch $DIR/$tdir/guard || error "(2) Fail to create"
16891
16892         local PREFIX=$(str_repeat 'A' 128)
16893         echo "Create 1K hard links start at $(date)"
16894         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16895                 error "(3) Fail to hard link"
16896
16897         echo "Links count should be right although linkEA overflow"
16898         stat $DIR/$tdir/guard || error "(4) Fail to stat"
16899         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
16900         [ $linkcount -eq 1001 ] ||
16901                 error "(5) Unexpected hard links count: $linkcount"
16902
16903         echo "List all links start at $(date)"
16904         ls -l $DIR/$tdir/foo > /dev/null ||
16905                 error "(6) Fail to list $DIR/$tdir/foo"
16906
16907         echo "Unlink hard links start at $(date)"
16908         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16909                 error "(7) Fail to unlink"
16910 }
16911 run_test 409 "Large amount of cross-MDTs hard links on the same file"
16912
16913 test_410()
16914 {
16915         [[ $(lustre_version_code client) -lt $(version_code 2.9.59) ]] &&
16916                 skip "Need client version at least 2.9.59" && return
16917
16918         # Create a file, and stat it from the kernel
16919         local testfile=$DIR/$tfile
16920         touch $testfile
16921
16922         local run_id=$RANDOM
16923         local my_ino=$(stat --format "%i" $testfile)
16924
16925         # Try to insert the module. This will always fail as the
16926         # module is designed to not be inserted.
16927         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
16928             &> /dev/null
16929
16930         # Anything but success is a test failure
16931         dmesg | grep -q \
16932             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
16933             error "no inode match"
16934 }
16935 run_test 410 "Test inode number returned from kernel thread"
16936
16937 prep_801() {
16938         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
16939         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
16940                 skip "Need server version at least 2.9.55" & exit 0
16941         start_full_debug_logging
16942 }
16943
16944 post_801() {
16945         stop_full_debug_logging
16946 }
16947
16948 barrier_stat() {
16949         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16950                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16951                            awk '/The barrier for/ { print $7 }')
16952                 echo $st
16953         else
16954                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
16955                 echo \'$st\'
16956         fi
16957 }
16958
16959 barrier_expired() {
16960         local expired
16961
16962         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16963                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16964                           awk '/will be expired/ { print $7 }')
16965         else
16966                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
16967         fi
16968
16969         echo $expired
16970 }
16971
16972 test_801a() {
16973         prep_801
16974
16975         echo "Start barrier_freeze at: $(date)"
16976         #define OBD_FAIL_BARRIER_DELAY          0x2202
16977         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
16978         do_facet mgs $LCTL barrier_freeze $FSNAME 10 &
16979
16980         sleep 2
16981         local b_status=$(barrier_stat)
16982         echo "Got barrier status at: $(date)"
16983         [ "$b_status" = "'freezing_p1'" ] ||
16984                 error "(1) unexpected barrier status $b_status"
16985
16986         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
16987         wait
16988         b_status=$(barrier_stat)
16989         [ "$b_status" = "'frozen'" ] ||
16990                 error "(2) unexpected barrier status $b_status"
16991
16992         local expired=$(barrier_expired)
16993         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
16994         sleep $((expired + 3))
16995
16996         b_status=$(barrier_stat)
16997         [ "$b_status" = "'expired'" ] ||
16998                 error "(3) unexpected barrier status $b_status"
16999
17000         do_facet mgs $LCTL barrier_freeze $FSNAME 10 ||
17001                 error "(4) fail to freeze barrier"
17002
17003         b_status=$(barrier_stat)
17004         [ "$b_status" = "'frozen'" ] ||
17005                 error "(5) unexpected barrier status $b_status"
17006
17007         echo "Start barrier_thaw at: $(date)"
17008         #define OBD_FAIL_BARRIER_DELAY          0x2202
17009         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
17010         do_facet mgs $LCTL barrier_thaw $FSNAME &
17011
17012         sleep 2
17013         b_status=$(barrier_stat)
17014         echo "Got barrier status at: $(date)"
17015         [ "$b_status" = "'thawing'" ] ||
17016                 error "(6) unexpected barrier status $b_status"
17017
17018         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
17019         wait
17020         b_status=$(barrier_stat)
17021         [ "$b_status" = "'thawed'" ] ||
17022                 error "(7) unexpected barrier status $b_status"
17023
17024         #define OBD_FAIL_BARRIER_FAILURE        0x2203
17025         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
17026         do_facet mgs $LCTL barrier_freeze $FSNAME
17027
17028         b_status=$(barrier_stat)
17029         [ "$b_status" = "'failed'" ] ||
17030                 error "(8) unexpected barrier status $b_status"
17031
17032         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
17033         do_facet mgs $LCTL barrier_thaw $FSNAME
17034
17035         post_801
17036 }
17037 run_test 801a "write barrier user interfaces and stat machine"
17038
17039 test_801b() {
17040         prep_801
17041
17042         mkdir $DIR/$tdir || error "(1) fail to mkdir"
17043         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
17044         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
17045         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
17046         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
17047
17048         cancel_lru_locks mdc
17049
17050         # 180 seconds should be long enough
17051         do_facet mgs $LCTL barrier_freeze $FSNAME 180
17052
17053         local b_status=$(barrier_stat)
17054         [ "$b_status" = "'frozen'" ] ||
17055                 error "(6) unexpected barrier status $b_status"
17056
17057         mkdir $DIR/$tdir/d0/d10 &
17058         mkdir_pid=$!
17059
17060         touch $DIR/$tdir/d1/f13 &
17061         touch_pid=$!
17062
17063         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
17064         ln_pid=$!
17065
17066         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
17067         mv_pid=$!
17068
17069         rm -f $DIR/$tdir/d4/f12 &
17070         rm_pid=$!
17071
17072         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
17073
17074         # To guarantee taht the 'stat' is not blocked
17075         b_status=$(barrier_stat)
17076         [ "$b_status" = "'frozen'" ] ||
17077                 error "(8) unexpected barrier status $b_status"
17078
17079         # let above commands to run at background
17080         sleep 5
17081
17082         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
17083         ps -p $touch_pid || error "(10) touch should be blocked"
17084         ps -p $ln_pid || error "(11) link should be blocked"
17085         ps -p $mv_pid || error "(12) rename should be blocked"
17086         ps -p $rm_pid || error "(13) unlink should be blocked"
17087
17088         b_status=$(barrier_stat)
17089         [ "$b_status" = "'frozen'" ] ||
17090                 error "(14) unexpected barrier status $b_status"
17091
17092         do_facet mgs $LCTL barrier_thaw $FSNAME
17093         b_status=$(barrier_stat)
17094         [ "$b_status" = "'thawed'" ] ||
17095                 error "(15) unexpected barrier status $b_status"
17096
17097         wait $mkdir_pid || error "(16) mkdir should succeed"
17098         wait $touch_pid || error "(17) touch should succeed"
17099         wait $ln_pid || error "(18) link should succeed"
17100         wait $mv_pid || error "(19) rename should succeed"
17101         wait $rm_pid || error "(20) unlink should succeed"
17102
17103         post_801
17104 }
17105 run_test 801b "modification will be blocked by write barrier"
17106
17107 test_801c() {
17108         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
17109
17110         prep_801
17111
17112         stop mds2 || error "(1) Fail to stop mds2"
17113
17114         do_facet mgs $LCTL barrier_freeze $FSNAME 30
17115
17116         local b_status=$(barrier_stat)
17117         [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || {
17118                 do_facet mgs $LCTL barrier_thaw $FSNAME
17119                 error "(2) unexpected barrier status $b_status"
17120         }
17121
17122         do_facet mgs $LCTL barrier_rescan $FSNAME ||
17123                 error "(3) Fail to rescan barrier bitmap"
17124
17125         do_facet mgs $LCTL barrier_freeze $FSNAME 10
17126
17127         b_status=$(barrier_stat)
17128         [ "$b_status" = "'frozen'" ] ||
17129                 error "(4) unexpected barrier status $b_status"
17130
17131         do_facet mgs $LCTL barrier_thaw $FSNAME
17132         b_status=$(barrier_stat)
17133         [ "$b_status" = "'thawed'" ] ||
17134                 error "(5) unexpected barrier status $b_status"
17135
17136         local devname=$(mdsdevname 2)
17137
17138         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
17139
17140         do_facet mgs $LCTL barrier_rescan $FSNAME ||
17141                 error "(7) Fail to rescan barrier bitmap"
17142
17143         post_801
17144 }
17145 run_test 801c "rescan barrier bitmap"
17146
17147 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
17148 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
17149 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
17150
17151 cleanup_802() {
17152         trap 0
17153
17154         stopall
17155         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
17156         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
17157         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
17158         setupall
17159 }
17160
17161 test_802() {
17162
17163         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
17164         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
17165                 skip "Need server version at least 2.9.55" & exit 0
17166
17167         mkdir $DIR/$tdir || error "(1) fail to mkdir"
17168
17169         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
17170                 error "(2) Fail to copy"
17171
17172         trap cleanup_802 EXIT
17173
17174         # sync by force before remount as readonly
17175         sync; sync_all_data; sleep 3; sync_all_data
17176
17177         stopall
17178
17179         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
17180         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
17181         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
17182
17183         echo "Mount the server as read only"
17184         setupall server_only || error "(3) Fail to start servers"
17185
17186         echo "Mount client without ro should fail"
17187         mount_client $MOUNT &&
17188                 error "(4) Mount client without 'ro' should fail"
17189
17190         echo "Mount client with ro should succeed"
17191         mount_client $MOUNT ro ||
17192                 error "(5) Mount client with 'ro' should succeed"
17193
17194         echo "Modify should be refused"
17195         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
17196
17197         echo "Read should be allowed"
17198         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
17199                 error "(7) Read should succeed under ro mode"
17200
17201         cleanup_802
17202 }
17203 run_test 802 "simulate readonly device"
17204
17205 cleanup_805() {
17206         do_facet $SINGLEMDS zfs set quota=$old $fsset
17207         unlinkmany $DIR/$tdir/f- 1000000
17208         trap 0
17209 }
17210
17211 test_805() {
17212         local zfs_version=$(do_node $SINGLEMDS cat /sys/module/zfs/version)
17213         [ "$(facet_fstype mds1)" != "zfs" ] &&
17214                 skip "ZFS specific test" && return
17215         [ $(version_code $zfs_version) -lt $(version_code 0.7.2) ] &&
17216                 skip "netfree not implemented before 0.7" && return
17217         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.57) ]] ||
17218                 { skip "Need MDS version at least 2.10.57" && return 0; }
17219
17220         local fsset
17221         local freekb
17222         local usedkb
17223         local old
17224         local quota
17225         local pref="osd-zfs.lustre-MDT0000."
17226
17227         # limit available space on MDS dataset to meet nospace issue
17228         # quickly. then ZFS 0.7.2 can use reserved space if asked
17229         # properly (using netfree flag in osd_declare_destroy()
17230         fsset=$(do_facet $SINGLEMDS lctl get_param -n $pref.mntdev)
17231         old=$(do_facet $SINGLEMDS zfs get -H quota $fsset | \
17232                 gawk '{print $3}')
17233         freekb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytesfree)
17234         usedkb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytestotal)
17235         let "usedkb=usedkb-freekb"
17236         let "freekb=freekb/2"
17237         if let "freekb > 5000"; then
17238                 let "freekb=5000"
17239         fi
17240         do_facet $SINGLEMDS zfs set quota=$(((usedkb+freekb)*1024)) $fsset
17241         trap cleanup_805 EXIT
17242         mkdir $DIR/$tdir
17243         $LFS setstripe -E 1M -L mdt $DIR/$tdir || error "DoM not working"
17244         createmany -m $DIR/$tdir/f- 1000000 && error "ENOSPC wasn't met"
17245         rm -rf $DIR/$tdir || error "not able to remove"
17246         do_facet $SINGLEMDS zfs set quota=$old $fsset
17247         trap 0
17248 }
17249 run_test 805 "ZFS can remove from full fs"
17250
17251 test_810() {
17252         local ORIG
17253         local CSUM
17254
17255         lctl set_param fail_loc=0x411
17256         dd if=/dev/urandom of=$DIR/$tfile bs=10240 count=2
17257         ORIG=$(md5sum $DIR/$tfile)
17258         lctl set_param ldlm.namespaces.*osc*.lru_size=clear
17259         CSUM=$(md5sum $DIR/$tfile)
17260         if [ "$ORIG" != "$CSUM" ]; then
17261                 error "$ORIG != $CSUM"
17262         fi
17263 }
17264 run_test 810 "partial page writes on ZFS (LU-11663)"
17265
17266 #
17267 # tests that do cleanup/setup should be run at the end
17268 #
17269
17270 test_900() {
17271         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
17272         local ls
17273         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
17274         $LCTL set_param fail_loc=0x903
17275
17276         cancel_lru_locks MGC
17277
17278         FAIL_ON_ERROR=true cleanup
17279         FAIL_ON_ERROR=true setup
17280 }
17281 run_test 900 "umount should not race with any mgc requeue thread"
17282
17283 complete $SECONDS
17284 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
17285 check_and_cleanup_lustre
17286 if [ "$I_MOUNTED" != "yes" ]; then
17287         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
17288 fi
17289 exit_status